@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.
Files changed (80) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +7 -7
  3. package/src/Message.res +46 -0
  4. package/src/Message.res.mjs +45 -0
  5. package/src/Projection.res +269 -131
  6. package/src/Projection.res.mjs +338 -224
  7. package/src/ViewChange.res +194 -0
  8. package/src/ViewChange.res.mjs +235 -0
  9. package/src/adapter/Runtime/AggregateRuntime_Builder_Common.res.mjs +5 -5
  10. package/src/adapter/Runtime/EventCollectorRuntime_Builder_Single.res.mjs +2 -2
  11. package/src/admin/Platform_Admin_Callback.res.mjs +1 -1
  12. package/src/components/Aggregate/Aggregate_Callback.res +93 -18
  13. package/src/components/Aggregate/Aggregate_Callback.res.mjs +54 -32
  14. package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +1 -1
  15. package/src/components/AutomationSlice/AutomationSlice_Callback.res +29 -9
  16. package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +35 -20
  17. package/src/components/CommandGenerator/CommandGenerator_Callback.res +47 -6
  18. package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +41 -4
  19. package/src/components/CommandTopic/CommandTopic.res.mjs +5 -2
  20. package/src/components/CommandTopic/CommandTopic_Callback.res.mjs +1 -1
  21. package/src/components/CommandTopic/CommandTopic_Helpers.res +64 -26
  22. package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +37 -17
  23. package/src/components/CommandTopic/CommandTopic_Operations.res +2 -0
  24. package/src/components/CommandTopic/CommandTopic_Operations.res.mjs +2 -2
  25. package/src/components/Counter/Counter_Callback.res.mjs +3 -3
  26. package/src/components/Counter/Counter_Operations.res.mjs +4 -4
  27. package/src/components/DcbEventLog/DcbEventLog_Operations.res.mjs +3 -3
  28. package/src/components/EventLog/EventLog_Operations.res +1 -0
  29. package/src/components/EventLog/EventLog_Operations.res.mjs +3 -3
  30. package/src/components/EventMapper/EventMapper_Callback.res +4 -0
  31. package/src/components/EventMapper/EventMapper_Callback.res.mjs +13 -12
  32. package/src/components/EventTopic/EventTopic_Operations.res +2 -0
  33. package/src/components/EventTopic/EventTopic_Operations.res.mjs +2 -2
  34. package/src/components/Extension/Extension_Operations.res +4 -0
  35. package/src/components/Extension/Extension_Operations.res.mjs +8 -8
  36. package/src/components/ExtensionPoint/ExtensionPoint_Callback.res.mjs +2 -2
  37. package/src/components/ExtensionPoint/ExtensionPoint_Operations.res +2 -0
  38. package/src/components/ExtensionPoint/ExtensionPoint_Operations.res.mjs +9 -8
  39. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +1 -1
  40. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +1 -1
  41. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +6 -2
  42. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +7 -3
  43. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +33 -12
  44. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +30 -17
  45. package/src/components/ReadModel/ReadModel_Callback.res +24 -3
  46. package/src/components/ReadModel/ReadModel_Callback.res.mjs +15 -3
  47. package/src/components/SideEffectHandler/SideEffectHandler_Callback.res +2 -0
  48. package/src/components/SideEffectHandler/SideEffectHandler_Callback.res.mjs +6 -6
  49. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +43 -7
  50. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +38 -20
  51. package/src/components/StateViewSlice/StateViewSlice_Builder.res +16 -2
  52. package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +15 -4
  53. package/src/components/StateViewSlice/StateViewSlice_Callback.res +35 -4
  54. package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +12 -4
  55. package/src/plugin/component/Plugin_Callback.res.mjs +2 -2
  56. package/src/plugin/connect/PluginExtensionPoint_Plugin.res.mjs +6 -6
  57. package/src/util/CommandPublisher.res.mjs +9 -9
  58. package/src/util/EffectLogger.res +111 -42
  59. package/src/util/EffectLogger.res.mjs +72 -30
  60. package/src/util/FTPHandler.res.mjs +6 -6
  61. package/src/util/Logger.res +231 -35
  62. package/src/util/Logger.res.mjs +263 -42
  63. package/src/util/ScheduleOps.res.mjs +4 -4
  64. package/src/util/Util_AdapterRuntime.res.mjs +2 -2
  65. package/src/util/Util_Promise.res.mjs +1 -1
  66. package/src/util/Util_QueryDbRuntime.res.mjs +1 -1
  67. package/src/util/Validation.res.mjs +1 -1
  68. package/tests/commandgenerator/OwnerActingTest.res +3 -1
  69. package/tests/commandgenerator/OwnerStampingTest.res +65 -0
  70. package/tests/commandgenerator/OwnerStampingTest.res.mjs +62 -0
  71. package/tests/commandtopic/CommandOutcomeHookTest.res +99 -2
  72. package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +120 -0
  73. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +4 -4
  74. package/tests/logger/ComponentLineIdsTest.res +97 -0
  75. package/tests/logger/ComponentLineIdsTest.res.mjs +118 -0
  76. package/tests/logger/LogFormatTest.res.mjs +5 -5
  77. package/tests/logger/LoggerSinkTest.res +205 -0
  78. package/tests/logger/LoggerSinkTest.res.mjs +209 -0
  79. package/tests/projection/ViewChangeTest.res +173 -0
  80. package/tests/projection/ViewChangeTest.res.mjs +292 -0
