@reventlessdev/reventless-core 3.0.0-alpha.310 → 3.0.0-alpha.312
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 +44 -0
- package/package.json +6 -6
- package/src/Message.res +23 -6
- package/src/Message.res.mjs +15 -6
- package/src/adapter/Secrets/Secrets_Node_Backend.res +41 -2
- package/src/adapter/Secrets/Secrets_Node_Backend.res.mjs +65 -23
- package/src/admin/Platform_Admin.res.mjs +0 -2
- package/src/components/Aggregate/Aggregate_Callback.res +111 -48
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +107 -49
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +2 -2
- package/src/components/Builder_Helpers.res +0 -17
- package/src/components/Builder_Helpers.res.mjs +0 -15
- package/src/components/CommandGenerator/CommandGenerator.res +3 -1
- package/src/components/CommandGenerator/CommandGenerator_Callback.res +0 -1
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +0 -2
- package/src/components/Counter/Counter_Callback.res.mjs +1 -1
- package/src/components/DcbEventLog/DcbEventLog_Operations.res.mjs +1 -1
- package/src/components/EventLog/EventLog.res +7 -0
- package/src/components/EventLog/EventLog_Builder.res +2 -0
- package/src/components/EventLog/EventLog_Builder.res.mjs +1 -0
- package/src/components/EventLog/EventLog_Operations.res +30 -0
- package/src/components/EventLog/EventLog_Operations.res.mjs +18 -0
- package/src/components/Extension/Extension.res +0 -2
- package/src/components/Extension/Extension_Builder.res +2 -20
- package/src/components/Extension/Extension_Builder.res.mjs +1 -3
- package/src/components/Extension/Extension_Operations.res +0 -19
- package/src/components/Extension/Extension_Operations.res.mjs +1 -7
- package/src/components/Heartbeat/Heartbeat_Callback.res +0 -1
- package/src/components/Heartbeat/Heartbeat_Callback.res.mjs +0 -1
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +1 -1
- package/src/components/ReadModel/ReadModel_Builder.res +12 -2
- package/src/components/ReadModel/ReadModel_Builder.res.mjs +2 -1
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +72 -35
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +45 -31
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +2 -2
- package/src/plugin/component/Plugin_Builder.res +1 -26
- package/src/plugin/component/Plugin_Builder.res.mjs +6 -20
- package/src/plugin/component/Plugin_Helpers.res +0 -37
- package/src/plugin/component/Plugin_Helpers.res.mjs +8 -21
- package/src/plugin/connect/PluginExtensionPoint_Plugin.res.mjs +1 -1
- package/src/util/CommandPublisher.res.mjs +1 -1
- package/tests/Secrets_Node_BackendTest.res +32 -0
- package/tests/Secrets_Node_BackendTest.res.mjs +29 -1
- package/tests/aggregate/AggregateCacheTest.res +6 -0
- package/tests/aggregate/AggregateCacheTest.res.mjs +5 -0
- package/tests/aggregate/AggregateConflictTest.res +6 -0
- package/tests/aggregate/AggregateConflictTest.res.mjs +5 -0
- package/tests/aggregate/AggregateFixtures.res +6 -0
- package/tests/aggregate/AggregateFixtures.res.mjs +5 -0
- package/tests/aggregate/AggregateRepeatTest.res +186 -0
- package/tests/aggregate/AggregateRepeatTest.res.mjs +332 -0
- package/tests/aggregate/AggregateSnapshotTest.res +6 -0
- package/tests/aggregate/AggregateSnapshotTest.res.mjs +12 -0
- package/tests/commandgenerator/OwnerActingTest.res +6 -0
- package/tests/commandgenerator/OwnerActingTest.res.mjs +5 -0
- package/tests/dcb/DcbEventLogOperationsTest.res.mjs +1 -1
- package/tests/extensionpoint/DerivedMessageIdTest.res +217 -0
- package/tests/extensionpoint/DerivedMessageIdTest.res.mjs +361 -0
- package/tests/logger/LogFormatTest.res +1 -2
- package/tests/logger/LogFormatTest.res.mjs +2 -3
- package/tests/message/MessageTest.res +57 -1
- package/tests/message/MessageTest.res.mjs +61 -2
- package/tests/message/MetaEnvelopeTest.res +37 -20
- package/tests/message/MetaEnvelopeTest.res.mjs +32 -17
- package/tests/plugin/HeartbeatDisconnectGraceTest.res.mjs +1 -1
- package/tests/plugin/pluginDefinitionRequiredScalars.txt +0 -1
|
@@ -46,25 +46,41 @@ function Make(Spec) {
|
|
|
46
46
|
return owners;
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
let processCommand = seq => ((
|
|
49
|
+
let processCommand = seq => ((acc, topicItem) => {
|
|
50
50
|
let reference = topicItem.reference;
|
|
51
51
|
let command$p = topicItem.command;
|
|
52
|
-
let outcomes =
|
|
53
|
-
let
|
|
54
|
-
let
|
|
52
|
+
let outcomes = acc.outcomes;
|
|
53
|
+
let causes = acc.causes;
|
|
54
|
+
let owners = acc.owners;
|
|
55
|
+
let state = acc.state;
|
|
55
56
|
let meta = Message$ReventlessCore.deriveMeta(command$p.meta, undefined);
|
|
56
57
|
let id = Spec.Id.toString(command$p.id);
|
|
57
58
|
let cmdVariant = Message$ReventlessCore.variantNameOfJson(Message$ReventlessCore.encode(command$p.command, Spec.commandSchema));
|
|
58
59
|
let cmdName = LogFormat$ReventlessCore.bold(cmdVariant);
|
|
59
60
|
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, `deciding: id=` + id + ` seq=` + seq.toString() + ` cmd=` + cmdName));
|
|
60
|
-
let
|
|
61
|
+
let repeated = Message$ReventlessCore.hasStableMsgId(command$p.meta) && causes.includes(command$p.meta.msgId);
|
|
62
|
+
let refusal = repeated || !actsOnOwned ? undefined : CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(command$p.meta.callerClaim, owners), Spec.name, cmdVariant);
|
|
63
|
+
if (repeated) {
|
|
64
|
+
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, `repeat dropped: ` + cmdName + `(` + id + `) msgId=` + command$p.meta.msgId + ` already caused events`));
|
|
65
|
+
return {
|
|
66
|
+
state: acc.state,
|
|
67
|
+
owners: acc.owners,
|
|
68
|
+
causes: acc.causes,
|
|
69
|
+
outcomes: outcomes.concat([[
|
|
70
|
+
reference,
|
|
71
|
+
"CmdRepeated",
|
|
72
|
+
meta
|
|
73
|
+
]])
|
|
74
|
+
};
|
|
75
|
+
}
|
|
61
76
|
if (refusal !== undefined) {
|
|
62
77
|
let line = `refused: ` + refusal.rejected.errorDetail + ` id=` + id;
|
|
63
78
|
Effect.runSync(refusal.isDefect ? EffectLogger$ReventlessCore.logError(comp, undefined, line) : EffectLogger$ReventlessCore.logWarn(comp, undefined, line));
|
|
64
|
-
return
|
|
65
|
-
state,
|
|
66
|
-
owners,
|
|
67
|
-
|
|
79
|
+
return {
|
|
80
|
+
state: acc.state,
|
|
81
|
+
owners: acc.owners,
|
|
82
|
+
causes: acc.causes,
|
|
83
|
+
outcomes: outcomes.concat([[
|
|
68
84
|
reference,
|
|
69
85
|
{
|
|
70
86
|
TAG: "CmdRefused",
|
|
@@ -72,16 +88,17 @@ function Make(Spec) {
|
|
|
72
88
|
},
|
|
73
89
|
meta
|
|
74
90
|
]])
|
|
75
|
-
|
|
91
|
+
};
|
|
76
92
|
}
|
|
77
93
|
let generatedEvents = Decision.decide(state, command$p.command);
|
|
78
94
|
if (generatedEvents.TAG === "Ok") {
|
|
79
95
|
let generatedEvents$1 = generatedEvents._0;
|
|
80
96
|
let newState = Stdlib_Array.reduce(generatedEvents$1, state, Decision.evolve);
|
|
81
|
-
return
|
|
82
|
-
newState,
|
|
83
|
-
Stdlib_Array.reduce(generatedEvents$1, owners, recordEventOwners),
|
|
84
|
-
|
|
97
|
+
return {
|
|
98
|
+
state: newState,
|
|
99
|
+
owners: Stdlib_Array.reduce(generatedEvents$1, owners, recordEventOwners),
|
|
100
|
+
causes: generatedEvents$1.length === 0 ? causes : causes.concat([command$p.meta.msgId]),
|
|
101
|
+
outcomes: outcomes.concat([[
|
|
85
102
|
reference,
|
|
86
103
|
{
|
|
87
104
|
TAG: "CmdOk",
|
|
@@ -89,7 +106,7 @@ function Make(Spec) {
|
|
|
89
106
|
},
|
|
90
107
|
meta
|
|
91
108
|
]])
|
|
92
|
-
|
|
109
|
+
};
|
|
93
110
|
}
|
|
94
111
|
let errorJson = Message$ReventlessCore.encode(generatedEvents._0, Spec.errorSchema);
|
|
95
112
|
let errorCode = Message$ReventlessCore.variantNameOfJson(errorJson);
|
|
@@ -97,10 +114,11 @@ function Make(Spec) {
|
|
|
97
114
|
let payloadDict = match[1];
|
|
98
115
|
let errorDetail = Object.entries(payloadDict).length === 0 ? "" : JSON.stringify(payloadDict);
|
|
99
116
|
Effect.runSync(EffectLogger$ReventlessCore.logError(comp, undefined, `decide rejected: ` + errorCode + ` ` + errorDetail + ` id=` + id));
|
|
100
|
-
return
|
|
101
|
-
state,
|
|
102
|
-
owners,
|
|
103
|
-
|
|
117
|
+
return {
|
|
118
|
+
state: acc.state,
|
|
119
|
+
owners: acc.owners,
|
|
120
|
+
causes: acc.causes,
|
|
121
|
+
outcomes: outcomes.concat([[
|
|
104
122
|
reference,
|
|
105
123
|
{
|
|
106
124
|
TAG: "CmdRejected",
|
|
@@ -109,7 +127,7 @@ function Make(Spec) {
|
|
|
109
127
|
},
|
|
110
128
|
meta
|
|
111
129
|
]])
|
|
112
|
-
|
|
130
|
+
};
|
|
113
131
|
});
|
|
114
132
|
let replayCache = Lru$ReventlessCore.make(100);
|
|
115
133
|
let resetCache = () => Lru$ReventlessCore.clear(replayCache);
|
|
@@ -205,6 +223,24 @@ function Make(Spec) {
|
|
|
205
223
|
});
|
|
206
224
|
});
|
|
207
225
|
};
|
|
226
|
+
let coldReadCauses = id => {
|
|
227
|
+
let idStr = Spec.Id.toString(id);
|
|
228
|
+
return Effect.tap(Stream.runFold(Ops.eventLog["replayStream'"](id, 0), [
|
|
229
|
+
Decision.initialState,
|
|
230
|
+
0,
|
|
231
|
+
[],
|
|
232
|
+
[]
|
|
233
|
+
], (param, ev$p) => {
|
|
234
|
+
let causes = param[3];
|
|
235
|
+
let c = ev$p.meta.causationId;
|
|
236
|
+
return [
|
|
237
|
+
Decision.evolve(param[0], ev$p.event),
|
|
238
|
+
param[1] + 1 | 0,
|
|
239
|
+
recordEventOwners(param[2], ev$p.event),
|
|
240
|
+
c !== undefined && !causes.includes(c) ? causes.concat([c]) : causes
|
|
241
|
+
];
|
|
242
|
+
}), param => EffectLogger$ReventlessCore.logInfo(comp, undefined, `replay (with causes, for a stable-id command): id=` + idStr + `, ` + param[1].toString() + ` event(s)`));
|
|
243
|
+
};
|
|
208
244
|
let maybeWriteSnapshot = (id, idStr, oldSeq, newSeq, state) => {
|
|
209
245
|
if (snapshotConfig === undefined) {
|
|
210
246
|
return;
|
|
@@ -242,6 +278,16 @@ function Make(Spec) {
|
|
|
242
278
|
return outcomes.map(param => {
|
|
243
279
|
let outcome = param[1];
|
|
244
280
|
let reference = param[0];
|
|
281
|
+
if (typeof outcome !== "object") {
|
|
282
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, reference, {
|
|
283
|
+
entityId: entityId,
|
|
284
|
+
eventCount: 0
|
|
285
|
+
});
|
|
286
|
+
return {
|
|
287
|
+
TAG: "Ok",
|
|
288
|
+
_0: reference
|
|
289
|
+
};
|
|
290
|
+
}
|
|
245
291
|
switch (outcome.TAG) {
|
|
246
292
|
case "CmdOk" :
|
|
247
293
|
if (appendSucceeded) {
|
|
@@ -283,45 +329,57 @@ function Make(Spec) {
|
|
|
283
329
|
};
|
|
284
330
|
let replayProcessAppend = (id, topicItemsForId) => {
|
|
285
331
|
let idStr = Spec.Id.toString(id);
|
|
286
|
-
let
|
|
332
|
+
let asksForRepeats = topicItemsForId.some(item => Message$ReventlessCore.hasStableMsgId(item.command.meta));
|
|
287
333
|
let readState;
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
let seqNr = match[1];
|
|
291
|
-
let state = match[0];
|
|
292
|
-
readState = Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, `replay skipped (cached): id=` + idStr + `, seq=` + seqNr.toString()), () => [
|
|
293
|
-
state,
|
|
294
|
-
seqNr,
|
|
295
|
-
owners
|
|
296
|
-
]);
|
|
334
|
+
if (asksForRepeats) {
|
|
335
|
+
readState = coldReadCauses(id);
|
|
297
336
|
} else {
|
|
298
|
-
|
|
337
|
+
let match = Lru$ReventlessCore.get(replayCache, idStr);
|
|
338
|
+
if (match !== undefined) {
|
|
339
|
+
let owners = match[2];
|
|
340
|
+
let seqNr = match[1];
|
|
341
|
+
let state = match[0];
|
|
342
|
+
readState = Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, `replay skipped (cached): id=` + idStr + `, seq=` + seqNr.toString()), () => [
|
|
343
|
+
state,
|
|
344
|
+
seqNr,
|
|
345
|
+
owners,
|
|
346
|
+
[]
|
|
347
|
+
]);
|
|
348
|
+
} else {
|
|
349
|
+
readState = Effect.map(coldReadState(id), param => [
|
|
350
|
+
param[0],
|
|
351
|
+
param[1],
|
|
352
|
+
param[2],
|
|
353
|
+
[]
|
|
354
|
+
]);
|
|
355
|
+
}
|
|
299
356
|
}
|
|
300
357
|
return Effect.flatMap(readState, param => {
|
|
301
358
|
let initialOwners = param[2];
|
|
302
359
|
let sequenceNr = param[1];
|
|
303
360
|
let initialState = param[0];
|
|
304
|
-
let match = Stdlib_Array.reduce(topicItemsForId,
|
|
305
|
-
initialState,
|
|
306
|
-
initialOwners,
|
|
307
|
-
[]
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
let
|
|
311
|
-
let
|
|
361
|
+
let match = Stdlib_Array.reduce(topicItemsForId, {
|
|
362
|
+
state: initialState,
|
|
363
|
+
owners: initialOwners,
|
|
364
|
+
causes: param[3],
|
|
365
|
+
outcomes: []
|
|
366
|
+
}, processCommand(sequenceNr));
|
|
367
|
+
let outcomes = match.outcomes;
|
|
368
|
+
let finalOwners = match.owners;
|
|
369
|
+
let finalState = match.state;
|
|
312
370
|
let eventsToAppend = outcomes.map(param => {
|
|
313
371
|
let meta = param[2];
|
|
314
372
|
let outcome = param[1];
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
373
|
+
if (typeof outcome !== "object") {
|
|
374
|
+
return [];
|
|
375
|
+
} else if (outcome.TAG === "CmdOk") {
|
|
376
|
+
return outcome._0.map(event => ({
|
|
377
|
+
id: id,
|
|
378
|
+
meta: meta,
|
|
379
|
+
event: event
|
|
380
|
+
}));
|
|
381
|
+
} else {
|
|
382
|
+
return [];
|
|
325
383
|
}
|
|
326
384
|
}).flat();
|
|
327
385
|
if (eventsToAppend.length !== 0) {
|
|
@@ -49,7 +49,7 @@ function todoRowSchemaFor(itemSchema) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function tickEvent(key, at) {
|
|
52
|
-
let newrecord = {...Message$ReventlessCore.generateMeta(Clock$Reventless.name, undefined, undefined, undefined, undefined, undefined, undefined
|
|
52
|
+
let newrecord = {...Message$ReventlessCore.generateMeta(Clock$Reventless.name, undefined, undefined, undefined, undefined, undefined, undefined)};
|
|
53
53
|
return Object.fromEntries([
|
|
54
54
|
[
|
|
55
55
|
"id",
|
|
@@ -83,7 +83,7 @@ function Make(Spec) {
|
|
|
83
83
|
return changes;
|
|
84
84
|
};
|
|
85
85
|
let readsClock = Automation.mappings.some(M => M.sourceName === Clock$Reventless.name);
|
|
86
|
-
let makeMeta = () => Message$ReventlessCore.generateMeta(Spec.targetName, undefined, undefined, undefined, undefined, undefined, undefined
|
|
86
|
+
let makeMeta = () => Message$ReventlessCore.generateMeta(Spec.targetName, undefined, undefined, undefined, undefined, undefined, undefined);
|
|
87
87
|
let processingTimeoutMs = 15 * 60 * 1000;
|
|
88
88
|
let afterFailedAttempt = row => {
|
|
89
89
|
let retryCount = row.retryCount + 1 | 0;
|
|
@@ -118,9 +118,6 @@ let finishTasks = () =>
|
|
|
118
118
|
->Pulumi.Output.apply(_ => taskSideEffectFinishFns->Array.forEach(finishFn => finishFn()))
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
let readModelNamesForSourceName = Dict.make()
|
|
122
|
-
let publishToReadModels = Dict.make()
|
|
123
|
-
|
|
124
121
|
let finishReadModels = readModels => {
|
|
125
122
|
let _ =
|
|
126
123
|
readModels
|
|
@@ -161,20 +158,6 @@ let createReadModels = (
|
|
|
161
158
|
)
|
|
162
159
|
let rmOutputs = SpecificReadModel.outputs(readModel)
|
|
163
160
|
let rmOperations = SpecificReadModel.operations(readModel)
|
|
164
|
-
rmOutputs.sourceNames->Array.forEach(sourceName =>
|
|
165
|
-
switch readModelNamesForSourceName->Dict.get(sourceName) {
|
|
166
|
-
| Some(readModelNames) =>
|
|
167
|
-
readModelNamesForSourceName->Dict.set(
|
|
168
|
-
sourceName,
|
|
169
|
-
readModelNames->Array.concat([SpecificReadModel.Spec.name]),
|
|
170
|
-
)
|
|
171
|
-
| None => Dict.set(readModelNamesForSourceName, sourceName, [SpecificReadModel.Spec.name])
|
|
172
|
-
}
|
|
173
|
-
)
|
|
174
|
-
publishToReadModels->Dict.set(
|
|
175
|
-
SpecificReadModel.Spec.name,
|
|
176
|
-
rmOperations->Pulumi.Output.apply(({enqueueEvent}) => enqueueEvent),
|
|
177
|
-
)
|
|
178
161
|
|
|
179
162
|
// Deferred to `finishReadModels`, which runs it from an apply — wrap it here
|
|
180
163
|
// so the read model's runtime is attributed to the plugin building it.
|
|
@@ -67,10 +67,6 @@ function finishTasks() {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
let readModelNamesForSourceName = {};
|
|
71
|
-
|
|
72
|
-
let publishToReadModels = {};
|
|
73
|
-
|
|
74
70
|
function finishReadModels(readModels) {
|
|
75
71
|
Pulumi.all(readModels.map(param => param[1].operations)).apply(param => {
|
|
76
72
|
readModels.forEach(param => param[1].finish());
|
|
@@ -89,15 +85,6 @@ function createReadModels(readModels, api, apiRole, componentRuntime, allEventTo
|
|
|
89
85
|
let readModel = SpecificReadModel.make(api, apiRole, allEventTopics, componentRuntime[SpecificReadModel.Spec.name], opts);
|
|
90
86
|
let rmOutputs = SpecificReadModel.outputs(readModel);
|
|
91
87
|
let rmOperations = SpecificReadModel.operations(readModel);
|
|
92
|
-
rmOutputs.sourceNames.forEach(sourceName => {
|
|
93
|
-
let readModelNames = readModelNamesForSourceName[sourceName];
|
|
94
|
-
if (readModelNames !== undefined) {
|
|
95
|
-
readModelNamesForSourceName[sourceName] = readModelNames.concat([SpecificReadModel.Spec.name]);
|
|
96
|
-
} else {
|
|
97
|
-
readModelNamesForSourceName[sourceName] = [SpecificReadModel.Spec.name];
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
publishToReadModels[SpecificReadModel.Spec.name] = rmOperations.apply(param => param.enqueueEvent);
|
|
101
88
|
return [
|
|
102
89
|
SpecificReadModel.Spec.name,
|
|
103
90
|
{
|
|
@@ -154,8 +141,6 @@ export {
|
|
|
154
141
|
taskSideEffectFinishFns,
|
|
155
142
|
registerTaskSideEffectHandler,
|
|
156
143
|
finishTasks,
|
|
157
|
-
readModelNamesForSourceName,
|
|
158
|
-
publishToReadModels,
|
|
159
144
|
finishReadModels,
|
|
160
145
|
extractReadModelsOutputs,
|
|
161
146
|
createReadModels,
|
|
@@ -13,7 +13,9 @@ The `id` field is the envelope id for the produced command message:
|
|
|
13
13
|
source of truth.
|
|
14
14
|
*/
|
|
15
15
|
type arguments = {id: string}
|
|
16
|
-
|
|
16
|
+
// `ip` is what a resolver written before the caller's address left the envelope
|
|
17
|
+
// still sends; nothing reads it, so it never reaches a message.
|
|
18
|
+
type meta = {ip?: array<string>, user: string, info: string}
|
|
17
19
|
type payload = {
|
|
18
20
|
command: string,
|
|
19
21
|
arguments: arguments,
|
|
@@ -64,13 +64,11 @@ function makeGenerateCommand(publishJsons, publishJsonsAndWait, serviceName, com
|
|
|
64
64
|
let msgId = Message$ReventlessCore.uuid();
|
|
65
65
|
let scope = OwnerScope$Reventless.resolve(payload.identity, undefined);
|
|
66
66
|
let meta_time = Message$ReventlessCore.nowAsISOString();
|
|
67
|
-
let meta_ip = Stdlib_Option.getOr(payload.meta.ip.shift(), "");
|
|
68
67
|
let meta_user = payload.meta.user;
|
|
69
68
|
let meta_callerClaim = OwnerScope$Reventless.toClaim(scope);
|
|
70
69
|
let meta = {
|
|
71
70
|
service: serviceName,
|
|
72
71
|
time: meta_time,
|
|
73
|
-
ip: meta_ip,
|
|
74
72
|
user: meta_user,
|
|
75
73
|
msgId: msgId,
|
|
76
74
|
correlationId: msgId,
|
|
@@ -39,7 +39,7 @@ function Make(Spec) {
|
|
|
39
39
|
if (count === 0) {
|
|
40
40
|
let match$1 = Counter$ReventlessCore.unmakeId(id);
|
|
41
41
|
Effect.runSync(EffectLogger$ReventlessCore.logInfo("Counter_Callback-ReventlessCore", undefined, `counterHandler: counted down ` + Spec.name + `(` + id + `) to ` + count.toString()));
|
|
42
|
-
let meta = Message$ReventlessCore.generateMeta(ComponentType$ReventlessCore.toName("Counter"),
|
|
42
|
+
let meta = Message$ReventlessCore.generateMeta(ComponentType$ReventlessCore.toName("Counter"), "Counter", undefined, undefined, undefined, undefined, undefined);
|
|
43
43
|
return Object.fromEntries([
|
|
44
44
|
[
|
|
45
45
|
"id",
|
|
@@ -17,7 +17,7 @@ function Make(Ops) {
|
|
|
17
17
|
let serviceName = Ops.serviceName;
|
|
18
18
|
let publishToEventTopic = async rawEvents => {
|
|
19
19
|
let re = rawEvents[0];
|
|
20
|
-
let representativeMeta = re !== undefined ? re.meta : Message$ReventlessCore.generateMeta(serviceName, undefined, undefined, undefined, undefined, undefined, undefined
|
|
20
|
+
let representativeMeta = re !== undefined ? re.meta : Message$ReventlessCore.generateMeta(serviceName, undefined, undefined, undefined, undefined, undefined, undefined);
|
|
21
21
|
let rawEventsJson = rawEvents.map(rawEvent => Message$ReventlessCore.combineMessage(rawEvent.eventType, Stdlib_Option.getOr(Stdlib_JSON.Decode.object(rawEvent.data), {})));
|
|
22
22
|
let hook = EventPublish_Callback$ReventlessCore.beforePublishHook.contents;
|
|
23
23
|
let finalRawEventsJson;
|
|
@@ -33,6 +33,12 @@ type replay<'id, 'event> = 'id => promise<array<'event>>
|
|
|
33
33
|
// `fromSeq` starts the replay at that sequence number (inclusive; default 0) —
|
|
34
34
|
// the delta read after seeding from a snapshot at seqNr = fromSeq.
|
|
35
35
|
type replayStream<'id, 'event> = ('id, ~fromSeq: int=?) => Stream.t<'event, string, unit>
|
|
36
|
+
// The same replay as envelopes, meta included — for a reader that needs to know
|
|
37
|
+
// which command caused each event, not only what happened.
|
|
38
|
+
type replayStream'<'id, 'event> = (
|
|
39
|
+
'id,
|
|
40
|
+
~fromSeq: int=?,
|
|
41
|
+
) => Stream.t<Message.event'<'id, 'event>, string, unit>
|
|
36
42
|
type appendStream<'id, 'event> = (
|
|
37
43
|
int,
|
|
38
44
|
'id,
|
|
@@ -52,6 +58,7 @@ module type T = {
|
|
|
52
58
|
append: append<Spec.Id.t, Message.event'<Spec.Id.t, Spec.event>>,
|
|
53
59
|
replay: replay<Spec.Id.t, Spec.event>,
|
|
54
60
|
replayStream: replayStream<Spec.Id.t, Spec.event>,
|
|
61
|
+
replayStream': replayStream'<Spec.Id.t, Spec.event>,
|
|
55
62
|
appendStream: appendStream<Spec.Id.t, Spec.event>,
|
|
56
63
|
latestSnapshot: latestSnapshot<Spec.Id.t>,
|
|
57
64
|
writeSnapshot: writeSnapshot<Spec.Id.t>,
|
|
@@ -9,6 +9,7 @@ module Make = (
|
|
|
9
9
|
append: EventLog.append<Spec.Id.t, Message.event'<Spec.Id.t, Spec.event>>,
|
|
10
10
|
replay: EventLog.replay<Spec.Id.t, Spec.event>,
|
|
11
11
|
replayStream: EventLog.replayStream<Spec.Id.t, Spec.event>,
|
|
12
|
+
replayStream': EventLog.replayStream'<Spec.Id.t, Spec.event>,
|
|
12
13
|
appendStream: EventLog.appendStream<Spec.Id.t, Spec.event>,
|
|
13
14
|
latestSnapshot: EventLog.latestSnapshot<Spec.Id.t>,
|
|
14
15
|
writeSnapshot: EventLog.writeSnapshot<Spec.Id.t>,
|
|
@@ -58,6 +59,7 @@ module Make = (
|
|
|
58
59
|
append: Ops.append,
|
|
59
60
|
replay: Ops.replay,
|
|
60
61
|
replayStream: Ops.replayStream,
|
|
62
|
+
replayStream': Ops.replayStream',
|
|
61
63
|
appendStream: Ops.appendStream,
|
|
62
64
|
latestSnapshot: Ops.latestSnapshot,
|
|
63
65
|
writeSnapshot: Ops.writeSnapshot,
|
|
@@ -10,6 +10,7 @@ module type T = {
|
|
|
10
10
|
let append: EventLog.append<Spec.Id.t, Message.event'<Spec.Id.t, Spec.event>>
|
|
11
11
|
let replay: EventLog.replay<Spec.Id.t, Spec.event>
|
|
12
12
|
let replayStream: EventLog.replayStream<Spec.Id.t, Spec.event>
|
|
13
|
+
let replayStream': EventLog.replayStream'<Spec.Id.t, Spec.event>
|
|
13
14
|
let appendStream: EventLog.appendStream<Spec.Id.t, Spec.event>
|
|
14
15
|
let latestSnapshot: EventLog.latestSnapshot<Spec.Id.t>
|
|
15
16
|
let writeSnapshot: EventLog.writeSnapshot<Spec.Id.t>
|
|
@@ -199,6 +200,35 @@ module Make = (Spec: ReventlessInfra.EventLog.T, Ops: Ops with module Spec = Spe
|
|
|
199
200
|
Effect.sync(() => decodeEvent(id->Spec.Id.toString, json))
|
|
200
201
|
)
|
|
201
202
|
|
|
203
|
+
// The stored item is the flat form `storedEventToFlatJson` writes: meta.* at the
|
|
204
|
+
// top level, reassembled the way `flatJsonToStoredEvent` does.
|
|
205
|
+
let decodeMeta = (id, json) =>
|
|
206
|
+
try {
|
|
207
|
+
json
|
|
208
|
+
->JSON.Decode.object
|
|
209
|
+
->Option.getOrThrow
|
|
210
|
+
->Message.composeMeta
|
|
211
|
+
->Reventless.Util_Sury.fromJson(Message.metaSchema)
|
|
212
|
+
} catch {
|
|
213
|
+
| exn =>
|
|
214
|
+
JsError.throwWithMessage(
|
|
215
|
+
`EventLog.replay: Error: id:${id}: Couldn't decode meta of ${json->JSON.stringify}: ${Reventless.Util_Sury.exnMessage(
|
|
216
|
+
exn,
|
|
217
|
+
)}`,
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let replayStream' = (id, ~fromSeq=?) => {
|
|
222
|
+
let idStr = id->Spec.Id.toString
|
|
223
|
+
Ops.storage.replayStream(idStr, ~fromSeq?)->Stream.mapEffect(json =>
|
|
224
|
+
Effect.sync(() => {
|
|
225
|
+
Reventless.Message.id,
|
|
226
|
+
meta: decodeMeta(idStr, json),
|
|
227
|
+
event: decodeEvent(idStr, json),
|
|
228
|
+
})
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
|
|
202
232
|
// Snapshot passthrough — the state stays JSON at this layer; the consumer
|
|
203
233
|
// (Aggregate_Callback) decodes it against its own state schema and hash-gates
|
|
204
234
|
// staleness, so a drifted snapshot degrades to full replay, never to an error.
|
|
@@ -11,6 +11,7 @@ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
|
11
11
|
import * as Duration from "effect/Duration";
|
|
12
12
|
import * as Schedule from "effect/Schedule";
|
|
13
13
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
14
|
+
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
14
15
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
15
16
|
import * as Util_Error$ReventlessCore from "../../util/Util_Error.res.mjs";
|
|
16
17
|
import * as EffectLogger$ReventlessCore from "../../util/EffectLogger.res.mjs";
|
|
@@ -187,6 +188,22 @@ function Make(Spec) {
|
|
|
187
188
|
return eventsJson.map(json => decodeEvent(id$1, json));
|
|
188
189
|
};
|
|
189
190
|
let replayStream = (id, fromSeq) => Stream.mapEffect(Ops.storage.replayStream(Spec.Id.toString(id), fromSeq), json => Effect$1.sync(() => decodeEvent(Spec.Id.toString(id), json)));
|
|
191
|
+
let decodeMeta = (id, json) => {
|
|
192
|
+
try {
|
|
193
|
+
return Util_Sury$Reventless.fromJson(Message$ReventlessCore.composeMeta(Stdlib_Option.getOrThrow(Stdlib_JSON.Decode.object(json), undefined)), Message$ReventlessCore.metaSchema);
|
|
194
|
+
} catch (raw_exn) {
|
|
195
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
196
|
+
return Stdlib_JsError.throwWithMessage(`EventLog.replay: Error: id:` + id + `: Couldn't decode meta of ` + JSON.stringify(json) + `: ` + Util_Sury$Reventless.exnMessage(exn, undefined));
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
let replayStream$p = (id, fromSeq) => {
|
|
200
|
+
let idStr = Spec.Id.toString(id);
|
|
201
|
+
return Stream.mapEffect(Ops.storage.replayStream(idStr, fromSeq), json => Effect$1.sync(() => ({
|
|
202
|
+
id: id,
|
|
203
|
+
meta: decodeMeta(idStr, json),
|
|
204
|
+
event: decodeEvent(idStr, json)
|
|
205
|
+
})));
|
|
206
|
+
};
|
|
190
207
|
let latestSnapshot = id => Ops.storage.latestSnapshot(Spec.Id.toString(id));
|
|
191
208
|
let writeSnapshot = (id, snap) => Ops.storage.writeSnapshot(Spec.Id.toString(id), snap);
|
|
192
209
|
let appendStream = (startingSeqNr, id, stream) => Ops.storage.appendStream(startingSeqNr, Spec.Id.toString(id), Stream.map(stream, event => {
|
|
@@ -208,6 +225,7 @@ function Make(Spec) {
|
|
|
208
225
|
append: append,
|
|
209
226
|
replay: replay,
|
|
210
227
|
replayStream: replayStream,
|
|
228
|
+
replayStream$p: replayStream$p,
|
|
211
229
|
appendStream: appendStream,
|
|
212
230
|
latestSnapshot: latestSnapshot,
|
|
213
231
|
writeSnapshot: writeSnapshot
|
|
@@ -17,8 +17,6 @@ module type T = {
|
|
|
17
17
|
let make: (
|
|
18
18
|
~publishToPluginExtensionPoint: CommandTopic.publishJsons,
|
|
19
19
|
~publishToAggregates: dict<CommandTopic.publishJsons>,
|
|
20
|
-
~readModelNamesForSourceName: dict<array<string>>,
|
|
21
|
-
~publishToReadModels: dict<EventCollector.enqueueEvent>,
|
|
22
20
|
~queryEngine: Reventless.QueryEngine.operations,
|
|
23
21
|
~opts: option<Pulumi.ComponentResource.options>,
|
|
24
22
|
) => component
|
|
@@ -8,8 +8,6 @@ module Make = (
|
|
|
8
8
|
let construct = (
|
|
9
9
|
~publishToPluginExtensionPoint: CommandTopic.publishJsons,
|
|
10
10
|
~publishToAggregates: dict<CommandTopic.publishJsons>,
|
|
11
|
-
~readModelNamesForSourceName: dict<array<string>>,
|
|
12
|
-
~publishToReadModels: dict<EventCollector.enqueueEvent>,
|
|
13
11
|
~queryEngine,
|
|
14
12
|
self,
|
|
15
13
|
name,
|
|
@@ -20,8 +18,6 @@ module Make = (
|
|
|
20
18
|
{
|
|
21
19
|
let publishToAggregates = publishToAggregates
|
|
22
20
|
let publishToPluginExtensionPoint = publishToPluginExtensionPoint
|
|
23
|
-
let readModelNamesForSourceName = readModelNamesForSourceName
|
|
24
|
-
let publishToReadModels = publishToReadModels
|
|
25
21
|
let queryEngine = queryEngine
|
|
26
22
|
},
|
|
27
23
|
)
|
|
@@ -55,25 +51,11 @@ module Make = (
|
|
|
55
51
|
self->Component.setOutputs(extOutputs)
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
let make = (
|
|
59
|
-
~publishToPluginExtensionPoint,
|
|
60
|
-
~publishToAggregates,
|
|
61
|
-
~readModelNamesForSourceName,
|
|
62
|
-
~publishToReadModels,
|
|
63
|
-
~queryEngine,
|
|
64
|
-
~opts,
|
|
65
|
-
) =>
|
|
54
|
+
let make = (~publishToPluginExtensionPoint, ~publishToAggregates, ~queryEngine, ~opts) =>
|
|
66
55
|
Component.make(
|
|
67
56
|
~componentType=Extension.componentType->ComponentType.toString,
|
|
68
57
|
~name=Spec.name ++ ("." ++ Mappings.name),
|
|
69
|
-
~construct=construct(
|
|
70
|
-
~publishToPluginExtensionPoint,
|
|
71
|
-
~publishToAggregates,
|
|
72
|
-
~readModelNamesForSourceName,
|
|
73
|
-
~publishToReadModels,
|
|
74
|
-
~queryEngine,
|
|
75
|
-
...
|
|
76
|
-
),
|
|
58
|
+
~construct=construct(~publishToPluginExtensionPoint, ~publishToAggregates, ~queryEngine, ...),
|
|
77
59
|
~opts,
|
|
78
60
|
)
|
|
79
61
|
|
|
@@ -10,15 +10,13 @@ import * as Extension_Operations$ReventlessCore from "./Extension_Operations.res
|
|
|
10
10
|
|
|
11
11
|
function Make(Spec) {
|
|
12
12
|
return Mappings => {
|
|
13
|
-
let make = (publishToPluginExtensionPoint, publishToAggregates,
|
|
13
|
+
let make = (publishToPluginExtensionPoint, publishToAggregates, queryEngine, opts) => Component$ReventlessCore.make(ComponentType$ReventlessCore.toString(Extension$ReventlessCore.componentType), Spec.name + ("." + Mappings.name), (extra, extra$1) => {
|
|
14
14
|
let Operations = Extension_Operations$ReventlessCore.Make(Spec)({
|
|
15
15
|
name: Mappings.name,
|
|
16
16
|
mappings: Mappings.mappings
|
|
17
17
|
})({
|
|
18
18
|
publishToAggregates: publishToAggregates,
|
|
19
19
|
publishToPluginExtensionPoint: publishToPluginExtensionPoint,
|
|
20
|
-
readModelNamesForSourceName: readModelNamesForSourceName,
|
|
21
|
-
publishToReadModels: publishToReadModels,
|
|
22
20
|
queryEngine: queryEngine
|
|
23
21
|
});
|
|
24
22
|
let operations_incomingJsonEventsHandler = Operations.incomingJsonEventsHandler;
|
|
@@ -11,8 +11,6 @@ module type Mappings = {
|
|
|
11
11
|
module type Ops = {
|
|
12
12
|
let publishToAggregates: dict<CommandTopic.publishJsons>
|
|
13
13
|
let publishToPluginExtensionPoint: CommandTopic.publishJsons
|
|
14
|
-
let readModelNamesForSourceName: dict<array<string>>
|
|
15
|
-
let publishToReadModels: dict<EventCollector.enqueueEvent>
|
|
16
14
|
let queryEngine: Reventless.QueryEngine.operations
|
|
17
15
|
}
|
|
18
16
|
|
|
@@ -171,23 +169,6 @@ module Make = (
|
|
|
171
169
|
->Util.Promise.toUnit
|
|
172
170
|
}
|
|
173
171
|
await commandActions->apply
|
|
174
|
-
|
|
175
|
-
switch Ops.readModelNamesForSourceName
|
|
176
|
-
->Dict.get(event'.meta.service)
|
|
177
|
-
->Option.map(readModelNames =>
|
|
178
|
-
readModelNames
|
|
179
|
-
->Array.filterMap(readModelName =>
|
|
180
|
-
Ops.publishToReadModels
|
|
181
|
-
->Dict.get(readModelName)
|
|
182
|
-
->Option.map(enqueueEvent => enqueueEvent(0, event'.id, eventJson'->JSON.stringify))
|
|
183
|
-
) // FIXME Error handling
|
|
184
|
-
->Promise.all
|
|
185
|
-
) {
|
|
186
|
-
| Some(p) =>
|
|
187
|
-
let _ = await p
|
|
188
|
-
| None => ()
|
|
189
|
-
}
|
|
190
|
-
|
|
191
172
|
| exception err =>
|
|
192
173
|
let errMsg = err->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown")
|
|
193
174
|
EffectLogger.logError(
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
4
3
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
5
4
|
import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
|
|
6
5
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
@@ -123,12 +122,7 @@ function Make(MappingSpec) {
|
|
|
123
122
|
}
|
|
124
123
|
let commandActions = mapIncomingEvent(event$p, pluginDef, Ops.queryEngine);
|
|
125
124
|
let apply = async commandActions => await Util_Promise$ReventlessCore.toUnit(Promise.all(commandActions.map(applyIncomingCommandAction)));
|
|
126
|
-
await apply(commandActions);
|
|
127
|
-
let p = Stdlib_Option.map(Ops.readModelNamesForSourceName[event$p.meta.service], readModelNames => Promise.all(Stdlib_Array.filterMap(readModelNames, readModelName => Stdlib_Option.map(Ops.publishToReadModels[readModelName], enqueueEvent => enqueueEvent(0, event$p.id, JSON.stringify(eventJson$p))))));
|
|
128
|
-
if (p !== undefined) {
|
|
129
|
-
await p;
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
125
|
+
return await apply(commandActions);
|
|
132
126
|
};
|
|
133
127
|
let outgoingJsonEventsHandler = (eventJson$p, pluginDef) => {
|
|
134
128
|
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, `outgoing delegate event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
|