@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
@@ -27,19 +27,19 @@ function Make(MappingSpec) {
27
27
  if (mapOutgoingEvent$1 !== undefined) {
28
28
  return mapOutgoingEvent$1(eventJson$p, pluginDef);
29
29
  } else {
30
- Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, "mapOutgoingEvent: shouldn't be called, because Plugin EventCollector shouldn't subscribe to EventLog stream not having mapOutgoingEvent() !"));
30
+ Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, undefined, "mapOutgoingEvent: shouldn't be called, because Plugin EventCollector shouldn't subscribe to EventLog stream not having mapOutgoingEvent() !"));
31
31
  return [];
32
32
  }
33
33
  };
34
34
  let publishAggregateCommand = async (aggregateName, cmdJson) => {
35
- Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, `EP→` + aggregateName + `: ` + LogFormat$ReventlessCore.bold(Message$ReventlessCore.variantNameOfJson(cmdJson.commandJson)) + `(` + cmdJson.id + `)`));
35
+ Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, EffectLogger$ReventlessCore.idsOf(undefined, undefined, cmdJson.meta), `EP→` + aggregateName + `: ` + LogFormat$ReventlessCore.bold(Message$ReventlessCore.variantNameOfJson(cmdJson.commandJson)) + `(` + cmdJson.id + `)`));
36
36
  let pub = Stdlib_Option.getOrThrow(Ops.publishToAggregates[aggregateName], undefined);
37
37
  try {
38
38
  return await pub([cmdJson]);
39
39
  } catch (raw_err) {
40
40
  let err = Primitive_exceptions.internalToException(raw_err);
41
41
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
42
- return Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, `Error on publish command to aggregate ` + aggregateName + `: ` + errMsg));
42
+ return Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, undefined, `Error on publish command to aggregate ` + aggregateName + `: ` + errMsg));
43
43
  }
44
44
  };
45
45
  let publishPluginExtensionPointCommand = async cmdJson => {
@@ -48,7 +48,7 @@ function Make(MappingSpec) {
48
48
  } catch (raw_err) {
49
49
  let err = Primitive_exceptions.internalToException(raw_err);
50
50
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
51
- return Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, `Error on publish command to Plugin ExtensionPoint: ` + errMsg));
51
+ return Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, undefined, `Error on publish command to Plugin ExtensionPoint: ` + errMsg));
52
52
  }
53
53
  };
54
54
  let forwardCommand = (extensionPointName, commandJson) => {
@@ -72,7 +72,7 @@ function Make(MappingSpec) {
72
72
  } catch (raw_err) {
73
73
  let err = Primitive_exceptions.internalToException(raw_err);
74
74
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
75
- return Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, `Error on handling directive: ` + errMsg));
75
+ return Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, undefined, `Error on handling directive: ` + errMsg));
76
76
  }
77
77
  };
78
78
  let applyIncomingCommandAction = async action => {
@@ -115,14 +115,14 @@ function Make(MappingSpec) {
115
115
  if (Pii$Reventless.needsPrepare([eventJson$p])) {
116
116
  await Pii$Reventless.prepareOrThrow([eventJson$p]);
117
117
  }
118
- Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, `incoming EP event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
118
+ Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, EffectLogger$ReventlessCore.idsOfJson(eventJson$p), `incoming EP event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
119
119
  let event$p;
120
120
  try {
121
121
  event$p = Message$ReventlessCore.decodeEvent$p(eventJson$p, Id$Reventless.StringPure.schema, MappingSpec.eventSchema);
122
122
  } catch (raw_err) {
123
123
  let err = Primitive_exceptions.internalToException(raw_err);
124
124
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
125
- return Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, `Could not decode event': ` + JSON.stringify(eventJson$p) + ` ` + errMsg));
125
+ return Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, EffectLogger$ReventlessCore.idsOfJson(eventJson$p), `Could not decode event': ` + JSON.stringify(eventJson$p) + ` ` + errMsg));
126
126
  }
127
127
  let commandActions = mapIncomingEvent(event$p, pluginDef, Ops.queryEngine);
128
128
  let apply = async commandActions => await Util_Promise$ReventlessCore.toUnit(Promise.all(commandActions.map(applyIncomingCommandAction)));
@@ -132,7 +132,7 @@ function Make(MappingSpec) {
132
132
  if (Pii$Reventless.needsPrepare([eventJson$p])) {
133
133
  await Pii$Reventless.prepareOrThrow([eventJson$p]);
134
134
  }
135
- Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, `outgoing delegate event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
135
+ Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, EffectLogger$ReventlessCore.idsOfJson(eventJson$p), `outgoing delegate event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
136
136
  let commandActions = mapOutgoingEvent(eventJson$p, pluginDef);
137
137
  return await Util_Promise$ReventlessCore.toUnit(Promise.all(commandActions.map(applyOutgoingCommandAction)));
138
138
  };
