@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
|
@@ -151,7 +151,7 @@ function Make(Spec) {
|
|
|
151
151
|
return Translation => {
|
|
152
152
|
let auditLog = {};
|
|
153
153
|
let sensitive = Sensitive$Reventless.fieldNames(Spec.externalInputSchema);
|
|
154
|
-
let makeMeta = () => Message$ReventlessCore.generateMeta(Spec.targetName, undefined, undefined, undefined, undefined, undefined, undefined
|
|
154
|
+
let makeMeta = () => Message$ReventlessCore.generateMeta(Spec.targetName, undefined, undefined, undefined, undefined, undefined, undefined);
|
|
155
155
|
let messageOf = (exn, fallback) => Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), fallback);
|
|
156
156
|
let failWith = (requestId, input, door, caller, errorCode, error) => {
|
|
157
157
|
auditLog[requestId] = {
|
|
@@ -46,7 +46,7 @@ function todoRowSchemaFor(itemSchema) {
|
|
|
46
46
|
function Make(Spec) {
|
|
47
47
|
return Translation => {
|
|
48
48
|
let todoItems = {};
|
|
49
|
-
let makeMeta = () => Message$ReventlessCore.generateMeta(Stdlib_Option.getOr(Spec.targetName, `OutboundTranslationSlice:` + Spec.name), undefined, undefined, undefined, undefined, undefined, undefined
|
|
49
|
+
let makeMeta = () => Message$ReventlessCore.generateMeta(Stdlib_Option.getOr(Spec.targetName, `OutboundTranslationSlice:` + Spec.name), undefined, undefined, undefined, undefined, undefined, undefined);
|
|
50
50
|
let afterFailedAttempt = (row, lastError) => {
|
|
51
51
|
let retryCount = row.retryCount + 1 | 0;
|
|
52
52
|
let newrecord = {...row};
|
|
@@ -93,18 +93,28 @@ module Make = (
|
|
|
93
93
|
// Fail-fast: every Mapping.sourceName must resolve to a topic in allEventTopics,
|
|
94
94
|
// otherwise EventTopic.filter silently drops it and the projection runs on no events.
|
|
95
95
|
// Catches both Aggregate-name typos and DCB-source-name typos (e.g. "FooDcb" instead
|
|
96
|
-
// of "FooDcbEventLog").
|
|
96
|
+
// of "FooDcbEventLog"). A dotted name is an extension point's: another plugin's
|
|
97
|
+
// facts reach a read model only through an Extension and a slice of this plugin.
|
|
97
98
|
sourceNames
|
|
98
99
|
->Belt.Set.String.toArray
|
|
99
100
|
->Array.forEach(sourceName =>
|
|
100
101
|
if !(allEventTopics->Dict.has(sourceName)) {
|
|
101
102
|
let availableNames =
|
|
102
103
|
allEventTopics->Dict.keysToArray->Array.toSorted(String.compare)->Array.join(", ")
|
|
104
|
+
let hint =
|
|
105
|
+
sourceName->String.includes(".")
|
|
106
|
+
? ` "${sourceName}" looks like an extension point name: a read model cannot ` ++
|
|
107
|
+
`hear another plugin's extension point directly. Declare an Extension that ` ++
|
|
108
|
+
`maps its events to a command of one of this plugin's slices or aggregates, ` ++
|
|
109
|
+
`and project that component's events (see the Extension doc, ` ++ `"Targeting a StateChangeSlice instead of an Aggregate").`
|
|
110
|
+
: ""
|
|
103
111
|
JsError.throwWithMessage(
|
|
104
112
|
`ReadModel "${Spec.name}" has a Mapping with sourceName "${sourceName}", ` ++
|
|
105
113
|
`but no EventTopic with that key exists in allEventTopics. ` ++
|
|
106
114
|
`Available source names: [${availableNames}]. ` ++
|
|
107
|
-
`Check Mapping.Make's first arg matches an Aggregate Spec.name or a DCB ` ++
|
|
115
|
+
`Check Mapping.Make's first arg matches an Aggregate Spec.name or a DCB ` ++
|
|
116
|
+
`source name (typically "<pluginName>DcbEventLog").` ++
|
|
117
|
+
hint,
|
|
108
118
|
)
|
|
109
119
|
}
|
|
110
120
|
)
|
|
@@ -62,7 +62,8 @@ function Make(Spec) {
|
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
let availableNames = Object.keys(allEventTopics).toSorted(Primitive_string.compare).join(", ");
|
|
65
|
-
|
|
65
|
+
let hint = sourceName.includes(".") ? ` "` + sourceName + `" looks like an extension point name: a read model cannot hear another plugin's extension point directly. Declare an Extension that maps its events to a command of one of this plugin's slices or aggregates, and project that component's events (see the Extension doc, "Targeting a StateChangeSlice instead of an Aggregate").` : "";
|
|
66
|
+
Stdlib_JsError.throwWithMessage(`ReadModel "` + Spec.name + `" has a Mapping with sourceName "` + sourceName + `", but no EventTopic with that key exists in allEventTopics. ` + (`Available source names: [` + availableNames + `]. `) + `Check Mapping.Make's first arg matches an Aggregate Spec.name or a DCB source name (typically "<pluginName>DcbEventLog").` + hint);
|
|
66
67
|
});
|
|
67
68
|
let SpecificEventCollector = EventCollector_Builder$ReventlessCore.Make(RuntimeEnvironment)(EventCollectorChannel);
|
|
68
69
|
let eventCollector = Component$ReventlessCore.operations(queryDb).apply(operations => {
|
|
@@ -31,6 +31,20 @@ module Make = (
|
|
|
31
31
|
let decoder = Reventless.DcbDecode.makeDecoder(Spec.consumedEventSchema)
|
|
32
32
|
let queryEventTypes = decoder.eventTypes
|
|
33
33
|
|
|
34
|
+
// For a command with a stable id the read also covers the slice's own produced
|
|
35
|
+
// types: an event among them whose `causationId` is this command's `msgId` says
|
|
36
|
+
// the command was handled already. Reading them through the same query, rather
|
|
37
|
+
// than a tag of their own, keeps every event's tag set — and so the
|
|
38
|
+
// `tag_composite` key a composite read depends on — exactly what the model
|
|
39
|
+
// declares; it also puts the produced types under the append condition, so two
|
|
40
|
+
// concurrent copies cannot both append. The produced types not consumed are
|
|
41
|
+
// dropped by the decoder and never reach `evolve`.
|
|
42
|
+
let producedEventTypes = Reventless.DcbTag.extractAllVariantNames(Spec.eventSchema)
|
|
43
|
+
let queryEventTypesWithOwn = Array.concat(
|
|
44
|
+
queryEventTypes,
|
|
45
|
+
producedEventTypes->Array.filter(t => !(queryEventTypes->Array.includes(t))),
|
|
46
|
+
)
|
|
47
|
+
|
|
34
48
|
let encodeEvent = (
|
|
35
49
|
~parentMeta: Message.meta,
|
|
36
50
|
~tagKeysByEventType: Dict.t<array<string>>,
|
|
@@ -199,8 +213,11 @@ module Make = (
|
|
|
199
213
|
`handling command: ${cmdJson->LogFormat.cmdDetailNoId}`,
|
|
200
214
|
)->Effect.runSync
|
|
201
215
|
|
|
216
|
+
// A command an Extension derived carries a stable id: the read then also asks
|
|
217
|
+
// whether this very command already left events (see `queryEventTypesWithOwn`).
|
|
218
|
+
let asksForRepeat = Message.hasStableMsgId(command'.meta)
|
|
202
219
|
let query = Reventless.DcbTag.buildQueryFromCommand(
|
|
203
|
-
~eventTypes=queryEventTypes,
|
|
220
|
+
~eventTypes=asksForRepeat ? queryEventTypesWithOwn : queryEventTypes,
|
|
204
221
|
~schema=Spec.commandSchema,
|
|
205
222
|
~value=command'.command,
|
|
206
223
|
~tagKeysByEventType,
|
|
@@ -265,7 +282,12 @@ module Make = (
|
|
|
265
282
|
// one shared cache slot, so one slice's folded state could seed another's —
|
|
266
283
|
// a silent correctness bug. `None` simply bypasses the cache (cold read, no
|
|
267
284
|
// write) for that operation.
|
|
268
|
-
|
|
285
|
+
//
|
|
286
|
+
// A command asking for a repeat bypasses the cache too: a cached head sits
|
|
287
|
+
// past the events an earlier delivery left, so a delta read could not see
|
|
288
|
+
// them. Such a command pays a full read of its partition for the guarantee
|
|
289
|
+
// that a second delivery changes nothing.
|
|
290
|
+
let cacheKey = asksForRepeat ? None : query->JSON.stringifyAny
|
|
269
291
|
let cacheGet = () =>
|
|
270
292
|
switch cacheKey {
|
|
271
293
|
| Some(k) => Lru.get(projectionCache, k)
|
|
@@ -323,41 +345,38 @@ module Make = (
|
|
|
323
345
|
}
|
|
324
346
|
|
|
325
347
|
dcbEventLog.readStream(~query, ~after=?afterPos, ~strongConsistency)
|
|
326
|
-
->Stream.map(raw => {
|
|
327
|
-
let data = raw.data->JSON.Decode.object->Option.getOr(Dict.make())
|
|
328
|
-
let decoded = decoder.decode(~eventType=raw.eventType, ~data)
|
|
329
|
-
decoded->Option.map(event => (
|
|
330
|
-
event,
|
|
331
|
-
raw.position,
|
|
332
|
-
raw.eventType,
|
|
333
|
-
readEventId(~partitionTag, raw.tags),
|
|
334
|
-
(ownerFieldsOf(raw), data),
|
|
335
|
-
))
|
|
336
|
-
})
|
|
337
|
-
->Stream.flatMap(opt =>
|
|
338
|
-
switch opt {
|
|
339
|
-
| Some(v) => Stream.fromIterable([v])
|
|
340
|
-
| None => Stream.empty
|
|
341
|
-
}
|
|
342
|
-
)
|
|
343
348
|
// The head accumulator starts at `afterPos` (the seeded head), not `None`,
|
|
344
349
|
// so an empty delta read keeps the cached head — the append must condition
|
|
345
350
|
// on the head that actually exists, not assert "no events exist yet".
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
351
|
+
// Every read event moves the head and is checked as this command's own
|
|
352
|
+
// doing before it is decoded; only the consumed ones reach `evolve`.
|
|
353
|
+
->Stream.runFold((baseState, afterPos, [], baseOwners, false), (
|
|
354
|
+
(dm, _pos, reads, owners, repeated),
|
|
355
|
+
raw,
|
|
356
|
+
) => {
|
|
357
|
+
// Only a command with a stable id asks; a fresh id never matches a stored
|
|
358
|
+
// cause, and asking would only make the answer depend on what the slice
|
|
359
|
+
// happens to read.
|
|
360
|
+
let repeated =
|
|
361
|
+
repeated || (asksForRepeat && raw.meta.causationId == Some(command'.meta.msgId))
|
|
362
|
+
let data = raw.data->JSON.Decode.object->Option.getOr(Dict.make())
|
|
363
|
+
switch decoder.decode(~eventType=raw.eventType, ~data) {
|
|
364
|
+
| None => (dm, Some(raw.position), reads, owners, repeated)
|
|
365
|
+
| Some(event) => (
|
|
366
|
+
Decision.evolve(dm, event),
|
|
367
|
+
Some(raw.position),
|
|
368
|
+
reads->Array.concat([
|
|
369
|
+
switch readEventId(~partitionTag, raw.tags) {
|
|
370
|
+
| Some(id) => `${raw.eventType->LogFormat.bold}(${id})`
|
|
371
|
+
| None => raw.eventType->LogFormat.bold
|
|
372
|
+
},
|
|
373
|
+
]),
|
|
374
|
+
owners->Reventless.OwnerScope.recordOwners(~fields=ownerFieldsOf(raw), data),
|
|
375
|
+
repeated,
|
|
376
|
+
)
|
|
377
|
+
}
|
|
378
|
+
})
|
|
379
|
+
->Effect.tap(((_, _, reads, _, _)) => {
|
|
361
380
|
// On a warm first attempt, record how many events the delta read
|
|
362
381
|
// returned — near-zero on a healthy hit; a large value means the entity
|
|
363
382
|
// churned between commands, so the cache saved little. Gated to the first
|
|
@@ -380,7 +399,7 @@ module Make = (
|
|
|
380
399
|
: ` [${reads->Array.join(", ")}]`}`,
|
|
381
400
|
)
|
|
382
401
|
})
|
|
383
|
-
->Effect.flatMap(((state, headPosition, _, owners)) =>
|
|
402
|
+
->Effect.flatMap(((state, headPosition, _, owners, repeated)) =>
|
|
384
403
|
// Identity, not content: the decision model folds the whole matched
|
|
385
404
|
// history, so serialising it here makes the line's size a function of
|
|
386
405
|
// how long the entity has been in use.
|
|
@@ -391,6 +410,24 @@ module Make = (
|
|
|
391
410
|
)} cmd=${cmdJson->LogFormat.cmdName}`,
|
|
392
411
|
)->Effect.flatMap(_ =>
|
|
393
412
|
switch ownershipRefusal(owners) {
|
|
413
|
+
| _ if repeated =>
|
|
414
|
+
// Before `decide`, and before the ownership check it passed the first
|
|
415
|
+
// time: the partition already holds events this command caused, so it
|
|
416
|
+
// was delivered again. Accepted, nothing new.
|
|
417
|
+
CommandTopic_Helpers.reportAccepted(
|
|
418
|
+
~component=Spec.name,
|
|
419
|
+
cmdJson.meta.msgId,
|
|
420
|
+
switch entityId {
|
|
421
|
+
| Some(eid) => {entityId: eid, eventCount: 0}
|
|
422
|
+
| None => {eventCount: 0}
|
|
423
|
+
},
|
|
424
|
+
)
|
|
425
|
+
EffectLogger.logInfo(
|
|
426
|
+
~comp,
|
|
427
|
+
`repeat dropped: ${cmdJson->LogFormat.cmdName} msgId=${cmdJson.meta.msgId} already caused events in id=${entityId->Option.getOr(
|
|
428
|
+
"-",
|
|
429
|
+
)}`,
|
|
430
|
+
)->Effect.map(_ => Ok("ok"))
|
|
394
431
|
| Some({rejected, isDefect}) =>
|
|
395
432
|
// Refused before `decide`; the read snapshot is still valid.
|
|
396
433
|
cachePut((state, headPosition, owners))
|
|
@@ -9,6 +9,8 @@ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
|
9
9
|
import * as Effect from "effect/Effect";
|
|
10
10
|
import * as Stream$1 from "effect/Stream";
|
|
11
11
|
import * as Owner$Reventless from "@reventlessdev/reventless-spec/src/components/Owner.res.mjs";
|
|
12
|
+
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
13
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
12
14
|
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
13
15
|
import * as Lru$ReventlessCore from "../../util/Lru.res.mjs";
|
|
14
16
|
import * as DcbDecode$Reventless from "@reventlessdev/reventless-spec/src/components/DcbDecode.res.mjs";
|
|
@@ -26,6 +28,8 @@ function Make(Spec) {
|
|
|
26
28
|
let comp = `StateChangeSlice(` + Spec.name + `)`;
|
|
27
29
|
let decoder = DcbDecode$Reventless.makeDecoder(Spec.consumedEventSchema);
|
|
28
30
|
let queryEventTypes = decoder.eventTypes;
|
|
31
|
+
let producedEventTypes = DcbTag$Reventless.extractAllVariantNames(Spec.eventSchema);
|
|
32
|
+
let queryEventTypesWithOwn = queryEventTypes.concat(producedEventTypes.filter(t => !queryEventTypes.includes(t)));
|
|
29
33
|
let slicePartitionTag = Stdlib_Lazy.make(() => {
|
|
30
34
|
try {
|
|
31
35
|
return DcbTag$Reventless.deriveSlicePartition({
|
|
@@ -79,7 +83,8 @@ function Make(Spec) {
|
|
|
79
83
|
let handleSingleCommand = (tagKeysByEventType, crossPartitionTagKeys, payloadTagKeys, partitionTag, dcbEventLog, command$p) => {
|
|
80
84
|
let cmdJson = Message$ReventlessCore.commandJsonOfCommand$p(Id$Reventless.$$String.toString, Spec.commandSchema, command$p);
|
|
81
85
|
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, cmdJson.commandJson, `handling command: ` + LogFormat$ReventlessCore.cmdDetailNoId(cmdJson)));
|
|
82
|
-
let
|
|
86
|
+
let asksForRepeat = Message$ReventlessCore.hasStableMsgId(command$p.meta);
|
|
87
|
+
let query = DcbTag$Reventless.buildQueryFromCommand(asksForRepeat ? queryEventTypesWithOwn : queryEventTypes, Spec.commandSchema, command$p.command, tagKeysByEventType, crossPartitionTagKeys, payloadTagKeys);
|
|
83
88
|
let queryDetail = query.map(qi => {
|
|
84
89
|
let ts = qi.eventTypes;
|
|
85
90
|
let types = ts !== undefined ? ts.map(LogFormat$ReventlessCore.bold).join("|") : "*";
|
|
@@ -129,7 +134,7 @@ function Make(Spec) {
|
|
|
129
134
|
return CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(command$p.meta.callerClaim, Stdlib_Option.map(entityId, param => owners)), Spec.name, Message$ReventlessCore.variantNameOfJson(cmdJson.commandJson));
|
|
130
135
|
}
|
|
131
136
|
};
|
|
132
|
-
let cacheKey = JSON.stringify(query);
|
|
137
|
+
let cacheKey = asksForRepeat ? undefined : JSON.stringify(query);
|
|
133
138
|
let cacheGet = () => {
|
|
134
139
|
if (cacheKey !== undefined) {
|
|
135
140
|
return Lru$ReventlessCore.get(projectionCache, cacheKey);
|
|
@@ -174,39 +179,35 @@ function Make(Spec) {
|
|
|
174
179
|
strongConsistency = false;
|
|
175
180
|
break;
|
|
176
181
|
}
|
|
177
|
-
return Effect.flatMap(Effect.tap(Stream$1.runFold(
|
|
178
|
-
let data = Stdlib_Option.getOr(Stdlib_JSON.Decode.object(raw.data), {});
|
|
179
|
-
let decoded = decoder.decode(raw.eventType, data);
|
|
180
|
-
return Stdlib_Option.map(decoded, event => [
|
|
181
|
-
event,
|
|
182
|
-
raw.position,
|
|
183
|
-
raw.eventType,
|
|
184
|
-
readEventId(partitionTag, raw.tags),
|
|
185
|
-
[
|
|
186
|
-
ownerFieldsOf(raw),
|
|
187
|
-
data
|
|
188
|
-
]
|
|
189
|
-
]);
|
|
190
|
-
}), opt => {
|
|
191
|
-
if (opt !== undefined) {
|
|
192
|
-
return Stream$1.fromIterable([opt]);
|
|
193
|
-
} else {
|
|
194
|
-
return Stream$1.empty;
|
|
195
|
-
}
|
|
196
|
-
}), [
|
|
182
|
+
return Effect.flatMap(Effect.tap(Stream$1.runFold(dcbEventLog.readStream(query, afterPos, strongConsistency), [
|
|
197
183
|
match$1[0],
|
|
198
184
|
afterPos,
|
|
199
185
|
[],
|
|
200
|
-
match$1[2]
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
let
|
|
204
|
-
let
|
|
186
|
+
match$1[2],
|
|
187
|
+
false
|
|
188
|
+
], (param, raw) => {
|
|
189
|
+
let owners = param[3];
|
|
190
|
+
let reads = param[2];
|
|
191
|
+
let dm = param[0];
|
|
192
|
+
let repeated = param[4] || asksForRepeat && Primitive_object.equal(raw.meta.causationId, command$p.meta.msgId);
|
|
193
|
+
let data = Stdlib_Option.getOr(Stdlib_JSON.Decode.object(raw.data), {});
|
|
194
|
+
let event = decoder.decode(raw.eventType, data);
|
|
195
|
+
if (event === undefined) {
|
|
196
|
+
return [
|
|
197
|
+
dm,
|
|
198
|
+
raw.position,
|
|
199
|
+
reads,
|
|
200
|
+
owners,
|
|
201
|
+
repeated
|
|
202
|
+
];
|
|
203
|
+
}
|
|
204
|
+
let id = readEventId(partitionTag, raw.tags);
|
|
205
205
|
return [
|
|
206
|
-
Decision.evolve(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
OwnerScope$Reventless.recordOwners(
|
|
206
|
+
Decision.evolve(dm, Primitive_option.valFromOption(event)),
|
|
207
|
+
raw.position,
|
|
208
|
+
reads.concat([id !== undefined ? LogFormat$ReventlessCore.bold(raw.eventType) + `(` + id + `)` : LogFormat$ReventlessCore.bold(raw.eventType)]),
|
|
209
|
+
OwnerScope$Reventless.recordOwners(owners, ownerFieldsOf(raw), data),
|
|
210
|
+
repeated
|
|
210
211
|
];
|
|
211
212
|
}), param => {
|
|
212
213
|
let reads = param[2];
|
|
@@ -219,11 +220,24 @@ function Make(Spec) {
|
|
|
219
220
|
reads.length === 0 ? "" : ` [` + reads.join(", ") + `]`
|
|
220
221
|
));
|
|
221
222
|
}), param => {
|
|
223
|
+
let repeated = param[4];
|
|
222
224
|
let owners = param[3];
|
|
223
225
|
let headPosition = param[1];
|
|
224
226
|
let state = param[0];
|
|
225
227
|
return Effect.flatMap(EffectLogger$ReventlessCore.logDebug(comp, undefined, `deciding: id=` + Stdlib_Option.getOr(entityId, "-") + ` head=` + Stdlib_Option.getOr(headPosition, "-") + ` cmd=` + LogFormat$ReventlessCore.cmdName(cmdJson)), () => {
|
|
226
228
|
let match = ownershipRefusal(owners);
|
|
229
|
+
if (repeated) {
|
|
230
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
231
|
+
entityId: entityId,
|
|
232
|
+
eventCount: 0
|
|
233
|
+
}) : ({
|
|
234
|
+
eventCount: 0
|
|
235
|
+
}));
|
|
236
|
+
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, `repeat dropped: ` + LogFormat$ReventlessCore.cmdName(cmdJson) + ` msgId=` + cmdJson.meta.msgId + ` already caused events in id=` + Stdlib_Option.getOr(entityId, "-")), () => ({
|
|
237
|
+
TAG: "Ok",
|
|
238
|
+
_0: "ok"
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
227
241
|
if (match !== undefined) {
|
|
228
242
|
let rejected = match.rejected;
|
|
229
243
|
cachePut([
|
|
@@ -90,10 +90,10 @@ function Make(RuntimeEnvironment) {
|
|
|
90
90
|
try {
|
|
91
91
|
meta = Util_Sury$Reventless.fromJson(m, Message$ReventlessCore.metaSchema);
|
|
92
92
|
} catch (exn) {
|
|
93
|
-
meta = Message$ReventlessCore.generateMeta(Spec.name, undefined, undefined, undefined, undefined, undefined, undefined
|
|
93
|
+
meta = Message$ReventlessCore.generateMeta(Spec.name, undefined, undefined, undefined, undefined, undefined, undefined);
|
|
94
94
|
}
|
|
95
95
|
} else {
|
|
96
|
-
meta = Message$ReventlessCore.generateMeta(Spec.name, undefined, undefined, undefined, undefined, undefined, undefined
|
|
96
|
+
meta = Message$ReventlessCore.generateMeta(Spec.name, undefined, undefined, undefined, undefined, undefined, undefined);
|
|
97
97
|
}
|
|
98
98
|
let recordedAt = Stdlib_Option.getOr(Stdlib_Option.flatMap(envelopeDict["recordedAt"], Stdlib_JSON.Decode.string), "");
|
|
99
99
|
let match = Message$ReventlessCore.splitMessage(rawEvent);
|
|
@@ -650,11 +650,10 @@ module Make = (
|
|
|
650
650
|
(interstackAdminExtensionPoints, localAdminResolvedEP, schemaPushed)->Pulumi.Output.all3,
|
|
651
651
|
aggregateResources->Pulumi.Output.allDict,
|
|
652
652
|
publishToAggregates->Pulumi.Output.allDict,
|
|
653
|
-
publishToReadModels->Pulumi.Output.allDict,
|
|
654
653
|
scheduler,
|
|
655
654
|
queryEngine,
|
|
656
655
|
)
|
|
657
|
-
->Pulumi.Output.
|
|
656
|
+
->Pulumi.Output.all5
|
|
658
657
|
// `applyAttributed`, not `apply`: this callback provisions real resources —
|
|
659
658
|
// extension points, tasks, the heartbeat, resolvers — and it runs after
|
|
660
659
|
// this construct has returned, when the ambient attribution context is
|
|
@@ -663,7 +662,6 @@ module Make = (
|
|
|
663
662
|
(interstackAdminExtensionPoints, localAdminResolvedEP, _),
|
|
664
663
|
aggregateResources,
|
|
665
664
|
publishToAggregates,
|
|
666
|
-
publishToReadModels,
|
|
667
665
|
scheduler,
|
|
668
666
|
queryEngine,
|
|
669
667
|
)) => {
|
|
@@ -717,7 +715,6 @@ module Make = (
|
|
|
717
715
|
~pluginName=name,
|
|
718
716
|
~publishToPluginExtensionPoint,
|
|
719
717
|
~publishToAggregates,
|
|
720
|
-
~publishToReadModels,
|
|
721
718
|
~queryEngine,
|
|
722
719
|
~opts,
|
|
723
720
|
)
|
|
@@ -851,22 +848,6 @@ module Make = (
|
|
|
851
848
|
aggregateQueueUrls->Dict.set(Sc.Spec.name, dcbResult.dcbCommandTopicQueueUrl)
|
|
852
849
|
)
|
|
853
850
|
|
|
854
|
-
// Per-RM EventCollector SQS URL — populated only for plugins that
|
|
855
|
-
// expose RMs the bundled handler may enqueue events into directly.
|
|
856
|
-
let readModelQueueUrls: dict<Pulumi.Output.t<string>> = Dict.make()
|
|
857
|
-
readModelsOutputs
|
|
858
|
-
->Dict.toArray
|
|
859
|
-
->Array.forEach(((rmName, rmOut)) => {
|
|
860
|
-
let urlOutput = rmOut.eventCollector->Pulumi.Output.flatMap(
|
|
861
|
-
ecOutputs =>
|
|
862
|
-
switch ecOutputs.resources->Array.get(0) {
|
|
863
|
-
| Some(r) => r.id
|
|
864
|
-
| None => Pulumi.Output.make("")
|
|
865
|
-
},
|
|
866
|
-
)
|
|
867
|
-
readModelQueueUrls->Dict.set(rmName, urlOutput)
|
|
868
|
-
})
|
|
869
|
-
|
|
870
851
|
switch coreSetup {
|
|
871
852
|
| Some((pluginExtensionPointUnwrapped, _)) => {
|
|
872
853
|
let (
|
|
@@ -877,8 +858,6 @@ module Make = (
|
|
|
877
858
|
~uiFragments,
|
|
878
859
|
~publishToPluginExtensionPoint,
|
|
879
860
|
~publishToAggregates,
|
|
880
|
-
~readModelNamesForSourceName,
|
|
881
|
-
~publishToReadModels,
|
|
882
861
|
~queryEngine,
|
|
883
862
|
~opts,
|
|
884
863
|
)
|
|
@@ -897,8 +876,6 @@ module Make = (
|
|
|
897
876
|
~extensionRegistryInfos,
|
|
898
877
|
~extensionPointRegistryInfos,
|
|
899
878
|
~aggregateQueueUrls,
|
|
900
|
-
~readModelQueueUrls,
|
|
901
|
-
~readModelNamesForSourceName,
|
|
902
879
|
)
|
|
903
880
|
}
|
|
904
881
|
| None =>
|
|
@@ -914,8 +891,6 @@ module Make = (
|
|
|
914
891
|
~extensionPointsHandlers,
|
|
915
892
|
~extensionRegistryInfos,
|
|
916
893
|
~aggregateQueueUrls,
|
|
917
|
-
~readModelQueueUrls,
|
|
918
|
-
~readModelNamesForSourceName,
|
|
919
894
|
)
|
|
920
895
|
}
|
|
921
896
|
|
|
@@ -443,13 +443,11 @@ function Make(Spec) {
|
|
|
443
443
|
]),
|
|
444
444
|
Pulumi.all(Plugin_Helpers$ReventlessCore.aggregateResources),
|
|
445
445
|
Pulumi.all(Plugin_Helpers$ReventlessCore.publishToAggregates),
|
|
446
|
-
Pulumi.all(Plugin_Helpers$ReventlessCore.publishToReadModels),
|
|
447
446
|
scheduler,
|
|
448
447
|
queryEngine
|
|
449
448
|
]), param => {
|
|
450
|
-
let queryEngine = param[
|
|
451
|
-
let scheduler = param[
|
|
452
|
-
let publishToReadModels = param[3];
|
|
449
|
+
let queryEngine = param[4];
|
|
450
|
+
let scheduler = param[3];
|
|
453
451
|
let publishToAggregates = param[2];
|
|
454
452
|
let aggregateResources = param[1];
|
|
455
453
|
let match = param[0];
|
|
@@ -477,7 +475,7 @@ function Make(Spec) {
|
|
|
477
475
|
coreSetup = undefined;
|
|
478
476
|
}
|
|
479
477
|
let publishToPluginExtensionPoint = coreSetup !== undefined ? coreSetup[1].remotePublish : async param => {};
|
|
480
|
-
let match$2 = Plugin_Helpers$ReventlessCore.createExtensions(extensions, extra$1, publishToPluginExtensionPoint, publishToAggregates,
|
|
478
|
+
let match$2 = Plugin_Helpers$ReventlessCore.createExtensions(extensions, extra$1, publishToPluginExtensionPoint, publishToAggregates, queryEngine, opts);
|
|
481
479
|
let extensionRegistryInfos = match$2[2];
|
|
482
480
|
let extensionsHandlers = match$2[1];
|
|
483
481
|
let extensionsOutputs = match$2[0];
|
|
@@ -541,23 +539,11 @@ function Make(Spec) {
|
|
|
541
539
|
stateChangeSlices.forEach(Sc => {
|
|
542
540
|
aggregateQueueUrls[Sc.Spec.name] = dcbResult.dcbCommandTopicQueueUrl;
|
|
543
541
|
});
|
|
544
|
-
let readModelQueueUrls = {};
|
|
545
|
-
Object.entries(readModelsOutputs).forEach(param => {
|
|
546
|
-
let urlOutput = Output$Pulumi.flatMap(param[1].eventCollector, ecOutputs => {
|
|
547
|
-
let r = ecOutputs.resources[0];
|
|
548
|
-
if (r !== undefined) {
|
|
549
|
-
return r.id;
|
|
550
|
-
} else {
|
|
551
|
-
return Pulumi.output("");
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
readModelQueueUrls[param[0]] = urlOutput;
|
|
555
|
-
});
|
|
556
542
|
if (coreSetup !== undefined) {
|
|
557
|
-
let match$4 = Plugin_Helpers$ReventlessCore.createConnectPluginExtension(pluginDefinition, uiFragments, publishToPluginExtensionPoint, publishToAggregates,
|
|
558
|
-
EventCollectorHelper.connect(eventCollector, eventTopics, extensionPointsOutputs, extensionsOutputs, coreSetup[0], pluginDefinition, Primitive_option.some(uiFragments), match$4[1], extensionsHandlers, extensionPointsHandlers, match$4[0], extensionRegistryInfos, match$1[2], aggregateQueueUrls
|
|
543
|
+
let match$4 = Plugin_Helpers$ReventlessCore.createConnectPluginExtension(pluginDefinition, uiFragments, publishToPluginExtensionPoint, publishToAggregates, queryEngine, opts);
|
|
544
|
+
EventCollectorHelper.connect(eventCollector, eventTopics, extensionPointsOutputs, extensionsOutputs, coreSetup[0], pluginDefinition, Primitive_option.some(uiFragments), match$4[1], extensionsHandlers, extensionPointsHandlers, match$4[0], extensionRegistryInfos, match$1[2], aggregateQueueUrls);
|
|
559
545
|
} else {
|
|
560
|
-
EventCollectorHelper.connect(eventCollector, eventTopics, extensionPointsOutputs, extensionsOutputs, undefined, pluginDefinition, Primitive_option.some(uiFragments), undefined, extensionsHandlers, extensionPointsHandlers, undefined, extensionRegistryInfos, undefined, aggregateQueueUrls
|
|
546
|
+
EventCollectorHelper.connect(eventCollector, eventTopics, extensionPointsOutputs, extensionsOutputs, undefined, pluginDefinition, Primitive_option.some(uiFragments), undefined, extensionsHandlers, extensionPointsHandlers, undefined, extensionRegistryInfos, undefined, aggregateQueueUrls);
|
|
561
547
|
}
|
|
562
548
|
let tasksOutputs = Plugin_Helpers$ReventlessCore.createTasks(tasks, aggregatesOutputs, scheduler, schedulerRoleUrn, publishToAggregates, queryEngine, Spec.resourceNaming, componentRuntime, opts);
|
|
563
549
|
let resolvers = Plugin_Helpers$ReventlessCore.createResolvers(allQueryDbs);
|
|
@@ -136,10 +136,6 @@ type extensionEntry = {
|
|
|
136
136
|
// Subset of top-level publishToAggregates this extension publishes to —
|
|
137
137
|
// derived from Extension.outputs.aggregateNames.
|
|
138
138
|
aggregateNames: array<string>,
|
|
139
|
-
// RMs this extension's mapping may enqueue events into directly. Derived
|
|
140
|
-
// from readModelNamesForSourceName by reverse lookup on the extension's
|
|
141
|
-
// EP name (the source carried on incoming events).
|
|
142
|
-
readModelNames: array<string>,
|
|
143
139
|
}
|
|
144
140
|
|
|
145
141
|
type eventCollectorContext = {
|
|
@@ -169,12 +165,6 @@ type eventCollectorContext = {
|
|
|
169
165
|
// any user extension publishes to plus the admin's Plugin aggregate when
|
|
170
166
|
// ConnectExtension is wired.
|
|
171
167
|
publishToAggregates: dict<Pulumi.Output.t<string>>,
|
|
172
|
-
// rmName → RM EventCollector SQS URL. Populated only for RMs that user
|
|
173
|
-
// extensions feed directly via Extension_Operations.publishToReadModels.
|
|
174
|
-
readModelQueueUrls: dict<Pulumi.Output.t<string>>,
|
|
175
|
-
// Inversion of RM.sourceNames — sourceServiceName → [rmName]. Same dict
|
|
176
|
-
// surface used by Builder_Helpers; serialised verbatim into HANDLER_CONFIG.
|
|
177
|
-
readModelNamesForSourceName: dict<array<string>>,
|
|
178
168
|
}
|
|
179
169
|
|
|
180
170
|
let eventCollectorContextRef: ref<dict<eventCollectorContext>> = ref(Dict.make())
|
|
@@ -254,7 +244,6 @@ let createExtensions = (
|
|
|
254
244
|
~pluginName,
|
|
255
245
|
~publishToPluginExtensionPoint,
|
|
256
246
|
~publishToAggregates,
|
|
257
|
-
~publishToReadModels,
|
|
258
247
|
~queryEngine,
|
|
259
248
|
~opts,
|
|
260
249
|
) => {
|
|
@@ -297,8 +286,6 @@ let createExtensions = (
|
|
|
297
286
|
let extension = ExtensionMaker.make(
|
|
298
287
|
~publishToPluginExtensionPoint,
|
|
299
288
|
~publishToAggregates,
|
|
300
|
-
~readModelNamesForSourceName,
|
|
301
|
-
~publishToReadModels,
|
|
302
289
|
~queryEngine,
|
|
303
290
|
~opts=Some(opts),
|
|
304
291
|
)
|
|
@@ -359,15 +346,10 @@ let extractExtensionPointDefinitions = (extensionPointsOutputs: array<ExtensionP
|
|
|
359
346
|
)
|
|
360
347
|
->Pulumi.Output.all
|
|
361
348
|
|
|
362
|
-
// `dcbSources` lists cross-plugin DCB EventLog names this extension consumes.
|
|
363
|
-
// Empty for now: the current Extension model is mono-source (single EP Spec).
|
|
364
|
-
// Future work will populate this by walking extension blueprint mappings for
|
|
365
|
-
// `Source { name = "<peer>DcbEventLog" }` declarations.
|
|
366
349
|
let extractExtensionDefinitions = (extensionsOutputs: array<Extension.outputs>) =>
|
|
367
350
|
extensionsOutputs->Array.map(extensionOutputs => {
|
|
368
351
|
Reventless.Plugin.name: extensionOutputs.name,
|
|
369
352
|
extensionPointName: extensionOutputs.extensionPointName,
|
|
370
|
-
dcbSources: [],
|
|
371
353
|
})
|
|
372
354
|
|
|
373
355
|
let createConnectPluginExtension = (
|
|
@@ -375,8 +357,6 @@ let createConnectPluginExtension = (
|
|
|
375
357
|
~uiFragments: option<Reventless.Plugin.uiFragmentManifest>,
|
|
376
358
|
~publishToPluginExtensionPoint,
|
|
377
359
|
~publishToAggregates,
|
|
378
|
-
~readModelNamesForSourceName,
|
|
379
|
-
~publishToReadModels,
|
|
380
360
|
~queryEngine,
|
|
381
361
|
~opts,
|
|
382
362
|
) =>
|
|
@@ -392,8 +372,6 @@ let createConnectPluginExtension = (
|
|
|
392
372
|
let connectPluginExtension = ConnectPluginExtension.make(
|
|
393
373
|
~publishToPluginExtensionPoint,
|
|
394
374
|
~publishToAggregates,
|
|
395
|
-
~readModelNamesForSourceName,
|
|
396
|
-
~publishToReadModels,
|
|
397
375
|
~queryEngine,
|
|
398
376
|
~opts=Some(opts),
|
|
399
377
|
)
|
|
@@ -515,14 +493,6 @@ module MakeEventCollectorHelper = (
|
|
|
515
493
|
// that a user extension may publish to. The full plugin dict is fine —
|
|
516
494
|
// the runtime filters to ext.aggregateNames when invoking each extension.
|
|
517
495
|
~aggregateQueueUrls: dict<Pulumi.Output.t<string>>=Dict.make(),
|
|
518
|
-
// rmName → RM EventCollector SQS URL. Populated only for RMs that
|
|
519
|
-
// user extensions may enqueue events into directly. Plugin RMs fed
|
|
520
|
-
// through the normal EventTopic → EventColl subscription path don't
|
|
521
|
-
// need entries here.
|
|
522
|
-
~readModelQueueUrls: dict<Pulumi.Output.t<string>>=Dict.make(),
|
|
523
|
-
// The global readModelNamesForSourceName inversion (sourceName → [rmName]).
|
|
524
|
-
// Plain dict — no Pulumi outputs because it's pure name metadata.
|
|
525
|
-
~readModelNamesForSourceName: dict<array<string>>=Dict.make(),
|
|
526
496
|
) => {
|
|
527
497
|
let resources =
|
|
528
498
|
extensionPointsOutputs
|
|
@@ -649,10 +619,6 @@ module MakeEventCollectorHelper = (
|
|
|
649
619
|
) {
|
|
650
620
|
extensionsOutputs->Array.mapWithIndex((output, i) => {
|
|
651
621
|
let info = extensionRegistryInfos->Array.getUnsafe(i)
|
|
652
|
-
let rmNames =
|
|
653
|
-
readModelNamesForSourceName
|
|
654
|
-
->Dict.get(output.extensionPointName)
|
|
655
|
-
->Option.getOr([])
|
|
656
622
|
{
|
|
657
623
|
name: output.name,
|
|
658
624
|
specModule: info.specModule,
|
|
@@ -660,7 +626,6 @@ module MakeEventCollectorHelper = (
|
|
|
660
626
|
delegateModule: info.delegateModule,
|
|
661
627
|
extensionPointName: output.extensionPointName,
|
|
662
628
|
aggregateNames: output.aggregateNames,
|
|
663
|
-
readModelNames: rmNames,
|
|
664
629
|
}
|
|
665
630
|
})
|
|
666
631
|
} else {
|
|
@@ -724,8 +689,6 @@ module MakeEventCollectorHelper = (
|
|
|
724
689
|
extensions,
|
|
725
690
|
pluginExtensionPointCmdTopicUrl,
|
|
726
691
|
publishToAggregates: mergedAggregateUrls,
|
|
727
|
-
readModelQueueUrls,
|
|
728
|
-
readModelNamesForSourceName,
|
|
729
692
|
},
|
|
730
693
|
)
|
|
731
694
|
|