@@ -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)) {
@@ -40,15 +43,20 @@ function Make(Spec) {
40
43
  recordedAt: raw.recordedAt
41
44
  }).map(__x => Projection$Reventless.mapActionId(__x, Spec.Id.toString, Spec.Id.makeFromString));
42
45
  let actionsStr = LogFormat$ReventlessCore.actionNames(actions);
43
- Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, raw.data, `handling event ` + idx.contents.toString() + `/` + count + `: ` + LogFormat$ReventlessCore.bold(raw.eventType) + `(` + id + `) ` + actionsStr));
44
- allActions.push(...actions.map(__x => Projection$ReventlessCore.rewriteAction(__x, raw.meta.time, Spec.stateSchema)));
46
+ let tag = raw.tags[0];
47
+ Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, raw.data, EffectLogger$ReventlessCore.idsOf(Stdlib_Option.map(tag, t => t.value), Stdlib_Option.map(tag, t => t.key), raw.meta), `handling event ` + idx.contents.toString() + `/` + count + `: ` + LogFormat$ReventlessCore.bold(raw.eventType) + `(` + id + `) ` + actionsStr));
48
+ 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)];
49
+ allActions.push(...actions.map(action => ({
50
+ action: Projection$ReventlessCore.rewriteAction(action, raw.meta.time, Spec.stateSchema),
51
+ sources: sources
52
+ })));
45
53
  return Primitive_option.some(event);
46
54
  });
47
55
  let skipped = rawEvents.length - events.length | 0;
48
56
  if (skipped > 0) {
49
- Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `skipped=` + skipped.toString() + ` events (decode mismatch)`));
57
+ Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, undefined, `skipped=` + skipped.toString() + ` events (decode mismatch)`));
50
58
  }
51
- return await Projection$ReventlessCore.handleActions(comp, allActions, queryDbOps, Spec.subIdConfig);
59
+ return await Projection$ReventlessCore.handleSourcedActions(comp, onChange, allActions, queryDbOps, Spec.subIdConfig);
52
60
  };
