@reventlessdev/reventless-core 3.0.0-alpha.326 → 3.0.0-alpha.328
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/package.json +6 -6
- package/src/CommandSent.res +22 -0
- package/src/CommandSent.res.mjs +22 -0
- package/src/Projection.res +26 -1
- package/src/Projection.res.mjs +19 -1
- package/src/RowChange.res +37 -0
- package/src/RowChange.res.mjs +62 -0
- package/src/adapter/Runtime/AggregateRuntime_Builder_Common.res.mjs +5 -5
- package/src/adapter/Runtime/EventCollectorRuntime_Builder_Single.res.mjs +2 -2
- package/src/admin/Platform_Admin_Callback.res.mjs +1 -1
- package/src/components/Aggregate/Aggregate_Callback.res +88 -18
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +53 -32
- package/src/components/Api/GraphQL_FragmentGenerator.res +22 -0
- package/src/components/Api/GraphQL_FragmentGenerator.res.mjs +20 -4
- package/src/components/Api/GraphQL_SchemaInspector.res.mjs +2 -2
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +1 -1
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +9 -0
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +20 -14
- package/src/components/CommandGenerator/CommandGenerator_Callback.res +47 -6
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +41 -4
- package/src/components/CommandTopic/CommandTopic_Callback.res.mjs +1 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res +9 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +7 -6
- package/src/components/CommandTopic/CommandTopic_Operations.res +2 -0
- package/src/components/CommandTopic/CommandTopic_Operations.res.mjs +2 -2
- package/src/components/Counter/Counter_Callback.res.mjs +3 -3
- package/src/components/Counter/Counter_Operations.res.mjs +4 -4
- package/src/components/DcbEventLog/DcbEventLog_Operations.res.mjs +3 -3
- package/src/components/EventLog/EventLog_Operations.res +1 -0
- package/src/components/EventLog/EventLog_Operations.res.mjs +3 -3
- package/src/components/EventMapper/EventMapper_Callback.res +12 -2
- package/src/components/EventMapper/EventMapper_Callback.res.mjs +16 -14
- package/src/components/EventTopic/EventTopic_Operations.res +2 -0
- package/src/components/EventTopic/EventTopic_Operations.res.mjs +2 -2
- package/src/components/Extension/Extension_Operations.res +4 -0
- package/src/components/Extension/Extension_Operations.res.mjs +8 -8
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res +5 -1
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res.mjs +4 -3
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res +2 -0
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res.mjs +9 -8
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +4 -0
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +4 -2
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +12 -0
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +14 -12
- package/src/components/QueryDb/QueryDb_Operations.res +2 -0
- package/src/components/QueryDb/QueryDb_Operations.res.mjs +3 -0
- package/src/components/ReadModel/ReadModel_Callback.res +1 -0
- package/src/components/ReadModel/ReadModel_Callback.res.mjs +1 -1
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res +2 -0
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res.mjs +6 -6
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +36 -7
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +38 -20
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +2 -0
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +2 -2
- package/src/components/StateViewSlice/StateViewSlice_Callback.res +6 -0
- package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +3 -2
- package/src/components/Task/Task_Builder.res +5 -3
- package/src/components/Task/Task_Builder.res.mjs +2 -1
- package/src/plugin/component/Plugin_Callback.res +6 -2
- package/src/plugin/component/Plugin_Callback.res.mjs +3 -2
- package/src/plugin/connect/PluginExtensionPoint_Plugin.res.mjs +6 -6
- package/src/util/CommandPublisher.res.mjs +9 -9
- package/src/util/EffectLogger.res +85 -17
- package/src/util/EffectLogger.res.mjs +63 -12
- package/src/util/FTPHandler.res.mjs +6 -6
- package/src/util/Metrics.res +151 -16
- package/src/util/Metrics.res.mjs +123 -3
- package/src/util/ScheduleOps.res.mjs +4 -4
- package/src/util/Util_AdapterRuntime.res.mjs +2 -2
- package/src/util/Util_Promise.res.mjs +1 -1
- package/src/util/Util_QueryDbRuntime.res.mjs +1 -1
- package/src/util/Validation.res.mjs +1 -1
- package/tests/api/GraphQL_FragmentGeneratorTest.res.mjs +2 -2
- package/tests/api/IdentitySemanticTest.res.mjs +1 -1
- package/tests/commandgenerator/OwnerStampingTest.res +65 -0
- package/tests/commandgenerator/OwnerStampingTest.res.mjs +62 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res +25 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +28 -0
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +4 -4
- package/tests/logger/ComponentLineIdsTest.res +97 -0
- package/tests/logger/ComponentLineIdsTest.res.mjs +118 -0
- package/tests/logger/LogFormatTest.res.mjs +5 -5
- package/tests/logger/LoggerSinkTest.res.mjs +3 -3
- package/tests/querydb/RowChangeTest.res +87 -0
- package/tests/querydb/RowChangeTest.res.mjs +157 -0
- package/tests/util/MetricsTest.res +72 -0
- package/tests/util/MetricsTest.res.mjs +108 -0
|
@@ -38,6 +38,15 @@ let commandResultSdlTypes: array<string> = [
|
|
|
38
38
|
}`,
|
|
39
39
|
]
|
|
40
40
|
|
|
41
|
+
// The last change a view row was written by: its flow, the event behind it and the time
|
|
42
|
+
// (`RowChange`). Every view type carries it as `_change`, answered to elevated callers only;
|
|
43
|
+
// emitted once per fragment that has a view, deduped by name like the command results.
|
|
44
|
+
let rowChangeSdlType = `type RowChange {
|
|
45
|
+
flow: String
|
|
46
|
+
msgId: String!
|
|
47
|
+
at: String!
|
|
48
|
+
}`
|
|
49
|
+
|
|
41
50
|
// ── SchemaType → GraphQL type reference ──────────────────────────────────────
|
|
42
51
|
|
|
43
52
|
let rec fromSchemaType = (
|
|
@@ -196,6 +205,7 @@ let deriveObjectTypeWithNested = (
|
|
|
196
205
|
~excludeFields: array<string>=[],
|
|
197
206
|
~includeIdParam: bool=true,
|
|
198
207
|
~resolvedFields: array<resolvedFieldEntry>=[],
|
|
208
|
+
~rowChange: bool=false,
|
|
199
209
|
schema: S.t<unknown>,
|
|
200
210
|
): array<string> => {
|
|
201
211
|
reportUnclassifiedUnions(~typeName, schema)
|
|
@@ -241,6 +251,14 @@ let deriveObjectTypeWithNested = (
|
|
|
241
251
|
} else {
|
|
242
252
|
mainType
|
|
243
253
|
}
|
|
254
|
+
if rowChange && filteredFields->Dict.get(RowChange.key)->Option.isSome {
|
|
255
|
+
JsError.throwWithMessage(
|
|
256
|
+
`${typeName}.${RowChange.key} is a field of the state record, and every view row carries its last change under that name. Name the field something else.`,
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
let mainTypeWithId = rowChange
|
|
260
|
+
? mainTypeWithId->String.replace("{\n", `{\n ${RowChange.key}: RowChange\n`)
|
|
261
|
+
: mainTypeWithId
|
|
244
262
|
// A cross-table field shares the type with the state record's own fields, so
|
|
245
263
|
// a name already taken would emit the field twice and fail the whole document
|
|
246
264
|
// — for every plugin in the merge, not just this one. Refuse at build time,
|
|
@@ -935,6 +953,7 @@ let generate = (
|
|
|
935
953
|
~excludeFields,
|
|
936
954
|
~includeIdParam,
|
|
937
955
|
~resolvedFields=entry.resolvedFields->Option.getOr([]),
|
|
956
|
+
~rowChange=true,
|
|
938
957
|
entry.stateSchema,
|
|
939
958
|
)
|
|
940
959
|
nestedTypes->Array.forEach(t => {
|
|
@@ -1080,6 +1099,9 @@ let generate = (
|
|
|
1080
1099
|
if mutations->Array.length > 0 {
|
|
1081
1100
|
commandResultSdlTypes->Array.forEach(t => types->Array.push(t))
|
|
1082
1101
|
}
|
|
1102
|
+
if queryEntries->Array.length > 0 {
|
|
1103
|
+
types->Array.push(rowChangeSdlType)
|
|
1104
|
+
}
|
|
1083
1105
|
|
|
1084
1106
|
GraphQL_Stitcher.encode({
|
|
1085
1107
|
types,
|
|
@@ -8,6 +8,7 @@ import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js
|
|
|
8
8
|
import * as Semantic$Reventless from "@reventlessdev/reventless-spec/src/semantic/Semantic.res.mjs";
|
|
9
9
|
import * as ReadModel$Reventless from "@reventlessdev/reventless-spec/src/components/ReadModel.res.mjs";
|
|
10
10
|
import * as Logger$ReventlessCore from "../../util/Logger.res.mjs";
|
|
11
|
+
import * as RowChange$ReventlessCore from "../../RowChange.res.mjs";
|
|
11
12
|
import * as Api_Naming$ReventlessCore from "./Api_Naming.res.mjs";
|
|
12
13
|
import * as SchemaType$ReventlessCore from "./SchemaType.res.mjs";
|
|
13
14
|
import * as SchemaWalker$ReventlessCore from "../../plugin/component/SchemaWalker.res.mjs";
|
|
@@ -39,6 +40,12 @@ let commandResultSdlTypes = [
|
|
|
39
40
|
}`
|
|
40
41
|
];
|
|
41
42
|
|
|
43
|
+
let rowChangeSdlType = `type RowChange {
|
|
44
|
+
flow: String
|
|
45
|
+
msgId: String!
|
|
46
|
+
at: String!
|
|
47
|
+
}`;
|
|
48
|
+
|
|
42
49
|
function fromSchemaType(_required, _asInputOpt, _st, collectedTypes, seenTypes) {
|
|
43
50
|
while (true) {
|
|
44
51
|
let asInputOpt = _asInputOpt;
|
|
@@ -156,10 +163,11 @@ function resolvedFieldSdl(param) {
|
|
|
156
163
|
}
|
|
157
164
|
}
|
|
158
165
|
|
|
159
|
-
function deriveObjectTypeWithNested(typeName, excludeFieldsOpt, includeIdParamOpt, resolvedFieldsOpt, schema) {
|
|
166
|
+
function deriveObjectTypeWithNested(typeName, excludeFieldsOpt, includeIdParamOpt, resolvedFieldsOpt, rowChangeOpt, schema) {
|
|
160
167
|
let excludeFields = excludeFieldsOpt !== undefined ? excludeFieldsOpt : [];
|
|
161
168
|
let includeIdParam = includeIdParamOpt !== undefined ? includeIdParamOpt : true;
|
|
162
169
|
let resolvedFields = resolvedFieldsOpt !== undefined ? resolvedFieldsOpt : [];
|
|
170
|
+
let rowChange = rowChangeOpt !== undefined ? rowChangeOpt : false;
|
|
163
171
|
reportUnclassifiedUnions(typeName, schema);
|
|
164
172
|
let fields = SchemaType$ReventlessCore.fromSuryObject(typeName, schema);
|
|
165
173
|
if (fields === undefined) {
|
|
@@ -186,6 +194,10 @@ function deriveObjectTypeWithNested(typeName, excludeFieldsOpt, includeIdParamOp
|
|
|
186
194
|
seenTypes.add(typeName);
|
|
187
195
|
let mainType = objectRefToGraphQL(undefined, typeName, filteredFields, collectedTypes, seenTypes);
|
|
188
196
|
let mainTypeWithId = includeIdParam ? mainType.replace(`type ` + typeName + ` {\n`, `type ` + typeName + ` implements Node {\n id: ID!\n`) : mainType;
|
|
197
|
+
if (rowChange && Stdlib_Option.isSome(filteredFields[RowChange$ReventlessCore.key])) {
|
|
198
|
+
Stdlib_JsError.throwWithMessage(typeName + `.` + RowChange$ReventlessCore.key + ` is a field of the state record, and every view row carries its last change under that name. Name the field something else.`);
|
|
199
|
+
}
|
|
200
|
+
let mainTypeWithId$1 = rowChange ? mainTypeWithId.replace("{\n", `{\n ` + RowChange$ReventlessCore.key + `: RowChange\n`) : mainTypeWithId;
|
|
189
201
|
resolvedFields.forEach(param => {
|
|
190
202
|
let fieldName = param.fieldName;
|
|
191
203
|
if (Stdlib_Option.isSome(filteredFields[fieldName]) || includeIdParam && fieldName === "id") {
|
|
@@ -194,9 +206,9 @@ function deriveObjectTypeWithNested(typeName, excludeFieldsOpt, includeIdParamOp
|
|
|
194
206
|
});
|
|
195
207
|
let mainTypeComplete;
|
|
196
208
|
if (resolvedFields.length === 0) {
|
|
197
|
-
mainTypeComplete = mainTypeWithId;
|
|
209
|
+
mainTypeComplete = mainTypeWithId$1;
|
|
198
210
|
} else {
|
|
199
|
-
let body = mainTypeWithId.slice(0, mainTypeWithId.length - 1 | 0);
|
|
211
|
+
let body = mainTypeWithId$1.slice(0, mainTypeWithId$1.length - 1 | 0);
|
|
200
212
|
mainTypeComplete = body + resolvedFields.map(resolvedFieldSdl).join("\n") + "\n}";
|
|
201
213
|
}
|
|
202
214
|
return collectedTypes.concat([mainTypeComplete]);
|
|
@@ -624,7 +636,7 @@ function generate(mutationEntries, queryEntries) {
|
|
|
624
636
|
seenTypes.add(entry.returnTypeName);
|
|
625
637
|
let fields = entry.excludeFields;
|
|
626
638
|
let excludeFields = fields !== undefined ? fields : [];
|
|
627
|
-
let nestedTypes = deriveObjectTypeWithNested(entry.returnTypeName, excludeFields, includeIdParam, Stdlib_Option.getOr(entry.resolvedFields, []), entry.stateSchema);
|
|
639
|
+
let nestedTypes = deriveObjectTypeWithNested(entry.returnTypeName, excludeFields, includeIdParam, Stdlib_Option.getOr(entry.resolvedFields, []), true, entry.stateSchema);
|
|
628
640
|
nestedTypes.forEach(t => {
|
|
629
641
|
types.push(t);
|
|
630
642
|
});
|
|
@@ -703,6 +715,9 @@ function generate(mutationEntries, queryEntries) {
|
|
|
703
715
|
types.push(t);
|
|
704
716
|
});
|
|
705
717
|
}
|
|
718
|
+
if (queryEntries.length !== 0) {
|
|
719
|
+
types.push(rowChangeSdlType);
|
|
720
|
+
}
|
|
706
721
|
return GraphQL_Stitcher$ReventlessCore.encode({
|
|
707
722
|
types: types,
|
|
708
723
|
mutations: mutations,
|
|
@@ -715,6 +730,7 @@ function generate(mutationEntries, queryEntries) {
|
|
|
715
730
|
export {
|
|
716
731
|
log,
|
|
717
732
|
commandResultSdlTypes,
|
|
733
|
+
rowChangeSdlType,
|
|
718
734
|
fromSchemaType,
|
|
719
735
|
objectRefToGraphQL,
|
|
720
736
|
deriveFieldType,
|
|
@@ -13,7 +13,7 @@ function inspectScalar(schema) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function inspectObjectType(typeName, schema) {
|
|
16
|
-
let types = GraphQL_FragmentGenerator$ReventlessCore.deriveObjectTypeWithNested(typeName, undefined, undefined, undefined, schema);
|
|
16
|
+
let types = GraphQL_FragmentGenerator$ReventlessCore.deriveObjectTypeWithNested(typeName, undefined, undefined, undefined, undefined, schema);
|
|
17
17
|
return types[types.length - 1 | 0];
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -42,7 +42,7 @@ function inspectMutationFields(fieldPrefix, commandSchema) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
function inspectQueryFields(name, typeName, stateSchema) {
|
|
45
|
-
let types = GraphQL_FragmentGenerator$ReventlessCore.deriveObjectTypeWithNested(typeName, undefined, undefined, undefined, stateSchema);
|
|
45
|
+
let types = GraphQL_FragmentGenerator$ReventlessCore.deriveObjectTypeWithNested(typeName, undefined, undefined, undefined, undefined, stateSchema);
|
|
46
46
|
let typeDef = types[types.length - 1 | 0];
|
|
47
47
|
let singleQuery = GraphQL_FragmentGenerator$ReventlessCore.deriveObjectQueryField(name, typeName, undefined, undefined);
|
|
48
48
|
let pluralName = name + "s";
|
|
@@ -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
|
}
|
|
@@ -457,6 +462,7 @@ module Make = (
|
|
|
457
462
|
}
|
|
458
463
|
|
|
459
464
|
let phase2 = async (publishJsons: ReventlessInfra.CommandTopic.publishJsons) => {
|
|
465
|
+
let publishJsons = CommandSent.announcing(~comp=`AutomationSlice(${Spec.name})`, publishJsons)
|
|
460
466
|
let currentTime = await Clock.currentTimeMillis->Effect.runPromise
|
|
461
467
|
// A `Failed` row at or past the ceiling is one an older build left stranded,
|
|
462
468
|
// or one whose Spec lowered `maxRetries` under it. Either way it is abandoned
|
|
@@ -503,12 +509,14 @@ module Make = (
|
|
|
503
509
|
| Gone(field) =>
|
|
504
510
|
EffectLogger.logInfo(
|
|
505
511
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
512
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
506
513
|
`${id}: its ${field} was erased; nothing to do`,
|
|
507
514
|
)->Effect.runSync
|
|
508
515
|
todoItems->Dict.set(id, {...row, status: Completed, completedAt: now()})
|
|
509
516
|
| Unopened(errMsg) =>
|
|
510
517
|
EffectLogger.logError(
|
|
511
518
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
519
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
512
520
|
`failed to decode todoItem: ${errMsg}`,
|
|
513
521
|
)->Effect.runSync
|
|
514
522
|
| Open({key, item}) =>
|
|
@@ -523,6 +531,7 @@ module Make = (
|
|
|
523
531
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
|
|
524
532
|
EffectLogger.logError(
|
|
525
533
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
534
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
526
535
|
`failed to encode command: ${errMsg}`,
|
|
527
536
|
)->Effect.runSync
|
|
528
537
|
let updated = row->afterFailedAttempt
|
|
@@ -15,6 +15,7 @@ import * as Message$Reventless from "@reventlessdev/reventless-spec/src/types/Me
|
|
|
15
15
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
16
16
|
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
17
17
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
18
|
+
import * as CommandSent$ReventlessCore from "../../CommandSent.res.mjs";
|
|
18
19
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
19
20
|
import * as AutomationSlice_Route$ReventlessCore from "./AutomationSlice_Route.res.mjs";
|
|
20
21
|
import * as AutomationSlice_Schedules$ReventlessCore from "./AutomationSlice_Schedules.res.mjs";
|
|
@@ -110,12 +111,12 @@ function Make(Spec) {
|
|
|
110
111
|
}
|
|
111
112
|
let why = fingerprint._0._0;
|
|
112
113
|
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 + `)`));
|
|
114
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, undefined, `a work item was not stored: its row id cannot be fingerprinted (` + why + `)`));
|
|
114
115
|
return;
|
|
115
116
|
} else {
|
|
116
117
|
if (!warnedUnkeyed.contents) {
|
|
117
118
|
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 + `)`));
|
|
119
|
+
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
120
|
}
|
|
120
121
|
return key;
|
|
121
122
|
}
|
|
@@ -203,7 +204,7 @@ function Make(Spec) {
|
|
|
203
204
|
try {
|
|
204
205
|
commandJson = Util_Sury$Reventless.toJson(param[1], Spec.commandSchema);
|
|
205
206
|
} catch (exn) {
|
|
206
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `retries exhausted for ` + id + `, and the abandonment command could not be encoded`));
|
|
207
|
+
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
208
|
return;
|
|
208
209
|
}
|
|
209
210
|
return {
|
|
@@ -215,7 +216,7 @@ function Make(Spec) {
|
|
|
215
216
|
case "Gone" :
|
|
216
217
|
return;
|
|
217
218
|
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`));
|
|
219
|
+
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
220
|
return;
|
|
220
221
|
}
|
|
221
222
|
};
|
|
@@ -250,7 +251,7 @@ function Make(Spec) {
|
|
|
250
251
|
};
|
|
251
252
|
todoItems[id] = row;
|
|
252
253
|
} else {
|
|
253
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `a work item was not stored: ` + why._0));
|
|
254
|
+
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
255
|
}
|
|
255
256
|
}
|
|
256
257
|
}
|
|
@@ -265,14 +266,18 @@ function Make(Spec) {
|
|
|
265
266
|
routed.forEach(r => {
|
|
266
267
|
r.rescheduled.forEach(change => {
|
|
267
268
|
if (!readsClock) {
|
|
268
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined,
|
|
269
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, {
|
|
270
|
+
msgId: setBy
|
|
271
|
+
}, `a mapping changed a schedule, but no mapping reads the Clock, so no tick would reach the slice; the change is skipped`));
|
|
269
272
|
}
|
|
270
273
|
let platformChange = AutomationSlice_Schedules$ReventlessCore.apply(schedules, change, setBy, recordedAt);
|
|
271
274
|
if (platformChange.TAG === "Ok") {
|
|
272
275
|
scheduleChanges.contents = scheduleChanges.contents.concat([platformChange._0]);
|
|
273
276
|
return;
|
|
274
277
|
} else {
|
|
275
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined,
|
|
278
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, {
|
|
279
|
+
msgId: setBy
|
|
280
|
+
}, platformChange._0 + `; the change is skipped`));
|
|
276
281
|
}
|
|
277
282
|
});
|
|
278
283
|
});
|
|
@@ -322,6 +327,7 @@ function Make(Spec) {
|
|
|
322
327
|
scheduleChanges.contents = [];
|
|
323
328
|
};
|
|
324
329
|
let phase2 = async publishJsons => {
|
|
330
|
+
let publishJsons$1 = CommandSent$ReventlessCore.announcing(`AutomationSlice(` + Spec.name + `)`, publishJsons);
|
|
325
331
|
let currentTime = await Effect.runPromise(Clock.currentTimeMillis);
|
|
326
332
|
let newlyAbandoned = [];
|
|
327
333
|
Object.entries(todoItems).forEach(param => {
|
|
@@ -387,7 +393,7 @@ function Make(Spec) {
|
|
|
387
393
|
} catch (raw_exn) {
|
|
388
394
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
389
395
|
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));
|
|
396
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to encode command: ` + errMsg));
|
|
391
397
|
let updated = afterFailedAttempt(row);
|
|
392
398
|
todoItems[id] = updated;
|
|
393
399
|
if (updated.status === "Abandoned") {
|
|
@@ -407,24 +413,24 @@ function Make(Spec) {
|
|
|
407
413
|
}
|
|
408
414
|
break;
|
|
409
415
|
case "Gone" :
|
|
410
|
-
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`AutomationSlice(` + Spec.name + `)`, undefined, id + `: its ` + field._0 + ` was erased; nothing to do`));
|
|
416
|
+
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
417
|
let newrecord$1 = {...row};
|
|
412
418
|
newrecord$1.completedAt = new Date().toISOString();
|
|
413
419
|
newrecord$1.status = "Completed";
|
|
414
420
|
todoItems[id] = newrecord$1;
|
|
415
421
|
break;
|
|
416
422
|
case "Unopened" :
|
|
417
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, `failed to decode todoItem: ` + field._0));
|
|
423
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, Stdlib_Option.map(row.source, EffectLogger$ReventlessCore.idsOfSource), `failed to decode todoItem: ` + field._0));
|
|
418
424
|
break;
|
|
419
425
|
}
|
|
420
426
|
}
|
|
421
427
|
if (commands.length !== 0) {
|
|
422
428
|
try {
|
|
423
|
-
await publishJsons(commands);
|
|
429
|
+
await publishJsons$1(commands);
|
|
424
430
|
} catch (raw_exn$1) {
|
|
425
431
|
let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
|
|
426
432
|
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));
|
|
433
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, undefined, `failed to publish commands: ` + errMsg$1));
|
|
428
434
|
pending.forEach(param => {
|
|
429
435
|
let id = param[0];
|
|
430
436
|
let current = todoItems[id];
|
|
@@ -458,11 +464,11 @@ function Make(Spec) {
|
|
|
458
464
|
return;
|
|
459
465
|
}
|
|
460
466
|
try {
|
|
461
|
-
return await publishJsons(abandonmentCommands);
|
|
467
|
+
return await publishJsons$1(abandonmentCommands);
|
|
462
468
|
} catch (raw_exn$2) {
|
|
463
469
|
let exn$2 = Primitive_exceptions.internalToException(raw_exn$2);
|
|
464
470
|
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));
|
|
471
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logError(`AutomationSlice(` + Spec.name + `)`, undefined, undefined, `failed to publish abandonment commands: ` + errMsg$2));
|
|
466
472
|
}
|
|
467
473
|
};
|
|
468
474
|
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
|
}
|
|
@@ -22,7 +22,7 @@ function Make(Spec) {
|
|
|
22
22
|
let err = Primitive_exceptions.internalToException(raw_err);
|
|
23
23
|
let commandStr = JSON.stringify(LogRedaction$Reventless.redactJson(json));
|
|
24
24
|
let errMsg = Util_Sury$Reventless.exnMessage(err, undefined);
|
|
25
|
-
Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, `decode failed: ` + commandStr + ` err=` + errMsg));
|
|
25
|
+
Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, undefined, `decode failed: ` + commandStr + ` err=` + errMsg));
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
28
|
return {
|
|
@@ -54,6 +54,9 @@ type commandOutcomeReport = {
|
|
|
54
54
|
component: string,
|
|
55
55
|
reference: string,
|
|
56
56
|
correlationId?: string,
|
|
57
|
+
/** The message that caused the command: the event an automation or a translation acted on,
|
|
58
|
+
when it sent the command. */
|
|
59
|
+
causationId?: string,
|
|
57
60
|
outcome: observedOutcome,
|
|
58
61
|
}
|
|
59
62
|
|
|
@@ -95,12 +98,13 @@ let fireCommandOutcome = (
|
|
|
95
98
|
~component: string,
|
|
96
99
|
~reference: string,
|
|
97
100
|
~correlationId: option<string>=?,
|
|
101
|
+
~causationId: option<string>=?,
|
|
98
102
|
outcome: observedOutcome,
|
|
99
103
|
) =>
|
|
100
104
|
switch commandOutcomeHooks.contents {
|
|
101
105
|
| [] => ()
|
|
102
106
|
| hooks =>
|
|
103
|
-
let report = {component, reference, ?correlationId, outcome}
|
|
107
|
+
let report = {component, reference, ?correlationId, ?causationId, outcome}
|
|
104
108
|
hooks->Array.forEach(({hook}) =>
|
|
105
109
|
switch hook(report) {
|
|
106
110
|
| () => ()
|
|
@@ -168,6 +172,7 @@ let ownershipRefusal = (
|
|
|
168
172
|
let reportAccepted = (
|
|
169
173
|
~component: string,
|
|
170
174
|
~correlationId: option<string>=?,
|
|
175
|
+
~causationId: option<string>=?,
|
|
171
176
|
reference: string,
|
|
172
177
|
result: acceptedResult,
|
|
173
178
|
) => {
|
|
@@ -176,6 +181,7 @@ let reportAccepted = (
|
|
|
176
181
|
~component,
|
|
177
182
|
~reference,
|
|
178
183
|
~correlationId?,
|
|
184
|
+
~causationId?,
|
|
179
185
|
OutcomeAccepted({entityId: result.entityId, eventCount: result.eventCount}),
|
|
180
186
|
)
|
|
181
187
|
}
|
|
@@ -184,6 +190,7 @@ let reportRejected = (
|
|
|
184
190
|
~component: string,
|
|
185
191
|
~cause: refusalCause,
|
|
186
192
|
~correlationId: option<string>=?,
|
|
193
|
+
~causationId: option<string>=?,
|
|
187
194
|
reference: string,
|
|
188
195
|
result: rejectedResult,
|
|
189
196
|
) => {
|
|
@@ -192,6 +199,7 @@ let reportRejected = (
|
|
|
192
199
|
~component,
|
|
193
200
|
~reference,
|
|
194
201
|
~correlationId?,
|
|
202
|
+
~causationId?,
|
|
195
203
|
OutcomeRejected({errorCode: result.errorCode, errorDetail: result.errorDetail, cause}),
|
|
196
204
|
)
|
|
197
205
|
}
|