@reventlessdev/reventless-spec 3.0.0-alpha.97 → 3.0.0-alpha.98
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
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.98 (2026-08-03)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **aws:** let a deployment hand its plugins a geocoder ([143bf41](https://github.com/ReventlessDev/reventless-core/commit/143bf4137765362ce07dd42db0f4a57057da9f13))
|
|
11
|
+
* **outbound:** let an outbound slice read an aggregate, and geocode addresses with it ([867e63e](https://github.com/ReventlessDev/reventless-core/commit/867e63e774ebc8b78b2b19c78645c8a12a8d06f6))
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# 3.0.0-alpha.97 (2026-08-02)
|
|
7
15
|
|
|
8
16
|
### Features
|
package/package.json
CHANGED
|
@@ -76,6 +76,29 @@ module type Spec = {
|
|
|
76
76
|
/** Name of the aggregate or StateChangeSlice that receives the inbound command, or None for fire-and-forget. */
|
|
77
77
|
let targetName: option<string>
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
Event sources this slice subscribes to, by topic key.
|
|
81
|
+
|
|
82
|
+
`[]` — the default and the historical behaviour — means this plugin's own DCB
|
|
83
|
+
event log. Naming sources explicitly subscribes to them instead: an Aggregate's
|
|
84
|
+
`Spec.name`, or a DCB source name (conventionally `"<pluginName>DcbEventLog"`),
|
|
85
|
+
matching the keys `AutomationSlice` mappings already use.
|
|
86
|
+
|
|
87
|
+
This exists because an outbound slice is the framework's one component for
|
|
88
|
+
*calling an external service and feeding the answer back*, and that job is not
|
|
89
|
+
specific to DCB-modelled entities. An Aggregate whose events should trigger an
|
|
90
|
+
outbound call had no route to one while this list was hard-wired.
|
|
91
|
+
|
|
92
|
+
Unlike `AutomationSlice`, the sources are a flat list rather than per-source
|
|
93
|
+
`Mapping` modules. An automation needs a `resolve` per source (a different
|
|
94
|
+
event completes the item depending on where it came from); an outbound item is
|
|
95
|
+
resolved by its own `translate` succeeding, so the only thing that varies per
|
|
96
|
+
source is the decode — and the one `consumedEvent` union already covers that.
|
|
97
|
+
The cost of the flat form is that two sources sharing an event-type name are
|
|
98
|
+
indistinguishable; declare only the sources whose events you mean.
|
|
99
|
+
*/
|
|
100
|
+
let sourceNames: array<string>
|
|
101
|
+
|
|
79
102
|
/** Optional display name of the foreign system this anti-corruption slice publishes
|
|
80
103
|
to (e.g. `"EmailService"`). Drives the **external box** drawn outside the plugin
|
|
81
104
|
in the Event Graph / Context Map (see docs/plans/translation-external-boxes.md).
|
|
@@ -94,8 +117,15 @@ module type Translation = {
|
|
|
94
117
|
Collect: map an incoming event to zero or more new outbound items.
|
|
95
118
|
Each item has an `id` (deduplication key) and the `outboundItem` payload.
|
|
96
119
|
Returns empty array if this event is not relevant.
|
|
120
|
+
|
|
121
|
+
`~sourceId` is the id of the entity the event was published for — the envelope's
|
|
122
|
+
`id`, not part of the event payload. A DCB event usually names its own subject
|
|
123
|
+
in the payload (`OrderPlaced({orderId, …})`) and can ignore this; an Aggregate's
|
|
124
|
+
event generally does not, because the aggregate id is what addressed it in the
|
|
125
|
+
first place. Without this the outbound item for `Registered({email, address})`
|
|
126
|
+
would have no way to say *which customer* it is for.
|
|
97
127
|
*/
|
|
98
|
-
let collect: Spec.consumedEvent => array<(string, Spec.outboundItem)>
|
|
128
|
+
let collect: (Spec.consumedEvent, ~sourceId: string) => array<(string, Spec.outboundItem)>
|
|
99
129
|
|
|
100
130
|
/**
|
|
101
131
|
Translate: call the external service for a single outbound item.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Turning an address into a point, and deciding whether to believe the answer.
|
|
3
|
+
|
|
4
|
+
The *transport* is provider-specific — Amazon Location, a self-hosted Nominatim,
|
|
5
|
+
a vendor's HTTP API — and lives with its provider. What lives here is everything
|
|
6
|
+
that is the same regardless of who answers: the shape of an answer, the two ways
|
|
7
|
+
a lookup can fail, and the rule for when a ranked list is confident enough to
|
|
8
|
+
write a coordinate into an event log.
|
|
9
|
+
|
|
10
|
+
That split matters because the confidence rule is the part that is easy to get
|
|
11
|
+
wrong and expensive to get wrong twice. A caller that re-derives it — takes
|
|
12
|
+
`results[0]` because the list was ranked — produces a plausible marker in the
|
|
13
|
+
wrong region, drawn without an error anywhere. Deciding it once, here, is what
|
|
14
|
+
stops each transport inventing its own answer.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** One candidate a geocoder returned. */
|
|
18
|
+
type candidate = {
|
|
19
|
+
/** The provider's canonical rendering of the address it matched. */
|
|
20
|
+
label: string,
|
|
21
|
+
point: GeoPoint.t,
|
|
22
|
+
/**
|
|
23
|
+
How well this result matches the query, 0…1.
|
|
24
|
+
|
|
25
|
+
`None` when the provider does not score its results. That is not the same as a
|
|
26
|
+
low score and must not be read as a high one — `confidentMatch` declines it,
|
|
27
|
+
because an unscored list cannot support an unattended decision.
|
|
28
|
+
*/
|
|
29
|
+
relevance: option<float>,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
Why a lookup produced no usable point.
|
|
34
|
+
|
|
35
|
+
Two constructors rather than one message because the caller's retry decision
|
|
36
|
+
turns on exactly this distinction, and a `switch` is the only form of it that
|
|
37
|
+
cannot be got wrong. A translator that cannot tell "no such address" from "the
|
|
38
|
+
service is down" turns one outage into a permanent verdict on every address in
|
|
39
|
+
flight.
|
|
40
|
+
*/
|
|
41
|
+
type failure =
|
|
42
|
+
| /** The provider could not be reached, or refused the call. Retry. */
|
|
43
|
+
Unavailable(string)
|
|
44
|
+
| /** The provider answered, and had nothing for this text. Do not retry. */
|
|
45
|
+
NoMatch
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
The port a caller reaches a geocoder through.
|
|
49
|
+
|
|
50
|
+
Everything above says what an answer looks like; this says how one is asked for.
|
|
51
|
+
Written down as a type before anything is injected against it, so that swapping
|
|
52
|
+
the implementation underneath a caller is a change of *supplier* rather than a
|
|
53
|
+
change of call site: whatever eventually hands a translator its geocoder — an
|
|
54
|
+
HTTP client reading an endpoint out of its environment, a provider SDK called
|
|
55
|
+
directly — has to satisfy this, and the `await search(~text=…)` in the caller
|
|
56
|
+
does not move.
|
|
57
|
+
|
|
58
|
+
`~text` is the address as a human typed it, unnormalised. Normalising it is the
|
|
59
|
+
provider's job, and its canonical rendering comes back as `candidate.label`.
|
|
60
|
+
*/
|
|
61
|
+
type search = (~text: string) => promise<result<array<candidate>, failure>>
|
|
62
|
+
|
|
63
|
+
/** The default confidence floor. A starting point, not a finding — the first
|
|
64
|
+
real corpus of addresses is what should set it. */
|
|
65
|
+
let defaultMinRelevance = 0.8
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
The one candidate confident enough to store, or `None`.
|
|
69
|
+
|
|
70
|
+
Two ways to be unsure, and both decline:
|
|
71
|
+
|
|
72
|
+
- the top candidate scores below `minRelevance` — the provider matched
|
|
73
|
+
something, loosely;
|
|
74
|
+
- the runner-up scores within `ambiguityMargin` of the top — the provider
|
|
75
|
+
matched several things about equally well, which is what a bare town name
|
|
76
|
+
does.
|
|
77
|
+
|
|
78
|
+
`None` means "ask a human", not "no result". The candidates are still there for
|
|
79
|
+
a caller that wants to show them.
|
|
80
|
+
*/
|
|
81
|
+
let confidentMatch = (
|
|
82
|
+
candidates: array<candidate>,
|
|
83
|
+
~minRelevance: float=defaultMinRelevance,
|
|
84
|
+
~ambiguityMargin: float=0.1,
|
|
85
|
+
): option<candidate> =>
|
|
86
|
+
switch candidates->Array.get(0) {
|
|
87
|
+
| None => None
|
|
88
|
+
| Some(top) =>
|
|
89
|
+
switch top.relevance {
|
|
90
|
+
| None => None
|
|
91
|
+
| Some(topScore) =>
|
|
92
|
+
if topScore < minRelevance {
|
|
93
|
+
None
|
|
94
|
+
} else {
|
|
95
|
+
switch candidates->Array.get(1)->Option.flatMap(c => c.relevance) {
|
|
96
|
+
| Some(runnerUp) if topScore -. runnerUp < ambiguityMargin => None
|
|
97
|
+
| _ => Some(top)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
|
+
|
|
5
|
+
function confidentMatch(candidates, minRelevanceOpt, ambiguityMarginOpt) {
|
|
6
|
+
let minRelevance = minRelevanceOpt !== undefined ? minRelevanceOpt : 0.8;
|
|
7
|
+
let ambiguityMargin = ambiguityMarginOpt !== undefined ? ambiguityMarginOpt : 0.1;
|
|
8
|
+
let top = candidates[0];
|
|
9
|
+
if (top === undefined) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
let topScore = top.relevance;
|
|
13
|
+
if (topScore === undefined) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (topScore < minRelevance) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let runnerUp = Stdlib_Option.flatMap(candidates[1], c => c.relevance);
|
|
20
|
+
if (runnerUp !== undefined && topScore - runnerUp < ambiguityMargin) {
|
|
21
|
+
return;
|
|
22
|
+
} else {
|
|
23
|
+
return top;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let defaultMinRelevance = 0.8;
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
defaultMinRelevance,
|
|
31
|
+
confidentMatch,
|
|
32
|
+
}
|
|
33
|
+
/* No side effect */
|