53
61
  return {
54
62
  Spec: Spec,
@@ -27,7 +27,7 @@ function Make(Spec) {
27
27
  return Stdlib_Option.mapOr(Message$ReventlessCore.serviceNameOfMsg(eventJson$p), Effect.succeed(), serviceName => {
28
28
  let isHandled = Stdlib_Option.isSome(Spec.incomingConnectExtensionEventHandlers[serviceName]) || Stdlib_Option.isSome(Spec.outgoingExtensionPointEventHandlers[serviceName]) || Stdlib_Option.isSome(Spec.outgoingExtensionEventHandlers[serviceName]) || Stdlib_Option.isSome(Spec.incomingExtensionEventHandlers[serviceName]);
29
29
  if (isHandled) {
30
- return Effect.zipRight(EffectLogger$ReventlessCore.logInfo(`Plugin(` + id + `)`, undefined, `incoming event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)), Effect.zipRight(handleEventEffect(eventJson$p, Spec.incomingConnectExtensionEventHandlers), Effect.map(Effect.all([
30
+ return Effect.zipRight(EffectLogger$ReventlessCore.logInfo(`Plugin(` + id + `)`, undefined, undefined, `incoming event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)), Effect.zipRight(handleEventEffect(eventJson$p, Spec.incomingConnectExtensionEventHandlers), Effect.map(Effect.all([
31
31
  handleEventEffect(eventJson$p, Spec.outgoingExtensionPointEventHandlers),
32
32
  handleEventEffect(eventJson$p, Spec.outgoingExtensionEventHandlers),
33
33
  handleEventEffect(eventJson$p, Spec.incomingExtensionEventHandlers)
@@ -40,7 +40,7 @@ function Make(Spec) {
40
40
  }
41
41
  warnedServices.contents = Belt_SetString.add(warnedServices.contents, serviceName);
42
42
  let known = knownServiceNames().join(", ");
43
- return EffectLogger$ReventlessCore.logWarn(`Plugin(` + id + `)`, undefined, `incoming event has service="` + serviceName + `" but no handler is registered for it — known services: [` + known + `]. Likely cause: an ExtensionPointMapping/Extension Delegate.name does not match the source's serviceName (DCB sources use "<plugin>DcbEventLog").`);
43
+ return EffectLogger$ReventlessCore.logWarn(`Plugin(` + id + `)`, undefined, undefined, `incoming event has service="` + serviceName + `" but no handler is registered for it — known services: [` + known + `]. Likely cause: an ExtensionPointMapping/Extension Delegate.name does not match the source's serviceName (DCB sources use "<plugin>DcbEventLog").`);
44
44
  }
45
45
  });
46
46
  }));
@@ -44,7 +44,7 @@ function Make(Spec) {
44
44
  ]
45
45
  ], 1000);
46
46
  if (jsons.length === 0) {
47
- return Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `ForwardCommand: Couldn't find Plugin with ExtensionPoint ` + extensionPointName));
47
+ return Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `ForwardCommand: Couldn't find Plugin with ExtensionPoint ` + extensionPointName));
48
48
  }
49
49
  let plugin = jsons[0];
50
50
  let exit = 0;
@@ -55,12 +55,12 @@ function Make(Spec) {
55
55
  } catch (raw_err) {
56
56
  let err = Primitive_exceptions.internalToException(raw_err);
57
57
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
58
- return Effect.runSync(EffectLogger$ReventlessCore.logError(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `ForwardCommand: Couldn't decode Plugin: ` + errMsg));
58
+ return Effect.runSync(EffectLogger$ReventlessCore.logError(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `ForwardCommand: Couldn't decode Plugin: ` + errMsg));
59
59
  }
60
60
  if (exit === 1) {
61
61
  let extensionPoint = plugin$1.extensionPoints.find(extensionPoint => extensionPoint.name === extensionPointName);
62
62
  if (extensionPoint === undefined) {
63
- return Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `ForwardCommand: Couldn't find ExtensionPoint ` + extensionPointName + ` in ` + plugin$1.name));
63
+ return Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `ForwardCommand: Couldn't find ExtensionPoint ` + extensionPointName + ` in ` + plugin$1.name));
64
64
  }
65
65
  let exit$1 = 0;
66
66
  let val;
@@ -70,10 +70,10 @@ function Make(Spec) {
70
70
  } catch (raw_err$1) {
71
71
  let err$1 = Primitive_exceptions.internalToException(raw_err$1);
72
72
  let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err$1), Stdlib_JsExn.message), "unknown");
73
- return Effect.runSync(EffectLogger$ReventlessCore.logError(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `ForwardCommand: Error on publish command: ` + errMsg$1));
73
+ return Effect.runSync(EffectLogger$ReventlessCore.logError(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `ForwardCommand: Error on publish command: ` + errMsg$1));
74
74
  }
75
75
  if (exit$1 === 2) {
76
- return Effect.runSync(EffectLogger$ReventlessCore.logInfo(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `ForwardCommand: published command to ` + plugin$1.name + ` ` + extensionPoint.commandTopic));
76
+ return Effect.runSync(EffectLogger$ReventlessCore.logInfo(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `ForwardCommand: published command to ` + plugin$1.name + ` ` + extensionPoint.commandTopic));
77
77
  }
