@reventlessdev/reventless-core 3.0.0-alpha.326 → 3.0.0-alpha.328
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 +18 -0
- package/package.json +6 -6
- package/src/CommandSent.res +22 -0
- package/src/CommandSent.res.mjs +22 -0
- package/src/Projection.res +26 -1
- package/src/Projection.res.mjs +19 -1
- package/src/RowChange.res +37 -0
- package/src/RowChange.res.mjs +62 -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 +88 -18
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +53 -32
- package/src/components/Api/GraphQL_FragmentGenerator.res +22 -0
- package/src/components/Api/GraphQL_FragmentGenerator.res.mjs +20 -4
- package/src/components/Api/GraphQL_SchemaInspector.res.mjs +2 -2
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +1 -1
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +9 -0
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +20 -14
- package/src/components/CommandGenerator/CommandGenerator_Callback.res +47 -6
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +41 -4
- package/src/components/CommandTopic/CommandTopic_Callback.res.mjs +1 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res +9 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +7 -6
- 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 +12 -2
- package/src/components/EventMapper/EventMapper_Callback.res.mjs +16 -14
- 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 +5 -1
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res.mjs +4 -3
- 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 +4 -0
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +4 -2
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +12 -0
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +14 -12
- package/src/components/QueryDb/QueryDb_Operations.res +2 -0
- package/src/components/QueryDb/QueryDb_Operations.res.mjs +3 -0
- package/src/components/ReadModel/ReadModel_Callback.res +1 -0
- package/src/components/ReadModel/ReadModel_Callback.res.mjs +1 -1
- 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 +36 -7
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +38 -20
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +2 -0
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +2 -2
- package/src/components/StateViewSlice/StateViewSlice_Callback.res +6 -0
- package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +3 -2
- package/src/components/Task/Task_Builder.res +5 -3
- package/src/components/Task/Task_Builder.res.mjs +2 -1
- package/src/plugin/component/Plugin_Callback.res +6 -2
- package/src/plugin/component/Plugin_Callback.res.mjs +3 -2
- package/src/plugin/connect/PluginExtensionPoint_Plugin.res.mjs +6 -6
- package/src/util/CommandPublisher.res.mjs +9 -9
- package/src/util/EffectLogger.res +85 -17
- package/src/util/EffectLogger.res.mjs +63 -12
- package/src/util/FTPHandler.res.mjs +6 -6
- package/src/util/Metrics.res +151 -16
- package/src/util/Metrics.res.mjs +123 -3
- 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/api/GraphQL_FragmentGeneratorTest.res.mjs +2 -2
- package/tests/api/IdentitySemanticTest.res.mjs +1 -1
- package/tests/commandgenerator/OwnerStampingTest.res +65 -0
- package/tests/commandgenerator/OwnerStampingTest.res.mjs +62 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res +25 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +28 -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.mjs +3 -3
- package/tests/querydb/RowChangeTest.res +87 -0
- package/tests/querydb/RowChangeTest.res.mjs +157 -0
- package/tests/util/MetricsTest.res +72 -0
- package/tests/util/MetricsTest.res.mjs +108 -0
|
@@ -8,8 +8,10 @@ import * as Owner$Reventless from "@reventlessdev/reventless-spec/src/components
|
|
|
8
8
|
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
9
9
|
import * as Identity$Reventless from "@reventlessdev/reventless-spec/src/types/Identity.res.mjs";
|
|
10
10
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
11
|
+
import * as Logger$ReventlessCore from "../../src/util/Logger.res.mjs";
|
|
11
12
|
import * as OwnerScope$Reventless from "@reventlessdev/reventless-spec/src/types/OwnerScope.res.mjs";
|
|
12
13
|
import * as Message$ReventlessCore from "../../src/Message.res.mjs";
|
|
14
|
+
import * as CommandTopic_Helpers$ReventlessCore from "../../src/components/CommandTopic/CommandTopic_Helpers.res.mjs";
|
|
13
15
|
import * as Plugin_ResolverError$ReventlessCore from "../../src/plugin/component/Plugin_ResolverError.res.mjs";
|
|
14
16
|
import * as CommandGenerator_Callback$ReventlessCore from "../../src/components/CommandGenerator/CommandGenerator_Callback.res.mjs";
|
|
15
17
|
|
|
@@ -296,6 +298,66 @@ globalThis.describe("the caller claim on the envelope:", () => {
|
|
|
296
298
|
});
|
|
297
299
|
});
|
|
298
300
|
|
|
301
|
+
globalThis.describe("the command's entry names the command on its lines", () => {
|
|
302
|
+
let capture = async run => {
|
|
303
|
+
let lines = [];
|
|
304
|
+
let remove = Logger$ReventlessCore.addSink(r => {
|
|
305
|
+
lines.push(r);
|
|
306
|
+
});
|
|
307
|
+
await run();
|
|
308
|
+
remove();
|
|
309
|
+
return lines;
|
|
310
|
+
};
|
|
311
|
+
globalThis.test("a generated command's line carries its own msgId and flow", async () => {
|
|
312
|
+
let lines = await capture(async () => {
|
|
313
|
+
await Effect.runPromise(generate(placeOrder("cust-A", cognito("cust-A", []))));
|
|
314
|
+
});
|
|
315
|
+
let line = Stdlib_Option.getOrThrow(lines.find(r => r.message.startsWith("generated command")), undefined);
|
|
316
|
+
let msgId = line.annotations["msgId"];
|
|
317
|
+
globalThis.expect(Stdlib_Option.isSome(msgId)).toBe(true);
|
|
318
|
+
globalThis.expect(line.annotations["correlationId"]).toEqual(msgId);
|
|
319
|
+
globalThis.expect(published.contents[published.contents.length - 1 | 0].meta.msgId).toEqual(msgId);
|
|
320
|
+
});
|
|
321
|
+
globalThis.test("a refusal before the handler is logged with the command's ids, and heard", async () => {
|
|
322
|
+
let heard = [];
|
|
323
|
+
let remove = CommandTopic_Helpers$ReventlessCore.registerCommandOutcome(r => {
|
|
324
|
+
heard.push(r);
|
|
325
|
+
});
|
|
326
|
+
let lines = await capture(async () => {
|
|
327
|
+
try {
|
|
328
|
+
await Effect.runPromise(generate(placeOrder("cust-B", Identity$Reventless.anonymous)));
|
|
329
|
+
return;
|
|
330
|
+
} catch (exn) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
remove();
|
|
335
|
+
let line = Stdlib_Option.getOrThrow(lines.find(r => r.message.startsWith("refused before its handler")), undefined);
|
|
336
|
+
globalThis.expect(line.level).toEqual("Warn");
|
|
337
|
+
globalThis.expect(Stdlib_Option.isSome(line.annotations["msgId"])).toBe(true);
|
|
338
|
+
globalThis.expect(heard.map(r => [
|
|
339
|
+
r.component,
|
|
340
|
+
r.reference === Stdlib_Option.getOr(line.annotations["msgId"], "")
|
|
341
|
+
])).toEqual([[
|
|
342
|
+
"Ordering",
|
|
343
|
+
true
|
|
344
|
+
]]);
|
|
345
|
+
globalThis.expect(heard.map(r => {
|
|
346
|
+
let match = r.outcome;
|
|
347
|
+
if (match.TAG === "OutcomeAccepted") {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
switch (match.cause) {
|
|
351
|
+
case "DomainRejection" :
|
|
352
|
+
case "InfrastructureFailure" :
|
|
353
|
+
return false;
|
|
354
|
+
case "AccessRefusal" :
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
})).toEqual([true]);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
|
|
299
361
|
export {
|
|
300
362
|
commandSchema,
|
|
301
363
|
published,
|
|
@@ -371,5 +371,30 @@ describe("CommandTopic command-outcome hook:", () => {
|
|
|
371
371
|
)
|
|
372
372
|
},
|
|
373
373
|
)
|
|
374
|
+
|
|
375
|
+
testPromise(
|
|
376
|
+
"an outcome carries the message that caused the command",
|
|
377
|
+
async () => {
|
|
378
|
+
record()
|
|
379
|
+
let item = AggregateFixtures.makeTopicItem(
|
|
380
|
+
"ref-1",
|
|
381
|
+
AggregateFixtures.AggSpec.Create({name: "Widget"}),
|
|
382
|
+
)
|
|
383
|
+
let caused = {
|
|
384
|
+
...item,
|
|
385
|
+
command: {...item.command, meta: {...item.command.meta, causationId: "evt-7"}},
|
|
386
|
+
}
|
|
387
|
+
let _ = await Stream.fromIterable([caused])
|
|
388
|
+
->AggregateFixtures.TestHandler.handleCommands
|
|
389
|
+
->Effect.runPromise
|
|
390
|
+
let _ = await runAgg(
|
|
391
|
+
"ref-2",
|
|
392
|
+
AggregateFixtures.AggSpec.Create({name: "Gadget"}),
|
|
393
|
+
~aggId="agg-2",
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
expect(observed.contents->Array.map(r => r.causationId))->toEqual([Some("evt-7"), None])
|
|
397
|
+
},
|
|
398
|
+
)
|
|
374
399
|
})
|
|
375
400
|
})
|
|
@@ -457,6 +457,34 @@ globalThis.describe("CommandTopic command-outcome hook:", () => {
|
|
|
457
457
|
]);
|
|
458
458
|
globalThis.expect(observed.contents[1].correlationId).toEqual(DcbFixtures$ReventlessCore.testMeta.correlationId);
|
|
459
459
|
});
|
|
460
|
+
globalThis.test("an outcome carries the message that caused the command", async () => {
|
|
461
|
+
record();
|
|
462
|
+
let item = AggregateFixtures$ReventlessCore.makeTopicItem(undefined, "ref-1", {
|
|
463
|
+
TAG: "Create",
|
|
464
|
+
name: "Widget"
|
|
465
|
+
});
|
|
466
|
+
let init = item.command;
|
|
467
|
+
let newrecord = {...item.command.meta};
|
|
468
|
+
let caused_command = {
|
|
469
|
+
id: init.id,
|
|
470
|
+
meta: (newrecord.causationId = "evt-7", newrecord),
|
|
471
|
+
command: init.command
|
|
472
|
+
};
|
|
473
|
+
let caused_reference = item.reference;
|
|
474
|
+
let caused = {
|
|
475
|
+
command: caused_command,
|
|
476
|
+
reference: caused_reference
|
|
477
|
+
};
|
|
478
|
+
await Effect.runPromise(AggregateFixtures$ReventlessCore.TestHandler.handleCommands(Stream.fromIterable([caused])));
|
|
479
|
+
await runAgg("agg-2", "ref-2", {
|
|
480
|
+
TAG: "Create",
|
|
481
|
+
name: "Gadget"
|
|
482
|
+
});
|
|
483
|
+
globalThis.expect(observed.contents.map(r => r.causationId)).toEqual([
|
|
484
|
+
"evt-7",
|
|
485
|
+
undefined
|
|
486
|
+
]);
|
|
487
|
+
});
|
|
460
488
|
});
|
|
461
489
|
});
|
|
462
490
|
|
|
@@ -32,11 +32,11 @@ globalThis.describe("CommandTopic_Helpers.runInlineAndCollect:", () => {
|
|
|
32
32
|
globalThis.test("Rejected from rejectedResultChannel beats Accepted from acceptedResultChannel", async () => {
|
|
33
33
|
let handler = stream => Effect.map(Stream.runCollect(stream), items => {
|
|
34
34
|
items.forEach(item => {
|
|
35
|
-
CommandTopic_Helpers$ReventlessCore.reportAccepted("TestService", undefined, item.reference, {
|
|
35
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted("TestService", undefined, undefined, item.reference, {
|
|
36
36
|
entityId: "agg-1",
|
|
37
37
|
eventCount: 0
|
|
38
38
|
});
|
|
39
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected("TestService", "DomainRejection", undefined, item.reference, {
|
|
39
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected("TestService", "DomainRejection", undefined, undefined, item.reference, {
|
|
40
40
|
errorCode: "AlreadyExists",
|
|
41
41
|
errorDetail: ""
|
|
42
42
|
});
|
|
@@ -64,7 +64,7 @@ globalThis.describe("CommandTopic_Helpers.runInlineAndCollect:", () => {
|
|
|
64
64
|
});
|
|
65
65
|
globalThis.test("Rejected from rejectedResultChannel beats Error result (synthesized Conflict)", async () => {
|
|
66
66
|
let handler = stream => Effect.map(Stream.runCollect(stream), items => {
|
|
67
|
-
items.forEach(item => CommandTopic_Helpers$ReventlessCore.reportRejected("TestService", "DomainRejection", undefined, item.reference, {
|
|
67
|
+
items.forEach(item => CommandTopic_Helpers$ReventlessCore.reportRejected("TestService", "DomainRejection", undefined, undefined, item.reference, {
|
|
68
68
|
errorCode: "BusinessRuleViolated",
|
|
69
69
|
errorDetail: "{\"reason\":\"x\"}"
|
|
70
70
|
}));
|
|
@@ -106,7 +106,7 @@ globalThis.describe("CommandTopic_Helpers.runInlineAndCollect:", () => {
|
|
|
106
106
|
});
|
|
107
107
|
globalThis.test("a reported access refusal keeps its cause", async () => {
|
|
108
108
|
let handler = stream => Effect.map(Stream.runCollect(stream), items => {
|
|
109
|
-
items.forEach(item => CommandTopic_Helpers$ReventlessCore.reportRejected("TestService", "AccessRefusal", undefined, item.reference, {
|
|
109
|
+
items.forEach(item => CommandTopic_Helpers$ReventlessCore.reportRejected("TestService", "AccessRefusal", undefined, undefined, item.reference, {
|
|
110
110
|
errorCode: "Forbidden",
|
|
111
111
|
errorDetail: "not the owner"
|
|
112
112
|
}));
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// A component's log line carries the ids of the message it is about: its own msgId, its flow's
|
|
2
|
+
// correlationId and its causationId, and the entity a command is handled for. They come from the
|
|
3
|
+
// message, not from the invocation, so two commands of different flows in one batch keep their
|
|
4
|
+
// own, also on the lines that run on a fiber of their own.
|
|
5
|
+
|
|
6
|
+
open JestGlobals
|
|
7
|
+
|
|
8
|
+
let capture = async (run: unit => promise<unit>): array<Logger.record> => {
|
|
9
|
+
let lines = []
|
|
10
|
+
let remove = Logger.addSink(r => lines->Array.push(r))
|
|
11
|
+
await run()
|
|
12
|
+
remove()
|
|
13
|
+
lines
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let field = (r: Logger.record, k: string) => r.annotations->Dict.get(k)
|
|
17
|
+
|
|
18
|
+
let meta = (~msgId, ~correlationId, ~causationId=?): Message.meta => {
|
|
19
|
+
...AggregateFixtures.testMeta,
|
|
20
|
+
msgId,
|
|
21
|
+
correlationId,
|
|
22
|
+
?causationId,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("the log call carries a message's ids", () => {
|
|
26
|
+
testPromise("a line on a fiber of its own keeps the ids it was given", async () => {
|
|
27
|
+
let lines = await capture(
|
|
28
|
+
async () =>
|
|
29
|
+
EffectLogger.logInfo(
|
|
30
|
+
~comp="Aggregate(Order)",
|
|
31
|
+
~ids=EffectLogger.idsOf(
|
|
32
|
+
meta(~msgId="m-1", ~correlationId="flow-1", ~causationId="e-0"),
|
|
33
|
+
~entityId="o-1",
|
|
34
|
+
~entityType="Order",
|
|
35
|
+
),
|
|
36
|
+
"deciding",
|
|
37
|
+
)->Effect.runSync,
|
|
38
|
+
)
|
|
39
|
+
let line = lines->Array.find(r => r.message == "deciding")->Option.getOrThrow
|
|
40
|
+
expect(
|
|
41
|
+
["msgId", "correlationId", "causationId", "entityId", "entityType"]->Array.map(
|
|
42
|
+
k => line->field(k),
|
|
43
|
+
),
|
|
44
|
+
)->toEqual([Some("m-1"), Some("flow-1"), Some("e-0"), Some("o-1"), Some("Order")])
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
testPromise("the message's flow wins over the one the invocation annotated", async () => {
|
|
48
|
+
let lines = await capture(
|
|
49
|
+
async () =>
|
|
50
|
+
EffectLogger.logInfo(
|
|
51
|
+
~ids=EffectLogger.idsOf(meta(~msgId="m-2", ~correlationId="flow-2")),
|
|
52
|
+
"deciding",
|
|
53
|
+
)
|
|
54
|
+
->Runtime.annotateInvocation(~correlationId="flow-of-the-batch", ~comp="Aggregate(Order)")
|
|
55
|
+
->Effect.runSync,
|
|
56
|
+
)
|
|
57
|
+
let line = lines->Array.find(r => r.message == "deciding")->Option.getOrThrow
|
|
58
|
+
expect(line->field("correlationId"))->toEqual(Some("flow-2"))
|
|
59
|
+
expect(line.comp)->toEqual(Some("Aggregate(Order)"))
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
describe("component lines in a batch of several flows", () => {
|
|
64
|
+
let _ = beforeEach(() => AggregateFixtures.mock.reset())
|
|
65
|
+
|
|
66
|
+
testPromise("each command's aggregate lines carry its own ids and its entity", async () => {
|
|
67
|
+
let item = (reference, flow) => {
|
|
68
|
+
let i = AggregateFixtures.makeTopicItem(
|
|
69
|
+
reference,
|
|
70
|
+
AggregateFixtures.AggSpec.Create({name: "Widget"}),
|
|
71
|
+
)
|
|
72
|
+
{
|
|
73
|
+
...i,
|
|
74
|
+
command: {
|
|
75
|
+
...i.command,
|
|
76
|
+
meta: meta(~msgId=`m-${reference}`, ~correlationId=flow, ~causationId=`e-${reference}`),
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let lines = await capture(
|
|
81
|
+
async () => {
|
|
82
|
+
let _ = await Stream.fromIterable([item("1", "flow-a"), item("2", "flow-b")])
|
|
83
|
+
->AggregateFixtures.TestHandler.handleCommands
|
|
84
|
+
->Effect.runPromise
|
|
85
|
+
},
|
|
86
|
+
)
|
|
87
|
+
let deciding = lines->Array.filter(r => r.message->String.startsWith("handling command"))
|
|
88
|
+
expect(deciding->Array.map(r => (r->field("msgId"), r->field("correlationId"))))->toEqual([
|
|
89
|
+
(Some("m-1"), Some("flow-a")),
|
|
90
|
+
(Some("m-2"), Some("flow-b")),
|
|
91
|
+
])
|
|
92
|
+
expect(deciding->Array.map(r => (r->field("entityId"), r->field("entityType"))))->toEqual([
|
|
93
|
+
(Some("agg-1"), Some("TestAggregate")),
|
|
94
|
+
(Some("agg-1"), Some("TestAggregate")),
|
|
95
|
+
])
|
|
96
|
+
})
|
|
97
|
+
})
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Stream from "effect/Stream";
|
|
6
|
+
import * as Logger$ReventlessCore from "../../src/util/Logger.res.mjs";
|
|
7
|
+
import * as Runtime$ReventlessCore from "../../src/adapter/Runtime/Runtime.res.mjs";
|
|
8
|
+
import * as EffectLogger$ReventlessCore from "../../src/util/EffectLogger.res.mjs";
|
|
9
|
+
import * as AggregateFixtures$ReventlessCore from "../aggregate/AggregateFixtures.res.mjs";
|
|
10
|
+
|
|
11
|
+
async function capture(run) {
|
|
12
|
+
let lines = [];
|
|
13
|
+
let remove = Logger$ReventlessCore.addSink(r => {
|
|
14
|
+
lines.push(r);
|
|
15
|
+
});
|
|
16
|
+
await run();
|
|
17
|
+
remove();
|
|
18
|
+
return lines;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function field(r, k) {
|
|
22
|
+
return r.annotations[k];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function meta(msgId, correlationId, causationId) {
|
|
26
|
+
let newrecord = {...AggregateFixtures$ReventlessCore.testMeta};
|
|
27
|
+
newrecord.causationId = causationId;
|
|
28
|
+
newrecord.correlationId = correlationId;
|
|
29
|
+
newrecord.msgId = msgId;
|
|
30
|
+
return newrecord;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
globalThis.describe("the log call carries a message's ids", () => {
|
|
34
|
+
globalThis.test("a line on a fiber of its own keeps the ids it was given", async () => {
|
|
35
|
+
let lines = await capture(async () => Effect.runSync(EffectLogger$ReventlessCore.logInfo("Aggregate(Order)", undefined, EffectLogger$ReventlessCore.idsOf("o-1", "Order", meta("m-1", "flow-1", "e-0")), "deciding")));
|
|
36
|
+
let line = Stdlib_Option.getOrThrow(lines.find(r => r.message === "deciding"), undefined);
|
|
37
|
+
globalThis.expect([
|
|
38
|
+
"msgId",
|
|
39
|
+
"correlationId",
|
|
40
|
+
"causationId",
|
|
41
|
+
"entityId",
|
|
42
|
+
"entityType"
|
|
43
|
+
].map(k => line.annotations[k])).toEqual([
|
|
44
|
+
"m-1",
|
|
45
|
+
"flow-1",
|
|
46
|
+
"e-0",
|
|
47
|
+
"o-1",
|
|
48
|
+
"Order"
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
globalThis.test("the message's flow wins over the one the invocation annotated", async () => {
|
|
52
|
+
let lines = await capture(async () => Effect.runSync(Runtime$ReventlessCore.annotateInvocation(EffectLogger$ReventlessCore.logInfo(undefined, undefined, EffectLogger$ReventlessCore.idsOf(undefined, undefined, meta("m-2", "flow-2", undefined)), "deciding"), "flow-of-the-batch", undefined, "Aggregate(Order)", undefined, undefined, undefined, undefined, undefined)));
|
|
53
|
+
let line = Stdlib_Option.getOrThrow(lines.find(r => r.message === "deciding"), undefined);
|
|
54
|
+
globalThis.expect(line.annotations["correlationId"]).toEqual("flow-2");
|
|
55
|
+
globalThis.expect(line.comp).toEqual("Aggregate(Order)");
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
globalThis.describe("component lines in a batch of several flows", () => {
|
|
60
|
+
globalThis.beforeEach(() => AggregateFixtures$ReventlessCore.mock.reset());
|
|
61
|
+
globalThis.test("each command's aggregate lines carry its own ids and its entity", async () => {
|
|
62
|
+
let item = (reference, flow) => {
|
|
63
|
+
let i = AggregateFixtures$ReventlessCore.makeTopicItem(undefined, reference, {
|
|
64
|
+
TAG: "Create",
|
|
65
|
+
name: "Widget"
|
|
66
|
+
});
|
|
67
|
+
let init = i.command;
|
|
68
|
+
return {
|
|
69
|
+
command: {
|
|
70
|
+
id: init.id,
|
|
71
|
+
meta: meta(`m-` + reference, flow, `e-` + reference),
|
|
72
|
+
command: init.command
|
|
73
|
+
},
|
|
74
|
+
reference: i.reference
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
let lines = await capture(async () => {
|
|
78
|
+
await Effect.runPromise(AggregateFixtures$ReventlessCore.TestHandler.handleCommands(Stream.fromIterable([
|
|
79
|
+
item("1", "flow-a"),
|
|
80
|
+
item("2", "flow-b")
|
|
81
|
+
])));
|
|
82
|
+
});
|
|
83
|
+
let deciding = lines.filter(r => r.message.startsWith("handling command"));
|
|
84
|
+
globalThis.expect(deciding.map(r => [
|
|
85
|
+
r.annotations["msgId"],
|
|
86
|
+
r.annotations["correlationId"]
|
|
87
|
+
])).toEqual([
|
|
88
|
+
[
|
|
89
|
+
"m-1",
|
|
90
|
+
"flow-a"
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
"m-2",
|
|
94
|
+
"flow-b"
|
|
95
|
+
]
|
|
96
|
+
]);
|
|
97
|
+
globalThis.expect(deciding.map(r => [
|
|
98
|
+
r.annotations["entityId"],
|
|
99
|
+
r.annotations["entityType"]
|
|
100
|
+
])).toEqual([
|
|
101
|
+
[
|
|
102
|
+
"agg-1",
|
|
103
|
+
"TestAggregate"
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"agg-1",
|
|
107
|
+
"TestAggregate"
|
|
108
|
+
]
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
capture,
|
|
115
|
+
field,
|
|
116
|
+
meta,
|
|
117
|
+
}
|
|
118
|
+
/* Not a pure module */
|
|
@@ -260,7 +260,7 @@ globalThis.describe("JSON sink", () => {
|
|
|
260
260
|
globalThis.expect(lines.length === 1 && Primitive_object.equal(fieldOf(line, "plugin"), "Billing")).toBe(true);
|
|
261
261
|
});
|
|
262
262
|
globalThis.test("dispatch annotation carries comp onto a handler line that passes none", () => {
|
|
263
|
-
let lines = captureLogs(() => Effect.runSync(Runtime$ReventlessCore.annotateInvocation(EffectLogger$ReventlessCore.logInfo(undefined, undefined, "projected"), "cid-1", "parent-1", "EventCollector(ProductsReadModel)", undefined, undefined, undefined, undefined, undefined)));
|
|
263
|
+
let lines = captureLogs(() => Effect.runSync(Runtime$ReventlessCore.annotateInvocation(EffectLogger$ReventlessCore.logInfo(undefined, undefined, undefined, "projected"), "cid-1", "parent-1", "EventCollector(ProductsReadModel)", undefined, undefined, undefined, undefined, undefined)));
|
|
264
264
|
let line = lines.length >= 1 ? lines[0] : "";
|
|
265
265
|
let ok = Primitive_object.equal(fieldOf(line, "comp"), "EventCollector(ProductsReadModel)") && Primitive_object.equal(fieldOf(line, "correlationId"), "cid-1") && Primitive_object.equal(fieldOf(line, "causationId"), "parent-1") && Primitive_object.equal(fieldOf(line, "message"), "projected");
|
|
266
266
|
globalThis.expect(ok).toBe(true);
|
|
@@ -274,12 +274,12 @@ globalThis.describe("JSON sink", () => {
|
|
|
274
274
|
globalThis.expect(lines.length === 1 && isCleanRecord(lines[0])).toBe(true);
|
|
275
275
|
});
|
|
276
276
|
globalThis.test("EffectLogger.logInfo emits clean JSON through install()", () => {
|
|
277
|
-
let lines = captureLogs(() => Effect.runSync(EffectLogger$ReventlessCore.logInfo("Aggregate(Product)", undefined, "replay done")));
|
|
277
|
+
let lines = captureLogs(() => Effect.runSync(EffectLogger$ReventlessCore.logInfo("Aggregate(Product)", undefined, undefined, "replay done")));
|
|
278
278
|
let allClean = lines.filter(l => !isCleanRecord(l)).length === 0;
|
|
279
279
|
globalThis.expect(lines.length >= 1 && allClean).toBe(true);
|
|
280
280
|
});
|
|
281
281
|
globalThis.test("EffectLogger.logInfo carries ~comp + ~detail as structured fields (no \\x00)", () => {
|
|
282
|
-
let lines = captureLogs(() => Effect.runSync(EffectLogger$ReventlessCore.logInfo("Aggregate(Product)", JSON.parse(`{"id":"p-1"}`), "added")));
|
|
282
|
+
let lines = captureLogs(() => Effect.runSync(EffectLogger$ReventlessCore.logInfo("Aggregate(Product)", JSON.parse(`{"id":"p-1"}`), undefined, "added")));
|
|
283
283
|
let ok = lines.some(line => {
|
|
284
284
|
let obj = Stdlib_JSON.Decode.object(JSON.parse(line));
|
|
285
285
|
if (obj !== undefined && Primitive_object.equal(Stdlib_Option.flatMap(obj["comp"], Stdlib_JSON.Decode.string), "Aggregate(Product)")) {
|
|
@@ -291,11 +291,11 @@ globalThis.describe("JSON sink", () => {
|
|
|
291
291
|
globalThis.expect(ok).toBe(true);
|
|
292
292
|
});
|
|
293
293
|
globalThis.test("Effect.annotateLogs(correlationId) surfaces as a top-level field", () => {
|
|
294
|
-
let lines = captureLogs(() => Effect.runSync(Effect.annotateLogs(EffectLogger$ReventlessCore.logInfo("Aggregate(Product)", undefined, "handling"), "correlationId", "c-123")));
|
|
294
|
+
let lines = captureLogs(() => Effect.runSync(Effect.annotateLogs(EffectLogger$ReventlessCore.logInfo("Aggregate(Product)", undefined, undefined, "handling"), "correlationId", "c-123")));
|
|
295
295
|
globalThis.expect(lines.some(line => Primitive_object.equal(fieldOf(line, "correlationId"), "c-123"))).toBe(true);
|
|
296
296
|
});
|
|
297
297
|
globalThis.test("Effect.annotateLogs(plugin) overrides registry resolution", () => {
|
|
298
|
-
let lines = captureLogs(() => Effect.runSync(Effect.annotateLogs(EffectLogger$ReventlessCore.logInfo("Aggregate(Unregistered)", undefined, "handling"), "plugin", "Ordering")));
|
|
298
|
+
let lines = captureLogs(() => Effect.runSync(Effect.annotateLogs(EffectLogger$ReventlessCore.logInfo("Aggregate(Unregistered)", undefined, undefined, "handling"), "plugin", "Ordering")));
|
|
299
299
|
globalThis.expect(lines.some(line => Primitive_object.equal(fieldOf(line, "plugin"), "Ordering"))).toBe(true);
|
|
300
300
|
});
|
|
301
301
|
globalThis.test("every JSON record carries an RFC 3339 time field", () => {
|
|
@@ -177,11 +177,11 @@ globalThis.describe("Logger levels set while running", () => {
|
|
|
177
177
|
globalThis.test("the Effect helpers follow a component's level", () => withLogLevel("info", () => {
|
|
178
178
|
let match = collecting();
|
|
179
179
|
capture(() => {
|
|
180
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug("Quiet", undefined, "not yet"));
|
|
180
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug("Quiet", undefined, undefined, "not yet"));
|
|
181
181
|
Logger$ReventlessCore.setLevel(undefined, "Quiet", "Debug");
|
|
182
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug("Quiet", undefined, "now"));
|
|
182
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug("Quiet", undefined, undefined, "now"));
|
|
183
183
|
Logger$ReventlessCore.setLevel(undefined, "Loud", "Error");
|
|
184
|
-
Effect.runSync(EffectLogger$ReventlessCore.logWarn("Loud", undefined, "dropped"));
|
|
184
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn("Loud", undefined, undefined, "dropped"));
|
|
185
185
|
});
|
|
186
186
|
match[1]();
|
|
187
187
|
globalThis.expect(match[0].map(r => r.message)).toEqual(["now"]);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// A view row carries the change that last wrote it: the flow, the event and the time, stamped
|
|
2
|
+
// by the encoder from what the projection is applying, and passed over when the row is read.
|
|
3
|
+
|
|
4
|
+
open JestGlobals
|
|
5
|
+
open QueryDbFixtures
|
|
6
|
+
|
|
7
|
+
module Ops = QueryDb_Operations.Make(
|
|
8
|
+
ItemQueryDbSpec,
|
|
9
|
+
{
|
|
10
|
+
let jsonOps = mockJsonOps
|
|
11
|
+
},
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
let _ = beforeEach(() => reset())
|
|
15
|
+
|
|
16
|
+
let ops: QueryDb.operations<string, ItemQueryDbSpec.state> = {
|
|
17
|
+
load: Ops.load,
|
|
18
|
+
loadStream: Ops.loadStream,
|
|
19
|
+
save: Ops.save,
|
|
20
|
+
saveBatch: Ops.saveBatch,
|
|
21
|
+
count: Ops.count,
|
|
22
|
+
delete: Ops.delete,
|
|
23
|
+
deleteBatch: Ops.deleteBatch,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let changeOf = (id: string): option<(option<string>, option<string>)> =>
|
|
27
|
+
store.contents
|
|
28
|
+
->Dict.get(id)
|
|
29
|
+
->Option.flatMap(rows => rows->Array.get(0))
|
|
30
|
+
->Option.flatMap(JSON.Decode.object)
|
|
31
|
+
->Option.flatMap(d => d->Dict.get(RowChange.key))
|
|
32
|
+
->Option.flatMap(JSON.Decode.object)
|
|
33
|
+
->Option.map(c => (
|
|
34
|
+
c->Dict.get("flow")->Option.flatMap(JSON.Decode.string),
|
|
35
|
+
c->Dict.get("msgId")->Option.flatMap(JSON.Decode.string),
|
|
36
|
+
))
|
|
37
|
+
|
|
38
|
+
let source = (~flow="flow-1", msgId): Projection.changeSource => {msgId, correlationId: flow}
|
|
39
|
+
|
|
40
|
+
describe("a row's last change", () => {
|
|
41
|
+
testPromise("is the last of the events the projection applied", async () => {
|
|
42
|
+
let _ = await Projection.handleAction(
|
|
43
|
+
~sources=[source("m-1"), source("m-2")],
|
|
44
|
+
Create("a", ({name: "A", count: 1}: ItemQueryDbSpec.state)),
|
|
45
|
+
ops,
|
|
46
|
+
None,
|
|
47
|
+
)
|
|
48
|
+
expect(changeOf("a"))->toEqual(Some((Some("flow-1"), Some("m-2"))))
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
testPromise("is not written by a save outside a projection", async () => {
|
|
52
|
+
let _ = await Ops.save("a", ({name: "A", count: 1}: ItemQueryDbSpec.state), Init, None)
|
|
53
|
+
expect(changeOf("a"))->toEqual(None)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
testPromise("is each row's own when a projection writes several at once", async () => {
|
|
57
|
+
let _ = await Promise.all([
|
|
58
|
+
Projection.handleAction(
|
|
59
|
+
~sources=[source(~flow="flow-a", "m-a")],
|
|
60
|
+
Create("a", ({name: "A", count: 1}: ItemQueryDbSpec.state)),
|
|
61
|
+
ops,
|
|
62
|
+
None,
|
|
63
|
+
),
|
|
64
|
+
Projection.handleAction(
|
|
65
|
+
~sources=[source(~flow="flow-b", "m-b")],
|
|
66
|
+
Create("b", ({name: "B", count: 1}: ItemQueryDbSpec.state)),
|
|
67
|
+
ops,
|
|
68
|
+
None,
|
|
69
|
+
),
|
|
70
|
+
])
|
|
71
|
+
expect((changeOf("a"), changeOf("b")))->toEqual((
|
|
72
|
+
Some((Some("flow-a"), Some("m-a"))),
|
|
73
|
+
Some((Some("flow-b"), Some("m-b"))),
|
|
74
|
+
))
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
testPromise("is passed over when the row is read back", async () => {
|
|
78
|
+
let _ = await Projection.handleAction(
|
|
79
|
+
~sources=[source("m-1")],
|
|
80
|
+
Create("a", ({name: "A", count: 1}: ItemQueryDbSpec.state)),
|
|
81
|
+
ops,
|
|
82
|
+
None,
|
|
83
|
+
)
|
|
84
|
+
let rows = await Ops.loadStream("a")->Stream.runCollect->Effect.runPromise
|
|
85
|
+
expect(rows->Array.map(r => (r.name, r.count)))->toEqual([("A", 1)])
|
|
86
|
+
})
|
|
87
|
+
})
|