@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.
- package/CHANGELOG.md +16 -0
- package/package.json +7 -7
- package/src/Message.res +46 -0
- package/src/Message.res.mjs +45 -0
- package/src/Projection.res +269 -131
- package/src/Projection.res.mjs +338 -224
- package/src/ViewChange.res +194 -0
- package/src/ViewChange.res.mjs +235 -0
- package/src/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 +93 -18
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +54 -32
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +1 -1
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +29 -9
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +35 -20
- package/src/components/CommandGenerator/CommandGenerator_Callback.res +47 -6
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +41 -4
- package/src/components/CommandTopic/CommandTopic.res.mjs +5 -2
- package/src/components/CommandTopic/CommandTopic_Callback.res.mjs +1 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res +64 -26
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +37 -17
- 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 +6 -2
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +7 -3
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +33 -12
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +30 -17
- package/src/components/ReadModel/ReadModel_Callback.res +24 -3
- package/src/components/ReadModel/ReadModel_Callback.res.mjs +15 -3
- 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 +43 -7
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +38 -20
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +16 -2
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +15 -4
- package/src/components/StateViewSlice/StateViewSlice_Callback.res +35 -4
- package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +12 -4
- 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 +111 -42
- package/src/util/EffectLogger.res.mjs +72 -30
- package/src/util/FTPHandler.res.mjs +6 -6
- package/src/util/Logger.res +231 -35
- package/src/util/Logger.res.mjs +263 -42
- 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/OwnerActingTest.res +3 -1
- package/tests/commandgenerator/OwnerStampingTest.res +65 -0
- package/tests/commandgenerator/OwnerStampingTest.res.mjs +62 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res +99 -2
- package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +120 -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 +205 -0
- package/tests/logger/LoggerSinkTest.res.mjs +209 -0
- package/tests/projection/ViewChangeTest.res +173 -0
- package/tests/projection/ViewChangeTest.res.mjs +292 -0
|
@@ -38,6 +38,9 @@ type todoRow = {
|
|
|
38
38
|
rehydrated through `S.parseOrThrow`, and a required field would fail that
|
|
39
39
|
decode — silently, since the restore swallows it per row. */
|
|
40
40
|
maxRetries?: int,
|
|
41
|
+
/** The event that created the row, so the commands sent for it continue its
|
|
42
|
+
flow. Absent on rows written before it existed, and on rows a tick created. */
|
|
43
|
+
source?: Message.flowSource,
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
/** The item schema seen through the `JSON.t` the row actually stores.
|
|
@@ -69,6 +72,7 @@ let todoRowSchemaFor = (itemSchema: S.t<'item>): S.t<todoRow> =>
|
|
|
69
72
|
completedAt: ?s.matches(S.option(S.string)),
|
|
70
73
|
retryCount: s.matches(S.int),
|
|
71
74
|
maxRetries: ?s.matches(S.option(S.int)),
|
|
75
|
+
source: ?s.matches(S.option(Message.flowSourceSchema)),
|
|
72
76
|
})
|
|
73
77
|
|
|
74
78
|
/**
|
|
@@ -170,17 +174,20 @@ module Make = (
|
|
|
170
174
|
|
|
171
175
|
let now = () => Date.make()->Date.toISOString
|
|
172
176
|
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
// later thread source meta through todoItems, switch to deriveMeta.
|
|
177
|
+
// Meta for a command emitted for a row: derived from the event that created
|
|
178
|
+
// the row, so the command continues its flow (its correlation id, the event's
|
|
179
|
+
// message id as causation, its user and trace parent). A row without a source
|
|
180
|
+
// (written before rows kept one, or created by a tick) starts a new flow.
|
|
178
181
|
// `service` names the command's TARGET, matching the API path
|
|
179
182
|
// (`CommandGenerator_Callback` passes `~serviceName=AggregateSpec.name`). An
|
|
180
183
|
// aggregate derives its event meta from the command's, and ReadModel /
|
|
181
184
|
// AutomationSlice callbacks dispatch mappings on `meta.service` — so naming
|
|
182
185
|
// the slice here makes the target's own events unmatchable, silently.
|
|
183
|
-
let makeMeta = (): Reventless.Message.meta =>
|
|
186
|
+
let makeMeta = (row: todoRow): Reventless.Message.meta =>
|
|
187
|
+
switch row.source {
|
|
188
|
+
| Some(source) => Message.deriveMetaFromSource(source, ~service=Spec.targetName)
|
|
189
|
+
| None => Message.generateMeta(~service=Spec.targetName)
|
|
190
|
+
}
|
|
184
191
|
|
|
185
192
|
// A work item that carries personal data is stored the way an event is: its
|
|
186
193
|
// marked fields sealed, its row keyed by a fingerprint of the key the mapping
|
|
@@ -296,10 +303,11 @@ module Make = (
|
|
|
296
303
|
| Open({key, item}) =>
|
|
297
304
|
Automation.onExhausted(key, item)->Option.flatMap(((targetId, command)) =>
|
|
298
305
|
switch command->Reventless.Util_Sury.toJson(Spec.commandSchema) {
|
|
299
|
-
| commandJson => Some({Reventless.Message.id: targetId, meta: makeMeta(), commandJson})
|
|
306
|
+
| commandJson => Some({Reventless.Message.id: targetId, meta: makeMeta(row), commandJson})
|
|
300
307
|
| exception _ =>
|
|
301
308
|
EffectLogger.logError(
|
|
302
309
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
310
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
303
311
|
`retries exhausted for ${id}, and the abandonment command could not be encoded`,
|
|
304
312
|
)->Effect.runSync
|
|
305
313
|
None
|
|
@@ -309,6 +317,7 @@ module Make = (
|
|
|
309
317
|
| Unopened(_) =>
|
|
310
318
|
EffectLogger.logError(
|
|
311
319
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
320
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
312
321
|
`retries exhausted for ${id}, and its item could not be decoded to announce it`,
|
|
313
322
|
)->Effect.runSync
|
|
314
323
|
None
|
|
@@ -326,6 +335,7 @@ module Make = (
|
|
|
326
335
|
let apply = async (
|
|
327
336
|
{collected, resolved}: AutomationSlice_Route.routed<Spec.todoItem>,
|
|
328
337
|
~capabilities,
|
|
338
|
+
~source: option<Message.flowSource>,
|
|
329
339
|
) => {
|
|
330
340
|
for i in 0 to collected->Array.length - 1 {
|
|
331
341
|
let (key, item) = collected->Array.getUnsafe(i)
|
|
@@ -337,6 +347,7 @@ module Make = (
|
|
|
337
347
|
| Error(why) =>
|
|
338
348
|
EffectLogger.logError(
|
|
339
349
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
350
|
+
~ids=?source->Option.map(EffectLogger.idsOfSource),
|
|
340
351
|
`a work item was not stored: ${why}`,
|
|
341
352
|
)->Effect.runSync
|
|
342
353
|
| Ok(stored) =>
|
|
@@ -346,6 +357,7 @@ module Make = (
|
|
|
346
357
|
createdAt: now(),
|
|
347
358
|
retryCount: 0,
|
|
348
359
|
maxRetries: Spec.maxRetries,
|
|
360
|
+
?source,
|
|
349
361
|
}
|
|
350
362
|
todoItems->Dict.set(id, row)
|
|
351
363
|
}
|
|
@@ -372,6 +384,7 @@ module Make = (
|
|
|
372
384
|
if !readsClock {
|
|
373
385
|
EffectLogger.logError(
|
|
374
386
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
387
|
+
~ids={msgId: setBy},
|
|
375
388
|
`a mapping changed a schedule, but no mapping reads the Clock, so no tick would reach the slice; the change is skipped`,
|
|
376
389
|
)->Effect.runSync
|
|
377
390
|
} else {
|
|
@@ -381,6 +394,7 @@ module Make = (
|
|
|
381
394
|
| Error(message) =>
|
|
382
395
|
EffectLogger.logError(
|
|
383
396
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
397
|
+
~ids={msgId: setBy},
|
|
384
398
|
`${message}; the change is skipped`,
|
|
385
399
|
)->Effect.runSync
|
|
386
400
|
}
|
|
@@ -410,8 +424,11 @@ module Make = (
|
|
|
410
424
|
}
|
|
411
425
|
// Multiple mappings can share a sourceName; all matching dispatches run.
|
|
412
426
|
let routed = Route.route(eventPayload, ~sourceName, ~sourceId=context.id, ctx)
|
|
427
|
+
// A tick's meta is made up as it fires, so a row it creates starts a flow.
|
|
428
|
+
let source =
|
|
429
|
+
sourceName == Reventless.Clock.name ? None : Some(Message.flowSourceOf(context.meta))
|
|
413
430
|
for j in 0 to routed->Array.length - 1 {
|
|
414
|
-
await apply(routed->Array.getUnsafe(j), ~capabilities)
|
|
431
|
+
await apply(routed->Array.getUnsafe(j), ~capabilities, ~source)
|
|
415
432
|
}
|
|
416
433
|
reschedule(
|
|
417
434
|
routed,
|
|
@@ -491,12 +508,14 @@ module Make = (
|
|
|
491
508
|
| Gone(field) =>
|
|
492
509
|
EffectLogger.logInfo(
|
|
493
510
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
511
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
494
512
|
`${id}: its ${field} was erased; nothing to do`,
|
|
495
513
|
)->Effect.runSync
|
|
496
514
|
todoItems->Dict.set(id, {...row, status: Completed, completedAt: now()})
|
|
497
515
|
| Unopened(errMsg) =>
|
|
498
516
|
EffectLogger.logError(
|
|
499
517
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
518
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
500
519
|
`failed to decode todoItem: ${errMsg}`,
|
|
501
520
|
)->Effect.runSync
|
|
502
521
|
| Open({key, item}) =>
|
|
@@ -511,6 +530,7 @@ module Make = (
|
|
|
511
530
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
|
|
512
531
|
EffectLogger.logError(
|
|
513
532
|
~comp=`AutomationSlice(${Spec.name})`,
|
|
533
|
+
~ids=?row.source->Option.map(EffectLogger.idsOfSource),
|
|
514
534
|
`failed to encode command: ${errMsg}`,
|
|
515
535
|
)->Effect.runSync
|
|
516
536
|
let updated = row->afterFailedAttempt
|
|
@@ -523,7 +543,7 @@ module Make = (
|
|
|
523
543
|
commandJson->Option.forEach(commandJson => {
|
|
524
544
|
let msg: Reventless.Message.commandJson = {
|
|
525
545
|
id: targetId,
|
|
526
|
-
meta: makeMeta(),
|
|
546
|
+
meta: makeMeta(row),
|
|
527
547
|
commandJson,
|
|
528
548
|
}
|
|
529
549
|
let _ = commands->Array.push(msg)
|
|
@@ -34,7 +34,8 @@ let todoRowSchema = Sury.$schema(s => ({
|
|
|
34
34
|
processedAt: s.m(Sury.$option(Sury.string)),
|
|
35
35
|
completedAt: s.m(Sury.$option(Sury.string)),
|
|
36
36
|
retryCount: s.m(Sury.int32),
|
|
37
|
-
maxRetries: s.m(Sury.$option(Sury.int32))
|
|
37
|
+
maxRetries: s.m(Sury.$option(Sury.int32)),
|
|
38
|
+
source: s.m(Sury.$option(Message$ReventlessCore.flowSourceSchema))
|
|
38
39
|
}));
|
|
39
40
|
|
|
40
41
|
function todoRowSchemaFor(itemSchema) {
|
|
@@ -45,7 +46,8 @@ function todoRowSchemaFor(itemSchema) {
|
|
|
45
46
|
processedAt: s.m(Sury.$option(Sury.string)),
|
|
46
47
|
completedAt: s.m(Sury.$option(Sury.string)),
|
|
47
48
|
retryCount: s.m(Sury.int32),
|
|
48
|
-
maxRetries: s.m(Sury.$option(Sury.int32))
|
|
49
|
+
maxRetries: s.m(Sury.$option(Sury.int32)),
|
|
50
|
+
source: s.m(Sury.$option(Message$ReventlessCore.flowSourceSchema))
|
|
49
51
|
}));
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -84,7 +86,14 @@ function Make(Spec) {
|
|
|
84
86
|
return changes;
|
|
85
87
|
};
|
|
86
88
|
let readsClock = Automation.mappings.some(M => M.sourceName === Clock$Reventless.name);
|
|
87
|
-
let makeMeta =
|
|
89
|
+
let makeMeta = row => {
|
|
90
|
+
let source = row.source;
|
|
91
|
+
if (source !== undefined) {
|
|
92
|
+
return Message$ReventlessCore.deriveMetaFromSource(source, Spec.targetName);
|
|
93
|
+
} else {
|
|
94
|
+
return Message$ReventlessCore.generateMeta(Spec.targetName, undefined, undefined, undefined, undefined, undefined, undefined);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
88
97
|
let personalFields = Pii$Reventless.recordFields(Spec.todoItemSchema);
|
|
89
98
|
let keyField = "$key";
|
|
90
99
|
let fingerprintPurpose = `automationWorkItem:` + Spec.name;
|
|
@@ -101,12 +110,12 @@ function Make(Spec) {
|
|
|
101
110
|
}
|
|
102
111
|
let why = fingerprint._0._0;
|
|
103
112
|
if (Pii$Reventless.Provider.isRequired()) {
|
|
104
|
-
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 + `)`));
|
|
105
114
|
return;
|
|
106
115
|
} else {
|
|
107
116
|
if (!warnedUnkeyed.contents) {
|
|
108
117
|
warnedUnkeyed.contents = true;
|
|
109
|
-
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 + `)`));
|
|
110
119
|
}
|
|
111
120
|
return key;
|
|
112
121
|
}
|
|
@@ -194,19 +203,19 @@ function Make(Spec) {
|
|
|
194
203
|
try {
|
|
195
204
|
commandJson = Util_Sury$Reventless.toJson(param[1], Spec.commandSchema);
|
|
196
205
|
} catch (exn) {
|
|
197
|
-
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`));
|
|
198
207
|
return;
|
|
199
208
|
}
|
|
200
209
|
return {
|
|
201
210
|
id: param[0],
|
|
202
|
-
meta: makeMeta(),
|
|
211
|
+
meta: makeMeta(row),
|
|
203
212
|
commandJson: commandJson
|
|
204
213
|
};
|
|
205
214
|
});
|
|
206
215
|
case "Gone" :
|
|
207
216
|
return;
|
|
208
217
|
case "Unopened" :
|
|
209
|
-
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`));
|
|
210
219
|
return;
|
|
211
220
|
}
|
|
212
221
|
};
|
|
@@ -219,7 +228,7 @@ function Make(Spec) {
|
|
|
219
228
|
return millis;
|
|
220
229
|
}
|
|
221
230
|
};
|
|
222
|
-
let apply = async (param, capabilities) => {
|
|
231
|
+
let apply = async (param, capabilities, source) => {
|
|
223
232
|
let collected = param.collected;
|
|
224
233
|
for (let i = 0, i_finish = collected.length; i < i_finish; ++i) {
|
|
225
234
|
let match = collected[i];
|
|
@@ -236,11 +245,12 @@ function Make(Spec) {
|
|
|
236
245
|
status: "Pending",
|
|
237
246
|
createdAt: row_createdAt,
|
|
238
247
|
retryCount: 0,
|
|
239
|
-
maxRetries: row_maxRetries
|
|
248
|
+
maxRetries: row_maxRetries,
|
|
249
|
+
source: source
|
|
240
250
|
};
|
|
241
251
|
todoItems[id] = row;
|
|
242
252
|
} else {
|
|
243
|
-
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));
|
|
244
254
|
}
|
|
245
255
|
}
|
|
246
256
|
}
|
|
@@ -255,14 +265,18 @@ function Make(Spec) {
|
|
|
255
265
|
routed.forEach(r => {
|
|
256
266
|
r.rescheduled.forEach(change => {
|
|
257
267
|
if (!readsClock) {
|
|
258
|
-
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`));
|
|
259
271
|
}
|
|
260
272
|
let platformChange = AutomationSlice_Schedules$ReventlessCore.apply(schedules, change, setBy, recordedAt);
|
|
261
273
|
if (platformChange.TAG === "Ok") {
|
|
262
274
|
scheduleChanges.contents = scheduleChanges.contents.concat([platformChange._0]);
|
|
263
275
|
return;
|
|
264
276
|
} else {
|
|
265
|
-
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`));
|
|
266
280
|
}
|
|
267
281
|
});
|
|
268
282
|
});
|
|
@@ -284,8 +298,9 @@ function Make(Spec) {
|
|
|
284
298
|
let dict = Stdlib_JSON.Decode.object(json);
|
|
285
299
|
let eventPayload = dict !== undefined ? Stdlib_Option.getOr(dict["event"], json) : json;
|
|
286
300
|
let routed = Route.route(eventPayload, sourceName, context.id, ctx);
|
|
301
|
+
let source = sourceName === Clock$Reventless.name ? undefined : Message$ReventlessCore.flowSourceOf(context.meta);
|
|
287
302
|
for (let j = 0, j_finish = routed.length; j < j_finish; ++j) {
|
|
288
|
-
await apply(routed[j], capabilities);
|
|
303
|
+
await apply(routed[j], capabilities, source);
|
|
289
304
|
}
|
|
290
305
|
reschedule(routed, context.meta.msgId, Stdlib_Option.getOr(ctx.recordedAt, Date.now()));
|
|
291
306
|
if (sourceName === Clock$Reventless.name) {
|
|
@@ -376,7 +391,7 @@ function Make(Spec) {
|
|
|
376
391
|
} catch (raw_exn) {
|
|
377
392
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
378
393
|
let errMsg = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown");
|
|
379
|
-
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));
|
|
380
395
|
let updated = afterFailedAttempt(row);
|
|
381
396
|
todoItems[id] = updated;
|
|
382
397
|
if (updated.status === "Abandoned") {
|
|
@@ -385,7 +400,7 @@ function Make(Spec) {
|
|
|
385
400
|
commandJson = undefined;
|
|
386
401
|
}
|
|
387
402
|
Stdlib_Option.forEach(commandJson, commandJson => {
|
|
388
|
-
let msg_meta = makeMeta();
|
|
403
|
+
let msg_meta = makeMeta(row);
|
|
389
404
|
let msg = {
|
|
390
405
|
id: targetId,
|
|
391
406
|
meta: msg_meta,
|
|
@@ -396,14 +411,14 @@ function Make(Spec) {
|
|
|
396
411
|
}
|
|
397
412
|
break;
|
|
398
413
|
case "Gone" :
|
|
399
|
-
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`));
|
|
400
415
|
let newrecord$1 = {...row};
|
|
401
416
|
newrecord$1.completedAt = new Date().toISOString();
|
|
402
417
|
newrecord$1.status = "Completed";
|
|
403
418
|
todoItems[id] = newrecord$1;
|
|
404
419
|
break;
|
|
405
420
|
case "Unopened" :
|
|
406
|
-
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));
|
|
407
422
|
break;
|
|
408
423
|
}
|
|
409
424
|
}
|
|
@@ -413,7 +428,7 @@ function Make(Spec) {
|
|
|
413
428
|
} catch (raw_exn$1) {
|
|
414
429
|
let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
|
|
415
430
|
let errMsg$1 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$1), Stdlib_JsExn.message), "unknown");
|
|
416
|
-
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));
|
|
417
432
|
pending.forEach(param => {
|
|
418
433
|
let id = param[0];
|
|
419
434
|
let current = todoItems[id];
|
|
@@ -451,7 +466,7 @@ function Make(Spec) {
|
|
|
451
466
|
} catch (raw_exn$2) {
|
|
452
467
|
let exn$2 = Primitive_exceptions.internalToException(raw_exn$2);
|
|
453
468
|
let errMsg$2 = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn$2), Stdlib_JsExn.message), "unknown");
|
|
454
|
-
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));
|
|
455
470
|
}
|
|
456
471
|
};
|
|
457
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
|
}
|
|
@@ -25,7 +25,9 @@ let componentType = "CommandTopic";
|
|
|
25
25
|
|
|
26
26
|
let refusalCauseToGraphQL = CommandTopic_Helpers$ReventlessCore.refusalCauseToGraphQL;
|
|
27
27
|
|
|
28
|
-
let
|
|
28
|
+
let commandOutcomeHooks = CommandTopic_Helpers$ReventlessCore.commandOutcomeHooks;
|
|
29
|
+
|
|
30
|
+
let nextOutcomeHookId = CommandTopic_Helpers$ReventlessCore.nextOutcomeHookId;
|
|
29
31
|
|
|
30
32
|
let registerCommandOutcome = CommandTopic_Helpers$ReventlessCore.registerCommandOutcome;
|
|
31
33
|
|
|
@@ -63,7 +65,8 @@ export {
|
|
|
63
65
|
componentType,
|
|
64
66
|
NotPublishedToChannel,
|
|
65
67
|
refusalCauseToGraphQL,
|
|
66
|
-
|
|
68
|
+
commandOutcomeHooks,
|
|
69
|
+
nextOutcomeHookId,
|
|
67
70
|
registerCommandOutcome,
|
|
68
71
|
clearCommandOutcome,
|
|
69
72
|
fireCommandOutcome,
|
|
@@ -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 {
|