78
78
  }
79
79
  };
@@ -164,7 +164,7 @@ function Make(Spec) {
164
164
  case "ConnectPlugin" :
165
165
  let pluginDefinition = cmd._0;
166
166
  let protocolErrors = pluginDefinition.extensionProtocols.flatMap(proto => Compat$ReventlessInterop.validateProtocol(CompatMatrix$ReventlessInterop.platformPlugin, proto.extensionPointName, proto.commandVersion, proto.eventVersion));
167
- let reportAction = protocolErrors.length !== 0 ? (Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, `Protocol version mismatch for plugin ` + pluginDefinition.id + `: ` + Stdlib_Option.getOr(JSON.stringify(protocolErrors), "[]"))), [{
167
+ let reportAction = protocolErrors.length !== 0 ? (Effect.runSync(EffectLogger$ReventlessCore.logWarn(PluginExtensionPointSpec$ReventlessInfra.name, undefined, undefined, `Protocol version mismatch for plugin ` + pluginDefinition.id + `: ` + Stdlib_Option.getOr(JSON.stringify(protocolErrors), "[]"))), [{
168
168
  TAG: "PublishCommand",
169
169
  _0: Plugin$ReventlessCore.name(id),
170
170
  _1: {
@@ -30,13 +30,13 @@ function Make(Spec) {
30
30
  let e = Primitive_exceptions.internalToException(raw_e);
31
31
  if (e.RE_EXN_ID === "JsExn") {
32
32
  let errMsg = Stdlib_Option.getOr(Stdlib_JsExn.message(e._1), "unknown");
33
- return Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, `Couldn't publish commands: ` + errMsg));
33
+ return Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, undefined, `Couldn't publish commands: ` + errMsg));
34
34
  }
35
35
  throw e;
36
36
  }
37
37
  };
38
38
  let toJsons = commandsToSend => {
39
- Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, `toJsons: commandsToSend: ` + commandsToSend.length.toString() + ` rest: ` + buffer.length.toString()));
39
+ Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, `toJsons: commandsToSend: ` + commandsToSend.length.toString() + ` rest: ` + buffer.length.toString()));
40
40
  return commandsToSend.map(param => {
41
41
  let commandJson = Message$ReventlessCore.encode(param[1], Spec.commandSchema);
42
42
  return {
@@ -67,13 +67,13 @@ function Make(Spec) {
67
67
  let e = Primitive_exceptions.internalToException(raw_e);
68
68
  if (e.RE_EXN_ID === "JsExn") {
69
69
  let errMsg = Stdlib_Option.getOr(Stdlib_JsExn.message(e._1), "unknown");
70
- Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, `send error: couldn't publish ` + size.toString() + ` commands: ` + errMsg));
70
+ Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, undefined, `send error: couldn't publish ` + size.toString() + ` commands: ` + errMsg));
71
71
  } else {
72
72
  throw e;
73
73
  }
74
74
  }
75
75
  if (exit === 1) {
76
- Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, `send: finished SendAllInOneChunk: ` + size.toString()));
76
+ Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, `send: finished SendAllInOneChunk: ` + size.toString()));
77
77
  }
78
78
  running.contents = undefined;
79
79
  return;
@@ -88,7 +88,7 @@ function Make(Spec) {
88
88
  let sizeStr = size$1.toString();
89
89
  let bufferSizeStr = buffer.length.toString();
90
90
  let chunkCountStr = chunkCount.contents.toString();
91
- Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, `send: bufferSize: ` + bufferSizeStr + `, chunk: ` + chunkCountStr + `, size: ` + sizeStr));
91
+ Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, `send: bufferSize: ` + bufferSizeStr + `, chunk: ` + chunkCountStr + `, size: ` + sizeStr));
92
92
  let commandsToSend$1 = buffer.slice(0, size$1);
93
93
  buffer.splice(0, size$1);
94
94
  let promise$1 = Config.publishCommands(Spec.name, toJsons(commandsToSend$1));
