@reventlessdev/reventless-core 3.0.0-alpha.326 → 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.
- package/CHANGELOG.md +8 -0
- package/package.json +5 -5
- package/src/adapter/Runtime/AggregateRuntime_Builder_Common.res.mjs +5 -5
- package/src/adapter/Runtime/EventCollectorRuntime_Builder_Single.res.mjs +2 -2
- package/src/admin/Platform_Admin_Callback.res.mjs +1 -1
- package/src/components/Aggregate/Aggregate_Callback.res +88 -18
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +53 -32
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +1 -1
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +8 -0
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +16 -12
- package/src/components/CommandGenerator/CommandGenerator_Callback.res +47 -6
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +41 -4
- package/src/components/CommandTopic/CommandTopic_Callback.res.mjs +1 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res +9 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +7 -6
- package/src/components/CommandTopic/CommandTopic_Operations.res +2 -0
- package/src/components/CommandTopic/CommandTopic_Operations.res.mjs +2 -2
- package/src/components/Counter/Counter_Callback.res.mjs +3 -3
- package/src/components/Counter/Counter_Operations.res.mjs +4 -4
- package/src/components/DcbEventLog/DcbEventLog_Operations.res.mjs +3 -3
- package/src/components/EventLog/EventLog_Operations.res +1 -0
- package/src/components/EventLog/EventLog_Operations.res.mjs +3 -3
- package/src/components/EventMapper/EventMapper_Callback.res +4 -0
- package/src/components/EventMapper/EventMapper_Callback.res.mjs +13 -12
- package/src/components/EventTopic/EventTopic_Operations.res +2 -0
- package/src/components/EventTopic/EventTopic_Operations.res.mjs +2 -2
- package/src/components/Extension/Extension_Operations.res +4 -0
- package/src/components/Extension/Extension_Operations.res.mjs +8 -8
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res.mjs +2 -2
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res +2 -0
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res.mjs +9 -8
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +1 -1
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +8 -0
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +10 -10
- package/src/components/ReadModel/ReadModel_Callback.res +1 -0
- package/src/components/ReadModel/ReadModel_Callback.res.mjs +1 -1
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res +2 -0
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res.mjs +6 -6
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +36 -7
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +38 -20
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +2 -0
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +2 -2
- package/src/components/StateViewSlice/StateViewSlice_Callback.res +6 -0
- package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +3 -2
- package/src/plugin/component/Plugin_Callback.res.mjs +2 -2
- package/src/plugin/connect/PluginExtensionPoint_Plugin.res.mjs +6 -6
- package/src/util/CommandPublisher.res.mjs +9 -9
- package/src/util/EffectLogger.res +85 -17
- package/src/util/EffectLogger.res.mjs +63 -12
- package/src/util/FTPHandler.res.mjs +6 -6
- package/src/util/ScheduleOps.res.mjs +4 -4
- package/src/util/Util_AdapterRuntime.res.mjs +2 -2
- package/src/util/Util_Promise.res.mjs +1 -1
- package/src/util/Util_QueryDbRuntime.res.mjs +1 -1
- package/src/util/Validation.res.mjs +1 -1
- package/tests/commandgenerator/OwnerStampingTest.res +65 -0
- package/tests/commandgenerator/OwnerStampingTest.res.mjs +62 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res +25 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +28 -0
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +4 -4
- package/tests/logger/ComponentLineIdsTest.res +97 -0
- package/tests/logger/ComponentLineIdsTest.res.mjs +118 -0
- package/tests/logger/LogFormatTest.res.mjs +5 -5
- package/tests/logger/LoggerSinkTest.res.mjs +3 -3
|
@@ -56,13 +56,14 @@ function Make(Spec) {
|
|
|
56
56
|
let state = acc.state;
|
|
57
57
|
let meta = Message$ReventlessCore.deriveMeta(command$p.meta, undefined);
|
|
58
58
|
let id = Spec.Id.toString(command$p.id);
|
|
59
|
+
let ids = EffectLogger$ReventlessCore.idsOf(id, Spec.name, command$p.meta);
|
|
59
60
|
let cmdVariant = Message$ReventlessCore.variantNameOfJson(Message$ReventlessCore.encode(command$p.command, Spec.commandSchema));
|
|
60
61
|
let cmdName = LogFormat$ReventlessCore.bold(cmdVariant);
|
|
61
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, `deciding: id=` + id + ` seq=` + seq.toString() + ` cmd=` + cmdName));
|
|
62
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, ids, `deciding: id=` + id + ` seq=` + seq.toString() + ` cmd=` + cmdName));
|
|
62
63
|
let repeated = Message$ReventlessCore.hasStableMsgId(command$p.meta) && causes.includes(command$p.meta.msgId);
|
|
63
64
|
let refusal = repeated || !(actsOnOwned || ownedById) ? undefined : CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(command$p.meta.callerClaim, Owner$Reventless.streamOwners(owners, ownedById, id)), Spec.name, cmdVariant);
|
|
64
65
|
if (repeated) {
|
|
65
|
-
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, `repeat dropped: ` + cmdName + `(` + id + `) msgId=` + command$p.meta.msgId + ` already caused events`));
|
|
66
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, ids, `repeat dropped: ` + cmdName + `(` + id + `) msgId=` + command$p.meta.msgId + ` already caused events`));
|
|
66
67
|
return {
|
|
67
68
|
state: acc.state,
|
|
68
69
|
owners: acc.owners,
|
|
@@ -70,13 +71,14 @@ function Make(Spec) {
|
|
|
70
71
|
outcomes: outcomes.concat([[
|
|
71
72
|
reference,
|
|
72
73
|
"CmdRepeated",
|
|
73
|
-
meta
|
|
74
|
+
meta,
|
|
75
|
+
command$p.meta.causationId
|
|
74
76
|
]])
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
79
|
if (refusal !== undefined) {
|
|
78
80
|
let line = `refused: ` + refusal.rejected.errorDetail + ` id=` + id;
|
|
79
|
-
Effect.runSync(refusal.isDefect ? EffectLogger$ReventlessCore.logError(comp, undefined, line) : EffectLogger$ReventlessCore.logWarn(comp, undefined, line));
|
|
81
|
+
Effect.runSync(refusal.isDefect ? EffectLogger$ReventlessCore.logError(comp, undefined, undefined, line) : EffectLogger$ReventlessCore.logWarn(comp, undefined, ids, line));
|
|
80
82
|
return {
|
|
81
83
|
state: acc.state,
|
|
82
84
|
owners: acc.owners,
|
|
@@ -87,7 +89,8 @@ function Make(Spec) {
|
|
|
87
89
|
TAG: "CmdRefused",
|
|
88
90
|
_0: refusal
|
|
89
91
|
},
|
|
90
|
-
meta
|
|
92
|
+
meta,
|
|
93
|
+
command$p.meta.causationId
|
|
91
94
|
]])
|
|
92
95
|
};
|
|
93
96
|
}
|
|
@@ -105,7 +108,8 @@ function Make(Spec) {
|
|
|
105
108
|
TAG: "CmdOk",
|
|
106
109
|
_0: generatedEvents$1
|
|
107
110
|
},
|
|
108
|
-
meta
|
|
111
|
+
meta,
|
|
112
|
+
command$p.meta.causationId
|
|
109
113
|
]])
|
|
110
114
|
};
|
|
111
115
|
}
|
|
@@ -114,7 +118,7 @@ function Make(Spec) {
|
|
|
114
118
|
let match = Message$ReventlessCore.splitMessage(errorJson);
|
|
115
119
|
let payloadDict = match[1];
|
|
116
120
|
let errorDetail = Object.entries(payloadDict).length === 0 ? "" : JSON.stringify(payloadDict);
|
|
117
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, `decide rejected: ` + errorCode + ` ` + errorDetail + ` id=` + id));
|
|
121
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, ids, `decide rejected: ` + errorCode + ` ` + errorDetail + ` id=` + id));
|
|
118
122
|
return {
|
|
119
123
|
state: acc.state,
|
|
120
124
|
owners: acc.owners,
|
|
@@ -126,7 +130,8 @@ function Make(Spec) {
|
|
|
126
130
|
errorCode: errorCode,
|
|
127
131
|
errorDetail: errorDetail
|
|
128
132
|
},
|
|
129
|
-
meta
|
|
133
|
+
meta,
|
|
134
|
+
command$p.meta.causationId
|
|
130
135
|
]])
|
|
131
136
|
};
|
|
132
137
|
});
|
|
@@ -134,7 +139,7 @@ function Make(Spec) {
|
|
|
134
139
|
let resetCache = () => Lru$ReventlessCore.clear(replayCache);
|
|
135
140
|
let snapshotConfig = actsOnOwned ? undefined : Decision.snapshot;
|
|
136
141
|
if (actsOnOwned && Stdlib_Option.isSome(Decision.snapshot)) {
|
|
137
|
-
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, "snapshots disabled: this aggregate records an @owner, which a snapshot does not carry"));
|
|
142
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, undefined, "snapshots disabled: this aggregate records an @owner, which a snapshot does not carry"));
|
|
138
143
|
}
|
|
139
144
|
let stateSchemaHash = snapshotConfig !== undefined ? HashObject(Object.fromEntries([[
|
|
140
145
|
"state",
|
|
@@ -166,6 +171,21 @@ function Make(Spec) {
|
|
|
166
171
|
}
|
|
167
172
|
return Primitive_option.some(state);
|
|
168
173
|
};
|
|
174
|
+
let entityIds = idStr => ({
|
|
175
|
+
entityId: idStr,
|
|
176
|
+
entityType: Spec.name
|
|
177
|
+
});
|
|
178
|
+
let batchIds = (idStr, items) => {
|
|
179
|
+
let flows = items.map(i => i.command.meta.correlationId);
|
|
180
|
+
let f = flows[0];
|
|
181
|
+
let one = f !== undefined && flows.every(x => x === f) ? f : undefined;
|
|
182
|
+
return {
|
|
183
|
+
msgId: items.length === 1 ? Stdlib_Option.map(items[0], i => i.command.meta.msgId) : undefined,
|
|
184
|
+
correlationId: one,
|
|
185
|
+
entityId: idStr,
|
|
186
|
+
entityType: Spec.name
|
|
187
|
+
};
|
|
188
|
+
};
|
|
169
189
|
let coldReadState = id => {
|
|
170
190
|
let idStr = Spec.Id.toString(id);
|
|
171
191
|
let seedEffect = snapshotConfig !== undefined ? Effect.map(Effect.promise(() => Ops.eventLog.latestSnapshot(id)), snapResult => {
|
|
@@ -185,20 +205,20 @@ function Make(Spec) {
|
|
|
185
205
|
snap.seqNr
|
|
186
206
|
];
|
|
187
207
|
} else {
|
|
188
|
-
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `snapshot ignored (undecodable): id=` + idStr + `, seq=` + snap.seqNr.toString() + ` — full replay`));
|
|
208
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, entityIds(idStr), `snapshot ignored (undecodable): id=` + idStr + `, seq=` + snap.seqNr.toString() + ` — full replay`));
|
|
189
209
|
return [
|
|
190
210
|
Decision.initialState,
|
|
191
211
|
0
|
|
192
212
|
];
|
|
193
213
|
}
|
|
194
214
|
}
|
|
195
|
-
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `snapshot ignored (schema drift): id=` + idStr + `, seq=` + snap.seqNr.toString() + ` — full replay`));
|
|
215
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, entityIds(idStr), `snapshot ignored (schema drift): id=` + idStr + `, seq=` + snap.seqNr.toString() + ` — full replay`));
|
|
196
216
|
return [
|
|
197
217
|
Decision.initialState,
|
|
198
218
|
0
|
|
199
219
|
];
|
|
200
220
|
}
|
|
201
|
-
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `snapshot read failed (ignored): id=` + idStr + `: ` + snapResult._0 + ` — full replay`));
|
|
221
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, entityIds(idStr), `snapshot read failed (ignored): id=` + idStr + `: ` + snapResult._0 + ` — full replay`));
|
|
202
222
|
return [
|
|
203
223
|
Decision.initialState,
|
|
204
224
|
0
|
|
@@ -220,7 +240,7 @@ function Make(Spec) {
|
|
|
220
240
|
]), param => {
|
|
221
241
|
let n = param[1];
|
|
222
242
|
let detail = seedSeq > 0 ? `(snapshot@` + seedSeq.toString() + `, ` + (n - seedSeq | 0).toString() + ` delta event(s))` : n.toString() + ` event(s)`;
|
|
223
|
-
return EffectLogger$ReventlessCore.logInfo(comp, undefined, `replay: id=` + idStr + `, ` + detail);
|
|
243
|
+
return EffectLogger$ReventlessCore.logInfo(comp, undefined, entityIds(idStr), `replay: id=` + idStr + `, ` + detail);
|
|
224
244
|
});
|
|
225
245
|
});
|
|
226
246
|
};
|
|
@@ -240,7 +260,7 @@ function Make(Spec) {
|
|
|
240
260
|
recordEventOwners(param[2], ev$p.event),
|
|
241
261
|
c !== undefined && !causes.includes(c) ? causes.concat([c]) : causes
|
|
242
262
|
];
|
|
243
|
-
}), param => EffectLogger$ReventlessCore.logInfo(comp, undefined, `replay (with causes, for a stable-id command): id=` + idStr + `, ` + param[1].toString() + ` event(s)`));
|
|
263
|
+
}), param => EffectLogger$ReventlessCore.logInfo(comp, undefined, entityIds(idStr), `replay (with causes, for a stable-id command): id=` + idStr + `, ` + param[1].toString() + ` event(s)`));
|
|
244
264
|
};
|
|
245
265
|
let maybeWriteSnapshot = (id, idStr, oldSeq, newSeq, state) => {
|
|
246
266
|
if (snapshotConfig === undefined) {
|
|
@@ -259,29 +279,30 @@ function Make(Spec) {
|
|
|
259
279
|
};
|
|
260
280
|
Stdlib_Promise.$$catch(Ops.eventLog.writeSnapshot(id, snap).then(result => {
|
|
261
281
|
if (result.TAG === "Ok") {
|
|
262
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, `snapshot written: id=` + idStr + `, seq=` + snap.seqNr.toString()));
|
|
282
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, entityIds(idStr), `snapshot written: id=` + idStr + `, seq=` + snap.seqNr.toString()));
|
|
263
283
|
} else {
|
|
264
|
-
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `snapshot write failed (ignored): id=` + idStr + `: ` + result._0));
|
|
284
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, entityIds(idStr), `snapshot write failed (ignored): id=` + idStr + `: ` + result._0));
|
|
265
285
|
}
|
|
266
286
|
return Promise.resolve();
|
|
267
287
|
}), err => {
|
|
268
288
|
let msg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message), "unknown");
|
|
269
|
-
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `snapshot write threw (ignored): id=` + idStr + `: ` + msg));
|
|
289
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, entityIds(idStr), `snapshot write threw (ignored): id=` + idStr + `: ` + msg));
|
|
270
290
|
return Promise.resolve();
|
|
271
291
|
});
|
|
272
292
|
return;
|
|
273
293
|
} else {
|
|
274
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `snapshot skipped (state not serializable): id=` + idStr + `, seq=` + newSeq.toString()));
|
|
294
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, entityIds(idStr), `snapshot skipped (state not serializable): id=` + idStr + `, seq=` + newSeq.toString()));
|
|
275
295
|
}
|
|
276
296
|
};
|
|
277
297
|
let reportFinalOutcomes = (outcomes, entityId, appendSucceeded, appendedEventCount, appendErrorDetailOpt) => {
|
|
278
298
|
let appendErrorDetail = appendErrorDetailOpt !== undefined ? appendErrorDetailOpt : "";
|
|
279
299
|
return outcomes.map(param => {
|
|
300
|
+
let causedBy = param[3];
|
|
280
301
|
let meta = param[2];
|
|
281
302
|
let outcome = param[1];
|
|
282
303
|
let reference = param[0];
|
|
283
304
|
if (typeof outcome !== "object") {
|
|
284
|
-
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, meta.correlationId, reference, {
|
|
305
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, meta.correlationId, causedBy, reference, {
|
|
285
306
|
entityId: entityId,
|
|
286
307
|
eventCount: 0
|
|
287
308
|
});
|
|
@@ -293,7 +314,7 @@ function Make(Spec) {
|
|
|
293
314
|
switch (outcome.TAG) {
|
|
294
315
|
case "CmdOk" :
|
|
295
316
|
if (appendSucceeded) {
|
|
296
|
-
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, meta.correlationId, reference, {
|
|
317
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, meta.correlationId, causedBy, reference, {
|
|
297
318
|
entityId: entityId,
|
|
298
319
|
eventCount: appendedEventCount
|
|
299
320
|
});
|
|
@@ -302,7 +323,7 @@ function Make(Spec) {
|
|
|
302
323
|
_0: reference
|
|
303
324
|
};
|
|
304
325
|
} else {
|
|
305
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", meta.correlationId, reference, {
|
|
326
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", meta.correlationId, causedBy, reference, {
|
|
306
327
|
errorCode: CommandOutcome$Reventless.code("AppendFailed"),
|
|
307
328
|
errorDetail: appendErrorDetail
|
|
308
329
|
});
|
|
@@ -312,7 +333,7 @@ function Make(Spec) {
|
|
|
312
333
|
};
|
|
313
334
|
}
|
|
314
335
|
case "CmdRejected" :
|
|
315
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "DomainRejection", meta.correlationId, reference, {
|
|
336
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "DomainRejection", meta.correlationId, causedBy, reference, {
|
|
316
337
|
errorCode: outcome.errorCode,
|
|
317
338
|
errorDetail: outcome.errorDetail
|
|
318
339
|
});
|
|
@@ -321,7 +342,7 @@ function Make(Spec) {
|
|
|
321
342
|
_0: reference
|
|
322
343
|
};
|
|
323
344
|
case "CmdRefused" :
|
|
324
|
-
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "AccessRefusal", meta.correlationId, reference, outcome._0.rejected);
|
|
345
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "AccessRefusal", meta.correlationId, causedBy, reference, outcome._0.rejected);
|
|
325
346
|
return {
|
|
326
347
|
TAG: "Ok",
|
|
327
348
|
_0: reference
|
|
@@ -341,7 +362,7 @@ function Make(Spec) {
|
|
|
341
362
|
let owners = match[2];
|
|
342
363
|
let seqNr = match[1];
|
|
343
364
|
let state = match[0];
|
|
344
|
-
readState = Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, `replay skipped (cached): id=` + idStr + `, seq=` + seqNr.toString()), () => [
|
|
365
|
+
readState = Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, batchIds(idStr, topicItemsForId), `replay skipped (cached): id=` + idStr + `, seq=` + seqNr.toString()), () => [
|
|
345
366
|
state,
|
|
346
367
|
seqNr,
|
|
347
368
|
owners,
|
|
@@ -393,7 +414,7 @@ function Make(Spec) {
|
|
|
393
414
|
return name + `(` + id + LogFormat$ReventlessCore.variantFields(json) + `)`;
|
|
394
415
|
}).join(", ");
|
|
395
416
|
let eventJsons = eventsToAppend.map(event$p => Message$ReventlessCore.encode(event$p.event, Spec.eventSchema));
|
|
396
|
-
return Effect.flatMap(Effect.flatMap(EffectLogger$ReventlessCore.logInfo(comp, eventJsons, `produced ` + eventCount + ` event(s): [` + eventDetails + `]`), () => Effect.promise(() => Ops.eventLog.append(sequenceNr, id, eventsToAppend))), appendResult => {
|
|
417
|
+
return Effect.flatMap(Effect.flatMap(EffectLogger$ReventlessCore.logInfo(comp, eventJsons, batchIds(idStr, topicItemsForId), `produced ` + eventCount + ` event(s): [` + eventDetails + `]`), () => Effect.promise(() => Ops.eventLog.append(sequenceNr, id, eventsToAppend))), appendResult => {
|
|
397
418
|
if (appendResult.TAG === "Ok") {
|
|
398
419
|
let newSeq = sequenceNr + eventsToAppend.length | 0;
|
|
399
420
|
Lru$ReventlessCore.put(replayCache, idStr, [
|
|
@@ -403,7 +424,7 @@ function Make(Spec) {
|
|
|
403
424
|
]);
|
|
404
425
|
maybeWriteSnapshot(id, idStr, sequenceNr, newSeq, finalState);
|
|
405
426
|
let perRef = reportFinalOutcomes(outcomes, idStr, true, eventsToAppend.length, undefined);
|
|
406
|
-
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, `append: id=` + idStr), () => ({
|
|
427
|
+
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, batchIds(idStr, topicItemsForId), `append: id=` + idStr), () => ({
|
|
407
428
|
TAG: "Ok",
|
|
408
429
|
_0: perRef
|
|
409
430
|
}));
|
|
@@ -411,7 +432,7 @@ function Make(Spec) {
|
|
|
411
432
|
let msg = appendResult._0;
|
|
412
433
|
if (typeof msg !== "object") {
|
|
413
434
|
Lru$ReventlessCore.invalidate(replayCache, idStr);
|
|
414
|
-
return Effect.map(EffectLogger$ReventlessCore.logWarn(comp, undefined, `conflict: id=` + idStr + `, will retry`), () => ({
|
|
435
|
+
return Effect.map(EffectLogger$ReventlessCore.logWarn(comp, undefined, batchIds(idStr, topicItemsForId), `conflict: id=` + idStr + `, will retry`), () => ({
|
|
415
436
|
TAG: "Error",
|
|
416
437
|
_0: "conflict"
|
|
417
438
|
}));
|
|
@@ -419,7 +440,7 @@ function Make(Spec) {
|
|
|
419
440
|
let msg$1 = msg._0;
|
|
420
441
|
Lru$ReventlessCore.invalidate(replayCache, idStr);
|
|
421
442
|
let perRef$1 = reportFinalOutcomes(outcomes, idStr, false, 0, msg$1);
|
|
422
|
-
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, `append failed: id=` + idStr + `: ` + msg$1), () => ({
|
|
443
|
+
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, batchIds(idStr, topicItemsForId), `append failed: id=` + idStr + `: ` + msg$1), () => ({
|
|
423
444
|
TAG: "Ok",
|
|
424
445
|
_0: perRef$1
|
|
425
446
|
}));
|
|
@@ -431,7 +452,7 @@ function Make(Spec) {
|
|
|
431
452
|
initialOwners
|
|
432
453
|
]);
|
|
433
454
|
let perRef = reportFinalOutcomes(outcomes, idStr, true, 0, undefined);
|
|
434
|
-
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, `no events produced: id=` + idStr), () => ({
|
|
455
|
+
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, batchIds(idStr, topicItemsForId), `no events produced: id=` + idStr), () => ({
|
|
435
456
|
TAG: "Ok",
|
|
436
457
|
_0: perRef
|
|
437
458
|
}));
|
|
@@ -445,7 +466,7 @@ function Make(Spec) {
|
|
|
445
466
|
let count = cmdJsons.length.toString();
|
|
446
467
|
cmdJsons.forEach((cmdJson, idx) => {
|
|
447
468
|
let idxStr = (idx + 1 | 0).toString();
|
|
448
|
-
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, cmdJson.commandJson, `handling command ` + idxStr + `/` + count + `: ` + LogFormat$ReventlessCore.cmdDetail(cmdJson)));
|
|
469
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, cmdJson.commandJson, EffectLogger$ReventlessCore.idsOf(idStr, Spec.name, cmdJson.meta), `handling command ` + idxStr + `/` + count + `: ` + LogFormat$ReventlessCore.cmdDetail(cmdJson)));
|
|
449
470
|
});
|
|
450
471
|
let references = topicItemsForId.map(item => item.reference);
|
|
451
472
|
let attempt = retryCount => Effect.flatMap(replayProcessAppend(id, topicItemsForId), result => {
|
|
@@ -454,10 +475,10 @@ function Make(Spec) {
|
|
|
454
475
|
}
|
|
455
476
|
let msg = result._0;
|
|
456
477
|
if (retryCount < 3) {
|
|
457
|
-
return Effect.flatMap(EffectLogger$ReventlessCore.logWarn(comp, undefined, `conflict retry id=` + idStr + ` ` + (retryCount + 1 | 0).toString() + `/` + (3).toString()), () => attempt(retryCount + 1 | 0));
|
|
478
|
+
return Effect.flatMap(EffectLogger$ReventlessCore.logWarn(comp, undefined, batchIds(idStr, topicItemsForId), `conflict retry id=` + idStr + ` ` + (retryCount + 1 | 0).toString() + `/` + (3).toString()), () => attempt(retryCount + 1 | 0));
|
|
458
479
|
}
|
|
459
480
|
let detail = `concurrent modification (` + (3).toString() + ` retries exhausted): ` + msg;
|
|
460
|
-
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, `max conflict retries exhausted id=` + idStr + `: ` + msg), () => references.map(param => ({
|
|
481
|
+
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, batchIds(idStr, topicItemsForId), `max conflict retries exhausted id=` + idStr + `: ` + msg), () => references.map(param => ({
|
|
461
482
|
TAG: "Error",
|
|
462
483
|
_0: detail
|
|
463
484
|
})));
|
|
@@ -140,7 +140,7 @@ function Make(RuntimeEnvironment) {
|
|
|
140
140
|
}
|
|
141
141
|
Stdlib_Promise.$$catch(Callback.phase2(publishJsonsFn).then(() => syncToQueryDb(queryDbOps)), exn => {
|
|
142
142
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
143
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `detached phase 2 error: ` + errMsg));
|
|
143
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, undefined, `detached phase 2 error: ` + errMsg));
|
|
144
144
|
return Promise.resolve();
|
|
145
145
|
});
|
|
146
146
|
}));
|
|
@@ -307,6 +307,7 @@ module Make = (
|
|
|
307
307
|
| exception _ =>
|
|
308
308
|
EffectLogger.logError(
|
|
309
309
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
310
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
310
311
|
`retries exhausted for ${id}, and the abandonment command could not be encoded`,
|
|
311
312
|
)->Effect.runSync
|
|
312
313
|
None
|
|
@@ -316,6 +317,7 @@ module Make = (
|
|
|
316
317
|
| Unopened(_) =>
|
|
317
318
|
EffectLogger.logError(
|
|
318
319
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
320
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
319
321
|
`retries exhausted for ${id}, and its item could not be decoded to announce it`,
|
|
320
322
|
)->Effect.runSync
|
|
321
323
|
None
|
|
@@ -345,6 +347,7 @@ module Make = (
|
|
|
345
347
|
| Error(why) =>
|
|
346
348
|
EffectLogger.logError(
|
|
347
349
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
350
|
+
~ids=?source->Option.map(EffectLogger.idsOfSource),
|
|
348
351
|
`a work item was not stored: ${why}`,
|
|
349
352
|
)->Effect.runSync
|
|
350
353
|
| Ok(stored) =>
|
|
@@ -381,6 +384,7 @@ module Make = (
|
|
|
381
384
|
if !readsClock {
|
|
382
385
|
EffectLogger.logError(
|
|
383
386
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
387
|
+
~ids={msgId: setBy},
|
|
384
388
|
`a mapping changed a schedule, but no mapping reads the Clock, so no tick would reach the slice; the change is skipped`,
|
|
385
389
|
)->Effect.runSync
|
|
386
390
|
} else {
|
|
@@ -390,6 +394,7 @@ module Make = (
|
|
|
390
394
|
| Error(message) =>
|
|
391
395
|
EffectLogger.logError(
|
|
392
396
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
397
|
+
~ids={msgId: setBy},
|
|
393
398
|
`${message}; the change is skipped`,
|
|
394
399
|
)->Effect.runSync
|
|
395
400
|
}
|
|
@@ -503,12 +508,14 @@ module Make = (
|
|
|
503
508
|
| Gone(field) =>
|
|
504
509
|
EffectLogger.logInfo(
|
|
505
510
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
511
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
506
512
|
`${id}: its ${field} was erased; nothing to do`,
|
|
507
513
|
)->Effect.runSync
|
|
508
514
|
todoItems->Dict.set(id, {...row, status: Completed, completedAt: now()})
|
|
509
515
|
| Unopened(errMsg) =>
|
|
510
516
|
EffectLogger.logError(
|
|
511
517
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
518
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
512
519
|
`failed to decode todoItem: ${errMsg}`,
|
|
513
520
|
)->Effect.runSync
|
|
514
521
|
| Open({key, item}) =>
|
|
@@ -523,6 +530,7 @@ module Make = (
|
|
|
523
530
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
|
|
524
531
|
EffectLogger.logError(
|
|
525
532
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
533
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
526
534
|
`failed to encode command: ${errMsg}`,
|
|
527
535
|
)->Effect.runSync
|
|
528
536
|
let updated = row->afterFailedAttempt
|
|
@@ -110,12 +110,12 @@ function Make(Spec) {
|
|
|
110
110
|
}
|
|
111
111
|
let why = fingerprint._0._0;
|
|
112
112
|
if (Pii$Reventless.Provider.isRequired()) {
|
|
113
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: its row id cannot be fingerprinted (` + why + `)`));
|
|
113
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, undefined, `a work item was not stored: its row id cannot be fingerprinted (` + why + `)`));
|
|
114
114
|
return;
|
|
115
115
|
} else {
|
|
116
116
|
if (!warnedUnkeyed.contents) {
|
|
117
117
|
warnedUnkeyed.contents = true;
|
|
118
|
-
Effect.runSync(EffectLogger$ReventlessCore.logWarn(`AutomationSlice(` + 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(`AutomationSlice(` + Spec.name + `)`, undefined, undefined, `work items carrying personal data are keyed in the clear: no key to fingerprint them with (` + why + `)`));
|
|
119
119
|
}
|
|
120
120
|
return key;
|
|
121
121
|
}
|
|
@@ -203,7 +203,7 @@ function Make(Spec) {
|
|
|
203
203
|
try {
|
|
204
204
|
commandJson = Util_Sury$Reventless.toJson(param[1], Spec.commandSchema);
|
|
205
205
|
} catch (exn) {
|
|
206
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and the abandonment command could not be encoded`));
|
|
206
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `retries exhausted for ` + id + `, and the abandonment command could not be encoded`));
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
209
|
return {
|
|
@@ -215,7 +215,7 @@ function Make(Spec) {
|
|
|
215
215
|
case "Gone" :
|
|
216
216
|
return;
|
|
217
217
|
case "Unopened" :
|
|
218
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and its item could not be decoded to announce it`));
|
|
218
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + 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`));
|
|
219
219
|
return;
|
|
220
220
|
}
|
|
221
221
|
};
|
|
@@ -250,7 +250,7 @@ function Make(Spec) {
|
|
|
250
250
|
};
|
|
251
251
|
todoItems[id] = row;
|
|
252
252
|
} else {
|
|
253
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: ` + why._0));
|
|
253
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(source, EffectLogger$ReventlessCore.idsOfSource), `a work item was not stored: ` + why._0));
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
}
|
|
@@ -265,14 +265,18 @@ function Make(Spec) {
|
|
|
265
265
|
routed.forEach(r => {
|
|
266
266
|
r.rescheduled.forEach(change => {
|
|
267
267
|
if (!readsClock) {
|
|
268
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined,
|
|
268
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, {
|
|
269
|
+
msgId: setBy
|
|
270
|
+
}, `a mapping changed a schedule, but no mapping reads the Clock, so no tick would reach the slice; the change is skipped`));
|
|
269
271
|
}
|
|
270
272
|
let platformChange = AutomationSlice_Schedules$ReventlessCore.apply(schedules, change, setBy, recordedAt);
|
|
271
273
|
if (platformChange.TAG === "Ok") {
|
|
272
274
|
scheduleChanges.contents = scheduleChanges.contents.concat([platformChange._0]);
|
|
273
275
|
return;
|
|
274
276
|
} else {
|
|
275
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined,
|
|
277
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, {
|
|
278
|
+
msgId: setBy
|
|
279
|
+
}, platformChange._0 + `; the change is skipped`));
|
|
276
280
|
}
|
|
277
281
|
});
|
|
278
282
|
});
|
|
@@ -387,7 +391,7 @@ function Make(Spec) {
|
|
|
387
391
|
} catch (raw_exn) {
|
|
388
392
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
389
393
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
390
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to encode command: ` + errMsg));
|
|
394
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to encode command: ` + errMsg));
|
|
391
395
|
let updated = afterFailedAttempt(row);
|
|
392
396
|
todoItems[id] = updated;
|
|
393
397
|
if (updated.status === "Abandoned") {
|
|
@@ -407,14 +411,14 @@ function Make(Spec) {
|
|
|
407
411
|
}
|
|
408
412
|
break;
|
|
409
413
|
case "Gone" :
|
|
410
|
-
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`AutomationSlice(` + Spec.name + `)`, undefined, id + `: its ` + field._0 + ` was erased; nothing to do`));
|
|
414
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`AutomationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), id + `: its ` + field._0 + ` was erased; nothing to do`));
|
|
411
415
|
let newrecord$1 = {...row};
|
|
412
416
|
newrecord$1.completedAt = new Date().toISOString();
|
|
413
417
|
newrecord$1.status = "Completed";
|
|
414
418
|
todoItems[id] = newrecord$1;
|
|
415
419
|
break;
|
|
416
420
|
case "Unopened" :
|
|
417
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to decode todoItem: ` + field._0));
|
|
421
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to decode todoItem: ` + field._0));
|
|
418
422
|
break;
|
|
419
423
|
}
|
|
420
424
|
}
|
|
@@ -424,7 +428,7 @@ function Make(Spec) {
|
|
|
424
428
|
} catch (raw_exn$1) {
|
|
425
429
|
let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
|
|
426
430
|
let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$1), Stdlib_JsExn.message), "unknown");
|
|
427
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to publish commands: ` + errMsg$1));
|
|
431
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, undefined, `failed to publish commands: ` + errMsg$1));
|
|
428
432
|
pending.forEach(param => {
|
|
429
433
|
let id = param[0];
|
|
430
434
|
let current = todoItems[id];
|
|
@@ -462,7 +466,7 @@ function Make(Spec) {
|
|
|
462
466
|
} catch (raw_exn$2) {
|
|
463
467
|
let exn$2 = Primitive_exceptions.internalToException(raw_exn$2);
|
|
464
468
|
let errMsg$2 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$2), Stdlib_JsExn.message), "unknown");
|
|
465
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to publish abandonment commands: ` + errMsg$2));
|
|
469
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, undefined, `failed to publish abandonment commands: ` + errMsg$2));
|
|
466
470
|
}
|
|
467
471
|
};
|
|
468
472
|
return {
|
|
@@ -115,6 +115,28 @@ let makeGenerateCommand = (
|
|
|
115
115
|
// The handling slice's partition; the envelope id is its value on the command.
|
|
116
116
|
~partitionTag: option<Reventless.DcbTag.derivedPartitionTag>=?,
|
|
117
117
|
): CommandGenerator.commandGenerator => {
|
|
118
|
+
// A command refused before its handler ran: one warning with its ids, and, when the caller
|
|
119
|
+
// may not act, the outcome a handler would have reported. A payload that cannot be decoded
|
|
120
|
+
// is the caller's mistake, not a refusal of access, and reaches no outcome listener.
|
|
121
|
+
let refusedBeforeHandler = (~meta: Message.meta, ~reason: string, ~access: bool) => {
|
|
122
|
+
EffectLogger.logWarn(
|
|
123
|
+
~comp=`CommandGenerator(${serviceName})`,
|
|
124
|
+
~ids=EffectLogger.idsOf(meta),
|
|
125
|
+
`refused before its handler: ${reason}`,
|
|
126
|
+
)->Effect.runSync
|
|
127
|
+
if access {
|
|
128
|
+
CommandTopic_Helpers.fireCommandOutcome(
|
|
129
|
+
~component=serviceName,
|
|
130
|
+
~reference=meta.msgId,
|
|
131
|
+
~correlationId=meta.correlationId,
|
|
132
|
+
OutcomeRejected({
|
|
133
|
+
errorCode: Reventless.CommandOutcome.code(Forbidden),
|
|
134
|
+
errorDetail: reason,
|
|
135
|
+
cause: AccessRefusal,
|
|
136
|
+
}),
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
118
140
|
(payload: CommandGenerator.payload) =>
|
|
119
141
|
Effect.sync(() => {
|
|
120
142
|
let msgId = Message.uuid()
|
|
@@ -141,16 +163,31 @@ let makeGenerateCommand = (
|
|
|
141
163
|
obj->Dict.delete("id")
|
|
142
164
|
}
|
|
143
165
|
obj->dropNullArguments
|
|
144
|
-
obj->stampOwnerFields(
|
|
166
|
+
try obj->stampOwnerFields(
|
|
167
|
+
~commandSchema,
|
|
168
|
+
~command=payload.command,
|
|
169
|
+
~scope,
|
|
170
|
+
~serviceName,
|
|
171
|
+
) catch {
|
|
172
|
+
| JsExn(e) =>
|
|
173
|
+
// The original error goes on, so a transport still sees it as the caller's.
|
|
174
|
+
refusedBeforeHandler(
|
|
175
|
+
~meta,
|
|
176
|
+
~reason=e->JsExn.message->Option.getOr("owner"),
|
|
177
|
+
~access=true,
|
|
178
|
+
)
|
|
179
|
+
JsExn.throw(e)
|
|
180
|
+
}
|
|
145
181
|
obj->Dict.toArray
|
|
146
182
|
}
|
|
147
183
|
| None =>
|
|
148
|
-
|
|
184
|
+
let reason =
|
|
149
185
|
"Couldn't decode:" ++
|
|
150
186
|
payload.arguments
|
|
151
187
|
->JSON.stringifyAny
|
|
152
|
-
->Option.getOr("<payload.arguments>")
|
|
153
|
-
)
|
|
188
|
+
->Option.getOr("<payload.arguments>")
|
|
189
|
+
refusedBeforeHandler(~meta, ~reason, ~access=false)
|
|
190
|
+
JsError.throwWithMessage(reason)
|
|
154
191
|
}
|
|
155
192
|
let commandStr = JSON.Encode.string(payload.command)
|
|
156
193
|
let commandJson = switch params->Array.length {
|
|
@@ -181,12 +218,13 @@ let makeGenerateCommand = (
|
|
|
181
218
|
}
|
|
182
219
|
(meta, commandJson, id)
|
|
183
220
|
})
|
|
184
|
-
->Effect.tap(((
|
|
221
|
+
->Effect.tap(((meta, commandJson, _id)) =>
|
|
185
222
|
// Render `Name({fields})` without the standalone id: it's the command's
|
|
186
223
|
// partition-tag value, already shown among the fields, so a leading
|
|
187
224
|
// `(id)` would just duplicate it.
|
|
188
225
|
EffectLogger.logInfo(
|
|
189
226
|
~comp=`CommandGenerator(${serviceName})`,
|
|
227
|
+
~ids=EffectLogger.idsOf(meta),
|
|
190
228
|
~detail=commandJson,
|
|
191
229
|
`generated command: ${commandJson->LogFormat.cmdLabelOfJson}`,
|
|
192
230
|
)
|
|
@@ -228,7 +266,9 @@ let makeGenerateCommand = (
|
|
|
228
266
|
_ => CommandTopic.Pending({msgId: meta.msgId}),
|
|
229
267
|
)
|
|
230
268
|
}
|
|
231
|
-
| Deny(msg) =>
|
|
269
|
+
| Deny(msg) =>
|
|
270
|
+
refusedBeforeHandler(~meta, ~reason=msg, ~access=true)
|
|
271
|
+
JsError.throwWithMessage(msg)
|
|
232
272
|
}
|
|
233
273
|
)
|
|
234
274
|
| exception err =>
|
|
@@ -250,6 +290,7 @@ let makeGenerateCommand = (
|
|
|
250
290
|
| Some(message) => message
|
|
251
291
|
| None => err->JSON.stringifyAny->Option.getOr("unknown error")
|
|
252
292
|
}
|
|
293
|
+
refusedBeforeHandler(~meta, ~reason, ~access=false)
|
|
253
294
|
Plugin_ResolverError.throwCallerFault(
|
|
254
295
|
`Error: Couldn't decode ${commandJson->JSON.stringify}: ${reason}`,
|
|
255
296
|
)
|
|
@@ -12,7 +12,9 @@ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_excep
|
|
|
12
12
|
import * as OwnerScope$Reventless from "@reventlessdev/reventless-spec/src/types/OwnerScope.res.mjs";
|
|
13
13
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
14
14
|
import * as LogFormat$ReventlessCore from "../../util/LogFormat.res.mjs";
|
|
15
|
+
import * as CommandOutcome$Reventless from "@reventlessdev/reventless-spec/src/components/CommandOutcome.res.mjs";
|
|
15
16
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
17
|
+
import * as CommandTopic_Helpers$ReventlessCore from "../CommandTopic/CommandTopic_Helpers.res.mjs";
|
|
16
18
|
import * as Plugin_ResolverError$ReventlessCore from "../../plugin/component/Plugin_ResolverError.res.mjs";
|
|
17
19
|
|
|
18
20
|
let commandInterceptorHook = {
|
|
@@ -60,6 +62,17 @@ function dropNullArguments(obj) {
|
|
|
60
62
|
|
|
61
63
|
function makeGenerateCommand(publishJsons, publishJsonsAndWait, serviceName, commandSchema, componentKind, stripIdFromParamsOpt, partitionTag) {
|
|
62
64
|
let stripIdFromParams = stripIdFromParamsOpt !== undefined ? stripIdFromParamsOpt : true;
|
|
65
|
+
let refusedBeforeHandler = (meta, reason, access) => {
|
|
66
|
+
Effect.runSync(EffectLogger$ReventlessCore.logWarn(`CommandGenerator(` + serviceName + `)`, undefined, EffectLogger$ReventlessCore.idsOf(undefined, undefined, meta), `refused before its handler: ` + reason));
|
|
67
|
+
if (access) {
|
|
68
|
+
return CommandTopic_Helpers$ReventlessCore.fireCommandOutcome(serviceName, meta.msgId, meta.correlationId, undefined, {
|
|
69
|
+
TAG: "OutcomeRejected",
|
|
70
|
+
errorCode: CommandOutcome$Reventless.code("Forbidden"),
|
|
71
|
+
errorDetail: reason,
|
|
72
|
+
cause: "AccessRefusal"
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
63
76
|
return payload => Effect.flatMap(Effect.tap(Effect.sync(() => {
|
|
64
77
|
let msgId = Message$ReventlessCore.uuid();
|
|
65
78
|
let scope = OwnerScope$Reventless.resolve(payload.identity, undefined);
|
|
@@ -75,7 +88,29 @@ function makeGenerateCommand(publishJsons, publishJsonsAndWait, serviceName, com
|
|
|
75
88
|
callerClaim: meta_callerClaim
|
|
76
89
|
};
|
|
77
90
|
let obj = Stdlib_Option.flatMap(JSON.stringify(payload.arguments), jsonString => Stdlib_JSON.Decode.object(JSON.parse(jsonString)));
|
|
78
|
-
let params
|
|
91
|
+
let params;
|
|
92
|
+
if (obj !== undefined) {
|
|
93
|
+
if (stripIdFromParams) {
|
|
94
|
+
Stdlib_Dict.$$delete(obj, "id");
|
|
95
|
+
}
|
|
96
|
+
dropNullArguments(obj);
|
|
97
|
+
try {
|
|
98
|
+
stampOwnerFields(obj, commandSchema, payload.command, scope, serviceName);
|
|
99
|
+
} catch (raw_e) {
|
|
100
|
+
let e = Primitive_exceptions.internalToException(raw_e);
|
|
101
|
+
if (e.RE_EXN_ID === "JsExn") {
|
|
102
|
+
let e$1 = e._1;
|
|
103
|
+
refusedBeforeHandler(meta, Stdlib_Option.getOr(Stdlib_JsExn.message(e$1), "owner"), true);
|
|
104
|
+
throw e$1;
|
|
105
|
+
}
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
108
|
+
params = Object.entries(obj);
|
|
109
|
+
} else {
|
|
110
|
+
let reason = "Couldn't decode:" + Stdlib_Option.getOr(JSON.stringify(payload.arguments), "<payload.arguments>");
|
|
111
|
+
refusedBeforeHandler(meta, reason, false);
|
|
112
|
+
params = Stdlib_JsError.throwWithMessage(reason);
|
|
113
|
+
}
|
|
79
114
|
let commandStr = payload.command;
|
|
80
115
|
let match = params.length;
|
|
81
116
|
let commandJson = match !== 0 ? Object.fromEntries([[
|
|
@@ -92,7 +127,7 @@ function makeGenerateCommand(publishJsons, publishJsonsAndWait, serviceName, com
|
|
|
92
127
|
];
|
|
93
128
|
}), param => {
|
|
94
129
|
let commandJson = param[1];
|
|
95
|
-
return EffectLogger$ReventlessCore.logInfo(`CommandGenerator(` + serviceName + `)`, commandJson, `generated command: ` + LogFormat$ReventlessCore.cmdLabelOfJson(commandJson));
|
|
130
|
+
return EffectLogger$ReventlessCore.logInfo(`CommandGenerator(` + serviceName + `)`, commandJson, EffectLogger$ReventlessCore.idsOf(undefined, undefined, param[0]), `generated command: ` + LogFormat$ReventlessCore.cmdLabelOfJson(commandJson));
|
|
96
131
|
}), param => {
|
|
97
132
|
let id = param[2];
|
|
98
133
|
let commandJson = param[1];
|
|
@@ -113,6 +148,7 @@ function makeGenerateCommand(publishJsons, publishJsonsAndWait, serviceName, com
|
|
|
113
148
|
}
|
|
114
149
|
let message = Stdlib_Option.flatMap(Stdlib_JsExn.fromException(err), Stdlib_JsExn.message);
|
|
115
150
|
let reason = message !== undefined ? message : Stdlib_Option.getOr(JSON.stringify(err), "unknown error");
|
|
151
|
+
refusedBeforeHandler(meta, reason, false);
|
|
116
152
|
return Plugin_ResolverError$ReventlessCore.throwCallerFault(`Error: Couldn't decode ` + JSON.stringify(commandJson) + `: ` + reason);
|
|
117
153
|
}
|
|
118
154
|
let interceptor = commandInterceptorHook.contents;
|
|
@@ -149,9 +185,10 @@ function makeGenerateCommand(publishJsons, publishJsonsAndWait, serviceName, com
|
|
|
149
185
|
msgId: meta.msgId
|
|
150
186
|
}));
|
|
151
187
|
}
|
|
152
|
-
} else {
|
|
153
|
-
return Stdlib_JsError.throwWithMessage(interceptResult._0);
|
|
154
188
|
}
|
|
189
|
+
let msg = interceptResult._0;
|
|
190
|
+
refusedBeforeHandler(meta, msg, true);
|
|
191
|
+
return Stdlib_JsError.throwWithMessage(msg);
|
|
155
192
|
});
|
|
156
193
|
});
|
|
157
194
|
}
|