@reventlessdev/reventless-core 3.0.0-alpha.315 → 3.0.0-alpha.317
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 +23 -0
- package/package.json +7 -7
- package/src/Message.res +3 -1
- package/src/Message.res.mjs +4 -1
- package/src/components/Aggregate/Aggregate_Callback.res +3 -0
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +1 -1
- package/src/components/EventLog/EventLog_Operations.res +174 -53
- package/src/components/EventLog/EventLog_Operations.res.mjs +148 -38
- package/src/components/Extension/Extension_Operations.res +8 -2
- package/src/components/Extension/Extension_Operations.res.mjs +9 -2
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res +3 -0
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res.mjs +4 -0
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +170 -90
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +153 -69
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +6 -0
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +8 -1
- package/src/components/StateViewSlice/StateViewSlice_Callback.res +5 -0
- package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +5 -0
- package/src/util/Lru.res +33 -6
- package/src/util/Lru.res.mjs +32 -8
- package/src/util/Lru.resi +8 -2
- package/tests/dcb/DcbPiiSliceTest.res +142 -0
- package/tests/dcb/DcbPiiSliceTest.res.mjs +275 -0
- package/tests/eventlog/EventLogFixtures.res +14 -5
- package/tests/eventlog/EventLogFixtures.res.mjs +10 -4
- package/tests/eventlog/EventLogPiiTest.res +114 -0
- package/tests/eventlog/EventLogPiiTest.res.mjs +230 -0
- package/tests/pii/PiiPrefetchTest.res +116 -0
- package/tests/pii/PiiPrefetchTest.res.mjs +206 -0
- package/tests/util/LruTest.res +35 -0
- package/tests/util/LruTest.res.mjs +46 -8
|
@@ -45,6 +45,64 @@ module Make = (
|
|
|
45
45
|
producedEventTypes->Array.filter(t => !(queryEventTypes->Array.includes(t))),
|
|
46
46
|
)
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
The produced events with their personal fields sealed by the installed provider:
|
|
50
|
+
the one form both the stored event and the published message carry. Refused,
|
|
51
|
+
never degraded, when a field cannot be sealed or comes out unsealed; the detail
|
|
52
|
+
names the event type and the field, never the value.
|
|
53
|
+
*/
|
|
54
|
+
let sealRawEvents = async (raws: array<ReventlessInfra.DcbEventLog.rawEvent>): result<
|
|
55
|
+
array<ReventlessInfra.DcbEventLog.rawEvent>,
|
|
56
|
+
string,
|
|
57
|
+
> => {
|
|
58
|
+
let out = []
|
|
59
|
+
let failure = ref(None)
|
|
60
|
+
for i in 0 to raws->Array.length - 1 {
|
|
61
|
+
let raw = raws->Array.getUnsafe(i)
|
|
62
|
+
switch (failure.contents, raw.data) {
|
|
63
|
+
| (None, Object(data)) =>
|
|
64
|
+
switch await Reventless.Pii.sealData(Spec.eventSchema, ~eventType=raw.eventType, data) {
|
|
65
|
+
| Error(e) =>
|
|
66
|
+
failure := Some(`cannot seal ${raw.eventType}: ${e->Reventless.Pii.errorMessage}`)
|
|
67
|
+
| Ok(sealed) =>
|
|
68
|
+
switch Reventless.Pii.unsealedField(Spec.eventSchema, ~eventType=raw.eventType, sealed) {
|
|
69
|
+
| Some(field) =>
|
|
70
|
+
failure := Some(`refused ${raw.eventType}: its personal field ${field} is not sealed`)
|
|
71
|
+
| None => out->Array.push({...raw, data: JSON.Object(sealed)})
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
| (None, _) => out->Array.push(raw)
|
|
75
|
+
| (Some(_), _) => ()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
switch failure.contents {
|
|
79
|
+
| Some(msg) => Error(msg)
|
|
80
|
+
| None => Ok(out)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A read event with its sealed personal fields opened, before the decoder
|
|
85
|
+
reads it. Most events hold nothing sealed and pass without a promise. */
|
|
86
|
+
let openRaw = (raw: ReventlessInfra.DcbEventLog.rawSequencedEvent) =>
|
|
87
|
+
switch raw.data {
|
|
88
|
+
| Object(data)
|
|
89
|
+
if Reventless.Pii.needsOpen(Spec.consumedEventSchema, ~eventType=raw.eventType, data) =>
|
|
90
|
+
Effect.promise(async () =>
|
|
91
|
+
switch await Reventless.Pii.openData(
|
|
92
|
+
Spec.consumedEventSchema,
|
|
93
|
+
~eventType=raw.eventType,
|
|
94
|
+
data,
|
|
95
|
+
) {
|
|
96
|
+
| Ok(opened) => {...raw, data: JSON.Object(opened)}
|
|
97
|
+
| Error(e) =>
|
|
98
|
+
JsError.throwWithMessage(
|
|
99
|
+
`cannot open ${raw.eventType}: ${e->Reventless.Pii.errorMessage}`,
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
| _ => Effect.succeed(raw)
|
|
104
|
+
}
|
|
105
|
+
|
|
48
106
|
let encodeEvent = (
|
|
49
107
|
~parentMeta: Message.meta,
|
|
50
108
|
~tagKeysByEventType: Dict.t<array<string>>,
|
|
@@ -179,7 +237,7 @@ module Make = (
|
|
|
179
237
|
let projectionCache: Lru.t<
|
|
180
238
|
string,
|
|
181
239
|
(Decision.state, option<Reventless.DcbTag.sequencePosition>, array<string>),
|
|
182
|
-
> = Lru.make(~capacity=projectionCacheCapacity)
|
|
240
|
+
> = Lru.make(~capacity=projectionCacheCapacity, ~ttlMs=Lru.decodedStateTtlMs())
|
|
183
241
|
|
|
184
242
|
let resetCache = () => projectionCache->Lru.clear
|
|
185
243
|
|
|
@@ -345,6 +403,7 @@ module Make = (
|
|
|
345
403
|
}
|
|
346
404
|
|
|
347
405
|
dcbEventLog.readStream(~query, ~after=?afterPos, ~strongConsistency)
|
|
406
|
+
->Stream.mapEffect(openRaw)
|
|
348
407
|
// The head accumulator starts at `afterPos` (the seeded head), not `None`,
|
|
349
408
|
// so an empty delta read keeps the cached head — the append must condition
|
|
350
409
|
// on the head that actually exists, not assert "no events exist yet".
|
|
@@ -457,107 +516,128 @@ module Make = (
|
|
|
457
516
|
)
|
|
458
517
|
EffectLogger.logInfo(~comp, "no events produced")->Effect.map(_ => Ok("ok"))
|
|
459
518
|
| Ok(newEvents) =>
|
|
460
|
-
let
|
|
519
|
+
let encoded =
|
|
461
520
|
newEvents->Array.map(
|
|
462
521
|
e => encodeEvent(~parentMeta=command'.meta, ~tagKeysByEventType, e),
|
|
463
522
|
)
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
| Object(dict) =>
|
|
471
|
-
let f =
|
|
472
|
-
dict
|
|
473
|
-
->Dict.toArray
|
|
474
|
-
->Array.map(((k, v)) => `${k}:${v->JSON.stringify}`)
|
|
475
|
-
->Array.join(",")
|
|
476
|
-
f == "" ? "" : `({${f}})`
|
|
477
|
-
| _ => ""
|
|
478
|
-
}
|
|
479
|
-
`${LogFormat.bold(e.eventType)}${fields}`
|
|
480
|
-
},
|
|
481
|
-
)
|
|
482
|
-
->Array.join(", ")
|
|
483
|
-
let eventJsons = rawEvents->Array.map(e => e.data)->JSON.Encode.array
|
|
484
|
-
let condition: Reventless.DcbTag.appendCondition = {
|
|
485
|
-
query,
|
|
486
|
-
after: ?headPosition,
|
|
487
|
-
}
|
|
488
|
-
EffectLogger.logInfo(
|
|
489
|
-
~comp,
|
|
490
|
-
~detail=eventJsons,
|
|
491
|
-
`produced ${eventCount} event(s): [${eventDetails}]`,
|
|
492
|
-
)
|
|
493
|
-
->Effect.flatMap(_ => Effect.promise(() => dcbEventLog.append(rawEvents, ~condition)))
|
|
494
|
-
->Effect.flatMap(
|
|
495
|
-
appendResult =>
|
|
496
|
-
switch appendResult {
|
|
497
|
-
| Ok(_position) =>
|
|
498
|
-
// Cache the decided-on state at the read head (NOT including the
|
|
499
|
-
// events we just appended, and NOT the returned position): the
|
|
500
|
-
// next command's delta read picks our events up from `headPosition`.
|
|
523
|
+
Effect.promise(() => sealRawEvents(encoded))->Effect.flatMap(
|
|
524
|
+
sealResult =>
|
|
525
|
+
switch sealResult {
|
|
526
|
+
| Error(detail) =>
|
|
527
|
+
// Refused before the append: nothing is stored, and the read
|
|
528
|
+
// snapshot is still valid.
|
|
501
529
|
cachePut((state, headPosition, owners))
|
|
502
|
-
CommandTopic_Helpers.
|
|
530
|
+
CommandTopic_Helpers.reportRejected(
|
|
503
531
|
~component=Spec.name,
|
|
532
|
+
~cause=InfrastructureFailure,
|
|
504
533
|
cmdJson.meta.msgId,
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
534
|
+
{
|
|
535
|
+
errorCode: Reventless.CommandOutcome.code(AppendFailed),
|
|
536
|
+
errorDetail: detail,
|
|
508
537
|
},
|
|
509
538
|
)
|
|
510
|
-
EffectLogger.
|
|
511
|
-
_ =>
|
|
539
|
+
EffectLogger.logError(~comp, `append refused: ${detail}`)->Effect.map(
|
|
540
|
+
_ => Error(detail),
|
|
512
541
|
)
|
|
513
|
-
|
|
|
514
|
-
|
|
515
|
-
//
|
|
516
|
-
let
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
542
|
+
| Ok(rawEvents) =>
|
|
543
|
+
let eventCount = rawEvents->Array.length->Int.toString
|
|
544
|
+
// Through the redacting formatter, like every other log line.
|
|
545
|
+
let eventDetails =
|
|
546
|
+
rawEvents
|
|
547
|
+
->Array.map(
|
|
548
|
+
e =>
|
|
549
|
+
switch e.data {
|
|
550
|
+
| Object(dict) =>
|
|
551
|
+
Message.combineMessage(e.eventType, dict)->LogFormat.cmdLabelOfJson
|
|
552
|
+
| _ => LogFormat.bold(e.eventType)
|
|
553
|
+
},
|
|
520
554
|
)
|
|
521
|
-
|
|
555
|
+
->Array.join(", ")
|
|
556
|
+
let eventJsons = rawEvents->Array.map(e => e.data)->JSON.Encode.array
|
|
557
|
+
let condition: Reventless.DcbTag.appendCondition = {
|
|
558
|
+
query,
|
|
559
|
+
after: ?headPosition,
|
|
522
560
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
561
|
+
EffectLogger.logInfo(
|
|
562
|
+
~comp,
|
|
563
|
+
~detail=eventJsons,
|
|
564
|
+
`produced ${eventCount} event(s): [${eventDetails}]`,
|
|
565
|
+
)
|
|
566
|
+
->Effect.flatMap(
|
|
567
|
+
_ => Effect.promise(() => dcbEventLog.append(rawEvents, ~condition)),
|
|
568
|
+
)
|
|
569
|
+
->Effect.flatMap(
|
|
570
|
+
appendResult =>
|
|
571
|
+
switch appendResult {
|
|
572
|
+
| Ok(_position) =>
|
|
573
|
+
// Cache the decided-on state at the read head (NOT including the
|
|
574
|
+
// events we just appended, and NOT the returned position): the
|
|
575
|
+
// next command's delta read picks our events up from `headPosition`.
|
|
576
|
+
cachePut((state, headPosition, owners))
|
|
577
|
+
CommandTopic_Helpers.reportAccepted(
|
|
578
|
+
~component=Spec.name,
|
|
579
|
+
cmdJson.meta.msgId,
|
|
580
|
+
switch entityId {
|
|
581
|
+
| Some(eid) => {entityId: eid, eventCount: rawEvents->Array.length}
|
|
582
|
+
| None => {eventCount: rawEvents->Array.length}
|
|
583
|
+
},
|
|
584
|
+
)
|
|
585
|
+
EffectLogger.logInfo(~comp, `append: ${eventCount} event(s)`)->Effect.map(
|
|
586
|
+
_ => Ok("ok"),
|
|
587
|
+
)
|
|
588
|
+
| Error(err) =>
|
|
589
|
+
// Typed classification (was substring-matching the error string,
|
|
590
|
+
// which disagreed with the backends' casing).
|
|
591
|
+
let (errorCode, errDetail) = switch err {
|
|
592
|
+
| ReventlessInfra.DcbEventLog.Conflict => (
|
|
593
|
+
Reventless.CommandOutcome.code(Conflict),
|
|
594
|
+
"conflict: condition check failed",
|
|
595
|
+
)
|
|
596
|
+
| StorageFailure(msg) => (
|
|
597
|
+
Reventless.CommandOutcome.code(AppendFailed),
|
|
598
|
+
msg,
|
|
599
|
+
)
|
|
600
|
+
}
|
|
601
|
+
if retries > 0 {
|
|
602
|
+
// Re-seed from the just-read snapshot so the retry reads only
|
|
603
|
+
// the delta the conflicting writer added, not full history.
|
|
604
|
+
seed := Some((state, headPosition, owners))
|
|
605
|
+
// Per-slice CloudWatch counter: rising AppendRetry signals a
|
|
606
|
+
// slice feeling contention (the metric to watch the eventual
|
|
607
|
+
// default with — see dcb-high-contention-handling.md).
|
|
608
|
+
Metrics.emitCount(~metric="AppendRetry", ~slice=Spec.name)
|
|
609
|
+
EffectLogger.logWarn(
|
|
610
|
+
~comp,
|
|
611
|
+
`append failed (retrying ${(maxRetries - retries + 1)
|
|
612
|
+
->Int.toString}/${maxRetries->Int.toString}): ${errDetail}`,
|
|
613
|
+
)->Effect.flatMap(_ => attempt(~retries=retries - 1))
|
|
614
|
+
} else {
|
|
615
|
+
// Retries exhausted — drop any cached snapshot so the next
|
|
616
|
+
// command for this entity takes the cold full-read path.
|
|
617
|
+
cacheInvalidate()
|
|
540
618
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
619
|
+
// A surfaced Conflict means the 3-retry loop could not absorb
|
|
620
|
+
// the contention — the operator signal for "this slice is hot"
|
|
621
|
+
// (consider sharding / async — Issue 10, §4 of the analysis).
|
|
622
|
+
if errorCode == Reventless.CommandOutcome.code(Conflict) {
|
|
623
|
+
Metrics.emitCount(~metric="AppendConflict", ~slice=Spec.name)
|
|
624
|
+
}
|
|
625
|
+
// Both arms here are storage, not the model: a surfaced Conflict is
|
|
626
|
+
// contention the retry loop couldn't absorb, and AppendFailed is the
|
|
627
|
+
// store failing. `decide` had already said Ok.
|
|
628
|
+
CommandTopic_Helpers.reportRejected(
|
|
629
|
+
~component=Spec.name,
|
|
630
|
+
~cause=InfrastructureFailure,
|
|
631
|
+
cmdJson.meta.msgId,
|
|
632
|
+
{errorCode, errorDetail: errDetail},
|
|
633
|
+
)
|
|
634
|
+
EffectLogger.logError(
|
|
635
|
+
~comp,
|
|
636
|
+
`append failed, retries exhausted: ${errDetail}`,
|
|
637
|
+
)->Effect.map(_ => Error(errDetail))
|
|
638
|
+
}
|
|
639
|
+
},
|
|
640
|
+
)
|
|
561
641
|
},
|
|
562
642
|
)
|
|
563
643
|
| Error(error) =>
|
|
@@ -8,6 +8,8 @@ import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.
|
|
|
8
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
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
12
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
11
13
|
import * as Owner$Reventless from "@reventlessdev/reventless-spec/src/components/Owner.res.mjs";
|
|
12
14
|
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
13
15
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
@@ -30,6 +32,72 @@ function Make(Spec) {
|
|
|
30
32
|
let queryEventTypes = decoder.eventTypes;
|
|
31
33
|
let producedEventTypes = DcbTag$Reventless.extractAllVariantNames(Spec.eventSchema);
|
|
32
34
|
let queryEventTypesWithOwn = queryEventTypes.concat(producedEventTypes.filter(t => !queryEventTypes.includes(t)));
|
|
35
|
+
let sealRawEvents = async raws => {
|
|
36
|
+
let out = [];
|
|
37
|
+
let failure;
|
|
38
|
+
for (let i = 0, i_finish = raws.length; i < i_finish; ++i) {
|
|
39
|
+
let raw = raws[i];
|
|
40
|
+
let match = failure;
|
|
41
|
+
let match$1 = raw.data;
|
|
42
|
+
if (match === undefined) {
|
|
43
|
+
if (typeof match$1 === "object" && match$1 !== null && !Array.isArray(match$1)) {
|
|
44
|
+
let e = await Pii$Reventless.sealData(Spec.eventSchema, raw.eventType, match$1);
|
|
45
|
+
if (e.TAG === "Ok") {
|
|
46
|
+
let sealed = e._0;
|
|
47
|
+
let field = Pii$Reventless.unsealedField(Spec.eventSchema, raw.eventType, sealed);
|
|
48
|
+
if (field !== undefined) {
|
|
49
|
+
failure = `refused ` + raw.eventType + `: its personal field ` + field + ` is not sealed`;
|
|
50
|
+
} else {
|
|
51
|
+
out.push({
|
|
52
|
+
eventType: raw.eventType,
|
|
53
|
+
data: sealed,
|
|
54
|
+
tags: raw.tags,
|
|
55
|
+
meta: raw.meta
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
failure = `cannot seal ` + raw.eventType + `: ` + Pii$Reventless.errorMessage(e._0);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
out.push(raw);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let msg = failure;
|
|
67
|
+
if (msg !== undefined) {
|
|
68
|
+
return {
|
|
69
|
+
TAG: "Error",
|
|
70
|
+
_0: msg
|
|
71
|
+
};
|
|
72
|
+
} else {
|
|
73
|
+
return {
|
|
74
|
+
TAG: "Ok",
|
|
75
|
+
_0: out
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
let openRaw = raw => {
|
|
80
|
+
let data = raw.data;
|
|
81
|
+
if (typeof data === "object" && data !== null && !Array.isArray(data) && Pii$Reventless.needsOpen(Spec.consumedEventSchema, raw.eventType, data)) {
|
|
82
|
+
return Effect.promise(async () => {
|
|
83
|
+
let opened = await Pii$Reventless.openData(Spec.consumedEventSchema, raw.eventType, data);
|
|
84
|
+
if (opened.TAG === "Ok") {
|
|
85
|
+
return {
|
|
86
|
+
position: raw.position,
|
|
87
|
+
eventType: raw.eventType,
|
|
88
|
+
data: opened._0,
|
|
89
|
+
tags: raw.tags,
|
|
90
|
+
meta: raw.meta,
|
|
91
|
+
recordedAt: raw.recordedAt
|
|
92
|
+
};
|
|
93
|
+
} else {
|
|
94
|
+
return Stdlib_JsError.throwWithMessage(`cannot open ` + raw.eventType + `: ` + Pii$Reventless.errorMessage(opened._0));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
} else {
|
|
98
|
+
return Effect.succeed(raw);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
33
101
|
let slicePartitionTag = Stdlib_Lazy.make(() => {
|
|
34
102
|
try {
|
|
35
103
|
return DcbTag$Reventless.deriveSlicePartition({
|
|
@@ -78,7 +146,7 @@ function Make(Spec) {
|
|
|
78
146
|
return v;
|
|
79
147
|
}
|
|
80
148
|
};
|
|
81
|
-
let projectionCache = Lru$ReventlessCore.make(100);
|
|
149
|
+
let projectionCache = Lru$ReventlessCore.make(100, Lru$ReventlessCore.decodedStateTtlMs(), undefined);
|
|
82
150
|
let resetCache = () => Lru$ReventlessCore.clear(projectionCache);
|
|
83
151
|
let handleSingleCommand = (tagKeysByEventType, crossPartitionTagKeys, payloadTagKeys, partitionTag, dcbEventLog, command$p) => {
|
|
84
152
|
let cmdJson = Message$ReventlessCore.commandJsonOfCommand$p(Id$Reventless.$$String.toString, Spec.commandSchema, command$p);
|
|
@@ -179,7 +247,7 @@ function Make(Spec) {
|
|
|
179
247
|
strongConsistency = false;
|
|
180
248
|
break;
|
|
181
249
|
}
|
|
182
|
-
return Effect.flatMap(Effect.tap(Stream$1.runFold(dcbEventLog.readStream(query, afterPos, strongConsistency), [
|
|
250
|
+
return Effect.flatMap(Effect.tap(Stream$1.runFold(Stream$1.mapEffect(dcbEventLog.readStream(query, afterPos, strongConsistency), openRaw), [
|
|
183
251
|
match$1[0],
|
|
184
252
|
afterPos,
|
|
185
253
|
[],
|
|
@@ -272,7 +340,7 @@ function Make(Spec) {
|
|
|
272
340
|
_0: "ok"
|
|
273
341
|
}));
|
|
274
342
|
}
|
|
275
|
-
let
|
|
343
|
+
let encoded = newEvents$1.map(e => {
|
|
276
344
|
let parentMeta = command$p.meta;
|
|
277
345
|
let json = Util_Sury$Reventless.toJson(e, Spec.eventSchema);
|
|
278
346
|
let match = Message$ReventlessCore.splitMessage(json);
|
|
@@ -288,74 +356,90 @@ function Make(Spec) {
|
|
|
288
356
|
meta: meta
|
|
289
357
|
};
|
|
290
358
|
});
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
359
|
+
return Effect.flatMap(Effect.promise(() => sealRawEvents(encoded)), sealResult => {
|
|
360
|
+
if (sealResult.TAG === "Ok") {
|
|
361
|
+
let rawEvents = sealResult._0;
|
|
362
|
+
let eventCount = rawEvents.length.toString();
|
|
363
|
+
let eventDetails = rawEvents.map(e => {
|
|
364
|
+
let dict = e.data;
|
|
365
|
+
if (typeof dict === "object" && dict !== null && !Array.isArray(dict)) {
|
|
366
|
+
return LogFormat$ReventlessCore.cmdLabelOfJson(Message$ReventlessCore.combineMessage(e.eventType, dict));
|
|
367
|
+
} else {
|
|
368
|
+
return LogFormat$ReventlessCore.bold(e.eventType);
|
|
369
|
+
}
|
|
370
|
+
}).join(", ");
|
|
371
|
+
let eventJsons = rawEvents.map(e => e.data);
|
|
372
|
+
let condition = {
|
|
373
|
+
query: query,
|
|
374
|
+
after: headPosition
|
|
375
|
+
};
|
|
376
|
+
return Effect.flatMap(Effect.flatMap(EffectLogger$ReventlessCore.logInfo(comp, eventJsons, `produced ` + eventCount + ` event(s): [` + eventDetails + `]`), () => Effect.promise(() => dcbEventLog.append(rawEvents, condition))), appendResult => {
|
|
377
|
+
if (appendResult.TAG === "Ok") {
|
|
378
|
+
cachePut([
|
|
379
|
+
state,
|
|
380
|
+
headPosition,
|
|
381
|
+
owners
|
|
382
|
+
]);
|
|
383
|
+
CommandTopic_Helpers$ReventlessCore.reportAccepted(Spec.name, cmdJson.meta.msgId, entityId !== undefined ? ({
|
|
384
|
+
entityId: entityId,
|
|
385
|
+
eventCount: rawEvents.length
|
|
386
|
+
}) : ({
|
|
387
|
+
eventCount: rawEvents.length
|
|
388
|
+
}));
|
|
389
|
+
return Effect.map(EffectLogger$ReventlessCore.logInfo(comp, undefined, `append: ` + eventCount + ` event(s)`), () => ({
|
|
390
|
+
TAG: "Ok",
|
|
391
|
+
_0: "ok"
|
|
392
|
+
}));
|
|
393
|
+
}
|
|
394
|
+
let err = appendResult._0;
|
|
395
|
+
let match;
|
|
396
|
+
match = typeof err !== "object" ? [
|
|
397
|
+
CommandOutcome$Reventless.code("Conflict"),
|
|
398
|
+
"conflict: condition check failed"
|
|
399
|
+
] : [
|
|
400
|
+
CommandOutcome$Reventless.code("AppendFailed"),
|
|
401
|
+
err._0
|
|
402
|
+
];
|
|
403
|
+
let errDetail = match[1];
|
|
404
|
+
let errorCode = match[0];
|
|
405
|
+
if (retries > 0) {
|
|
406
|
+
seed.contents = [
|
|
407
|
+
state,
|
|
408
|
+
headPosition,
|
|
409
|
+
owners
|
|
410
|
+
];
|
|
411
|
+
Metrics$ReventlessCore.emitCount("AppendRetry", Spec.name, undefined);
|
|
412
|
+
return Effect.flatMap(EffectLogger$ReventlessCore.logWarn(comp, undefined, `append failed (retrying ` + ((3 - retries | 0) + 1 | 0).toString() + `/` + (3).toString() + `): ` + errDetail), () => attempt(retries - 1 | 0));
|
|
413
|
+
} else {
|
|
414
|
+
cacheInvalidate();
|
|
415
|
+
if (errorCode === CommandOutcome$Reventless.code("Conflict")) {
|
|
416
|
+
Metrics$ReventlessCore.emitCount("AppendConflict", Spec.name, undefined);
|
|
417
|
+
}
|
|
418
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", cmdJson.meta.msgId, {
|
|
419
|
+
errorCode: errorCode,
|
|
420
|
+
errorDetail: errDetail
|
|
421
|
+
});
|
|
422
|
+
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, `append failed, retries exhausted: ` + errDetail), () => ({
|
|
423
|
+
TAG: "Error",
|
|
424
|
+
_0: errDetail
|
|
425
|
+
}));
|
|
426
|
+
}
|
|
353
427
|
});
|
|
354
|
-
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, `append failed, retries exhausted: ` + errDetail), () => ({
|
|
355
|
-
TAG: "Error",
|
|
356
|
-
_0: errDetail
|
|
357
|
-
}));
|
|
358
428
|
}
|
|
429
|
+
let detail = sealResult._0;
|
|
430
|
+
cachePut([
|
|
431
|
+
state,
|
|
432
|
+
headPosition,
|
|
433
|
+
owners
|
|
434
|
+
]);
|
|
435
|
+
CommandTopic_Helpers$ReventlessCore.reportRejected(Spec.name, "InfrastructureFailure", cmdJson.meta.msgId, {
|
|
436
|
+
errorCode: CommandOutcome$Reventless.code("AppendFailed"),
|
|
437
|
+
errorDetail: detail
|
|
438
|
+
});
|
|
439
|
+
return Effect.map(EffectLogger$ReventlessCore.logError(comp, undefined, `append refused: ` + detail), () => ({
|
|
440
|
+
TAG: "Error",
|
|
441
|
+
_0: detail
|
|
442
|
+
}));
|
|
359
443
|
});
|
|
360
444
|
}
|
|
361
445
|
cachePut([
|
|
@@ -98,6 +98,12 @@ module Make = (
|
|
|
98
98
|
let jsonEventsHandler: EventCollector.jsonEventsHandler = stream =>
|
|
99
99
|
stream
|
|
100
100
|
->Stream.runCollect
|
|
101
|
+
// The keys this batch's sealed fields name, before anything decodes it.
|
|
102
|
+
->Effect.tap(events =>
|
|
103
|
+
Reventless.Pii.needsPrepare(events)
|
|
104
|
+
? Effect.promise(() => Reventless.Pii.prepareOrThrow(events))
|
|
105
|
+
: Effect.succeed()
|
|
106
|
+
)
|
|
101
107
|
->Effect.flatMap(events => {
|
|
102
108
|
let total = events->Array.length->Int.toString
|
|
103
109
|
events
|
|
@@ -8,6 +8,7 @@ import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.
|
|
|
8
8
|
import * as Output$Pulumi from "@reventlessdev/rescript-pulumi-pulumi/src/Output.res.mjs";
|
|
9
9
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
10
10
|
import * as Effect from "effect/Effect";
|
|
11
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
11
12
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
12
13
|
import * as DcbDecode$Reventless from "@reventlessdev/reventless-spec/src/components/DcbDecode.res.mjs";
|
|
13
14
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
@@ -79,7 +80,13 @@ function Make(RuntimeEnvironment) {
|
|
|
79
80
|
name: Spec.name
|
|
80
81
|
}, opts);
|
|
81
82
|
let comp = `StateViewSlice(` + Spec.name + `)`;
|
|
82
|
-
let jsonEventsHandler = stream => Effect.flatMap(Stream.runCollect(stream), events => {
|
|
83
|
+
let jsonEventsHandler = stream => Effect.flatMap(Effect.tap(Stream.runCollect(stream), events => {
|
|
84
|
+
if (Pii$Reventless.needsPrepare(events)) {
|
|
85
|
+
return Effect.promise(() => Pii$Reventless.prepareOrThrow(events));
|
|
86
|
+
} else {
|
|
87
|
+
return Effect.succeed();
|
|
88
|
+
}
|
|
89
|
+
}), events => {
|
|
83
90
|
let total = events.length.toString();
|
|
84
91
|
return Stdlib_Array.reduce(events.map((json, i) => {
|
|
85
92
|
let envelopeDict = Stdlib_Option.getOr(Stdlib_JSON.Decode.object(json), {});
|
|
@@ -28,6 +28,11 @@ module Make = (
|
|
|
28
28
|
queryDbOps: queryDbOperations,
|
|
29
29
|
rawEvents: array<ReventlessInfra.DcbEventLog.rawSequencedEvent>,
|
|
30
30
|
) => {
|
|
31
|
+
// The keys this batch's sealed fields name, before anything decodes it.
|
|
32
|
+
let datas = rawEvents->Array.map(raw => raw.data)
|
|
33
|
+
if Reventless.Pii.needsPrepare(datas) {
|
|
34
|
+
await Reventless.Pii.prepareOrThrow(datas)
|
|
35
|
+
}
|
|
31
36
|
let count = rawEvents->Array.length->Int.toString
|
|
32
37
|
let idx = ref(0)
|
|
33
38
|
let allActions = []
|
|
@@ -4,6 +4,7 @@ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
|
4
4
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
5
5
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
6
6
|
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
7
8
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
8
9
|
import * as DcbDecode$Reventless from "@reventlessdev/reventless-spec/src/components/DcbDecode.res.mjs";
|
|
9
10
|
import * as Projection$Reventless from "@reventlessdev/reventless-spec/src/types/Projection.res.mjs";
|
|
@@ -16,6 +17,10 @@ function Make(Spec) {
|
|
|
16
17
|
let comp = `StateViewSlice(` + Spec.name + `)`;
|
|
17
18
|
let decoder = DcbDecode$Reventless.makeDecoder(Spec.consumedEventSchema);
|
|
18
19
|
let eventsHandler = async (queryDbOps, rawEvents) => {
|
|
20
|
+
let datas = rawEvents.map(raw => raw.data);
|
|
21
|
+
if (Pii$Reventless.needsPrepare(datas)) {
|
|
22
|
+
await Pii$Reventless.prepareOrThrow(datas);
|
|
23
|
+
}
|
|
19
24
|
let count = rawEvents.length.toString();
|
|
20
25
|
let idx = {
|
|
21
26
|
contents: 0
|