@@ -102,13 +102,13 @@ function Make(Spec) {
102
102
  let e$1 = Primitive_exceptions.internalToException(raw_e$1);
103
103
  if (e$1.RE_EXN_ID === "JsExn") {
104
104
  let errorMessage = Stdlib_Option.getOr(Stdlib_JsExn.message(e$1._1), "unknown Error");
105
- Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, `send error: couldn't publish chunk ` + chunkCountStr + ` (` + sizeStr + ` commands): ` + errorMessage));
105
+ Effect.runSync(EffectLogger$ReventlessCore.logError("CommandPublisher", undefined, undefined, `send error: couldn't publish chunk ` + chunkCountStr + ` (` + sizeStr + ` commands): ` + errorMessage));
106
106
  } else {
107
107
  throw e$1;
108
108
  }
109
109
  }
110
110
  if (exit$1 === 1) {
111
- Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, `send: finished chunk ` + chunkCountStr + `: ` + sizeStr));
111
+ Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, `send: finished chunk ` + chunkCountStr + `: ` + sizeStr));
112
112
  }
113
113
  return await send();
114
114
  };
@@ -128,12 +128,12 @@ function Make(Spec) {
128
128
  }
129
129
  };
130
130
  let clear = () => {
131
- Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, "clear"));
131
+ Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, "clear"));
132
132
  buffer.splice(0, buffer.length);
133
133
  flush.contents = false;
134
134
  };
135
135
  let flush$1 = async () => {
136
- Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, "flush"));
136
+ Effect.runSync(EffectLogger$ReventlessCore.logDebug("CommandPublisher", undefined, undefined, "flush"));
137
137
  flush.contents = true;
138
138
  return await send();
139
139
  };