@@ -35,7 +35,7 @@ function Make(Spec) {
35
35
  };
36
36
  }), param => {
37
37
  let errorResult = param[0];
38
- return Effect$1.map(EffectLogger$ReventlessCore.logError("ExtensionPoint", undefined, param[1]), () => errorResult);
38
+ return Effect$1.map(EffectLogger$ReventlessCore.logError("ExtensionPoint", undefined, undefined, param[1]), () => errorResult);
39
39
  });
40
40
  }
41
41
  let handler = action._1;
@@ -54,7 +54,7 @@ function Make(Spec) {
54
54
  _0: reference$1
55
55
  })), param => {
56
56
  let errorResult = param[0];
57
- return Effect$1.map(EffectLogger$ReventlessCore.logError("ExtensionPoint", undefined, param[1]), () => errorResult);
57
+ return Effect$1.map(EffectLogger$ReventlessCore.logError("ExtensionPoint", undefined, undefined, param[1]), () => errorResult);
58
58
  });
59
59
  };
60
60
  let handleIncomingCommands = stream => Effect$1.flatMap(Stream.runCollect(stream), topicItems => {
@@ -114,6 +114,7 @@ module Make = (
114
114
  | ReventlessInfra.ExtensionPointMapping.AbstractPublishEvent(id, meta, eventJson) =>
115
115
  EffectLogger.logInfo(
116
116
  ~comp=`ExtensionPoint(${MappingSpec.name})`,
117
+ ~ids=EffectLogger.idsOf(meta),
117
118
  `applying event: ${LogFormat.eventSummary(eventJson)}`,
118
119
  )->Effect.runSync
119
120
  await publishWithHooks(id, meta, eventJson)
@@ -138,6 +139,7 @@ module Make = (
138
139
  }
139
140
  EffectLogger.logInfo(
140
141
  ~comp=`ExtensionPoint(${MappingSpec.name})`,
142
+ ~ids=?EffectLogger.idsOfJson(eventJson'),
141
143
  `outgoing event: ${LogFormat.eventSummary(eventJson')}`,
142
144
  )->Effect.runSync
143
145
  let eventActions = mapOutgoingEvent(
@@ -25,7 +25,7 @@ function Make(MappingSpec) {
25
25
  if (mapOutgoingEvent$1 !== undefined) {
26
26
  return mapOutgoingEvent$1(eventJson$p, ScheduleOps$ReventlessCore.create(scheduler, queue, resourceNaming), ScheduleOps$ReventlessCore.$$delete(scheduler, queue, resourceNaming), queryEngine);
27
27
  } else {
28
- Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, "mapOutgoingEvent: shouldn't be called, because Plugin EventCollector shouldn't subscribe to EventLog stream not having mapOutgoingEvent() !"));
28
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, undefined, "mapOutgoingEvent: shouldn't be called, because Plugin EventCollector shouldn't subscribe to EventLog stream not having mapOutgoingEvent() !"));
29
29
  return [];
30
30
  }
31
31
  };
@@ -48,7 +48,7 @@ function Make(MappingSpec) {
48
48
  } catch (raw_err) {
49
49
  let err = Primitive_exceptions.internalToException(raw_err);
50
50
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
51
- Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `beforePublishHook error: ` + errMsg));
51
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, undefined, `beforePublishHook error: ` + errMsg));
52
52
  finalEventJson = eventJson;
53
53
  }
54
54
  } else {
@@ -59,7 +59,7 @@ function Make(MappingSpec) {
59
59
  } catch (raw_err$1) {
60
60
  let err$1 = Primitive_exceptions.internalToException(raw_err$1);
61
61
  let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err$1), Stdlib_JsExn.message), "unknown");
62
- Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `Error on publishToEventTopic command: ` + errMsg$1));
62
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, undefined, `Error on publishToEventTopic command: ` + errMsg$1));
63
63
  }
64
64
  let hook$1 = EventPublish_Callback$ReventlessCore.afterPublishHook.contents;
65
65
  if (hook$1 === undefined) {
@@ -80,15 +80,16 @@ function Make(MappingSpec) {
80
80
  } catch (raw_err$2) {
81
81
  let err$2 = Primitive_exceptions.internalToException(raw_err$2);
82
82
  let errMsg$2 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err$2), Stdlib_JsExn.message), "unknown");
