@reventlessdev/reventless-core 3.0.0-alpha.316 → 3.0.0-alpha.318
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 +35 -0
- package/package.json +4 -4
- package/src/Message.res +3 -1
- package/src/Message.res.mjs +4 -1
- 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/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/tests/dcb/DcbPiiSliceTest.res +2 -1
- package/tests/dcb/DcbPiiSliceTest.res.mjs +5 -1
- package/tests/eventlog/EventLogPiiTest.res +2 -1
- package/tests/eventlog/EventLogPiiTest.res.mjs +5 -1
- package/tests/pii/PiiPrefetchTest.res +116 -0
- package/tests/pii/PiiPrefetchTest.res.mjs +206 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 3.0.0-alpha.318 (2026-10-29)
|
|
7
|
+
|
|
8
|
+
* feat(core)!: every reader opens a sealed field, with the keys its batch prepared ([d4ac204](https://github.com/ReventlessDev/reventless-core/commit/d4ac204c307d34617d4e32c556030b44bb55b178))
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **aws:** every reader's Lambda fetches the keys its events name before decoding ([62b22c7](https://github.com/ReventlessDev/reventless-core/commit/62b22c74ba6e79783c67db962e43f86c273f4503))
|
|
12
|
+
|
|
13
|
+
### BREAKING CHANGES
|
|
14
|
+
|
|
15
|
+
* `Pii.provider` has `prefetch` and `openNow` in place of `open_`.
|
|
16
|
+
|
|
17
|
+
Not yet: `prepare` in the AWS entry points, the conformance scenario, the runs on
|
|
18
|
+
DynamoDB and Postgres.
|
|
19
|
+
|
|
20
|
+
Begins step PD10 of docs/plans/a-personal-field-is-marked-redacted-and-encrypted-at-the-seam.md.
|
|
21
|
+
Claude-Session: https://claude.ai/code/session_01HiQfdxVEsHwLHRoHSUcus1
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# 3.0.0-alpha.317 (2026-10-29)
|
|
26
|
+
|
|
27
|
+
* feat(core)!: every reader opens a sealed field, with the keys its batch prepared ([d4ac204](https://github.com/ReventlessDev/reventless-core/commit/d4ac204c307d34617d4e32c556030b44bb55b178))
|
|
28
|
+
|
|
29
|
+
### BREAKING CHANGES
|
|
30
|
+
|
|
31
|
+
* `Pii.provider` has `prefetch` and `openNow` in place of `open_`.
|
|
32
|
+
|
|
33
|
+
Not yet: `prepare` in the AWS entry points, the conformance scenario, the runs on
|
|
34
|
+
DynamoDB and Postgres.
|
|
35
|
+
|
|
36
|
+
Begins step PD10 of docs/plans/a-personal-field-is-marked-redacted-and-encrypted-at-the-seam.md.
|
|
37
|
+
Claude-Session: https://claude.ai/code/session_01HiQfdxVEsHwLHRoHSUcus1
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
6
41
|
# 3.0.0-alpha.316 (2026-10-29)
|
|
7
42
|
|
|
8
43
|
### Features
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.318",
|
|
4
4
|
"description": "Core package for Reventless framework",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"jest": {
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
"sury": "11.0.0",
|
|
30
30
|
"uuid": "^13.0.0",
|
|
31
31
|
"@reventlessdev/rescript-effect": "1.0.0-alpha.1",
|
|
32
|
-
"@reventlessdev/rescript-fast-csv": "2.0.0-alpha.24",
|
|
33
32
|
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
|
|
34
33
|
"@reventlessdev/rescript-jest": "1.0.0-alpha.13",
|
|
34
|
+
"@reventlessdev/rescript-fast-csv": "2.0.0-alpha.24",
|
|
35
35
|
"@reventlessdev/rescript-node": "2.0.0-alpha.24",
|
|
36
36
|
"@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
|
|
37
37
|
"@reventlessdev/rescript-ssh2": "2.0.0-alpha.25",
|
|
38
38
|
"@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
|
|
39
|
-
"@reventlessdev/reventless-infra": "3.0.0-alpha.
|
|
39
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.215",
|
|
40
40
|
"@reventlessdev/reventless-interop": "3.0.0-alpha.42",
|
|
41
|
-
"@reventlessdev/reventless-spec": "3.0.0-alpha.
|
|
41
|
+
"@reventlessdev/reventless-spec": "3.0.0-alpha.186"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"rescript": "12.3.1",
|
package/src/Message.res
CHANGED
|
@@ -71,7 +71,9 @@ let toCommandSchema' = (idSchema, commandSchema) =>
|
|
|
71
71
|
// `Reventless.Message.decode` (the other central decoder) is tolerant at the source.
|
|
72
72
|
// See docs/plans/done/platform-infrastructure-in-plugin-list.md (durable fix option 2).
|
|
73
73
|
let decodeEvent' = (json, idSchema, eventSchema) =>
|
|
74
|
-
json
|
|
74
|
+
json
|
|
75
|
+
->Reventless.Message.openEnvelope(eventSchema)
|
|
76
|
+
->parseJsonTolerant(toEventSchema'(idSchema, eventSchema))
|
|
75
77
|
let decodeCommand' = (json, idSchema, commandSchema) =>
|
|
76
78
|
json->parseJsonTolerant(toCommandSchema'(idSchema, commandSchema))
|
|
77
79
|
|
package/src/Message.res.mjs
CHANGED
|
@@ -46,7 +46,7 @@ function toCommandSchema$p(idSchema, commandSchema) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function decodeEvent$p(json, idSchema, eventSchema) {
|
|
49
|
-
return Message$Reventless.parseJsonTolerant(json, toEventSchema$p(idSchema, eventSchema));
|
|
49
|
+
return Message$Reventless.parseJsonTolerant(Message$Reventless.openEnvelope(json, eventSchema), toEventSchema$p(idSchema, eventSchema));
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function decodeCommand$p(json, idSchema, commandSchema) {
|
|
@@ -410,6 +410,8 @@ let encode = Message$Reventless.encode;
|
|
|
410
410
|
|
|
411
411
|
let InvalidEvent = Message$Reventless.InvalidEvent;
|
|
412
412
|
|
|
413
|
+
let openEnvelope = Message$Reventless.openEnvelope;
|
|
414
|
+
|
|
413
415
|
let deriveStableMeta = Message$ReventlessInfra.deriveStableMeta;
|
|
414
416
|
|
|
415
417
|
let hasStableMsgId = Message$ReventlessInfra.hasStableMsgId;
|
|
@@ -427,6 +429,7 @@ export {
|
|
|
427
429
|
decode,
|
|
428
430
|
encode,
|
|
429
431
|
InvalidEvent,
|
|
432
|
+
openEnvelope,
|
|
430
433
|
_rawMemoize,
|
|
431
434
|
memoizeBySchemaPair,
|
|
432
435
|
toEventSchema$p,
|
|
@@ -152,6 +152,9 @@ module Make = (
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
let incomingJsonEventsHandler = async (eventJson', pluginDef) => {
|
|
155
|
+
if Reventless.Pii.needsPrepare([eventJson']) {
|
|
156
|
+
await Reventless.Pii.prepareOrThrow([eventJson'])
|
|
157
|
+
}
|
|
155
158
|
EffectLogger.logInfo(
|
|
156
159
|
~comp,
|
|
157
160
|
`incoming EP event: ${LogFormat.eventSummary(eventJson')}`,
|
|
@@ -178,13 +181,16 @@ module Make = (
|
|
|
178
181
|
}
|
|
179
182
|
}
|
|
180
183
|
|
|
181
|
-
let outgoingJsonEventsHandler = (eventJson', pluginDef) => {
|
|
184
|
+
let outgoingJsonEventsHandler = async (eventJson', pluginDef) => {
|
|
185
|
+
if Reventless.Pii.needsPrepare([eventJson']) {
|
|
186
|
+
await Reventless.Pii.prepareOrThrow([eventJson'])
|
|
187
|
+
}
|
|
182
188
|
EffectLogger.logInfo(
|
|
183
189
|
~comp,
|
|
184
190
|
`outgoing delegate event: ${LogFormat.eventSummary(eventJson')}`,
|
|
185
191
|
)->Effect.runSync
|
|
186
192
|
let commandActions = mapOutgoingEvent(eventJson', pluginDef)
|
|
187
|
-
commandActions
|
|
193
|
+
await commandActions
|
|
188
194
|
->Array.map(applyOutgoingCommandAction)
|
|
189
195
|
->Promise.all
|
|
190
196
|
->Util.Promise.toUnit
|
|
@@ -4,6 +4,7 @@ import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
|
4
4
|
import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
|
|
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 Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
8
9
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
9
10
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
@@ -111,6 +112,9 @@ function Make(MappingSpec) {
|
|
|
111
112
|
}
|
|
112
113
|
};
|
|
113
114
|
let incomingJsonEventsHandler = async (eventJson$p, pluginDef) => {
|
|
115
|
+
if (Pii$Reventless.needsPrepare([eventJson$p])) {
|
|
116
|
+
await Pii$Reventless.prepareOrThrow([eventJson$p]);
|
|
117
|
+
}
|
|
114
118
|
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, `incoming EP event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
|
|
115
119
|
let event$p;
|
|
116
120
|
try {
|
|
@@ -124,10 +128,13 @@ function Make(MappingSpec) {
|
|
|
124
128
|
let apply = async commandActions => await Util_Promise$ReventlessCore.toUnit(Promise.all(commandActions.map(applyIncomingCommandAction)));
|
|
125
129
|
return await apply(commandActions);
|
|
126
130
|
};
|
|
127
|
-
let outgoingJsonEventsHandler = (eventJson$p, pluginDef) => {
|
|
131
|
+
let outgoingJsonEventsHandler = async (eventJson$p, pluginDef) => {
|
|
132
|
+
if (Pii$Reventless.needsPrepare([eventJson$p])) {
|
|
133
|
+
await Pii$Reventless.prepareOrThrow([eventJson$p]);
|
|
134
|
+
}
|
|
128
135
|
Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, `outgoing delegate event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
|
|
129
136
|
let commandActions = mapOutgoingEvent(eventJson$p, pluginDef);
|
|
130
|
-
return Util_Promise$ReventlessCore.toUnit(Promise.all(commandActions.map(applyOutgoingCommandAction)));
|
|
137
|
+
return await Util_Promise$ReventlessCore.toUnit(Promise.all(commandActions.map(applyOutgoingCommandAction)));
|
|
131
138
|
};
|
|
132
139
|
return {
|
|
133
140
|
incomingJsonEventsHandler: incomingJsonEventsHandler,
|
|
@@ -133,6 +133,9 @@ module Make = (
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
let outgoingJsonEventsHandler = async (eventJson', _pluginDef) => {
|
|
136
|
+
if Reventless.Pii.needsPrepare([eventJson']) {
|
|
137
|
+
await Reventless.Pii.prepareOrThrow([eventJson'])
|
|
138
|
+
}
|
|
136
139
|
EffectLogger.logInfo(
|
|
137
140
|
~comp=`ExtensionPoint(${MappingSpec.name})`,
|
|
138
141
|
`outgoing event: ${LogFormat.eventSummary(eventJson')}`,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
4
4
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
6
7
|
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
7
8
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
8
9
|
import * as Message$ReventlessCore from "../../Message.res.mjs";
|
|
@@ -102,6 +103,9 @@ function Make(MappingSpec) {
|
|
|
102
103
|
}
|
|
103
104
|
};
|
|
104
105
|
let outgoingJsonEventsHandler = async (eventJson$p, _pluginDef) => {
|
|
106
|
+
if (Pii$Reventless.needsPrepare([eventJson$p])) {
|
|
107
|
+
await Pii$Reventless.prepareOrThrow([eventJson$p]);
|
|
108
|
+
}
|
|
105
109
|
Effect.runSync(EffectLogger$ReventlessCore.logInfo(`ExtensionPoint(` + MappingSpec.name + `)`, undefined, `outgoing event: ` + LogFormat$ReventlessCore.eventSummary(eventJson$p)));
|
|
106
110
|
let eventActions = mapOutgoingEvent(eventJson$p, Mappings.mappings, Ops.scheduler, Ops.commandTopicResources, Ops.queryEngine, Ops.resourceNaming);
|
|
107
111
|
return await Util_Promise$ReventlessCore.toUnit(Promise.all(eventActions.map(applyEventAction)));
|
|
@@ -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
|
|
@@ -81,7 +81,8 @@ let fakeProvider = (~seals=true): Reventless.Pii.provider => {
|
|
|
81
81
|
seals
|
|
82
82
|
? Ok(Reventless.Pii.wrap(`enc:v1:${subject}:fake:${json->JSON.stringify->toBase64}`))
|
|
83
83
|
: Ok(json),
|
|
84
|
-
|
|
84
|
+
prefetch: async _ => Ok(),
|
|
85
|
+
openNow: (~field, json) =>
|
|
85
86
|
switch json->Reventless.Pii.unwrap->Option.flatMap(Reventless.Pii.parseStored) {
|
|
86
87
|
| Some(Cipher({bytes})) => Ok(bytes->fromBase64->JSON.parseOrThrow)
|
|
87
88
|
| _ => Error(Reventless.Pii.UnknownForm({field: field}))
|
|
@@ -167,7 +167,11 @@ function fakeProvider(sealsOpt) {
|
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
},
|
|
170
|
-
|
|
170
|
+
prefetch: async param => ({
|
|
171
|
+
TAG: "Ok",
|
|
172
|
+
_0: undefined
|
|
173
|
+
}),
|
|
174
|
+
openNow: (field, json) => {
|
|
171
175
|
let match = Stdlib_Option.flatMap(Pii$Reventless.unwrap(json), Pii$Reventless.parseStored);
|
|
172
176
|
if (match === undefined) {
|
|
173
177
|
return {
|
|
@@ -27,7 +27,8 @@ let fakeProvider = (~seals=true): Reventless.Pii.provider => {
|
|
|
27
27
|
seals
|
|
28
28
|
? Ok(Reventless.Pii.wrap(`enc:v1:${subject}:fake:${json->JSON.stringify->toBase64}`))
|
|
29
29
|
: Ok(json),
|
|
30
|
-
|
|
30
|
+
prefetch: async _ => Ok(),
|
|
31
|
+
openNow: (~field, json) =>
|
|
31
32
|
switch json->Reventless.Pii.unwrap->Option.flatMap(Reventless.Pii.parseStored) {
|
|
32
33
|
| Some(Cipher({bytes})) => Ok(bytes->fromBase64->JSON.parseOrThrow)
|
|
33
34
|
| _ => Error(Reventless.Pii.UnknownForm({field: field}))
|
|
@@ -98,7 +98,11 @@ function fakeProvider(sealsOpt) {
|
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
},
|
|
101
|
-
|
|
101
|
+
prefetch: async param => ({
|
|
102
|
+
TAG: "Ok",
|
|
103
|
+
_0: undefined
|
|
104
|
+
}),
|
|
105
|
+
openNow: (field, json) => {
|
|
102
106
|
let match = Stdlib_Option.flatMap(Pii$Reventless.unwrap(json), Pii$Reventless.parseStored);
|
|
103
107
|
if (match === undefined) {
|
|
104
108
|
return {
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// The decoders open sealed fields with the keys a batch prepared, and fail rather
|
|
2
|
+
// than drop an event whose key is not at hand.
|
|
3
|
+
|
|
4
|
+
open JestGlobals
|
|
5
|
+
|
|
6
|
+
module Spec = {
|
|
7
|
+
@schema
|
|
8
|
+
type event =
|
|
9
|
+
| MemberNamed({
|
|
10
|
+
memberId: string,
|
|
11
|
+
name: @s.matches(Reventless.Pii.marked(~subject="memberId", S.string))
|
|
12
|
+
Reventless.Pii.t<string>,
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let toBase64 = (s: string) =>
|
|
17
|
+
NodeCrypto.bufferFromString(s, "utf8")->NodeCrypto.bufferToString("base64")
|
|
18
|
+
let fromBase64 = (s: string) =>
|
|
19
|
+
NodeCrypto.bufferFromString(s, "base64")->NodeCrypto.bufferToString("utf8")
|
|
20
|
+
|
|
21
|
+
// Opens only what a prefetch made available, as a key store with a cache would.
|
|
22
|
+
let fetched: ref<array<string>> = ref([])
|
|
23
|
+
let asked: ref<array<array<string>>> = ref([])
|
|
24
|
+
let provider: Reventless.Pii.provider = {
|
|
25
|
+
name: "prefetching",
|
|
26
|
+
encrypts: true,
|
|
27
|
+
seal: async (~subject, ~field as _, ~forgettable as _, json) => Ok(
|
|
28
|
+
Reventless.Pii.wrap(`enc:v1:${subject}:fake:${json->JSON.stringify->toBase64}`),
|
|
29
|
+
),
|
|
30
|
+
prefetch: async keyIds => {
|
|
31
|
+
asked := asked.contents->Array.concat([keyIds])
|
|
32
|
+
fetched := fetched.contents->Array.concat(keyIds)
|
|
33
|
+
Ok()
|
|
34
|
+
},
|
|
35
|
+
openNow: (~field, json) =>
|
|
36
|
+
switch json->Reventless.Pii.unwrap->Option.flatMap(Reventless.Pii.parseStored) {
|
|
37
|
+
| Some(Cipher({keyId, bytes})) =>
|
|
38
|
+
fetched.contents->Array.includes(keyId)
|
|
39
|
+
? Ok(bytes->fromBase64->JSON.parseOrThrow)
|
|
40
|
+
: Error(Reventless.Pii.KeyUnavailable({subject: keyId}))
|
|
41
|
+
| _ => Error(Reventless.Pii.UnknownForm({field: field}))
|
|
42
|
+
},
|
|
43
|
+
release: async (~subject as _, ~ref as _) => Ok(),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let sealedData = () =>
|
|
47
|
+
Dict.fromArray([
|
|
48
|
+
("memberId", JSON.Encode.string("m-1")),
|
|
49
|
+
("name", Reventless.Pii.wrap(`enc:v1:m-1:fake:${"\"Ada\""->toBase64}`)),
|
|
50
|
+
])
|
|
51
|
+
|
|
52
|
+
let envelope = () =>
|
|
53
|
+
Dict.fromArray([
|
|
54
|
+
("id", JSON.Encode.string("m-1")),
|
|
55
|
+
(
|
|
56
|
+
"meta",
|
|
57
|
+
Message.generateMeta(~service="Members")->Reventless.Util_Sury.toJson(Message.metaSchema),
|
|
58
|
+
),
|
|
59
|
+
(
|
|
60
|
+
"event",
|
|
61
|
+
{
|
|
62
|
+
let d = sealedData()
|
|
63
|
+
d->Dict.set("TAG", JSON.Encode.string("MemberNamed"))
|
|
64
|
+
JSON.Object(d)
|
|
65
|
+
},
|
|
66
|
+
),
|
|
67
|
+
])->JSON.Encode.object
|
|
68
|
+
|
|
69
|
+
let threw = f =>
|
|
70
|
+
switch f() {
|
|
71
|
+
| _ => false
|
|
72
|
+
| exception _ => true
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
describe("decoding sealed fields with prepared keys", () => {
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
fetched := []
|
|
78
|
+
asked := []
|
|
79
|
+
Reventless.Pii.Provider.install(provider)
|
|
80
|
+
})
|
|
81
|
+
afterEach(() => Reventless.Pii.Provider.install(Reventless.Pii.plain))
|
|
82
|
+
|
|
83
|
+
let decoder = Reventless.DcbDecode.makeDecoder(Spec.eventSchema)
|
|
84
|
+
|
|
85
|
+
testSync("an unprepared key fails the read, it does not drop the event", () =>
|
|
86
|
+
expect(threw(() => decoder.decode(~eventType="MemberNamed", ~data=sealedData())))->toBe(true)
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
testPromise("after prepare the DCB decoder reads the value", async () => {
|
|
90
|
+
await Reventless.Pii.prepareOrThrow([JSON.Object(sealedData())])
|
|
91
|
+
expect(decoder.decode(~eventType="MemberNamed", ~data=sealedData()))->toEqual(
|
|
92
|
+
Some(Spec.MemberNamed({memberId: "m-1", name: Value("Ada")})),
|
|
93
|
+
)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
testPromise("after prepare an envelope decodes through decodeEvent'", async () => {
|
|
97
|
+
expect(
|
|
98
|
+
threw(
|
|
99
|
+
() => envelope()->Message.decodeEvent'(Reventless.Id.StringPure.schema, Spec.eventSchema),
|
|
100
|
+
),
|
|
101
|
+
)->toBe(true)
|
|
102
|
+
await Reventless.Pii.prepareOrThrow([envelope()])
|
|
103
|
+
let decoded =
|
|
104
|
+
envelope()->Message.decodeEvent'(Reventless.Id.StringPure.schema, Spec.eventSchema)
|
|
105
|
+
expect(decoded.event)->toEqual(Spec.MemberNamed({memberId: "m-1", name: Value("Ada")}))
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
testPromise(
|
|
109
|
+
"prepare asks for the keys a batch names, once each, and nothing for none",
|
|
110
|
+
async () => {
|
|
111
|
+
await Reventless.Pii.prepareOrThrow([envelope(), envelope()])
|
|
112
|
+
await Reventless.Pii.prepareOrThrow([JSON.Encode.string("nothing sealed")])
|
|
113
|
+
expect(asked.contents)->toEqual([["m-1"]])
|
|
114
|
+
},
|
|
115
|
+
)
|
|
116
|
+
})
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Sury from "sury";
|
|
4
|
+
import * as Nodebuffer from "node:buffer";
|
|
5
|
+
import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
|
|
6
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
8
|
+
import * as DcbDecode$Reventless from "@reventlessdev/reventless-spec/src/components/DcbDecode.res.mjs";
|
|
9
|
+
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
10
|
+
import * as Message$ReventlessCore from "../../src/Message.res.mjs";
|
|
11
|
+
|
|
12
|
+
let eventSchema = Sury.$schema(s => ({
|
|
13
|
+
TAG: "MemberNamed",
|
|
14
|
+
memberId: s.m(Sury.string),
|
|
15
|
+
name: s.m(Pii$Reventless.marked("memberId", undefined, Sury.string))
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
let Spec = {
|
|
19
|
+
eventSchema: eventSchema
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function toBase64(s) {
|
|
23
|
+
return Nodebuffer.Buffer.from(s, "utf8").toString("base64");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function fromBase64(s) {
|
|
27
|
+
return Nodebuffer.Buffer.from(s, "base64").toString("utf8");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let fetched = {
|
|
31
|
+
contents: []
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let asked = {
|
|
35
|
+
contents: []
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
async function provider_seal(subject, param, param$1, json) {
|
|
39
|
+
return {
|
|
40
|
+
TAG: "Ok",
|
|
41
|
+
_0: Pii$Reventless.wrap(`enc:v1:` + subject + `:fake:` + toBase64(JSON.stringify(json)))
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function provider_prefetch(keyIds) {
|
|
46
|
+
asked.contents = asked.contents.concat([keyIds]);
|
|
47
|
+
fetched.contents = fetched.contents.concat(keyIds);
|
|
48
|
+
return {
|
|
49
|
+
TAG: "Ok",
|
|
50
|
+
_0: undefined
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function provider_openNow(field, json) {
|
|
55
|
+
let match = Stdlib_Option.flatMap(Pii$Reventless.unwrap(json), Pii$Reventless.parseStored);
|
|
56
|
+
if (match === undefined) {
|
|
57
|
+
return {
|
|
58
|
+
TAG: "Error",
|
|
59
|
+
_0: {
|
|
60
|
+
TAG: "UnknownForm",
|
|
61
|
+
field: field
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
switch (match.TAG) {
|
|
66
|
+
case "Cipher" :
|
|
67
|
+
let keyId = match.keyId;
|
|
68
|
+
if (fetched.contents.includes(keyId)) {
|
|
69
|
+
return {
|
|
70
|
+
TAG: "Ok",
|
|
71
|
+
_0: JSON.parse(fromBase64(match.bytes))
|
|
72
|
+
};
|
|
73
|
+
} else {
|
|
74
|
+
return {
|
|
75
|
+
TAG: "Error",
|
|
76
|
+
_0: {
|
|
77
|
+
TAG: "KeyUnavailable",
|
|
78
|
+
subject: keyId
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
case "ErasedForm" :
|
|
83
|
+
case "ForgottenForm" :
|
|
84
|
+
return {
|
|
85
|
+
TAG: "Error",
|
|
86
|
+
_0: {
|
|
87
|
+
TAG: "UnknownForm",
|
|
88
|
+
field: field
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function provider_release(param, param$1) {
|
|
95
|
+
return {
|
|
96
|
+
TAG: "Ok",
|
|
97
|
+
_0: undefined
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let provider = {
|
|
102
|
+
name: "prefetching",
|
|
103
|
+
encrypts: true,
|
|
104
|
+
seal: provider_seal,
|
|
105
|
+
prefetch: provider_prefetch,
|
|
106
|
+
openNow: provider_openNow,
|
|
107
|
+
release: provider_release
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
function sealedData() {
|
|
111
|
+
return Object.fromEntries([
|
|
112
|
+
[
|
|
113
|
+
"memberId",
|
|
114
|
+
"m-1"
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
"name",
|
|
118
|
+
Pii$Reventless.wrap(`enc:v1:m-1:fake:` + toBase64("\"Ada\""))
|
|
119
|
+
]
|
|
120
|
+
]);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function envelope() {
|
|
124
|
+
let d = sealedData();
|
|
125
|
+
return Object.fromEntries([
|
|
126
|
+
[
|
|
127
|
+
"id",
|
|
128
|
+
"m-1"
|
|
129
|
+
],
|
|
130
|
+
[
|
|
131
|
+
"meta",
|
|
132
|
+
Util_Sury$Reventless.toJson(Message$ReventlessCore.generateMeta("Members", undefined, undefined, undefined, undefined, undefined, undefined), Message$ReventlessCore.metaSchema)
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
"event",
|
|
136
|
+
(d["TAG"] = "MemberNamed", d)
|
|
137
|
+
]
|
|
138
|
+
]);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function threw(f) {
|
|
142
|
+
try {
|
|
143
|
+
f();
|
|
144
|
+
return false;
|
|
145
|
+
} catch (exn) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
globalThis.describe("decoding sealed fields with prepared keys", () => {
|
|
151
|
+
globalThis.beforeEach(() => {
|
|
152
|
+
fetched.contents = [];
|
|
153
|
+
asked.contents = [];
|
|
154
|
+
Pii$Reventless.Provider.install(provider);
|
|
155
|
+
});
|
|
156
|
+
globalThis.afterEach(() => Pii$Reventless.Provider.install(Pii$Reventless.plain));
|
|
157
|
+
let decoder = DcbDecode$Reventless.makeDecoder(eventSchema);
|
|
158
|
+
globalThis.test("an unprepared key fails the read, it does not drop the event", () => {
|
|
159
|
+
globalThis.expect(threw(() => decoder.decode("MemberNamed", sealedData()))).toBe(true);
|
|
160
|
+
});
|
|
161
|
+
globalThis.test("after prepare the DCB decoder reads the value", async () => {
|
|
162
|
+
await Pii$Reventless.prepareOrThrow([sealedData()]);
|
|
163
|
+
globalThis.expect(decoder.decode("MemberNamed", sealedData())).toEqual({
|
|
164
|
+
TAG: "MemberNamed",
|
|
165
|
+
memberId: "m-1",
|
|
166
|
+
name: {
|
|
167
|
+
TAG: "Value",
|
|
168
|
+
_0: "Ada"
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
globalThis.test("after prepare an envelope decodes through decodeEvent'", async () => {
|
|
173
|
+
globalThis.expect(threw(() => Message$ReventlessCore.decodeEvent$p(envelope(), Id$Reventless.StringPure.schema, eventSchema))).toBe(true);
|
|
174
|
+
await Pii$Reventless.prepareOrThrow([envelope()]);
|
|
175
|
+
let decoded = Message$ReventlessCore.decodeEvent$p(envelope(), Id$Reventless.StringPure.schema, eventSchema);
|
|
176
|
+
globalThis.expect(decoded.event).toEqual({
|
|
177
|
+
TAG: "MemberNamed",
|
|
178
|
+
memberId: "m-1",
|
|
179
|
+
name: {
|
|
180
|
+
TAG: "Value",
|
|
181
|
+
_0: "Ada"
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
globalThis.test("prepare asks for the keys a batch names, once each, and nothing for none", async () => {
|
|
186
|
+
await Pii$Reventless.prepareOrThrow([
|
|
187
|
+
envelope(),
|
|
188
|
+
envelope()
|
|
189
|
+
]);
|
|
190
|
+
await Pii$Reventless.prepareOrThrow(["nothing sealed"]);
|
|
191
|
+
globalThis.expect(asked.contents).toEqual([["m-1"]]);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
export {
|
|
196
|
+
Spec,
|
|
197
|
+
toBase64,
|
|
198
|
+
fromBase64,
|
|
199
|
+
fetched,
|
|
200
|
+
asked,
|
|
201
|
+
provider,
|
|
202
|
+
sealedData,
|
|
203
|
+
envelope,
|
|
204
|
+
threw,
|
|
205
|
+
}
|
|
206
|
+
/* eventSchema Not a pure module */
|