@@ -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: explicit LOG_LEVEL wins, else the platform default.
77
- let _effectMin = (): effectLogLevel =>
78
- switch _envLogLevel {
79
- | Some("silent") => _llNone
80
- | Some("debug") => _llDebug
81
- | Some("info") => _llInfo
82
- | Some("warn") => _llWarning
83
- | Some("error") => _llError
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
- Logger.emit(
141
- ~level,
142
- ~comp=?comp.contents,
143
- ~plugin=?plugin.contents,
144
- ~detail=?detail.contents,
145
- ~annotations?,
146
- msg,
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.
@@ -152,29 +153,97 @@ install()
152
153
 
153
154
  // ─── Structured log helpers ──────────────────────────────────────────────────
154
155
  // Returns Effect.t<unit> — usable in Effect pipelines or with ->Effect.runSync.
156
+ // Run with ->Effect.runSync, a line is on a fiber of its own and loses what the
157
+ // invocation annotated (its correlationId, causationId, plugin): pass ~ids, the ids
158
+ // of the message the line is about, which ride on the log effect itself.
155
159
  //
156
- // ~comp / ~detail attach as Effect log annotations; install() reads them back.
160
+ // ~comp / ~detail / ~ids attach as Effect log annotations; install() reads them back.
157
161
  // ~detail: structured JSON shown only in a JSON sink (expandable on click);
158
162
  // the in-memory terminal output shows only the message line.
159
163
 
160
- // Attach comp/detail as annotations on the log effect. detail is stringified so
161
- // it rides through Effect's string-keyed annotation map; install() re-parses it.
162
- let _annotate = (eff, ~comp=?, ~detail=?) => {
163
- let eff = switch comp {
164
- | Some(c) => eff->Effect.annotateLogs("comp", c)
165
- | None => eff
164
+ /** The ids of the message a line is about, and of the entity it is handled for. Given on the
165
+ log call, they are annotations of the log effect itself, so they reach the line also when it
166
+ runs on a fiber of its own (`->Effect.runSync`), and they win over the same fields the
167
+ invocation annotated: one invocation can carry messages of several flows. */
168
+ type ids = {
169
+ msgId?: string,
170
+ correlationId?: string,
171
+ causationId?: string,
172
+ entityId?: string,
173
+ entityType?: string,
174
+ }
175
+
176
+ /** The ids of a message, from its meta; the entity when the caller knows it. */
177
+ let idsOf = (~entityId=?, ~entityType=?, meta: Message.meta): ids => {
178
+ msgId: meta.msgId,
179
+ correlationId: meta.correlationId,
180
+ causationId: ?meta.causationId,
181
+ ?entityId,
182
+ ?entityType,
183
+ }
184
+
185
+ /** The ids of the event a work item came from: an automation's or a translation's row. */
186
+ let idsOfSource = (source: Message.flowSource): ids => {
187
+ msgId: source.msgId,
188
+ correlationId: source.correlationId,
189
+ }
190
+
191
+ /** The ids of a message given as JSON, read from its `meta` without decoding the rest; none
192
+ when it has no meta. */
193
+ let idsOfJson = (json: JSON.t): option<ids> =>
194
+ switch json {
195
+ | JSON.Object(d) =>
196
+ switch d->Dict.get("meta") {
197
+ | Some(JSON.Object(m)) =>
198
+ let str = k =>
199
+ switch m->Dict.get(k) {
200
+ | Some(JSON.String(s)) if s != "" => Some(s)
201
+ | _ => None
202
+ }
203
+ Some({
204
+ msgId: ?str("msgId"),
205
+ correlationId: ?str("correlationId"),
206
+ causationId: ?str("causationId"),
207
+ })
208
+ | _ => None
209
+ }
210
+ | _ => None
166
211
  }
167
- switch detail {
168
- | Some(d) => eff->Effect.annotateLogs("detail", d->JSON.stringify)
212
+
213
+ // Attach comp/detail/ids as annotations on the log effect. detail is stringified
214
+ // so it rides through Effect's string-keyed annotation map; install() re-parses it.
215
+ let _annotate = (eff, ~comp=?, ~detail=?, ~ids: option<ids>=?) => {
216
+ let one = (eff, key, value) =>
217
+ switch value {
218
+ | Some(v) => eff->Effect.annotateLogs(key, v)
219
+ | None => eff
220
+ }
221
+ let eff = eff->one("comp", comp)->one("detail", detail->Option.map(d => d->JSON.stringify))
222
+ switch ids {
223
+ | Some(i) =>
224
+ eff
225
+ ->one("msgId", i.msgId)
226
+ ->one("correlationId", i.correlationId)
227
+ ->one("causationId", i.causationId)
228
+ ->one("entityId", i.entityId)
229
+ ->one("entityType", i.entityType)
169
230
  | None => eff
170
231
  }
171
232
  }
172
233
 
173
- let logInfo = (~comp=?, ~detail=?, msg) =>
174
- Effect.logInfo(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin())
175
- let logWarn = (~comp=?, ~detail=?, msg) =>
176
- Effect.logWarning(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin())
177
- let logError = (~comp=?, ~detail=?, msg) =>
178
- Effect.logError(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin())
179
- let logDebug = (~comp=?, ~detail=?, msg) =>
180
- Effect.logDebug(msg)->_annotate(~comp?, ~detail?)->_withMinimumLogLevel(_effectMin())
234
+ let logInfo = (~comp=?, ~detail=?, ~ids=?, msg) =>
235
+ Effect.logInfo(msg)
236
+ ->_annotate(~comp?, ~detail?, ~ids?)
237
+ ->_withMinimumLogLevel(_effectMin(~comp?, ()))
238
+ let logWarn = (~comp=?, ~detail=?, ~ids=?, msg) =>
239
+ Effect.logWarning(msg)
240
+ ->_annotate(~comp?, ~detail?, ~ids?)
241
+ ->_withMinimumLogLevel(_effectMin(~comp?, ()))
242
+ let logError = (~comp=?, ~detail=?, ~ids=?, msg) =>
243
+ Effect.logError(msg)
244
+ ->_annotate(~comp?, ~detail?, ~ids?)
245
+ ->_withMinimumLogLevel(_effectMin(~comp?, ()))
246
+ let logDebug = (~comp=?, ~detail=?, ~ids=?, msg) =>
247
+ Effect.logDebug(msg)
248
+ ->_annotate(~comp?, ~detail?, ~ids?)
249
+ ->_withMinimumLogLevel(_effectMin(~comp?, ()))
@@ -26,24 +26,12 @@ function _messageToString(msg) {
26
26
  }
27
27
  }
28
28
 
29
- function _effectMin() {
30
- let match = process.env.LOG_LEVEL;
31
- if (match !== undefined) {
32
- switch (match) {
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
- let match$1 = Logger$ReventlessCore.defaultMinLevel.contents;
46
- switch (match$1) {
34
+ switch (match) {
47
35
  case "Debug" :
48
36
  return LogLevel.Debug;
49
37
  case "Info" :
@@ -116,35 +104,86 @@ function install() {
116
104
  }
117
105
  });
118
106
  let annotations = Object.entries(extra).length === 0 ? undefined : extra;
119
- Logger$ReventlessCore.emit(level, comp.contents, plugin.contents, detail.contents, annotations, msg);
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
 
123
114
  install();
124
115
 
125
- function _annotate(eff, comp, detail) {
126
- let eff$1 = comp !== undefined ? Effect.annotateLogs(eff, "comp", comp) : eff;
127
- if (detail !== undefined) {
128
- return Effect.annotateLogs(eff$1, "detail", JSON.stringify(detail));
116
+ function idsOf(entityId, entityType, meta) {
117
+ return {
118
+ msgId: meta.msgId,
119
+ correlationId: meta.correlationId,
120
+ causationId: meta.causationId,
121
+ entityId: entityId,
122
+ entityType: entityType
123
+ };
124
+ }
125
+
126
+ function idsOfSource(source) {
127
+ return {
128
+ msgId: source.msgId,
129
+ correlationId: source.correlationId
130
+ };
131
+ }
132
+
133
+ function idsOfJson(json) {
134
+ if (typeof json !== "object" || json === null || Array.isArray(json)) {
135
+ return;
136
+ }
137
+ let match = json["meta"];
138
+ if (match === undefined) {
139
+ return;
140
+ }
141
+ if (typeof match !== "object" || match === null || Array.isArray(match)) {
142
+ return;
143
+ }
144
+ let str = k => {
145
+ let match$1 = match[k];
146
+ if (typeof match$1 === "string" && match$1 !== "") {
147
+ return match$1;
148
+ }
149
+ };
150
+ return {
151
+ msgId: str("msgId"),
152
+ correlationId: str("correlationId"),
153
+ causationId: str("causationId")
154
+ };
155
+ }
156
+
157
+ function _annotate(eff, comp, detail, ids) {
158
+ let one = (eff, key, value) => {
159
+ if (value !== undefined) {
160
+ return Effect.annotateLogs(eff, key, value);
161
+ } else {
162
+ return eff;
163
+ }
164
+ };
165
+ let eff$1 = one(one(eff, "comp", comp), "detail", Stdlib_Option.map(detail, d => JSON.stringify(d)));
166
+ if (ids !== undefined) {
167
+ return one(one(one(one(one(eff$1, "msgId", ids.msgId), "correlationId", ids.correlationId), "causationId", ids.causationId), "entityId", ids.entityId), "entityType", ids.entityType);
129
168
  } else {
130
169
  return eff$1;
131
170
  }
132
171
  }
133
172
 
134
- function logInfo(comp, detail, msg) {
135
- return Logger.withMinimumLogLevel(_annotate(Effect.logInfo(msg), comp, detail), _effectMin());
173
+ function logInfo(comp, detail, ids, msg) {
174
+ return Logger.withMinimumLogLevel(_annotate(Effect.logInfo(msg), comp, detail, ids), _effectMin(comp, undefined));
136
175
  }
137
176
 
138
- function logWarn(comp, detail, msg) {
139
- return Logger.withMinimumLogLevel(_annotate(Effect.logWarning(msg), comp, detail), _effectMin());
177
+ function logWarn(comp, detail, ids, msg) {
178
+ return Logger.withMinimumLogLevel(_annotate(Effect.logWarning(msg), comp, detail, ids), _effectMin(comp, undefined));
140
179
  }
141
180
 
142
- function logError(comp, detail, msg) {
143
- return Logger.withMinimumLogLevel(_annotate(Effect.logError(msg), comp, detail), _effectMin());
181
+ function logError(comp, detail, ids, msg) {
182
+ return Logger.withMinimumLogLevel(_annotate(Effect.logError(msg), comp, detail, ids), _effectMin(comp, undefined));
144
183
  }
145
184
 
146
- function logDebug(comp, detail, msg) {
147
- return Logger.withMinimumLogLevel(_annotate(Effect.logDebug(msg), comp, detail), _effectMin());
185
+ function logDebug(comp, detail, ids, msg) {
186
+ return Logger.withMinimumLogLevel(_annotate(Effect.logDebug(msg), comp, detail, ids), _effectMin(comp, undefined));
148
187
  }
149
188
 
150
189
  let setDefaultMinLevel = Logger$ReventlessCore.setDefaultMinLevel;
@@ -155,6 +194,9 @@ export {
155
194
  _effectMin,
156
195
  ordinalToLevel,
157
196
  install,
197
+ idsOf,
198
+ idsOfSource,
199
+ idsOfJson,
158
200
  _annotate,
159
201
  logInfo,
160
202
  logWarn,
@@ -45,7 +45,7 @@ function ftp(connectionParams, ftpAction) {
45
45
  readyTimeout: readyTimeout
46
46
  });
47
47
  SSH2.Client.onReady(client.on("end", () => {
48
- Effect.runSync(EffectLogger$ReventlessCore.logInfo("FTPHandler-ReventlessCore", undefined, "Client.onEnd"));
48
+ Effect.runSync(EffectLogger$ReventlessCore.logInfo("FTPHandler-ReventlessCore", undefined, undefined, "Client.onEnd"));
49
49
  resolve(result.contents);
50
50
  }).on("error", err => resolve({
51
51
  TAG: "Error",
@@ -74,8 +74,8 @@ function ftp(connectionParams, ftpAction) {
74
74
  let endFtp = () => {
75
75
  client.end();
76
76
  };
77
- sftp.on("end", () => Effect.runSync(EffectLogger$ReventlessCore.logInfo("FTPHandler-ReventlessCore", undefined, "end sftp stream"))).on("error", err => {
78
- Effect.runSync(EffectLogger$ReventlessCore.logError("FTPHandler-ReventlessCore", undefined, `Error: ` + Stdlib_Option.getOr(JSON.stringify(err), "unknown")));
77
+ sftp.on("end", () => Effect.runSync(EffectLogger$ReventlessCore.logInfo("FTPHandler-ReventlessCore", undefined, undefined, "end sftp stream"))).on("error", err => {
78
+ Effect.runSync(EffectLogger$ReventlessCore.logError("FTPHandler-ReventlessCore", undefined, undefined, `Error: ` + Stdlib_Option.getOr(JSON.stringify(err), "unknown")));
79
79
  client.emit("error", err);
80
80
  client.end();
81
81
  });
@@ -109,16 +109,16 @@ function ftp(connectionParams, ftpAction) {
109
109
  TAG: "Ok",
110
110
  _0: true
111
111
  };
112
- Effect.runSync(EffectLogger$ReventlessCore.logInfo("FTPHandler-ReventlessCore", undefined, "writable ended"));
112
+ Effect.runSync(EffectLogger$ReventlessCore.logInfo("FTPHandler-ReventlessCore", undefined, undefined, "writable ended"));
113
113
  }).on("close", () => {
114
114
  result.contents = {
115
115
  TAG: "Ok",
116
116
  _0: true
117
117
  };
118
- Effect.runSync(EffectLogger$ReventlessCore.logInfo("FTPHandler-ReventlessCore", undefined, "writable closed"));
118
+ Effect.runSync(EffectLogger$ReventlessCore.logInfo("FTPHandler-ReventlessCore", undefined, undefined, "writable closed"));
119
119
  client.end();
120
120
  }).on("error", err => {
121
- Effect.runSync(EffectLogger$ReventlessCore.logError("FTPHandler-ReventlessCore", undefined, `Error in Write Stream: ` + Stdlib_Option.getOr(Stdlib_JsExn.message(err), "unknown")));
121
+ Effect.runSync(EffectLogger$ReventlessCore.logError("FTPHandler-ReventlessCore", undefined, undefined, `Error in Write Stream: ` + Stdlib_Option.getOr(Stdlib_JsExn.message(err), "unknown")));
122
122
  let err$1 = new Error("FTPHandler: Error in Write Stream");
123
123
  sftp.emit("error", err$1);
124
124
  });