83
- return Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `afterPublishHook error: ` + errMsg$2));
83
+ return Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, undefined, `afterPublishHook error: ` + errMsg$2));
84
84
  }
85
85
  };
86
86
  let applyEventAction = async action => {
87
87
  switch (action.TAG) {
88
88
  case "AbstractPublishEvent" :
89
89
  let eventJson = action._2;
90
- Effect.runSync(EffectLogger$ReventlessCore.logInfo(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `applying event: ` + LogFormat$ReventlessCore.eventSummary(eventJson)));
91
- return await publishWithHooks(action._0, action._1, eventJson);
90
+ let meta = action._1;
91
+ Effect.runSync(EffectLogger$ReventlessCore.logInfo(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, EffectLogger$ReventlessCore.idsOf(undefined, undefined, meta), `applying event: ` + LogFormat$ReventlessCore.eventSummary(eventJson)));
92
+ return await publishWithHooks(action._0, meta, eventJson);
92
93
  case "AbstractPublishEventAsync" :
93
94
  let match = await action._0;
94
95
  return await publishWithHooks(match[0], match[1], match[2]);
@@ -98,7 +99,7 @@ function Make(MappingSpec) {
98
99
  } catch (raw_err) {
99
100
  let err = Primitive_exceptions.internalToException(raw_err);
100
101
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
101
- return Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `Error on handling directive: ` + errMsg));
102
+ return Effect.runSync(EffectLogger$ReventlessCore.logError(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, undefined, `Error on handling directive: ` + errMsg));
102
103
  }
103
104
  }
104
105
  };
@@ -106,7 +107,7 @@ function Make(MappingSpec) {
106
107
  if (Pii$Reventless.needsPrepare([eventJson$p])) {
107
108
  await Pii$Reventless.prepareOrThrow([eventJson$p]);
108
109
  }
109
- Effect.runSync(EffectLogger$ReventlessCore.logInfo(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `outgoing event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
110
+ Effect.runSync(EffectLogger$ReventlessCore.logInfo(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, EffectLogger$ReventlessCore.idsOfJson(eventJson$p), `outgoing event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
110
111
  let eventActions = mapOutgoingEvent(eventJson$p, Mappings.mappings, Ops.scheduler, Ops.commandTopicResources, Ops.queryEngine, Ops.resourceNaming);
111
112
  return await Util_Promise$ReventlessCore.toUnit(Promise.all(eventActions.map(applyEventAction)));
112
113
  };
@@ -183,7 +183,7 @@ function Make(Spec) {
183
183
  };
184
184
  } catch (raw_exn) {
185
185
  let exn = Primitive_exceptions.internalToException(raw_exn);
186
- Effect.runSync(EffectLogger$ReventlessCore.logError(`InboundTranslationSlice(` + Spec.name + `)`, undefined, `failed to encode command: ` + messageOf(exn, "unknown")));
186
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`InboundTranslationSlice(` + Spec.name + `)`, undefined, undefined, `failed to encode command: ` + messageOf(exn, "unknown")));
187
187
  return {
188
188
  TAG: "Error",
189
189
  _0: "failed to encode command"
@@ -260,7 +260,7 @@ async function serve(slice, secretOfOpt, nowSecondsOpt, request) {
260
260
  return respond(await slice.refuse(request.body, "InvalidBody", "body is not JSON"));
261
261
  }
262
262
  }
263
- Effect.runSync(EffectLogger$ReventlessCore.logError(`InboundTranslationSlice(` + slice.route.slice + `)`, undefined, `webhook secret ` + signed._0 + ` is not set; refusing every request`));
263
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`InboundTranslationSlice(` + slice.route.slice + `)`, undefined, undefined, `webhook secret ` + signed._0 + ` is not set; refusing every request`));
264
264
  return plain(500, "webhook is not configured");
265
265
  }
266
266
 
@@ -177,7 +177,7 @@ module Make = (
177
177
  ->Option.getOr("")
178
178
  let (eventType, dataDict) = rawEvent->Message.splitMessage
179
179
  switch decoder.decode(~eventType, ~data=dataDict) {
180
- | Some(event) => [(sourceId, event)]
180
+ | Some(event) => [(sourceId, event, Message.metaOfEnvelope(envelope))]
181
181
  | None => []
182
182
  }
183
183
  },
