@reventlessdev/reventless-core 3.0.0-alpha.324 → 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 +15 -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 +11 -3
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +8 -6
- 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 +205 -1
- package/tests/commandgenerator/OwnerActingTest.res.mjs +361 -0
- 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
|
@@ -475,6 +475,7 @@ module Make = (
|
|
|
475
475
|
// was delivered again. Accepted, nothing new.
|
|
476
476
|
CommandTopic_Helpers.reportAccepted(
|
|
477
477
|
~component=Spec.name,
|
|
478
|
+
~correlationId=cmdJson.meta.correlationId,
|
|
478
479
|
cmdJson.meta.msgId,
|
|
479
480
|
switch entityId {
|
|
480
481
|
| Some(eid) => {entityId: eid, eventCount: 0}
|
|
@@ -492,6 +493,7 @@ module Make = (
|
|
|
492
493
|
cachePut((state, headPosition, owners))
|
|
493
494
|
CommandTopic_Helpers.reportRejected(
|
|
494
495
|
~component=Spec.name,
|
|
496
|
+
~correlationId=cmdJson.meta.correlationId,
|
|
495
497
|
~cause=AccessRefusal,
|
|
496
498
|
cmdJson.meta.msgId,
|
|
497
499
|
rejected,
|
|
@@ -508,6 +510,7 @@ module Make = (
|
|
|
508
510
|
cachePut((state, headPosition, owners))
|
|
509
511
|
CommandTopic_Helpers.reportAccepted(
|
|
510
512
|
~component=Spec.name,
|
|
513
|
+
~correlationId=cmdJson.meta.correlationId,
|
|
511
514
|
cmdJson.meta.msgId,
|
|
512
515
|
switch entityId {
|
|
513
516
|
| Some(eid) => {entityId: eid, eventCount: 0}
|
|
@@ -529,6 +532,7 @@ module Make = (
|
|
|
529
532
|
cachePut((state, headPosition, owners))
|
|
530
533
|
CommandTopic_Helpers.reportRejected(
|
|
531
534
|
~component=Spec.name,
|
|
535
|
+
~correlationId=cmdJson.meta.correlationId,
|
|
532
536
|
~cause=InfrastructureFailure,
|
|
533
537
|
cmdJson.meta.msgId,
|
|
534
538
|
{
|
|
@@ -576,6 +580,7 @@ module Make = (
|
|
|
576
580
|
cachePut((state, headPosition, owners))
|
|
577
581
|
CommandTopic_Helpers.reportAccepted(
|
|
578
582
|
~component=Spec.name,
|
|
583
|
+
~correlationId=cmdJson.meta.correlationId,
|
|
579
584
|
cmdJson.meta.msgId,
|
|
580
585
|
switch entityId {
|
|
581
586
|
| Some(eid) => {entityId: eid, eventCount: rawEvents->Array.length}
|
|
@@ -627,6 +632,7 @@ module Make = (
|
|
|
627
632
|
// store failing. `decide` had already said Ok.
|
|
628
633
|
CommandTopic_Helpers.reportRejected(
|
|
629
634
|
~component=Spec.name,
|
|
635
|
+
~correlationId=cmdJson.meta.correlationId,
|
|
630
636
|
~cause=InfrastructureFailure,
|
|
631
637
|
cmdJson.meta.msgId,
|
|
632
638
|
{errorCode, errorDetail: errDetail},
|
|
@@ -652,6 +658,7 @@ module Make = (
|
|
|
652
658
|
: payloadDict->JSON.Encode.object->JSON.stringify
|
|
653
659
|
CommandTopic_Helpers.reportRejected(
|
|
654
660
|
~component=Spec.name,
|
|
661
|
+
~correlationId=cmdJson.meta.correlationId,
|
|
655
662
|
~cause=DomainRejection,
|
|
656
663
|
cmdJson.meta.msgId,
|
|
657
664
|
{errorCode, errorDetail},
|
|
@@ -295,7 +295,7 @@ function Make(Spec) {
|
|
|
295
295
|
return Effect.flatMap(EffectLogger$ReventlessCore.logDebug(comp, undefined, `deciding: id=` + Stdlib_Option.getOr(entityId, "-") + ` head=` + Stdlib_Option.getOr(headPosition, "-") + ` cmd=` + LogFormat$ReventlessCore.cmdName(cmdJson)), () => {
|
|
296
296
|
let match = ownershipRefusal(owners);
|
|
297
297
|
if (repeated) {
|
|
298
|
-
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
298
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.correlationId, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
299
299
|
entityId: entityId,
|
|
300
300
|
eventCount: 0
|
|
301
301
|
}) : ({
|
|
@@ -313,7 +313,7 @@ function Make(Spec) {
|
|
|
313
313
|
headPosition,
|
|
314
314
|
owners
|
|
315
315
|
]);
|
|
316
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "AccessRefusal", cmdJson.meta.msgId, rejected);
|
|
316
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "AccessRefusal", cmdJson.meta.correlationId, cmdJson.meta.msgId, rejected);
|
|
317
317
|
let line = `refused: ` + rejected.errorDetail + ` id=` + Stdlib_Option.getOr(entityId, "-");
|
|
318
318
|
return Effect.map(match.isDefect ? EffectLogger$ReventlessCore.logError(comp, undefined, line) : EffectLogger$ReventlessCore.logWarn(comp, undefined, line), () => ({
|
|
319
319
|
TAG: "Ok",
|
|
@@ -329,7 +329,7 @@ function Make(Spec) {
|
|
|
329
329
|
headPosition,
|
|
330
330
|
owners
|
|
331
331
|
]);
|
|
332
|
-
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
332
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.correlationId, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
333
333
|
entityId: entityId,
|
|
334
334
|
eventCount: 0
|
|
335
335
|
}) : ({
|
|
@@ -380,7 +380,7 @@ function Make(Spec) {
|
|
|
380
380
|
headPosition,
|
|
381
381
|
owners
|
|
382
382
|
]);
|
|
383
|
-
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
383
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.correlationId, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
384
384
|
entityId: entityId,
|
|
385
385
|
eventCount: rawEvents.length
|
|
386
386
|
}) : ({
|
|
@@ -415,7 +415,7 @@ function Make(Spec) {
|
|
|
415
415
|
if (errorCode === CommandOutcome$Reventless.code("Conflict")) {
|
|
416
416
|
Metrics$ReventlessCore.emitCount("AppendConflict", Spec.name, undefined);
|
|
417
417
|
}
|
|
418
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", cmdJson.meta.msgId, {
|
|
418
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", cmdJson.meta.correlationId, cmdJson.meta.msgId, {
|
|
419
419
|
errorCode: errorCode,
|
|
420
420
|
errorDetail: errDetail
|
|
421
421
|
});
|
|
@@ -432,7 +432,7 @@ function Make(Spec) {
|
|
|
432
432
|
headPosition,
|
|
433
433
|
owners
|
|
434
434
|
]);
|
|
435
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", cmdJson.meta.msgId, {
|
|
435
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", cmdJson.meta.correlationId, cmdJson.meta.msgId, {
|
|
436
436
|
errorCode: CommandOutcome$Reventless.code("AppendFailed"),
|
|
437
437
|
errorDetail: detail
|
|
438
438
|
});
|
|
@@ -452,7 +452,7 @@ function Make(Spec) {
|
|
|
452
452
|
let match$1 = Message$ReventlessCore.splitMessage(errorJson);
|
|
453
453
|
let payloadDict = match$1[1];
|
|
454
454
|
let errorDetail = Object.entries(payloadDict).length === 0 ? "" : JSON.stringify(payloadDict);
|
|
455
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "DomainRejection", cmdJson.meta.msgId, {
|
|
455
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "DomainRejection", cmdJson.meta.correlationId, cmdJson.meta.msgId, {
|
|
456
456
|
errorCode: errorCode,
|
|
457
457
|
errorDetail: errorDetail
|
|
458
458
|
});
|
|
@@ -94,6 +94,10 @@ module Make = (
|
|
|
94
94
|
)
|
|
95
95
|
|
|
96
96
|
let comp = `StateViewSlice(${Spec.name})`
|
|
97
|
+
// Each row the events change is logged, and handed to whoever listens.
|
|
98
|
+
let onChange = ViewChange.reporter(~comp, ~view=Spec.name, ~stateToJson=state =>
|
|
99
|
+
state->Reventless.Util_Sury.toJson(Spec.stateSchema)
|
|
100
|
+
)
|
|
97
101
|
|
|
98
102
|
let jsonEventsHandler: EventCollector.jsonEventsHandler = stream =>
|
|
99
103
|
stream
|
|
@@ -176,8 +180,14 @@ module Make = (
|
|
|
176
180
|
// ppx injects for a read model's, and the same lifecycle trail.
|
|
177
181
|
// Rewritten here rather than at the apply below because the
|
|
178
182
|
// trail entry is stamped with this envelope's own time.
|
|
183
|
+
// The event each action came from, kept for the change it makes.
|
|
184
|
+
let (entityId, entityType) = ViewChange.entityOfEnvelope(envelopeDict)
|
|
185
|
+
let sources = [ViewChange.sourceOf(~meta, ~entityId?, ~entityType?, ())]
|
|
179
186
|
actions->Array.map(
|
|
180
|
-
|
|
187
|
+
action => (
|
|
188
|
+
action->FrameworkProjection.rewriteAction(~at=meta.time, Spec.stateSchema),
|
|
189
|
+
sources,
|
|
190
|
+
),
|
|
181
191
|
)
|
|
182
192
|
| None => []
|
|
183
193
|
}
|
|
@@ -186,13 +196,15 @@ module Make = (
|
|
|
186
196
|
->Array.flat
|
|
187
197
|
->Array.reduce(
|
|
188
198
|
Effect.succeed(),
|
|
189
|
-
(acc, action) =>
|
|
199
|
+
(acc, (action, sources)) =>
|
|
190
200
|
acc->Effect.flatMap(
|
|
191
201
|
_ => {
|
|
192
202
|
Effect.promise(
|
|
193
203
|
() =>
|
|
194
204
|
FrameworkProjection.handleAction(
|
|
195
205
|
~comp,
|
|
206
|
+
~sources,
|
|
207
|
+
~onChange,
|
|
196
208
|
action,
|
|
197
209
|
projectionOps,
|
|
198
210
|
Spec.subIdConfig,
|
|
@@ -18,6 +18,7 @@ import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
|
18
18
|
import * as Component$ReventlessCore from "../Component.res.mjs";
|
|
19
19
|
import * as LogFormat$ReventlessCore from "../../util/LogFormat.res.mjs";
|
|
20
20
|
import * as Projection$ReventlessCore from "../../Projection.res.mjs";
|
|
21
|
+
import * as ViewChange$ReventlessCore from "../../ViewChange.res.mjs";
|
|
21
22
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
22
23
|
import * as ComponentType$ReventlessCore from "../../ComponentType.res.mjs";
|
|
23
24
|
import * as RuntimeHints$ReventlessInfra from "@reventlessdev/reventless-infra/src/types/RuntimeHints.res.mjs";
|
|
@@ -80,6 +81,7 @@ function Make(RuntimeEnvironment) {
|
|
|
80
81
|
name: Spec.name
|
|
81
82
|
}, opts);
|
|
82
83
|
let comp = `StateViewSlice(` + Spec.name + `)`;
|
|
84
|
+
let onChange = ViewChange$ReventlessCore.reporter(comp, Spec.name, state => Util_Sury$Reventless.toJson(state, Spec.stateSchema));
|
|
83
85
|
let jsonEventsHandler = stream => Effect.flatMap(Effect.tap(Stream.runCollect(stream), events => {
|
|
84
86
|
if (Pii$Reventless.needsPrepare(events)) {
|
|
85
87
|
return Effect.promise(() => Pii$Reventless.prepareOrThrow(events));
|
|
@@ -128,8 +130,17 @@ function Make(RuntimeEnvironment) {
|
|
|
128
130
|
let f = Object.entries(dataDict).map(param => param[0] + `:` + JSON.stringify(param[1])).join(",");
|
|
129
131
|
let fieldsStr = f === "" ? "" : `({` + f + `})`;
|
|
130
132
|
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, dataDict, `handling event ` + idxStr + `/` + total + `: ` + LogFormat$ReventlessCore.bold(eventType) + fieldsStr + ` ` + actionsStr));
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
let match$1 = ViewChange$ReventlessCore.entityOfEnvelope(envelopeDict);
|
|
134
|
+
let sources = [ViewChange$ReventlessCore.sourceOf(meta, match$1[0], match$1[1], undefined)];
|
|
135
|
+
return actions.map(action => [
|
|
136
|
+
Projection$ReventlessCore.rewriteAction(action, meta.time, Spec.stateSchema),
|
|
137
|
+
sources
|
|
138
|
+
]);
|
|
139
|
+
}).flat(), Effect.succeed(), (acc, param) => {
|
|
140
|
+
let sources = param[1];
|
|
141
|
+
let action = param[0];
|
|
142
|
+
return Effect.flatMap(acc, () => Effect.map(Effect.promise(() => Projection$ReventlessCore.handleAction(comp, sources, onChange, action, projectionOps, Spec.subIdConfig)), param => {}));
|
|
143
|
+
});
|
|
133
144
|
});
|
|
134
145
|
let handler = SpecificEventCollector.makeHandler(ec, jsonEventsHandler);
|
|
135
146
|
let resources = Component$ReventlessCore.outputs(queryDb).resources;
|
|
@@ -24,6 +24,11 @@ module Make = (
|
|
|
24
24
|
let comp = `StateViewSlice(${Spec.name})`
|
|
25
25
|
let decoder = Reventless.DcbDecode.makeDecoder(Spec.consumedEventSchema)
|
|
26
26
|
|
|
27
|
+
// Each row the events change is logged, and handed to whoever listens.
|
|
28
|
+
let onChange = ViewChange.reporter(~comp, ~view=Spec.name, ~stateToJson=state =>
|
|
29
|
+
state->Reventless.Util_Sury.toJson(Spec.stateSchema)
|
|
30
|
+
)
|
|
31
|
+
|
|
27
32
|
let eventsHandler = async (
|
|
28
33
|
queryDbOps: queryDbOperations,
|
|
29
34
|
rawEvents: array<ReventlessInfra.DcbEventLog.rawSequencedEvent>,
|
|
@@ -61,10 +66,24 @@ module Make = (
|
|
|
61
66
|
raw.eventType,
|
|
62
67
|
)}(${id}) ${actionsStr}`,
|
|
63
68
|
)->Effect.runSync
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
// The event each action came from, kept for the change it makes: the
|
|
70
|
+
// entity is the event's first tag.
|
|
71
|
+
let sources = [
|
|
72
|
+
ViewChange.sourceOf(
|
|
73
|
+
~meta=raw.meta,
|
|
74
|
+
~entityId=?raw.tags->Array.get(0)->Option.map(tag => tag.value),
|
|
75
|
+
~entityType=?raw.tags->Array.get(0)->Option.map(tag => tag.key),
|
|
76
|
+
(),
|
|
67
77
|
),
|
|
78
|
+
]
|
|
79
|
+
allActions->Array.pushMany(
|
|
80
|
+
actions->Array.map(action => {
|
|
81
|
+
FrameworkProjection.action: action->FrameworkProjection.rewriteAction(
|
|
82
|
+
~at=raw.meta.time,
|
|
83
|
+
Spec.stateSchema,
|
|
84
|
+
),
|
|
85
|
+
sources,
|
|
86
|
+
}),
|
|
68
87
|
)
|
|
69
88
|
Some(event)
|
|
70
89
|
| None => None
|
|
@@ -77,6 +96,12 @@ module Make = (
|
|
|
77
96
|
`skipped=${skipped->Int.toString} events (decode mismatch)`,
|
|
78
97
|
)->Effect.runSync
|
|
79
98
|
}
|
|
80
|
-
await FrameworkProjection.
|
|
99
|
+
await FrameworkProjection.handleSourcedActions(
|
|
100
|
+
~comp,
|
|
101
|
+
~onChange,
|
|
102
|
+
allActions,
|
|
103
|
+
queryDbOps,
|
|
104
|
+
Spec.subIdConfig,
|
|
105
|
+
)
|
|
81
106
|
}
|
|
82
107
|
}
|
|
@@ -7,15 +7,18 @@ import * as Effect from "effect/Effect";
|
|
|
7
7
|
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
8
8
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
9
9
|
import * as DcbDecode$Reventless from "@reventlessdev/reventless-spec/src/components/DcbDecode.res.mjs";
|
|
10
|
+
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
10
11
|
import * as Projection$Reventless from "@reventlessdev/reventless-spec/src/types/Projection.res.mjs";
|
|
11
12
|
import * as LogFormat$ReventlessCore from "../../util/LogFormat.res.mjs";
|
|
12
13
|
import * as Projection$ReventlessCore from "../../Projection.res.mjs";
|
|
14
|
+
import * as ViewChange$ReventlessCore from "../../ViewChange.res.mjs";
|
|
13
15
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
14
16
|
|
|
15
17
|
function Make(Spec) {
|
|
16
18
|
return Projection => {
|
|
17
19
|
let comp = `StateViewSlice(` + Spec.name + `)`;
|
|
18
20
|
let decoder = DcbDecode$Reventless.makeDecoder(Spec.consumedEventSchema);
|
|
21
|
+
let onChange = ViewChange$ReventlessCore.reporter(comp, Spec.name, state => Util_Sury$Reventless.toJson(state, Spec.stateSchema));
|
|
19
22
|
let eventsHandler = async (queryDbOps, rawEvents) => {
|
|
20
23
|
let datas = rawEvents.map(raw => raw.data);
|
|
21
24
|
if (Pii$Reventless.needsPrepare(datas)) {
|
|
@@ -41,14 +44,18 @@ function Make(Spec) {
|
|
|
41
44
|
}).map(__x => Projection$Reventless.mapActionId(__x, Spec.Id.toString, Spec.Id.makeFromString));
|
|
42
45
|
let actionsStr = LogFormat$ReventlessCore.actionNames(actions);
|
|
43
46
|
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, raw.data, `handling event ` + idx.contents.toString() + `/` + count + `: ` + LogFormat$ReventlessCore.bold(raw.eventType) + `(` + id + `) ` + actionsStr));
|
|
44
|
-
|
|
47
|
+
let sources = [ViewChange$ReventlessCore.sourceOf(raw.meta, Stdlib_Option.map(raw.tags[0], tag => tag.value), Stdlib_Option.map(raw.tags[0], tag => tag.key), undefined)];
|
|
48
|
+
allActions.push(...actions.map(action => ({
|
|
49
|
+
action: Projection$ReventlessCore.rewriteAction(action, raw.meta.time, Spec.stateSchema),
|
|
50
|
+
sources: sources
|
|
51
|
+
})));
|
|
45
52
|
return Primitive_option.some(event);
|
|
46
53
|
});
|
|
47
54
|
let skipped = rawEvents.length - events.length | 0;
|
|
48
55
|
if (skipped > 0) {
|
|
49
56
|
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `skipped=` + skipped.toString() + ` events (decode mismatch)`));
|
|
50
57
|
}
|
|
51
|
-
return await Projection$ReventlessCore.
|
|
58
|
+
return await Projection$ReventlessCore.handleSourcedActions(comp, onChange, allActions, queryDbOps, Spec.subIdConfig);
|
|
52
59
|
};
|
|
53
60
|
return {
|
|
54
61
|
Spec: Spec,
|
|
@@ -64,8 +64,6 @@ type effectLogLevel
|
|
|
64
64
|
external _withMinimumLogLevel: (Effect.t<'a, 'e, 'r>, effectLogLevel) => Effect.t<'a, 'e, 'r> =
|
|
65
65
|
"withMinimumLogLevel"
|
|
66
66
|
|
|
67
|
-
@val external _envLogLevel: option<string> = "process.env.LOG_LEVEL"
|
|
68
|
-
|
|
69
67
|
// Minimum level used when LOG_LEVEL is unset. Framework default is Info; a platform
|
|
70
68
|
// may lower it (e.g. the in-memory dev platform sets Debug) via setDefaultMinLevel.
|
|
71
69
|
// The ref lives in Logger (single source of truth) so both the record logger
|
|
@@ -73,21 +71,15 @@ external _withMinimumLogLevel: (Effect.t<'a, 'e, 'r>, effectLogLevel) => Effect.
|
|
|
73
71
|
// here so existing `EffectLogger.setDefaultMinLevel` callers keep working.
|
|
74
72
|
let setDefaultMinLevel = Logger.setDefaultMinLevel
|
|
75
73
|
|
|
76
|
-
// Resolve the active minimum
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
|
81
|
-
| Some(
|
|
82
|
-
| Some(
|
|
83
|
-
| Some(
|
|
84
|
-
|
|
|
85
|
-
switch Logger.defaultMinLevel.contents {
|
|
86
|
-
| Logger.Debug => _llDebug
|
|
87
|
-
| Logger.Info => _llInfo
|
|
88
|
-
| Logger.Warn => _llWarning
|
|
89
|
-
| Logger.Error => _llError
|
|
90
|
-
}
|
|
74
|
+
// Resolve the active minimum for one line of `comp`: a level set while running
|
|
75
|
+
// for it (or its plugin) first, then LOG_LEVEL, then the platform default.
|
|
76
|
+
let _effectMin = (~comp: option<string>=?, ()): effectLogLevel =>
|
|
77
|
+
switch Logger.minLevelFor(~comp?, ()) {
|
|
78
|
+
| None => _llNone
|
|
79
|
+
| Some(Logger.Debug) => _llDebug
|
|
80
|
+
| Some(Logger.Info) => _llInfo
|
|
81
|
+
| Some(Logger.Warn) => _llWarning
|
|
82
|
+
| Some(Logger.Error) => _llError
|
|
91
83
|
}
|
|
92
84
|
|
|
93
85
|
let ordinalToLevel = ordinal =>
|
|
@@ -137,14 +129,23 @@ let install = () =>
|
|
|
137
129
|
}
|
|
138
130
|
)
|
|
139
131
|
let annotations = extra->Dict.toArray->Array.length == 0 ? None : Some(extra)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
132
|
+
// Effect gated the line by the level it was given at the call. A level set
|
|
133
|
+
// while running for the line's plugin is only known here, where the plugin
|
|
134
|
+
// annotation is read, so it is applied again — only then, so a line logged
|
|
135
|
+
// without the helpers below keeps today's behaviour.
|
|
136
|
+
let passes =
|
|
137
|
+
!Logger.hasOverrides() ||
|
|
138
|
+
Logger.shouldLog(level, ~plugin=?plugin.contents, ~comp=?comp.contents, ())
|
|
139
|
+
if passes {
|
|
140
|
+
Logger.emit(
|
|
141
|
+
~level,
|
|
142
|
+
~comp=?comp.contents,
|
|
143
|
+
~plugin=?plugin.contents,
|
|
144
|
+
~detail=?detail.contents,
|
|
145
|
+
~annotations?,
|
|
146
|
+
msg,
|
|
147
|
+
)
|
|
148
|
+
}
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
// Self-installing: runs at module initialization time.
|
|
@@ -171,10 +172,10 @@ let _annotate = (eff, ~comp=?, ~detail=?) => {
|
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
let logInfo = (~comp=?, ~detail=?, msg) =>
|
|
174
|
-
Effect.logInfo(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin())
|
|
175
|
+
Effect.logInfo(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin(~comp?, ()))
|
|
175
176
|
let logWarn = (~comp=?, ~detail=?, msg) =>
|
|
176
|
-
Effect.logWarning(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin())
|
|
177
|
+
Effect.logWarning(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin(~comp?, ()))
|
|
177
178
|
let logError = (~comp=?, ~detail=?, msg) =>
|
|
178
|
-
Effect.logError(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin())
|
|
179
|
+
Effect.logError(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin(~comp?, ()))
|
|
179
180
|
let logDebug = (~comp=?, ~detail=?, msg) =>
|
|
180
|
-
Effect.logDebug(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin())
|
|
181
|
+
Effect.logDebug(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin(~comp?, ()))
|
|
@@ -26,24 +26,12 @@ function _messageToString(msg) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function _effectMin() {
|
|
30
|
-
let match =
|
|
31
|
-
if (match
|
|
32
|
-
|
|
33
|
-
case "debug" :
|
|
34
|
-
return LogLevel.Debug;
|
|
35
|
-
case "error" :
|
|
36
|
-
return LogLevel.Error;
|
|
37
|
-
case "info" :
|
|
38
|
-
return LogLevel.Info;
|
|
39
|
-
case "silent" :
|
|
40
|
-
return LogLevel.None;
|
|
41
|
-
case "warn" :
|
|
42
|
-
return LogLevel.Warning;
|
|
43
|
-
}
|
|
29
|
+
function _effectMin(comp, param) {
|
|
30
|
+
let match = Logger$ReventlessCore.minLevelFor(undefined, comp, undefined);
|
|
31
|
+
if (match === undefined) {
|
|
32
|
+
return LogLevel.None;
|
|
44
33
|
}
|
|
45
|
-
|
|
46
|
-
switch (match$1) {
|
|
34
|
+
switch (match) {
|
|
47
35
|
case "Debug" :
|
|
48
36
|
return LogLevel.Debug;
|
|
49
37
|
case "Info" :
|
|
@@ -116,7 +104,10 @@ function install() {
|
|
|
116
104
|
}
|
|
117
105
|
});
|
|
118
106
|
let annotations = Object.entries(extra).length === 0 ? undefined : extra;
|
|
119
|
-
Logger$ReventlessCore.
|
|
107
|
+
let passes = !Logger$ReventlessCore.hasOverrides() || Logger$ReventlessCore.shouldLog(level, plugin.contents, comp.contents, undefined);
|
|
108
|
+
if (passes) {
|
|
109
|
+
return Logger$ReventlessCore.emit(level, comp.contents, plugin.contents, detail.contents, annotations, msg);
|
|
110
|
+
}
|
|
120
111
|
};
|
|
121
112
|
}
|
|
122
113
|
|
|
@@ -132,19 +123,19 @@ function _annotate(eff, comp, detail) {
|
|
|
132
123
|
}
|
|
133
124
|
|
|
134
125
|
function logInfo(comp, detail, msg) {
|
|
135
|
-
return Logger.withMinimumLogLevel(_annotate(Effect.logInfo(msg), comp, detail), _effectMin());
|
|
126
|
+
return Logger.withMinimumLogLevel(_annotate(Effect.logInfo(msg), comp, detail), _effectMin(comp, undefined));
|
|
136
127
|
}
|
|
137
128
|
|
|
138
129
|
function logWarn(comp, detail, msg) {
|
|
139
|
-
return Logger.withMinimumLogLevel(_annotate(Effect.logWarning(msg), comp, detail), _effectMin());
|
|
130
|
+
return Logger.withMinimumLogLevel(_annotate(Effect.logWarning(msg), comp, detail), _effectMin(comp, undefined));
|
|
140
131
|
}
|
|
141
132
|
|
|
142
133
|
function logError(comp, detail, msg) {
|
|
143
|
-
return Logger.withMinimumLogLevel(_annotate(Effect.logError(msg), comp, detail), _effectMin());
|
|
134
|
+
return Logger.withMinimumLogLevel(_annotate(Effect.logError(msg), comp, detail), _effectMin(comp, undefined));
|
|
144
135
|
}
|
|
145
136
|
|
|
146
137
|
function logDebug(comp, detail, msg) {
|
|
147
|
-
return Logger.withMinimumLogLevel(_annotate(Effect.logDebug(msg), comp, detail), _effectMin());
|
|
138
|
+
return Logger.withMinimumLogLevel(_annotate(Effect.logDebug(msg), comp, detail), _effectMin(comp, undefined));
|
|
148
139
|
}
|
|
149
140
|
|
|
150
141
|
let setDefaultMinLevel = Logger$ReventlessCore.setDefaultMinLevel;
|