@reventlessdev/trait-address-geocoding 1.0.0-alpha.1
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/LICENSE +202 -0
- package/README.md +92 -0
- package/package.json +42 -0
- package/rescript.json +29 -0
- package/src/AddressGeocoding.res +177 -0
- package/src/AddressGeocoding.res.mjs +77 -0
- package/src/AddressGeocoding_Conformance.res +185 -0
- package/src/AddressGeocoding_Conformance.res.mjs +156 -0
- package/src/AddressGeocoding_Guards.res +58 -0
- package/src/AddressGeocoding_Guards.res.mjs +43 -0
- package/src/AddressGeocoding_Scaffold.res +599 -0
- package/src/AddressGeocoding_Scaffold.res.mjs +452 -0
- package/src/AddressGeocoding_Translate.res +40 -0
- package/src/AddressGeocoding_Translate.res.mjs +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2019-2026 Martin Lorenz
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @reventlessdev/trait-address-geocoding
|
|
2
|
+
|
|
3
|
+
A **domain trait**: the reusable middle of turning an aggregate's address into a map
|
|
4
|
+
point without corrupting the aggregate's data. The rules are a module the host calls;
|
|
5
|
+
the types are the host's own. What it ships:
|
|
6
|
+
|
|
7
|
+
| Part | Where |
|
|
8
|
+
|---|---|
|
|
9
|
+
| The decision rules | `src/AddressGeocoding_Guards.res` (staleness, redelivery, the supplied pair) |
|
|
10
|
+
| The slice body | `src/AddressGeocoding_Translate.res` (`translate`, `exhaustedReason`) |
|
|
11
|
+
| The host contract, as a type | `src/AddressGeocoding.res` (`module type Binding`) |
|
|
12
|
+
| The conformance suite | `src/AddressGeocoding_Conformance.res` (`Make(Binding).register()`) |
|
|
13
|
+
| The emitter | `src/AddressGeocoding_Scaffold.res` (`emit(~config, ~into, ~tests)`) |
|
|
14
|
+
|
|
15
|
+
The rule modules are compiled code a host imports at runtime, so a change to them is a
|
|
16
|
+
behavior change for every host: version it `fix:`/`feat:` accordingly.
|
|
17
|
+
|
|
18
|
+
Most of this graft is not emitted at all. The four facts and the two `@noApi` report
|
|
19
|
+
commands are real constructors the host **splices** — `...AddressGeocoding.events` and
|
|
20
|
+
`...AddressGeocoding.reportCommands` — so the compiler carries them, annotations and
|
|
21
|
+
schema included. The emitter writes the outbound slice, which the host does not have
|
|
22
|
+
yet, and prints the arms that belong inside the aggregate, its behavior and the
|
|
23
|
+
projection: those interleave with the host's own state machine, and placing an arm in
|
|
24
|
+
an ordered `switch` is an AST operation a text splice gets silently wrong.
|
|
25
|
+
|
|
26
|
+
The confidence rule — what a geocoder's reply *means* — is core's
|
|
27
|
+
(`Reventless.Geocoding`, `Reventless.Geolocation`). This package owns how that reply is
|
|
28
|
+
grafted onto an aggregate:
|
|
29
|
+
|
|
30
|
+
- **`resolvedFrom` is a staleness token.** An answer for an address the entity has
|
|
31
|
+
since changed is dropped, not applied.
|
|
32
|
+
- **Redelivery is a no-op.** The slice re-publishes on every heartbeat sweep until its
|
|
33
|
+
TODO clears, so an unchanged answer must not append a duplicate event.
|
|
34
|
+
- **An outage is not a verdict.** `Unavailable` retries; `NoMatch` records a fact.
|
|
35
|
+
- **The stand-down.** A client that supplies address and point together is not raced
|
|
36
|
+
by the geocoder: the pair-supplying event is not in the slice's consumed set.
|
|
37
|
+
- **Two state fields** (`location` + `locationResolvedFrom`), because never-asked,
|
|
38
|
+
found, and tried-and-found-wanting do not fit in one `option`.
|
|
39
|
+
|
|
40
|
+
## Grafting a host
|
|
41
|
+
|
|
42
|
+
1. Run the emitter. Every `--key` is a field of its config, and it validates them, so
|
|
43
|
+
run it once to be told what it wants:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
pnpm exec graft-trait @reventlessdev/trait-address-geocoding \
|
|
47
|
+
--into src/Customer --tests tests/Customer \
|
|
48
|
+
--entity Customer --entityId customerId --created Registered \
|
|
49
|
+
--createdFields 'email: string' --createdValues 'email: "alice@x.y"' \
|
|
50
|
+
--externalSystem AwsLocation
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
It writes the slice, its translation body and the conformance binding — whole, so
|
|
54
|
+
the suite below needs no hand-written file — and prints three patches.
|
|
55
|
+
|
|
56
|
+
2. Paste the three patches. The aggregate's is two spread lines plus the arms for
|
|
57
|
+
`commandTransition`; the behavior's is the state fields and the `evolve` / `decide`
|
|
58
|
+
arms; the projection's is the view's `geolocation` field and its arms.
|
|
59
|
+
|
|
60
|
+
Policy is yours and is not config. Which states an address may change in goes in
|
|
61
|
+
the `commandTransition` switch, over a `type lifecycleState = <YourView>.<enum>`
|
|
62
|
+
you declare beside it — the compiler resolves the constructors, the switch is
|
|
63
|
+
exhaustive so it names any spliced command you have not answered for, and every
|
|
64
|
+
arm has to draw on that one lifecycle. Who may send the commands goes in
|
|
65
|
+
`commandAuthorization` the same way.
|
|
66
|
+
|
|
67
|
+
A host whose subject is not called `address`, or is not a `string`, gets the same
|
|
68
|
+
graft with the constructors spelled out instead of spliced — pass `--subject`, and
|
|
69
|
+
the printed patch says which of the two you got.
|
|
70
|
+
|
|
71
|
+
3. Run the emitted conformance binding — `tests/<…>/AddressGeocodingConformance_GWT.res`
|
|
72
|
+
registers the suite as it stands, and it goes green once the patches are in. 13
|
|
73
|
+
assertions, over your constructors, not the trait's.
|
|
74
|
+
|
|
75
|
+
4. Keep the capability declaration the emitter wrote onto the slice's spec, so the
|
|
76
|
+
deployment is checked rather than trusted:
|
|
77
|
+
|
|
78
|
+
```rescript
|
|
79
|
+
let capabilityNeeds = TraitAddressGeocoding.AddressGeocoding.capabilityNeeds
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The declaration reaches the plugin's `capabilities.json`, the platform's
|
|
83
|
+
generated capability list, and a deploy-time gate that refuses a plugin whose
|
|
84
|
+
platform provisions no place index. Skip it and the deploy succeeds, the slice
|
|
85
|
+
exhausts its retries, and every address is recorded as permanently
|
|
86
|
+
unresolvable — with no error anywhere.
|
|
87
|
+
|
|
88
|
+
The platform provisions the capability itself: `Capability_Geocoding_AwsLocation`
|
|
89
|
+
on AWS, passed as `~geocoderPlaceIndex`; `Capabilities.none` locally, which
|
|
90
|
+
answers `Unavailable` on purpose.
|
|
91
|
+
|
|
92
|
+
The specimen host is `examples/online-shop-hybrid/ordering` (`Customer`).
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reventlessdev/trait-address-geocoding",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"description": "Address-geocoding domain trait: rules, host contract, conformance suite and emitter for grafting geocoding onto an aggregate",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"files": [
|
|
7
|
+
"src/**/*.res",
|
|
8
|
+
"src/**/*.resi",
|
|
9
|
+
"src/**/*.res.mjs",
|
|
10
|
+
"rescript.json",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"sury": "11.0.0-rc.2",
|
|
15
|
+
"sury-ppx": "11.0.0-rc.2",
|
|
16
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.153",
|
|
17
|
+
"@reventlessdev/reventless-gwt": "1.0.0-alpha.199",
|
|
18
|
+
"@reventlessdev/reventless-ppx": "1.0.0-alpha.75",
|
|
19
|
+
"@reventlessdev/reventless-spec": "3.0.0-alpha.125"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"rescript": "12.3.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"rescript": "12.3.0"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"registry": "https://registry.npmjs.org"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/ReventlessDev/reventless-core.git",
|
|
33
|
+
"directory": "traits/address-geocoding"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "rescript build",
|
|
37
|
+
"start": "rescript watch",
|
|
38
|
+
"clean": "rescript clean",
|
|
39
|
+
"rebuild": "pnpm run clean && pnpm run build",
|
|
40
|
+
"test": "echo \"The conformance suite runs in its hosts; see README.md.\""
|
|
41
|
+
}
|
|
42
|
+
}
|
package/rescript.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reventlessdev/trait-address-geocoding",
|
|
3
|
+
"package-specs": {
|
|
4
|
+
"module": "esmodule",
|
|
5
|
+
"in-source": true
|
|
6
|
+
},
|
|
7
|
+
"namespace": "TraitAddressGeocoding",
|
|
8
|
+
"ppx-flags": [
|
|
9
|
+
"@reventlessdev/reventless-ppx/bin",
|
|
10
|
+
"sury-ppx/bin"
|
|
11
|
+
],
|
|
12
|
+
"warnings": {
|
|
13
|
+
"error": "-44+101"
|
|
14
|
+
},
|
|
15
|
+
"sources": [
|
|
16
|
+
{
|
|
17
|
+
"dir": "src",
|
|
18
|
+
"subdirs": true
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"dependencies": [
|
|
22
|
+
"sury",
|
|
23
|
+
"@reventlessdev/reventless-spec",
|
|
24
|
+
"@reventlessdev/reventless-infra",
|
|
25
|
+
"@reventlessdev/reventless-gwt"
|
|
26
|
+
],
|
|
27
|
+
"compiler-flags": [],
|
|
28
|
+
"suffix": ".res.mjs"
|
|
29
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
The host contract of the address-geocoding trait: what an aggregate and its
|
|
3
|
+
outbound slice expose so the graft rules can be checked against them. The rules —
|
|
4
|
+
staleness, redelivery, an outage is not a verdict, the stand-down — live in
|
|
5
|
+
`AddressGeocoding_Guards` and `AddressGeocoding_Translate` and are asserted through a
|
|
6
|
+
host by `AddressGeocoding_Conformance`; the confidence rule stays core's
|
|
7
|
+
(`Reventless.Geocoding`). The spec surface is written by `AddressGeocoding_Scaffold`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Whether the graft reports back into its host. This trait does — the two `@noApi`
|
|
11
|
+
commands — and the runner accepts nothing else yet; the flag is here so a
|
|
12
|
+
competency that only observes is not mis-modelled as one that writes. */
|
|
13
|
+
type posture = WritesBack | Observes
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
This trait's own account of itself, for a host to name in its `traits` and for the
|
|
17
|
+
plugin structure to record.
|
|
18
|
+
|
|
19
|
+
The version is read from this package rather than written here, so it cannot drift
|
|
20
|
+
from what was actually installed. A host names this value, so a renamed or removed
|
|
21
|
+
trait is a build error rather than a row that outlives its dependency.
|
|
22
|
+
*/
|
|
23
|
+
let declaration: Reventless.Trait.t = {
|
|
24
|
+
trait: "@reventlessdev/trait-address-geocoding",
|
|
25
|
+
version: Reventless.PackageVersion.fromModuleUrl(%raw(`import.meta.url`)),
|
|
26
|
+
posture: WritesBack,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
The platform capabilities a host of this trait needs, for its outbound slice's
|
|
31
|
+
`capabilityNeeds` to name.
|
|
32
|
+
|
|
33
|
+
Exported as a value rather than stated in the README because forgetting it is
|
|
34
|
+
silent and terminal: an unprovisioned geocoder answers `Unavailable`, the slice
|
|
35
|
+
retries its budget, `onExhausted` fires, and every address the host ever sees is
|
|
36
|
+
recorded as permanently unresolvable — correct data, a permanent wrong verdict,
|
|
37
|
+
no error. A host that spells this reaches a deploy-time refusal instead.
|
|
38
|
+
*/
|
|
39
|
+
let capabilityNeeds: array<Reventless.CapabilityNeed.t> = [Geocoding]
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
The four facts the graft appends, as real constructors a host splices into its own
|
|
43
|
+
event type:
|
|
44
|
+
|
|
45
|
+
```rescript
|
|
46
|
+
type event =
|
|
47
|
+
| Registered({email: string, address: string})
|
|
48
|
+
| ...TraitAddressGeocoding.AddressGeocoding.events
|
|
49
|
+
| Deactivated
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The host's `evolve` then matches `LocationSet`, `AddressUpdated` and the rest
|
|
53
|
+
unqualified, and sury splices the schema flat — the wire format and the generated
|
|
54
|
+
GraphQL are identical to hand-written arms, not nested. This is what a spread
|
|
55
|
+
replaces: four declarations that every host copied and could mistype.
|
|
56
|
+
|
|
57
|
+
**Concrete, where `Binding` is abstract.** `Binding.subject` is abstract so the
|
|
58
|
+
trait's *rules* hold for any address-shaped thing; these constructors fix
|
|
59
|
+
`address: string` and fix the word "Address", because a spread cannot rename what
|
|
60
|
+
it splices. A host whose subject is not a string, or that calls it something else,
|
|
61
|
+
does not spread — it declares its own arms, which the scaffold's patch prints for
|
|
62
|
+
it. The rules, the contract and the conformance suite are the same either way.
|
|
63
|
+
|
|
64
|
+
Aggregate state is deliberately not here: it is snapshotted, so a trait-owned
|
|
65
|
+
record inside it would turn every reshaping release into a migration.
|
|
66
|
+
*/
|
|
67
|
+
@schema
|
|
68
|
+
type events =
|
|
69
|
+
/** A new address invalidates what was resolved, which is what puts the row back
|
|
70
|
+
in front of the slice. */
|
|
71
|
+
| AddressUpdated({address: string})
|
|
72
|
+
/** `resolvedFrom` is provenance, not the address of record; it is what makes "is
|
|
73
|
+
the pin still current?" decidable rather than assumed. */
|
|
74
|
+
| LocationSet({location: Reventless.GeoPoint.t, resolvedFrom: string})
|
|
75
|
+
/** Both halves from a client. Deliberately not `AddressUpdated` + `LocationSet`:
|
|
76
|
+
the slice collects the former, so emitting it here would spend a request
|
|
77
|
+
re-geocoding an address a human just pinned, then race the machine's answer
|
|
78
|
+
against theirs. This event is not in the slice's consumed set — the stand-down. */
|
|
79
|
+
| AddressLocated({address: string, location: Reventless.GeoPoint.t})
|
|
80
|
+
/** A fact, not an absence: `location: None` already means "not looked up yet",
|
|
81
|
+
and one state meaning two things is one nobody can act on. */
|
|
82
|
+
| AddressUnresolvable({address: string, reason: string})
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
The two commands the outbound slice reports its answer through, as constructors a
|
|
86
|
+
host splices into its own command type.
|
|
87
|
+
|
|
88
|
+
Both are `@noApi`: they are the slice's shape, not a caller's. `SetLocation`
|
|
89
|
+
carries a `resolvedFrom` staleness token that only the slice can supply, and a
|
|
90
|
+
client correcting a row does it through the host's own public command instead.
|
|
91
|
+
|
|
92
|
+
The exclusion travels with the spread — it is recorded on each member, not only
|
|
93
|
+
on this union — so a host that splices these does not publish them.
|
|
94
|
+
*/
|
|
95
|
+
@schema
|
|
96
|
+
type reportCommands =
|
|
97
|
+
| @noApi SetLocation({location: Reventless.GeoPoint.t, resolvedFrom: string})
|
|
98
|
+
| @noApi MarkAddressUnresolvable({address: string, reason: string})
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
The two commands a caller changes the address through, as constructors a host
|
|
102
|
+
splices into its own command type.
|
|
103
|
+
|
|
104
|
+
These are public, and that is what kept them out of the trait until now. Both
|
|
105
|
+
are legal only while the entity is in some state the HOST names, and a
|
|
106
|
+
`@transition` cannot be attached to a constructor a host did not declare — it
|
|
107
|
+
lowers to a dict on the parent union, and a spread splices members. So the pair
|
|
108
|
+
stayed hand-written in every host, which is the whole of what a spreading host
|
|
109
|
+
still had to transcribe.
|
|
110
|
+
|
|
111
|
+
`commandTransition` is what freed them: the host answers for them in an
|
|
112
|
+
exhaustive switch, in its own lifecycle vocabulary, and the compiler will not let
|
|
113
|
+
it forget. The trait owns the shape; the host owns the policy; nothing crosses as
|
|
114
|
+
a string.
|
|
115
|
+
|
|
116
|
+
The rule that shapes the pair: **whoever supplies a point supplies the address it
|
|
117
|
+
belongs to.** A caller never sends a bare coordinate — that is `SetLocation`
|
|
118
|
+
above, the slice's shape and internal. `SetAddressLocation` covers the pin-only
|
|
119
|
+
correction too, as the same address with a new point.
|
|
120
|
+
*/
|
|
121
|
+
@schema
|
|
122
|
+
type addressCommands =
|
|
123
|
+
/** Change the address and let the geocoder find the point. */
|
|
124
|
+
| UpdateAddress({address: string})
|
|
125
|
+
/** Change the address *and* say where it is — a client that already has a
|
|
126
|
+
point, because it geocoded or a human dragged the pin. Suppresses the
|
|
127
|
+
geocoder for this address, there being nothing left to look up. */
|
|
128
|
+
| SetAddressLocation({address: string, location: Reventless.GeoPoint.t})
|
|
129
|
+
|
|
130
|
+
/** One host, bound. Written over an abstract `subject` (the address) so retyping it
|
|
131
|
+
is a re-instantiation of this module, not a break in the trait. */
|
|
132
|
+
module type Binding = {
|
|
133
|
+
type subject
|
|
134
|
+
/** The text handed to the geocoder, and the second half of the TODO key. */
|
|
135
|
+
let subjectText: subject => string
|
|
136
|
+
/** Two subjects that differ, for histories in which the address changes. */
|
|
137
|
+
let subjectA: subject
|
|
138
|
+
let subjectB: subject
|
|
139
|
+
|
|
140
|
+
let posture: posture
|
|
141
|
+
|
|
142
|
+
module Spec: ReventlessGwt.Behavior_GWT.AggregateSpec
|
|
143
|
+
module Behavior: Reventless.Behavior.T with module Spec = Spec
|
|
144
|
+
|
|
145
|
+
/** History leaving the entity active at `subject` with nothing resolved. */
|
|
146
|
+
let created: subject => array<Spec.event>
|
|
147
|
+
/** The event a subject change appends. It must invalidate what was resolved. */
|
|
148
|
+
let subjectChanged: subject => Spec.event
|
|
149
|
+
/** The two facts the graft appends. */
|
|
150
|
+
let located: (~point: Reventless.GeoPoint.t, ~resolvedFrom: subject) => Spec.event
|
|
151
|
+
let unresolvable: (~subject: subject, ~reason: string) => Spec.event
|
|
152
|
+
/** The two commands the slice reports through. */
|
|
153
|
+
let setLocation: (~point: Reventless.GeoPoint.t, ~resolvedFrom: subject) => Spec.command
|
|
154
|
+
let markUnresolvable: (~subject: subject, ~reason: string) => Spec.command
|
|
155
|
+
|
|
156
|
+
module Slice: ReventlessGwt.OutboundTranslation_GWT.SliceSpec
|
|
157
|
+
let translate: (
|
|
158
|
+
string,
|
|
159
|
+
Slice.outboundItem,
|
|
160
|
+
~capabilities: Reventless.Capabilities.t,
|
|
161
|
+
) => promise<result<option<(string, Slice.inboundCommand)>, string>>
|
|
162
|
+
let item: (~entityId: string, ~subject: subject) => Slice.outboundItem
|
|
163
|
+
/** One consumed event per trigger, carrying `subject`. Every event type the slice
|
|
164
|
+
consumes must appear here — the consumed set may not be wider than its triggers. */
|
|
165
|
+
let triggers: subject => array<Slice.consumedEvent>
|
|
166
|
+
/** The host events that carry address and point together. The slice must not
|
|
167
|
+
consume them: that is the stand-down.
|
|
168
|
+
|
|
169
|
+
Real events rather than their type names. A name is a string the compiler
|
|
170
|
+
never sees, so a misspelling here does not fail — it names an event that
|
|
171
|
+
cannot be in any consumed set, and the assertion passes for the wrong
|
|
172
|
+
reason, which is the one outcome a conformance suite must not have. The
|
|
173
|
+
runner encodes these itself. */
|
|
174
|
+
let standsDownOn: array<Spec.event>
|
|
175
|
+
let isLocation: Slice.inboundCommand => bool
|
|
176
|
+
let isVerdict: Slice.inboundCommand => bool
|
|
177
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Sury from "sury";
|
|
4
|
+
import * as Api$ReventlessInfra from "@reventlessdev/reventless-infra/src/components/Api.res.mjs";
|
|
5
|
+
import * as GeoPoint$Reventless from "@reventlessdev/reventless-spec/src/semantic/GeoPoint.res.mjs";
|
|
6
|
+
import * as PackageVersion$Reventless from "@reventlessdev/reventless-spec/src/PackageVersion.res.mjs";
|
|
7
|
+
|
|
8
|
+
let declaration_version = PackageVersion$Reventless.fromModuleUrl(import.meta.url);
|
|
9
|
+
|
|
10
|
+
let declaration = {
|
|
11
|
+
trait: "@reventlessdev/trait-address-geocoding",
|
|
12
|
+
version: declaration_version,
|
|
13
|
+
posture: "WritesBack"
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
let capabilityNeeds = ["Geocoding"];
|
|
17
|
+
|
|
18
|
+
let eventsSchema = Sury.union([
|
|
19
|
+
Sury.$schema(s => ({
|
|
20
|
+
TAG: "AddressUpdated",
|
|
21
|
+
address: s.m(Sury.string)
|
|
22
|
+
})),
|
|
23
|
+
Sury.$schema(s => ({
|
|
24
|
+
TAG: "LocationSet",
|
|
25
|
+
location: s.m(GeoPoint$Reventless.schema),
|
|
26
|
+
resolvedFrom: s.m(Sury.string)
|
|
27
|
+
})),
|
|
28
|
+
Sury.$schema(s => ({
|
|
29
|
+
TAG: "AddressLocated",
|
|
30
|
+
address: s.m(Sury.string),
|
|
31
|
+
location: s.m(GeoPoint$Reventless.schema)
|
|
32
|
+
})),
|
|
33
|
+
Sury.$schema(s => ({
|
|
34
|
+
TAG: "AddressUnresolvable",
|
|
35
|
+
address: s.m(Sury.string),
|
|
36
|
+
reason: s.m(Sury.string)
|
|
37
|
+
}))
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
let reportCommandsSchema = Sury.union([
|
|
41
|
+
Sury.$schema(s => ({
|
|
42
|
+
TAG: "SetLocation",
|
|
43
|
+
location: s.m(GeoPoint$Reventless.schema),
|
|
44
|
+
resolvedFrom: s.m(Sury.string)
|
|
45
|
+
})),
|
|
46
|
+
Sury.$schema(s => ({
|
|
47
|
+
TAG: "MarkAddressUnresolvable",
|
|
48
|
+
address: s.m(Sury.string),
|
|
49
|
+
reason: s.m(Sury.string)
|
|
50
|
+
}))
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
let addressCommandsSchema = Sury.union([
|
|
54
|
+
Sury.$schema(s => ({
|
|
55
|
+
TAG: "UpdateAddress",
|
|
56
|
+
address: s.m(Sury.string)
|
|
57
|
+
})),
|
|
58
|
+
Sury.$schema(s => ({
|
|
59
|
+
TAG: "SetAddressLocation",
|
|
60
|
+
address: s.m(Sury.string),
|
|
61
|
+
location: s.m(GeoPoint$Reventless.schema)
|
|
62
|
+
}))
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
let reportCommandsSchema$1 = Api$ReventlessInfra.markNoApiVariants(reportCommandsSchema, [
|
|
66
|
+
"SetLocation",
|
|
67
|
+
"MarkAddressUnresolvable"
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
declaration,
|
|
72
|
+
capabilityNeeds,
|
|
73
|
+
eventsSchema,
|
|
74
|
+
addressCommandsSchema,
|
|
75
|
+
reportCommandsSchema$1 as reportCommandsSchema,
|
|
76
|
+
}
|
|
77
|
+
/* declaration Not a pure module */
|