@@ -189,7 +189,11 @@ module Make = (
189
189
  Effect.promise(
190
190
  async () => {
191
191
  // Phase 1: collect outbound items
192
- await Callback.phase1(eventsArr, ~capabilities=Capabilities.capabilities())
192
+ await Callback.phase1(
193
+ eventsArr->Array.map(((sourceId, event, _)) => (sourceId, event)),
194
+ ~metas=eventsArr->Array.map(((_, _, meta)) => meta),
195
+ ~capabilities=Capabilities.capabilities(),
196
+ )
193
197
  // Sync the post-phase-1 TODO state so consumers awaiting the
194
198
  // originating publishEvent observe Pending rows immediately.
195
199
  await syncToQueryDb(queryDbOps)
@@ -102,17 +102,21 @@ function Make(RuntimeEnvironment) {
102
102
  if (event !== undefined) {
103
103
  return [[
104
104
  sourceId,
105
- Primitive_option.valFromOption(event)
105
+ Primitive_option.valFromOption(event),
106
+ Message$ReventlessCore.metaOfEnvelope(envelope)
106
107
  ]];
107
108
  } else {
108
109
  return [];
109
110
  }
110
111
  })), events => Stream$1.fromIterable(events))), eventsArr => Effect.promise(async () => {
111
- await Callback.phase1(eventsArr, Capabilities.capabilities());
112
+ await Callback.phase1(eventsArr.map(param => [
113
+ param[0],
114
+ param[1]
115
+ ]), eventsArr.map(param => param[2]), Capabilities.capabilities());
112
116
  await syncToQueryDb(queryDbOps);
113
117
  Stdlib_Promise.$$catch(Callback.phase2(publishJsonsFn, Capabilities.capabilities()).then(() => syncToQueryDb(queryDbOps)), exn => {
114
118
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
115
- Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `detached phase 2 error: ` + errMsg));
119
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, undefined, `detached phase 2 error: ` + errMsg));
116
120
  return Promise.resolve();
117
121
  });
118
122
  }));
@@ -29,6 +29,9 @@ type todoRow = {
29
29
  decode — silently, since the restore swallows it per row. */
30
30
  maxRetries?: int,
31
31
  lastError?: string,
32
+ /** The event that created the row, so the command sent for it continues its
33
+ flow. Absent on rows written before it existed. */
34
+ source?: Message.flowSource,
32
35
  }
33
36
 
34
37
  /** The item schema seen through the `JSON.t` the row actually stores.
@@ -62,6 +65,7 @@ let todoRowSchemaFor = (itemSchema: S.t<'item>): S.t<todoRow> =>
62
65
  retryCount: s.matches(S.int),
63
66
  maxRetries: ?s.matches(S.option(S.int)),
64
67
  lastError: ?s.matches(S.option(S.string)),
68
+ source: ?s.matches(S.option(Message.flowSourceSchema)),
65
69
  })
66
70
 
67
71
  /**
@@ -81,6 +85,7 @@ runtime, as `undefined` destructured from a tuple that was never a tuple.
81
85
  */
82
86
  type phase1<'event> = (
83
87
  array<(string, 'event)>,
88
+ ~metas: array<option<Reventless.Message.meta>>=?,
84
89
  ~capabilities: Reventless.Capabilities.t,
85
90
  ) => promise<unit>
86
91
 
