@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
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,50 @@
|
|
|
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.312 (2026-10-29)
|
|
7
|
+
|
|
8
|
+
* feat(registration)!: the ledger tags an address by its keyed fingerprint ([ccafddf](https://github.com/ReventlessDev/reventless-core/commit/ccafddfc7eb8039687afc62a483ce34b8e7081dd))
|
|
9
|
+
* feat(core)!: the caller's IP address leaves the messages a request causes ([aa9e8c7](https://github.com/ReventlessDev/reventless-core/commit/aa9e8c79c0360528a5cfeda2bb88d1da52f28674))
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **spec:** personal data has a type, three stored forms and a provider seam ([134c0d1](https://github.com/ReventlessDev/reventless-core/commit/134c0d1e0a3c97304a5cd418db76c7d6b3447dcb))
|
|
13
|
+
|
|
14
|
+
### BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* `Secrets.t` has a third field, `fingerprint`; a hand-built provider
|
|
17
|
+
adds it. `Register` and `Invite` take `address`, and their `email` is the
|
|
18
|
+
fingerprint from `ContactAddressId.fingerprint`, not `makeFromString(address)`.
|
|
19
|
+
|
|
20
|
+
Step PD5 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
|
+
* `Message.generateMeta` no longer takes `~ip`. Drop the argument; a
|
|
23
|
+
message that must carry the address declares it as a field of its own payload.
|
|
24
|
+
|
|
25
|
+
Step PD3 of docs/plans/a-personal-field-is-marked-redacted-and-encrypted-at-the-seam.md.
|
|
26
|
+
Claude-Session: https://claude.ai/code/session_01HiQfdxVEsHwLHRoHSUcus1
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# 3.0.0-alpha.311 (2026-10-29)
|
|
31
|
+
|
|
32
|
+
* refactor!: drop `dcbSources`, the cross-plugin DCB subscription nobody declared ([cf3b66d](https://github.com/ReventlessDev/reventless-core/commit/cf3b66d8c1b5d87673197b64eaee174598bb8253))
|
|
33
|
+
* refactor!: a read model hears another plugin only through an Extension and a slice ([15c7cae](https://github.com/ReventlessDev/reventless-core/commit/15c7cae214d5aa04404779fcd87a8429aad1965c))
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
* **core:** a handler drops a command it has already handled ([605862b](https://github.com/ReventlessDev/reventless-core/commit/605862bba765b1501eb19d08f3924bf619159e21))
|
|
37
|
+
* **infra:** a message a mapping derives gets a stable id and names its parent ([a72a08f](https://github.com/ReventlessDev/reventless-core/commit/a72a08f9af4440eff5fa36e9a364a426bc70918c))
|
|
38
|
+
|
|
39
|
+
### BREAKING CHANGES
|
|
40
|
+
|
|
41
|
+
* `Reventless.Plugin.extensionDefinition` has no `dcbSources`
|
|
42
|
+
field, and `Platform_PluginExtensions.dcbSources` is gone from the GraphQL
|
|
43
|
+
schema. A query that selects it fails as a whole; drop the selection.
|
|
44
|
+
* `ReventlessInfra.Extension.T.make` and the core
|
|
45
|
+
`Extension_Builder.make` no longer take `~readModelNamesForSourceName` and
|
|
46
|
+
`~publishToReadModels`. Both arguments did nothing; drop them at the call site.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
6
50
|
# 3.0.0-alpha.310 (2026-10-25)
|
|
7
51
|
|
|
8
52
|
**Note:** Version bump only for package @reventlessdev/reventless-core
|
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.312",
|
|
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-fast-csv": "2.0.0-alpha.23",
|
|
32
|
-
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
|
|
33
|
-
"@reventlessdev/rescript-jest": "1.0.0-alpha.13",
|
|
34
32
|
"@reventlessdev/rescript-effect": "1.0.0-alpha.1",
|
|
33
|
+
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
|
|
35
34
|
"@reventlessdev/rescript-node": "2.0.0-alpha.23",
|
|
36
|
-
"@reventlessdev/rescript-
|
|
35
|
+
"@reventlessdev/rescript-jest": "1.0.0-alpha.13",
|
|
37
36
|
"@reventlessdev/rescript-ssh2": "2.0.0-alpha.24",
|
|
37
|
+
"@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
|
|
38
38
|
"@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
|
|
39
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.209",
|
|
39
40
|
"@reventlessdev/reventless-interop": "3.0.0-alpha.42",
|
|
40
|
-
"@reventlessdev/reventless-
|
|
41
|
-
"@reventlessdev/reventless-spec": "3.0.0-alpha.178"
|
|
41
|
+
"@reventlessdev/reventless-spec": "3.0.0-alpha.180"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"rescript": "12.3.1",
|
package/src/Message.res
CHANGED
|
@@ -211,7 +211,6 @@ let hrtimeToString: (~hrtime: hrtime, ~now: float) => string = (~hrtime, ~now) =
|
|
|
211
211
|
|
|
212
212
|
let generateMeta = (
|
|
213
213
|
~service,
|
|
214
|
-
~ip=?,
|
|
215
214
|
~user=?,
|
|
216
215
|
~causationId=?,
|
|
217
216
|
~traceparent=?,
|
|
@@ -225,7 +224,6 @@ let generateMeta = (
|
|
|
225
224
|
time: nowAsISOString(),
|
|
226
225
|
msgId,
|
|
227
226
|
correlationId: correlationId->Option.getOr(msgId),
|
|
228
|
-
?ip,
|
|
229
227
|
?user,
|
|
230
228
|
?causationId,
|
|
231
229
|
?traceparent,
|
|
@@ -238,7 +236,10 @@ let generateMeta = (
|
|
|
238
236
|
// - fresh `msgId` and `time`
|
|
239
237
|
// - `correlationId` inherited (so the chain root id stays stable)
|
|
240
238
|
// - `causationId` = parent.msgId (the *direct* parent)
|
|
241
|
-
// - `
|
|
239
|
+
// - `user`, `traceparent`, `schemaVersion`, `headers` inherited as-is,
|
|
240
|
+
// never `ip`: the caller's address is personal data and stays out of every
|
|
241
|
+
// message a request causes
|
|
242
|
+
// except the stable-id mark: this id is fresh, so the child must not carry it
|
|
242
243
|
// - `service` overridable; defaults to parent's service
|
|
243
244
|
let deriveMeta = (~parent: meta, ~service=?) => {
|
|
244
245
|
service: service->Option.getOr(parent.service),
|
|
@@ -246,13 +247,18 @@ let deriveMeta = (~parent: meta, ~service=?) => {
|
|
|
246
247
|
msgId: uuid(),
|
|
247
248
|
correlationId: parent.correlationId,
|
|
248
249
|
causationId: parent.msgId,
|
|
249
|
-
ip: ?parent.ip,
|
|
250
250
|
user: ?parent.user,
|
|
251
251
|
traceparent: ?parent.traceparent,
|
|
252
252
|
schemaVersion: ?parent.schemaVersion,
|
|
253
|
-
headers: ?parent.headers,
|
|
253
|
+
headers: ?ReventlessInfra.Message.withoutStableIdHeader(parent.headers),
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
// The same envelope with a `msgId` that is a function of its input, for a message
|
|
257
|
+
// a mapping derives from another; defined beside the mappings in infra. A handler
|
|
258
|
+
// asks `hasStableMsgId` whether a repeat of the command can be recognized.
|
|
259
|
+
let deriveStableMeta = ReventlessInfra.Message.deriveStableMeta
|
|
260
|
+
let hasStableMsgId = ReventlessInfra.Message.hasStableMsgId
|
|
261
|
+
|
|
256
262
|
let decomposeMeta = meta =>
|
|
257
263
|
meta
|
|
258
264
|
->Reventless.Util_Sury.toJson(metaSchema)
|
|
@@ -280,7 +286,16 @@ let composeMeta = (dict: dict<JSON.t>) => {
|
|
|
280
286
|
("msgId", dict->Dict.get("msgId")->Option.getOrThrow),
|
|
281
287
|
("correlationId", dict->Dict.get("correlationId")->Option.getOrThrow),
|
|
282
288
|
]
|
|
283
|
-
let optionalKeys = [
|
|
289
|
+
let optionalKeys = [
|
|
290
|
+
"ip",
|
|
291
|
+
"user",
|
|
292
|
+
"causationId",
|
|
293
|
+
"traceparent",
|
|
294
|
+
"schemaVersion",
|
|
295
|
+
"headers",
|
|
296
|
+
"dataClass",
|
|
297
|
+
"keyRef",
|
|
298
|
+
]
|
|
284
299
|
let optional =
|
|
285
300
|
optionalKeys
|
|
286
301
|
->Array.map(k => dict->Dict.get(k)->Option.map(v => (k, v)))
|
|
@@ -301,6 +316,8 @@ let metaKeys = [
|
|
|
301
316
|
"traceparent",
|
|
302
317
|
"schemaVersion",
|
|
303
318
|
"headers",
|
|
319
|
+
"dataClass",
|
|
320
|
+
"keyRef",
|
|
304
321
|
]
|
|
305
322
|
|
|
306
323
|
/*
|
package/src/Message.res.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import * as Message$Reventless from "@reventlessdev/reventless-spec/src/types/Me
|
|
|
10
10
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
11
11
|
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
12
12
|
import * as Logger$ReventlessCore from "./util/Logger.res.mjs";
|
|
13
|
+
import * as Message$ReventlessInfra from "@reventlessdev/reventless-infra/src/types/Message.res.mjs";
|
|
13
14
|
|
|
14
15
|
let logger = Logger$ReventlessCore.fromEnv();
|
|
15
16
|
|
|
@@ -169,12 +170,11 @@ function hrtimeToString(hrtime, now) {
|
|
|
169
170
|
return now.toString() + ("-" + ("0".repeat(9 - milLength | 0) + milString));
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
function generateMeta(service,
|
|
173
|
+
function generateMeta(service, user, causationId, traceparent, correlationId, schemaVersion, headers) {
|
|
173
174
|
let msgId = Uuid.v4();
|
|
174
175
|
return {
|
|
175
176
|
service: service,
|
|
176
177
|
time: new Date().toISOString(),
|
|
177
|
-
ip: ip,
|
|
178
178
|
user: user,
|
|
179
179
|
msgId: msgId,
|
|
180
180
|
correlationId: Stdlib_Option.getOr(correlationId, msgId),
|
|
@@ -189,14 +189,13 @@ function deriveMeta(parent, service) {
|
|
|
189
189
|
return {
|
|
190
190
|
service: Stdlib_Option.getOr(service, parent.service),
|
|
191
191
|
time: new Date().toISOString(),
|
|
192
|
-
ip: parent.ip,
|
|
193
192
|
user: parent.user,
|
|
194
193
|
msgId: Uuid.v4(),
|
|
195
194
|
correlationId: parent.correlationId,
|
|
196
195
|
causationId: parent.msgId,
|
|
197
196
|
traceparent: parent.traceparent,
|
|
198
197
|
schemaVersion: parent.schemaVersion,
|
|
199
|
-
headers: parent.headers
|
|
198
|
+
headers: Message$ReventlessInfra.withoutStableIdHeader(parent.headers)
|
|
200
199
|
};
|
|
201
200
|
}
|
|
202
201
|
|
|
@@ -250,7 +249,9 @@ function composeMeta(dict) {
|
|
|
250
249
|
"causationId",
|
|
251
250
|
"traceparent",
|
|
252
251
|
"schemaVersion",
|
|
253
|
-
"headers"
|
|
252
|
+
"headers",
|
|
253
|
+
"dataClass",
|
|
254
|
+
"keyRef"
|
|
254
255
|
];
|
|
255
256
|
let optional = Stdlib_Array.filterMap(optionalKeys.map(k => Stdlib_Option.map(dict[k], v => [
|
|
256
257
|
k,
|
|
@@ -269,7 +270,9 @@ let metaKeys = [
|
|
|
269
270
|
"causationId",
|
|
270
271
|
"traceparent",
|
|
271
272
|
"schemaVersion",
|
|
272
|
-
"headers"
|
|
273
|
+
"headers",
|
|
274
|
+
"dataClass",
|
|
275
|
+
"keyRef"
|
|
273
276
|
];
|
|
274
277
|
|
|
275
278
|
function storedEventToFlatJson(stored, idSchema) {
|
|
@@ -401,6 +404,10 @@ let encode = Message$Reventless.encode;
|
|
|
401
404
|
|
|
402
405
|
let InvalidEvent = Message$Reventless.InvalidEvent;
|
|
403
406
|
|
|
407
|
+
let deriveStableMeta = Message$ReventlessInfra.deriveStableMeta;
|
|
408
|
+
|
|
409
|
+
let hasStableMsgId = Message$ReventlessInfra.hasStableMsgId;
|
|
410
|
+
|
|
404
411
|
export {
|
|
405
412
|
logger,
|
|
406
413
|
serviceSchema,
|
|
@@ -436,6 +443,8 @@ export {
|
|
|
436
443
|
hrtimeToString,
|
|
437
444
|
generateMeta,
|
|
438
445
|
deriveMeta,
|
|
446
|
+
deriveStableMeta,
|
|
447
|
+
hasStableMsgId,
|
|
439
448
|
decomposeMeta,
|
|
440
449
|
composeEventJson$p,
|
|
441
450
|
composeMeta,
|
|
@@ -44,17 +44,56 @@ let _draw = (~length: int, ~from: string): string => {
|
|
|
44
44
|
out->Array.join("")
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/** The environment variable a deployment states its fingerprint key in. */
|
|
48
|
+
let fingerprintKeyVariable = "REVENTLESS_FINGERPRINT_KEY"
|
|
49
|
+
|
|
50
|
+
/** The shortest fingerprint key accepted: 16 bytes as hex. A shorter one is
|
|
51
|
+
refused rather than used, since a guessable key makes every fingerprint an
|
|
52
|
+
address again. */
|
|
53
|
+
let minimumFingerprintKeyLength = 32
|
|
54
|
+
|
|
55
|
+
/** HMAC-SHA256 of `purpose`, a NUL and `input`, as hex. The NUL keeps a purpose
|
|
56
|
+
that is a prefix of another from colliding with it. */
|
|
57
|
+
let fingerprintWith = (~key: string, ~purpose: string, input: string): string =>
|
|
58
|
+
NodeCrypto.createHmac("sha256", key)
|
|
59
|
+
->NodeCrypto.hmacUpdate(`${purpose}\u0000${input}`)
|
|
60
|
+
->NodeCrypto.hmacDigest("hex")
|
|
61
|
+
|
|
47
62
|
/**
|
|
48
|
-
|
|
63
|
+
A source whose fingerprints are keyed by what `fingerprintKey` answers, asked on
|
|
64
|
+
every call so a key installed after start is used.
|
|
49
65
|
|
|
50
66
|
`length` is refused rather than clamped when it is not positive: a caller asking
|
|
51
67
|
for a zero-length token has a bug, and answering `""` would hand back something
|
|
52
68
|
that compares equal to nothing and settles every challenge.
|
|
53
69
|
*/
|
|
54
|
-
let
|
|
70
|
+
let make = (~fingerprintKey: unit => option<string>): Reventless.Secrets.t => {
|
|
55
71
|
randomToken: (~length, ~alphabet) =>
|
|
56
72
|
length <= 0
|
|
57
73
|
? Error(Unavailable(`a token needs a positive length, not ${length->Int.toString}`))
|
|
58
74
|
: Ok(_draw(~length, ~from=Reventless.Secrets.characters(alphabet))),
|
|
59
75
|
hash: input => Ok(NodeCrypto.sha256Hex(input)),
|
|
76
|
+
fingerprint: (~purpose, input) =>
|
|
77
|
+
switch fingerprintKey() {
|
|
78
|
+
| Some(key) if key->String.length >= minimumFingerprintKeyLength =>
|
|
79
|
+
Ok(fingerprintWith(~key, ~purpose, input))
|
|
80
|
+
| Some(_) =>
|
|
81
|
+
Error(
|
|
82
|
+
Unavailable(
|
|
83
|
+
`the fingerprint key is shorter than ${minimumFingerprintKeyLength->Int.toString} characters`,
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
| None => Error(Unavailable(`no fingerprint key: set ${fingerprintKeyVariable}`))
|
|
87
|
+
},
|
|
60
88
|
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
The provider a deployed runtime passes: its fingerprint key is the deployment's,
|
|
92
|
+
from `REVENTLESS_FINGERPRINT_KEY`, and fingerprints are refused while none is set.
|
|
93
|
+
*/
|
|
94
|
+
let provider: Reventless.Secrets.t = make(~fingerprintKey=() =>
|
|
95
|
+
switch NodeProcess.env->Dict.get(fingerprintKeyVariable) {
|
|
96
|
+
| Some("") | None => None
|
|
97
|
+
| Some(key) => Some(key)
|
|
98
|
+
}
|
|
99
|
+
)
|
|
@@ -31,39 +31,81 @@ function _draw(length, from) {
|
|
|
31
31
|
return out.join("");
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
_0: {
|
|
39
|
-
TAG: "Unavailable",
|
|
40
|
-
_0: `a token needs a positive length, not ` + length.toString()
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
} else {
|
|
44
|
-
return {
|
|
45
|
-
TAG: "Ok",
|
|
46
|
-
_0: _draw(length, Secrets$Reventless.characters(alphabet))
|
|
47
|
-
};
|
|
48
|
-
}
|
|
34
|
+
let fingerprintKeyVariable = "REVENTLESS_FINGERPRINT_KEY";
|
|
35
|
+
|
|
36
|
+
function fingerprintWith(key, purpose, input) {
|
|
37
|
+
return Nodecrypto.createHmac("sha256", key).update(purpose + `\u0000` + input).digest("hex");
|
|
49
38
|
}
|
|
50
39
|
|
|
51
|
-
function
|
|
40
|
+
function make(fingerprintKey) {
|
|
52
41
|
return {
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
randomToken: (length, alphabet) => {
|
|
43
|
+
if (length <= 0) {
|
|
44
|
+
return {
|
|
45
|
+
TAG: "Error",
|
|
46
|
+
_0: {
|
|
47
|
+
TAG: "Unavailable",
|
|
48
|
+
_0: `a token needs a positive length, not ` + length.toString()
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
} else {
|
|
52
|
+
return {
|
|
53
|
+
TAG: "Ok",
|
|
54
|
+
_0: _draw(length, Secrets$Reventless.characters(alphabet))
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
hash: input => ({
|
|
59
|
+
TAG: "Ok",
|
|
60
|
+
_0: NodeCrypto.sha256Hex(input)
|
|
61
|
+
}),
|
|
62
|
+
fingerprint: (purpose, input) => {
|
|
63
|
+
let key = fingerprintKey();
|
|
64
|
+
if (key !== undefined) {
|
|
65
|
+
if (key.length >= 32) {
|
|
66
|
+
return {
|
|
67
|
+
TAG: "Ok",
|
|
68
|
+
_0: fingerprintWith(key, purpose, input)
|
|
69
|
+
};
|
|
70
|
+
} else {
|
|
71
|
+
return {
|
|
72
|
+
TAG: "Error",
|
|
73
|
+
_0: {
|
|
74
|
+
TAG: "Unavailable",
|
|
75
|
+
_0: `the fingerprint key is shorter than ` + (32).toString() + ` characters`
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
return {
|
|
81
|
+
TAG: "Error",
|
|
82
|
+
_0: {
|
|
83
|
+
TAG: "Unavailable",
|
|
84
|
+
_0: `no fingerprint key: set ` + fingerprintKeyVariable
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
55
89
|
};
|
|
56
90
|
}
|
|
57
91
|
|
|
58
|
-
let provider = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
92
|
+
let provider = make(() => {
|
|
93
|
+
let key = process.env[fingerprintKeyVariable];
|
|
94
|
+
if (key !== undefined && key !== "") {
|
|
95
|
+
return key;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
let minimumFingerprintKeyLength = 32;
|
|
62
100
|
|
|
63
101
|
export {
|
|
64
102
|
_bytes,
|
|
65
103
|
accepts,
|
|
66
104
|
_draw,
|
|
105
|
+
fingerprintKeyVariable,
|
|
106
|
+
minimumFingerprintKeyLength,
|
|
107
|
+
fingerprintWith,
|
|
108
|
+
make,
|
|
67
109
|
provider,
|
|
68
110
|
}
|
|
69
|
-
/*
|
|
111
|
+
/* provider Not a pure module */
|
|
@@ -228,8 +228,6 @@ function Make(RuntimeEnvironment) {
|
|
|
228
228
|
taskSideEffectFinishFns: Builder_Helpers$ReventlessCore.taskSideEffectFinishFns,
|
|
229
229
|
registerTaskSideEffectHandler: Builder_Helpers$ReventlessCore.registerTaskSideEffectHandler,
|
|
230
230
|
finishTasks: Builder_Helpers$ReventlessCore.finishTasks,
|
|
231
|
-
readModelNamesForSourceName: Builder_Helpers$ReventlessCore.readModelNamesForSourceName,
|
|
232
|
-
publishToReadModels: Builder_Helpers$ReventlessCore.publishToReadModels,
|
|
233
231
|
finishReadModels: Builder_Helpers$ReventlessCore.finishReadModels,
|
|
234
232
|
extractReadModelsOutputs: Builder_Helpers$ReventlessCore.extractReadModelsOutputs,
|
|
235
233
|
createReadModels: Builder_Helpers$ReventlessCore.createReadModels,
|
|
@@ -80,26 +80,31 @@ module Make = (
|
|
|
80
80
|
| CmdOk(array<Spec.event>)
|
|
81
81
|
| CmdRejected({errorCode: string, errorDetail: string})
|
|
82
82
|
| CmdRefused(CommandTopic_Helpers.ownershipRefusal)
|
|
83
|
+
// A command the stream already holds events for: delivered again, accepted
|
|
84
|
+
// again, nothing new.
|
|
85
|
+
| CmdRepeated
|
|
86
|
+
|
|
87
|
+
// What the fold carries from command to command: the state decided on, the
|
|
88
|
+
// distinct owners the stream records, and the `msgId`s of the commands that
|
|
89
|
+
// caused its events — the second only for a batch that can be asked about a
|
|
90
|
+
// repeat, the third only when a batch holds a command with a stable id.
|
|
91
|
+
type fold = {
|
|
92
|
+
state: Decision.state,
|
|
93
|
+
owners: array<string>,
|
|
94
|
+
causes: array<string>,
|
|
95
|
+
outcomes: array<(string, cmdOutcome, Message.meta)>,
|
|
96
|
+
}
|
|
83
97
|
|
|
84
|
-
// Folds a single command into the running accumulator
|
|
85
|
-
//
|
|
86
|
-
//
|
|
98
|
+
// Folds a single command into the running accumulator. A domain rejection from
|
|
99
|
+
// Decision.decide is recorded as `CmdRejected` (no state change, surviving
|
|
100
|
+
// commands in the batch continue); a successful decide records `CmdOk(events)`
|
|
87
101
|
// and advances state via `Decision.evolve`.
|
|
88
102
|
//
|
|
89
103
|
// `~seq` is the replayed sequence number the batch decides from, carried in so
|
|
90
104
|
// the line below can name the state rather than serialise it.
|
|
91
|
-
//
|
|
92
|
-
// `owners` are the distinct owners the stream records so far, including any a
|
|
93
|
-
// command earlier in the same batch just recorded.
|
|
94
105
|
let processCommand = (~seq: int) =>
|
|
95
|
-
(
|
|
96
|
-
|
|
97
|
-
Decision.state,
|
|
98
|
-
array<string>,
|
|
99
|
-
array<(string, cmdOutcome, Message.meta)>,
|
|
100
|
-
),
|
|
101
|
-
topicItem: CommandTopic.topicItem<Message.command'<Spec.Id.t, Spec.command>>,
|
|
102
|
-
) => {
|
|
106
|
+
(acc: fold, topicItem: CommandTopic.topicItem<Message.command'<Spec.Id.t, Spec.command>>) => {
|
|
107
|
+
let {state, owners, causes, outcomes} = acc
|
|
103
108
|
let {reference, command: command'} = topicItem
|
|
104
109
|
let meta = command'->updateMeta
|
|
105
110
|
let id = command'.id->Spec.Id.toString
|
|
@@ -114,31 +119,46 @@ module Make = (
|
|
|
114
119
|
~comp,
|
|
115
120
|
`deciding: id=${id} seq=${seq->Int.toString} cmd=${cmdName}`,
|
|
116
121
|
)->Effect.runSync
|
|
117
|
-
// Before `decide
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
// Before `decide`, first: a command with a stable id that the stream already
|
|
123
|
+
// holds events for was delivered a second time. Accepted, nothing new — the
|
|
124
|
+
// decision has run once and must not count the fact twice.
|
|
125
|
+
let repeated =
|
|
126
|
+
Message.hasStableMsgId(command'.meta) && causes->Array.includes(command'.meta.msgId)
|
|
127
|
+
// Before `decide`, second: an owner-marked aggregate refuses a caller who
|
|
128
|
+
// does not own the stream.
|
|
129
|
+
let refusal =
|
|
130
|
+
repeated || !actsOnOwned
|
|
131
|
+
? None
|
|
132
|
+
: Reventless.OwnerScope.decideActing(
|
|
133
|
+
~claim=command'.meta.callerClaim,
|
|
134
|
+
~recordedOwners=Some(owners),
|
|
135
|
+
)->CommandTopic_Helpers.ownershipRefusal(~component=Spec.name, ~command=cmdVariant)
|
|
125
136
|
switch refusal {
|
|
137
|
+
| _ if repeated =>
|
|
138
|
+
EffectLogger.logInfo(
|
|
139
|
+
~comp,
|
|
140
|
+
`repeat dropped: ${cmdName}(${id}) msgId=${command'.meta.msgId} already caused events`,
|
|
141
|
+
)->Effect.runSync
|
|
142
|
+
{...acc, outcomes: Array.concat(outcomes, [(reference, CmdRepeated, meta)])}
|
|
126
143
|
| Some(refused) =>
|
|
127
144
|
let line = `refused: ${refused.rejected.errorDetail} id=${id}`
|
|
128
145
|
|
|
129
146
|
(
|
|
130
147
|
refused.isDefect ? EffectLogger.logError(~comp, line) : EffectLogger.logWarn(~comp, line)
|
|
131
148
|
)->Effect.runSync
|
|
132
|
-
|
|
149
|
+
{...acc, outcomes: Array.concat(outcomes, [(reference, CmdRefused(refused), meta)])}
|
|
133
150
|
| None =>
|
|
134
151
|
switch Decision.decide(state, command'.command) {
|
|
135
152
|
| Ok(generatedEvents) =>
|
|
136
153
|
let newState = generatedEvents->Array.reduce(state, Decision.evolve)
|
|
137
|
-
|
|
138
|
-
newState,
|
|
139
|
-
generatedEvents->Array.reduce(owners, recordEventOwners),
|
|
140
|
-
Array.
|
|
141
|
-
|
|
154
|
+
{
|
|
155
|
+
state: newState,
|
|
156
|
+
owners: generatedEvents->Array.reduce(owners, recordEventOwners),
|
|
157
|
+
causes: generatedEvents->Array.length == 0
|
|
158
|
+
? causes
|
|
159
|
+
: causes->Array.concat([command'.meta.msgId]),
|
|
160
|
+
outcomes: Array.concat(outcomes, [(reference, CmdOk(generatedEvents), meta)]),
|
|
161
|
+
}
|
|
142
162
|
| Error(error) =>
|
|
143
163
|
let errorJson = error->Message.encode(Spec.errorSchema)
|
|
144
164
|
let errorCode = errorJson->Message.variantNameOfJson
|
|
@@ -152,11 +172,13 @@ module Make = (
|
|
|
152
172
|
~comp,
|
|
153
173
|
`decide rejected: ${errorCode} ${errorDetail} id=${id}`,
|
|
154
174
|
)->Effect.runSync
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
175
|
+
{
|
|
176
|
+
...acc,
|
|
177
|
+
outcomes: Array.concat(
|
|
178
|
+
outcomes,
|
|
179
|
+
[(reference, CmdRejected({errorCode, errorDetail}), meta)],
|
|
180
|
+
),
|
|
181
|
+
}
|
|
160
182
|
}
|
|
161
183
|
}
|
|
162
184
|
}
|
|
@@ -297,6 +319,31 @@ module Make = (
|
|
|
297
319
|
)
|
|
298
320
|
}
|
|
299
321
|
|
|
322
|
+
// The read for a batch holding a command with a stable id: the whole stream, as
|
|
323
|
+
// envelopes, so the `causationId`s say which commands already produced events.
|
|
324
|
+
// Neither the in-process cache nor a snapshot carries those, so this read skips
|
|
325
|
+
// both — a command an Extension derived pays a full replay for the guarantee
|
|
326
|
+
// that a second delivery of it changes nothing.
|
|
327
|
+
let coldReadCauses = id => {
|
|
328
|
+
let idStr = id->Spec.Id.toString
|
|
329
|
+
Ops.eventLog.replayStream'(id, ~fromSeq=0)
|
|
330
|
+
->Stream.runFold((Decision.initialState, 0, [], []), ((st, n, owners, causes), ev') => (
|
|
331
|
+
Decision.evolve(st, ev'.event),
|
|
332
|
+
n + 1,
|
|
333
|
+
owners->recordEventOwners(ev'.event),
|
|
334
|
+
switch ev'.meta.causationId {
|
|
335
|
+
| Some(c) if !(causes->Array.includes(c)) => causes->Array.concat([c])
|
|
336
|
+
| _ => causes
|
|
337
|
+
},
|
|
338
|
+
))
|
|
339
|
+
->Effect.tap(((_, n, _, _)) =>
|
|
340
|
+
EffectLogger.logInfo(
|
|
341
|
+
~comp,
|
|
342
|
+
`replay (with causes, for a stable-id command): id=${idStr}, ${n->Int.toString} event(s)`,
|
|
343
|
+
)
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
|
|
300
347
|
// Fire-and-forget snapshot write — never awaited, never fails the command. A
|
|
301
348
|
// failed write just means the next cold replay reads a longer delta.
|
|
302
349
|
let fireSnapshotWrite = (id, idStr, snap: EventLog.snapshot) => {
|
|
@@ -386,6 +433,13 @@ module Make = (
|
|
|
386
433
|
{entityId, eventCount: appendedEventCount},
|
|
387
434
|
)
|
|
388
435
|
Ok(reference)
|
|
436
|
+
| CmdRepeated =>
|
|
437
|
+
CommandTopic_Helpers.reportAccepted(
|
|
438
|
+
~component=Spec.name,
|
|
439
|
+
reference,
|
|
440
|
+
{entityId, eventCount: 0},
|
|
441
|
+
)
|
|
442
|
+
Ok(reference)
|
|
389
443
|
| CmdOk(_) =>
|
|
390
444
|
// The decision succeeded and the append did not — infrastructure, not the model.
|
|
391
445
|
CommandTopic_Helpers.reportRejected(
|
|
@@ -408,23 +462,32 @@ module Make = (
|
|
|
408
462
|
) => {
|
|
409
463
|
let idStr = id->Spec.Id.toString
|
|
410
464
|
|
|
411
|
-
//
|
|
412
|
-
//
|
|
413
|
-
// path
|
|
414
|
-
//
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
465
|
+
// A batch with a command whose id is stable reads the stream with its causes
|
|
466
|
+
// (`coldReadCauses`): the cache and the snapshot cannot say what already
|
|
467
|
+
// happened for that command. Otherwise, warm path: seed from the in-process
|
|
468
|
+
// cache and skip both the snapshot read and the event-log replay; the OCC
|
|
469
|
+
// append below fences any staleness. Cold path (`coldReadState`): seed from
|
|
470
|
+
// the persisted snapshot when enabled, else full replay.
|
|
471
|
+
let asksForRepeats =
|
|
472
|
+
topicItemsForId->Array.some(item => Message.hasStableMsgId(item.command.meta))
|
|
473
|
+
let readState = if asksForRepeats {
|
|
474
|
+
coldReadCauses(id)
|
|
475
|
+
} else {
|
|
476
|
+
switch replayCache->Lru.get(idStr) {
|
|
477
|
+
| Some((state, seqNr, owners)) =>
|
|
478
|
+
EffectLogger.logInfo(
|
|
479
|
+
~comp,
|
|
480
|
+
`replay skipped (cached): id=${idStr}, seq=${seqNr->Int.toString}`,
|
|
481
|
+
)->Effect.map(_ => (state, seqNr, owners, []))
|
|
482
|
+
| None =>
|
|
483
|
+
coldReadState(id)->Effect.map(((state, seqNr, owners)) => (state, seqNr, owners, []))
|
|
484
|
+
}
|
|
422
485
|
}
|
|
423
486
|
|
|
424
|
-
readState->Effect.flatMap(((initialState, sequenceNr, initialOwners)) => {
|
|
425
|
-
let
|
|
487
|
+
readState->Effect.flatMap(((initialState, sequenceNr, initialOwners, causes)) => {
|
|
488
|
+
let {state: finalState, owners: finalOwners, outcomes} =
|
|
426
489
|
topicItemsForId->Array.reduce(
|
|
427
|
-
|
|
490
|
+
{state: initialState, owners: initialOwners, causes, outcomes: []},
|
|
428
491
|
processCommand(~seq=sequenceNr),
|
|
429
492
|
)
|
|
430
493
|
|
|
@@ -433,7 +496,7 @@ module Make = (
|
|
|
433
496
|
->Array.map(((_reference, outcome, meta)) =>
|
|
434
497
|
switch outcome {
|
|
435
498
|
| CmdOk(events) => events->Array.map(event => {Message.id, meta, event})
|
|
436
|
-
| CmdRejected(_) | CmdRefused(_) => []
|
|
499
|
+
| CmdRejected(_) | CmdRefused(_) | CmdRepeated => []
|
|
437
500
|
}
|
|
438
501
|
)
|
|
439
502
|
->Array.flat
|