@@ -112,8 +117,9 @@ module type T = {
112
117
 
113
118
  /** Phase 1: update TODO list from a batch of `(sourceId, event)` pairs
114
119
  (collect only, no resolve). `sourceId` is the envelope id of the entity the
115
- event was published for. `~capabilities` supplies the key a personal item's
116
- row id is fingerprinted with. */
120
+ event was published for. `~metas`, by the same index, are the events' metas
121
+ where their envelopes had one: a row keeps its event's flow from them. `~capabilities` supplies the key a
122
+ personal item's row id is fingerprinted with. */
117
123
  let phase1: phase1<Spec.consumedEvent>
118
124
 
119
125
  /** Phase 2: translate all pending items, optionally publishing commands via publishJsons. */
@@ -131,10 +137,10 @@ module Make = (
131
137
 
132
138
  let now = () => Date.make()->Date.toISOString
133
139
 
134
- // Root meta for messages emitted by this OutboundTranslationSlice. Source-event
135
- // meta is not threaded from phase1 → phase2 today, so causation across the
136
- // translation hop is not preserved. If sources later carry meta into todoItems,
137
- // switch to Message.deriveMeta.
140
+ // Meta for a command emitted for a row: derived from the event that created
141
+ // the row, so the command continues its flow (its correlation id, the event's
142
+ // message id as causation, its user and trace parent). A row without a source
143
+ // (written before rows kept one, or given no meta) starts a new flow.
138
144
  //
139
145
  // `service` names the command's TARGET, matching what the API path does
140
146
  // (`CommandGenerator_Callback` passes `~serviceName=AggregateSpec.name`). It is
@@ -145,10 +151,13 @@ module Make = (
145
151
  // no error. Falls back to the slice's own name only when there is no target, in
146
152
  // which case the command goes to the plugin's DCB topic and nothing dispatches
147
153
  // on it.
148
- let makeMeta = (): Reventless.Message.meta =>
149
- Message.generateMeta(
150
- ~service=Spec.targetName->Option.getOr(`OutboundTranslationSlice:${Spec.name}`),
151
- )
154
+ let makeMeta = (row: todoRow): Reventless.Message.meta => {
155
+ let service = Spec.targetName->Option.getOr(`OutboundTranslationSlice:${Spec.name}`)
156
+ switch row.source {
157
+ | Some(source) => Message.deriveMetaFromSource(source, ~service)
158
+ | None => Message.generateMeta(~service)
159
+ }
160
+ }
152
161
 
153
162
  /** Record a failed attempt. The row is marked `Abandoned` at the moment the
154
163
  budget runs out rather than being left to fall out of the next pass's
@@ -184,7 +193,7 @@ module Make = (
184
193
  try {
185
194
  let msg: Reventless.Message.commandJson = {
186
195
  id: targetId,
187
- meta: makeMeta(),
196
+ meta: makeMeta(row),
188
197
  commandJson: cmd->Reventless.Util_Sury.toJson(Spec.inboundCommandSchema),
189
198
  }
190
199
  await publishJsons([msg])
@@ -194,6 +203,7 @@ module Make = (
194
203
  exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
195
204
  EffectLogger.logError(
196
205
  ~comp=`OutboundTranslationSlice(${Spec.name})`,
206
+ ~ids=?row.source->Option.map(EffectLogger.idsOfSource),
197
207
  `retries exhausted for ${id}, and the abandonment command could not be published: ${errMsg}`,
198
208
  )->Effect.runSync
199
209
  }
@@ -201,6 +211,7 @@ module Make = (
201
211
  | exception _ =>
202
212
  EffectLogger.logError(
203
213
  ~comp=`OutboundTranslationSlice(${Spec.name})`,
214
+ ~ids=?row.source->Option.map(EffectLogger.idsOfSource),
204
215
  `retries exhausted for ${id}, and its item could not be decoded to announce it`,
205
216
  )->Effect.runSync
206
217
  }
@@ -242,10 +253,13 @@ module Make = (
242
253
 
243
254
  let phase1 = async (
244
255
  events: array<(string, Spec.consumedEvent)>,
256
+ ~metas: array<option<Reventless.Message.meta>>=[],
245
257
  ~capabilities: Reventless.Capabilities.t,
246
258
  ) =>
247
259
  for i in 0 to events->Array.length - 1 {
248
260
  let (sourceId, event) = events->Array.getUnsafe(i)
261
+ let source =
262
+ metas->Array.get(i)->Option.flatMap(meta => meta)->Option.map(Message.flowSourceOf)
249
263
  // Collect new outbound items
250
264
  let collected = Translation.collect(event, ~sourceId)
251
265
  for j in 0 to collected->Array.length - 1 {
@@ -266,6 +280,7 @@ module Make = (
266
280
  | Error(e) =>
267
281
  EffectLogger.logError(
268
282
  ~comp=`OutboundTranslationSlice(${Spec.name})`,
283
+ ~ids=?source->Option.map(EffectLogger.idsOfSource),
269
284
  `a work item was not stored: ${e->Reventless.Pii.errorMessage}`,
270
285
  )->Effect.runSync
271
286
  | Ok(stored) =>
@@ -275,6 +290,7 @@ module Make = (
275
290
  createdAt: now(),
276
291
  retryCount: 0,
277
292
  maxRetries: Spec.maxRetries,
293
+ ?source,
278
294
  }
279
295
  todoItems->Dict.set(id, row)
280
296
  }
@@ -332,6 +348,7 @@ module Make = (
332
348
  | Error(#Gone(field)) =>
333
349
  EffectLogger.logInfo(
334
350
  ~comp=`OutboundTranslationSlice(${Spec.name})`,
351
+ ~ids=?row.source->Option.map(EffectLogger.idsOfSource),
335
352
  `${id}: its ${field} was erased; nothing to do`,
336
353
  )->Effect.runSync
337
354
  todoItems->Dict.set(id, {...row, status: Completed, completedAt: now()})
@@ -339,6 +356,7 @@ module Make = (
339
356
  | Error(#Unopened(why)) =>
340
357
  EffectLogger.logError(
341
358
  ~comp=`OutboundTranslationSlice(${Spec.name})`,
359
+ ~ids=?row.source->Option.map(EffectLogger.idsOfSource),
342
360
  `${id}: its work item does not open: ${why}`,
343
361
  )->Effect.runSync
344
362
  let updated = row->afterFailedAttempt(~lastError=why)
@@ -354,6 +372,7 @@ module Make = (
354
372
  exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
355
373
  EffectLogger.logError(
356
374
  ~comp=`OutboundTranslationSlice(${Spec.name})`,
375
+ ~ids=?row.source->Option.map(EffectLogger.idsOfSource),
357
376
  `failed to decode outboundItem: ${errMsg}`,
358
377
  )->Effect.runSync
359
378
  None
@@ -386,6 +405,7 @@ module Make = (
386
405
  exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
387
406
  EffectLogger.logError(
388
407
  ~comp=`OutboundTranslationSlice(${Spec.name})`,
408
+ ~ids=?row.source->Option.map(EffectLogger.idsOfSource),
389
409
  `failed to encode inbound command: ${errMsg}`,
390
410
  )->Effect.runSync
391
411
  None
@@ -396,7 +416,7 @@ module Make = (
396
416
  try {
397
417
  let msg: Reventless.Message.commandJson = {
398
418
  id: targetId,
399
- meta: makeMeta(),
419
+ meta: makeMeta(row),
400
420
  commandJson,
401
421
  }
402
422
  await publishJsons([msg])
@@ -407,6 +427,7 @@ module Make = (
407
427
  exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
408
428
  EffectLogger.logError(
409
429
  ~comp=`OutboundTranslationSlice(${Spec.name})`,
430
+ ~ids=?row.source->Option.map(EffectLogger.idsOfSource),
410
431
  `failed to publish command: ${errMsg}`,
411
432
  )->Effect.runSync
412
433
  let updated = row->afterFailedAttempt(~lastError=errMsg)
@@ -30,7 +30,8 @@ let todoRowSchema = Sury.$schema(s => ({
30
30
  completedAt: s.m(Sury.$option(Sury.string)),
31
31
  retryCount: s.m(Sury.int32),
32
32
  maxRetries: s.m(Sury.$option(Sury.int32)),
33
- lastError: s.m(Sury.$option(Sury.string))
33
+ lastError: s.m(Sury.$option(Sury.string)),
34
+ source: s.m(Sury.$option(Message$ReventlessCore.flowSourceSchema))
34
35
  }));
35
36
 
36
37
  function todoRowSchemaFor(itemSchema) {
@@ -42,14 +43,23 @@ function todoRowSchemaFor(itemSchema) {
42
43
  completedAt: s.m(Sury.$option(Sury.string)),
43
44
  retryCount: s.m(Sury.int32),
44
45
  maxRetries: s.m(Sury.$option(Sury.int32)),
45
- lastError: s.m(Sury.$option(Sury.string))
46
+ lastError: s.m(Sury.$option(Sury.string)),
47
+ source: s.m(Sury.$option(Message$ReventlessCore.flowSourceSchema))
46
48
  }));
47
49
  }
48
50
 
49
51
  function Make(Spec) {
50
52
  return Translation => {
51
53
  let todoItems = {};
52
- let makeMeta = () => Message$ReventlessCore.generateMeta(Stdlib_Option.getOr(Spec.targetName, `OutboundTranslationSlice:` + Spec.name), undefined, undefined, undefined, undefined, undefined, undefined);
54
+ let makeMeta = row => {
55
+ let service = Stdlib_Option.getOr(Spec.targetName, `OutboundTranslationSlice:` + Spec.name);
56
+ let source = row.source;
57
+ if (source !== undefined) {
58
+ return Message$ReventlessCore.deriveMetaFromSource(source, service);
59
+ } else {
60
+ return Message$ReventlessCore.generateMeta(service, undefined, undefined, undefined, undefined, undefined, undefined);
61
+ }
62
+ };
53
63
  let afterFailedAttempt = (row, lastError) => {
54
64
  let retryCount = row.retryCount + 1 | 0;
55
65
  let newrecord = {...row};
@@ -63,7 +73,7 @@ function Make(Spec) {
63
73
  try {
64
74
  item = Util_Sury$Reventless.fromJson(row.item, Spec.outboundItemSchema);
65
75
  } catch (exn) {
66
- return Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and its item could not be decoded to announce it`));
76
+ return Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `retries exhausted for ` + id + `, and its item could not be decoded to announce it`));
67
77
  }
68
78
  let match = Translation.onExhausted(id, item, row.lastError);
69
79
  if (match === undefined) {
@@ -71,7 +81,7 @@ function Make(Spec) {
71
81
  }
72
82
  try {
73
83
  let msg_id = match[0];
74
- let msg_meta = makeMeta();
84
+ let msg_meta = makeMeta(row);
75
85
  let msg_commandJson = Util_Sury$Reventless.toJson(match[1], Spec.inboundCommandSchema);
76
86
  let msg = {
77
87
  id: msg_id,
@@ -82,7 +92,7 @@ function Make(Spec) {
82
92
  } catch (raw_exn) {
83
93
  let exn$1 = Primitive_exceptions.internalToException(raw_exn);
84
94
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$1), Stdlib_JsExn.message), "unknown");
85
- return Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and the abandonment command could not be published: ` + errMsg));
95
+ return Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `retries exhausted for ` + id + `, and the abandonment command could not be published: ` + errMsg));
86
96
  }
87
97
  };
88
98
  let personalFields = Pii$Reventless.recordFields(Spec.outboundItemSchema);
@@ -100,19 +110,21 @@ function Make(Spec) {
100
110
  }
101
111
  let why = fingerprint._0._0;
102
112
  if (Pii$Reventless.Provider.isRequired()) {
103
- Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: its row id cannot be fingerprinted (` + why + `)`));
113
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, undefined, `a work item was not stored: its row id cannot be fingerprinted (` + why + `)`));
104
114
  return;
105
115
  } else {
106
116
  if (!warnedUnkeyed.contents) {
107
117
  warnedUnkeyed.contents = true;
108
- Effect.runSync(EffectLogger$ReventlessCore.logWarn(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `work items carrying personal data are keyed in the clear: no key to fingerprint them with (` + why + `)`));
118
+ Effect.runSync(EffectLogger$ReventlessCore.logWarn(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, undefined, `work items carrying personal data are keyed in the clear: no key to fingerprint them with (` + why + `)`));
109
119
  }
110
120
  return key;
111
121
  }
112
122
  };
113
- let phase1 = async (events, capabilities) => {
123
+ let phase1 = async (events, metasOpt, capabilities) => {
124
+ let metas = metasOpt !== undefined ? metasOpt : [];
114
125
  for (let i = 0, i_finish = events.length; i < i_finish; ++i) {
115
126
  let match = events[i];
127
+ let source = Stdlib_Option.map(Stdlib_Option.flatMap(metas[i], meta => meta), Message$ReventlessCore.flowSourceOf);
116
128
  let collected = Translation.collect(match[1], match[0]);
117
129
  for (let j = 0, j_finish = collected.length; j < j_finish; ++j) {
118
130
  let match$1 = collected[j];
@@ -133,11 +145,12 @@ function Make(Spec) {
133
145
  status: "Pending",
134
146
  createdAt: row_createdAt,
135
147
  retryCount: 0,
136
- maxRetries: row_maxRetries
148
+ maxRetries: row_maxRetries,
149
+ source: source
137
150
  };
138
151
  todoItems[id] = row;
139
152
  } else {
140
- Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: ` + Pii$Reventless.errorMessage(stored._0)));
153
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(source, EffectLogger$ReventlessCore.idsOfSource), `a work item was not stored: ` + Pii$Reventless.errorMessage(stored._0)));
141
154
  }
142
155
  }
143
156
  }
@@ -209,13 +222,13 @@ function Make(Spec) {
209
222
  } catch (raw_exn) {
210
223
  let exn = Primitive_exceptions.internalToException(raw_exn);
211
224
  let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
212
- Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `failed to decode outboundItem: ` + errMsg));
225
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to decode outboundItem: ` + errMsg));
213
226
  item = undefined;
214
227
  }
215
228
  } else {
216
229
  let match = opened._0;
217
230
  if (match.NAME === "Gone") {
218
- Effect.runSync(EffectLogger$ReventlessCore.logInfo(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, id + `: its ` + match.VAL + ` was erased; nothing to do`));
231
+ Effect.runSync(EffectLogger$ReventlessCore.logInfo(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), id + `: its ` + match.VAL + ` was erased; nothing to do`));
219
232
  let newrecord = {...row};
220
233
  newrecord.completedAt = new Date().toISOString();
221
234
  newrecord.status = "Completed";
@@ -223,7 +236,7 @@ function Make(Spec) {
223
236
  item = undefined;
224
237
  } else {
225
238
  let why = match.VAL;
226
- Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, id + `: its work item does not open: ` + why));
239
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), id + `: its work item does not open: ` + why));
227
240
  let updated = afterFailedAttempt(row, why);
228
241
  todoItems[id] = updated;
229
242
  if (updated.status === "Abandoned") {
@@ -259,13 +272,13 @@ function Make(Spec) {
259
272
  } catch (raw_exn$2) {
260
273
  let exn$2 = Primitive_exceptions.internalToException(raw_exn$2);
261
274
  let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$2), Stdlib_JsExn.message), "unknown");
262
- Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `failed to encode inbound command: ` + errMsg$1));
275
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to encode inbound command: ` + errMsg$1));
263
276
  commandJson = undefined;
264
277
  }
265
278
  if (commandJson !== undefined) {
266
279
  try {
267
280
  let msg_id = match$1[0];
268
- let msg_meta = makeMeta();
281
+ let msg_meta = makeMeta(row);
269
282
  let msg$1 = {
270
283
  id: msg_id,
271
284
  meta: msg_meta,
@@ -280,7 +293,7 @@ function Make(Spec) {
280
293
  } catch (raw_exn$3) {
281
294
  let exn$3 = Primitive_exceptions.internalToException(raw_exn$3);
282
295
  let errMsg$2 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$3), Stdlib_JsExn.message), "unknown");
283
- Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, `failed to publish command: ` + errMsg$2));
296
+ Effect.runSync(EffectLogger$ReventlessCore.logError(`OutboundTranslationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to publish command: ` + errMsg$2));
284
297
  let updated$1 = afterFailedAttempt(row, errMsg$2);
285
298
  todoItems[id] = updated$1;
286
299
  if (updated$1.status === "Abandoned") {
@@ -12,6 +12,11 @@ module Make = (
12
12
 
13
13
  let comp = `ReadModel(${ReadModelSpec.name})`
14
14
 
15
+ // Each row the events change is logged, and handed to whoever listens.
16
+ let onChange = ViewChange.reporter(~comp, ~view=ReadModelSpec.name, ~stateToJson=state =>
17
+ state->Reventless.Util_Sury.toJson(ReadModelSpec.stateSchema)
18
+ )
19
+
15
20
  let handleJsonEvents: EventCollector.jsonEventsHandler = stream =>
16
21
  stream
17
22
  ->Stream.runCollect
@@ -26,24 +31,40 @@ module Make = (
26
31
  let idxStr = (idx + 1)->Int.toString
27
32
  EffectLogger.logInfo(
28
33
  ~comp,
34
+ ~ids=EffectLogger.idsOf(context.meta, ~entityId=context.id, ~entityType=sourceName),
29
35
  ~detail=json,
30
36
  `handling event ${idxStr}/${total} from ${sourceName}: ${LogFormat.eventDetail(
31
37
  json,
32
38
  )} actions:${actionsStr}`,
33
39
  )->Effect.runSync
40
+ // The event each action came from, kept for the change it makes: the
41
+ // entity is the aggregate the event was published for.
42
+ let sources = [
43
+ ViewChange.sourceOf(~meta=context.meta, ~entityId=context.id, ~entityType=sourceName, ()),
44
+ ]
34
45
  // Rewritten here rather than at the apply below: a trail entry is
35
46
  // stamped with this envelope's own time.
36
47
  actions->Array.map(
37
- Projection.rewriteAction(_, ~at=context.meta.time, ReadModelSpec.stateSchema),
48
+ action => (
49
+ action->Projection.rewriteAction(~at=context.meta.time, ReadModelSpec.stateSchema),
50
+ sources,
51
+ ),
38
52
  )
39
53
  })
40
54
  ->Array.flat
41
- ->Array.reduce(Effect.succeed(), (acc, action) =>
55
+ ->Array.reduce(Effect.succeed(), (acc, (action, sources)) =>
42
56
  acc->Effect.flatMap(
43
57
  _ => {
44
58
  Effect.promise(
45
59
  () =>
46
- Projection.handleAction(~comp, action, Spec.operations, ReadModelSpec.subIdConfig),
60
+ Projection.handleAction(
61
+ ~comp,
62
+ ~sources,
63
+ ~onChange,
64
+ action,
65
+ Spec.operations,
66
+ ReadModelSpec.subIdConfig,
67
+ ),
47
68
  )->Effect.map(_ => ())
48
69
  },
49
70
  )