@reventlessdev/reventless-core 3.0.0-alpha.336 → 3.0.0-alpha.337
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 +12 -0
- package/package.json +7 -7
- package/src/adapter/Messaging/Messaging_Log_Backend.res +1 -0
- package/src/adapter/Messaging/Messaging_Log_Backend.res.mjs +14 -8
- package/src/admin/Platform_ComponentDefinitionsApi.res +3 -1
- package/src/admin/Platform_ComponentDefinitionsApi.res.mjs +9 -1
- package/src/admin/Platform_I18n.res +129 -0
- package/src/admin/Platform_I18n.res.mjs +149 -1
- package/src/admin/Platform_SelfRegistration.res +8 -1
- package/src/admin/Platform_SelfRegistration.res.mjs +9 -1
- package/src/components/Api/Api_Naming.res +43 -7
- package/src/components/Api/Api_Naming.res.mjs +41 -12
- package/src/components/Api/GraphQL_FragmentGenerator.res +4 -1
- package/src/components/Api/GraphQL_FragmentGenerator.res.mjs +1 -1
- package/src/components/Dcb/Dcb_Builder.res +12 -2
- package/src/components/Dcb/Dcb_Builder.res.mjs +2 -2
- package/src/plugin/component/Plugin_Builder.res +36 -3
- package/src/plugin/component/Plugin_Builder.res.mjs +5 -3
- package/src/plugin/component/Plugin_Structure.res +24 -3
- package/src/plugin/component/Plugin_Structure.res.mjs +27 -3
- package/tests/plugin/PluginStructureTest.res +84 -0
- package/tests/plugin/PluginStructureTest.res.mjs +143 -21
- package/tests/plugin/StateView/PsPeopleView.res +14 -0
- package/tests/plugin/StateView/PsPeopleView.res.mjs +82 -0
- package/tests/plugin/StateView/PsStatusView.res +15 -0
- package/tests/plugin/StateView/PsStatusView.res.mjs +83 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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.337 (2026-11-11)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **local:** a mail is written in the language of the account it goes to ([71cfabc](https://github.com/ReventlessDev/reventless-core/commit/71cfabc26bcb2ad94e53d9d99c949e7755e0753a))
|
|
11
|
+
* **local:** how far each language is translated, and the release gate ([889cf94](https://github.com/ReventlessDev/reventless-core/commit/889cf9470fcef1a9470557a959a368887b6c6165))
|
|
12
|
+
* **ppx:** [@plural](https://github.com/plural) names a view's plural and an uploadable field's store ([a6a0fb0](https://github.com/ReventlessDev/reventless-core/commit/a6a0fb085ca528afafafd78b23fbb84c6823fcd1))
|
|
13
|
+
* **ppx:** [@singular](https://github.com/singular) names a view's singular where the English rule is wrong ([1f114a4](https://github.com/ReventlessDev/reventless-core/commit/1f114a4a5d8857596f61e009e24718fb59c9c23d))
|
|
14
|
+
* **registration:** a visitor's mails are written in the language they asked in ([b677e08](https://github.com/ReventlessDev/reventless-core/commit/b677e08cafe11af28cf917270f9ae8fafb2425da))
|
|
15
|
+
* **spec:** a server's messages are written in the recipient's language ([31bbf5f](https://github.com/ReventlessDev/reventless-core/commit/31bbf5f0a613131113d6f3e8a569578d29c439af))
|
|
16
|
+
|
|
17
|
+
|
|
6
18
|
# 3.0.0-alpha.336 (2026-11-09)
|
|
7
19
|
|
|
8
20
|
### 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.337",
|
|
4
4
|
"description": "Core package for Reventless framework",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"jest": {
|
|
@@ -28,17 +28,17 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"sury": "11.1.0",
|
|
30
30
|
"uuid": "^13.0.0",
|
|
31
|
+
"@reventlessdev/rescript-jest": "1.0.0-alpha.13",
|
|
32
|
+
"@reventlessdev/rescript-node": "2.0.0-alpha.26",
|
|
31
33
|
"@reventlessdev/rescript-effect": "1.0.0-alpha.3",
|
|
32
|
-
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
|
|
33
34
|
"@reventlessdev/rescript-fast-csv": "2.0.0-alpha.26",
|
|
34
|
-
"@reventlessdev/rescript-
|
|
35
|
-
"@reventlessdev/rescript-jest": "1.0.0-alpha.13",
|
|
35
|
+
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
|
|
36
36
|
"@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
|
|
37
|
+
"@reventlessdev/rescript-ssh2": "2.0.0-alpha.27",
|
|
37
38
|
"@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
|
|
38
39
|
"@reventlessdev/reventless-interop": "3.0.0-alpha.43",
|
|
39
|
-
"@reventlessdev/
|
|
40
|
-
"@reventlessdev/reventless-infra": "3.0.0-alpha.
|
|
41
|
-
"@reventlessdev/reventless-spec": "3.0.0-alpha.198"
|
|
40
|
+
"@reventlessdev/reventless-spec": "3.0.0-alpha.199",
|
|
41
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.230"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"rescript": "12.3.1",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
3
4
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
5
|
import * as Messaging$Reventless from "@reventlessdev/reventless-spec/src/semantic/Messaging.res.mjs";
|
|
5
6
|
import * as Logger$ReventlessCore from "../../util/Logger.res.mjs";
|
|
@@ -19,14 +20,19 @@ function channels(sender) {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
function render(ref_, sender, to_, message) {
|
|
22
|
-
return [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
]
|
|
23
|
+
return Belt_Array.concatMany([
|
|
24
|
+
[
|
|
25
|
+
ref_ + ` — logged, not sent`,
|
|
26
|
+
` From: ` + sender,
|
|
27
|
+
` To: ` + to_,
|
|
28
|
+
` Subject: ` + Stdlib_Option.getOr(message.subject, "(none)")
|
|
29
|
+
],
|
|
30
|
+
Stdlib_Option.mapOr(message.language, [], language => [` Content-Language: ` + language]),
|
|
31
|
+
[
|
|
32
|
+
"",
|
|
33
|
+
message.body
|
|
34
|
+
]
|
|
35
|
+
]).join("\n");
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
async function send(sender, recipient, message) {
|
|
@@ -29,7 +29,7 @@ let sdlTypes: array<string> = [
|
|
|
29
29
|
// structures persisted before the fields existed decode as `None`, a hand-rolled
|
|
30
30
|
// def may decline to state them, and a state whose key cannot be resolved has no
|
|
31
31
|
// `idField` to report.
|
|
32
|
-
`type Platform_ReadSideDef {\n name: String!\n queryField: String!\n schema: String!\n consumedEventTypes: [String!]!\n linkedWriteSide: [String!]!\n labelField: String!\n searchableFields: [String!]!\n labelFieldSource: String\n lifecycleField: String\n visibility: String\n chapter: String\n singleQueryField: String\n idField: String\n idFieldSource: String\n requiredAccess: [String!]\n ownerField: String\n retiredField: String\n retiredValues: [String!]\n namedWhenRetired: Boolean!\n}`,
|
|
32
|
+
`type Platform_ReadSideDef {\n name: String!\n queryField: String!\n schema: String!\n consumedEventTypes: [String!]!\n linkedWriteSide: [String!]!\n labelField: String!\n searchableFields: [String!]!\n labelFieldSource: String\n lifecycleField: String\n visibility: String\n chapter: String\n singleQueryField: String\n plural: String\n pluralSource: String\n idField: String\n idFieldSource: String\n requiredAccess: [String!]\n ownerField: String\n retiredField: String\n retiredValues: [String!]\n namedWhenRetired: Boolean!\n}`,
|
|
33
33
|
`type Platform_AutomationSliceDef {\n name: String!\n consumedEventTypes: [String!]!\n producedCommandTypes: [String!]!\n targetName: String\n chapter: String\n schedule: String\n}`,
|
|
34
34
|
`type Platform_OutboundTranslationSliceDef {\n name: String!\n consumedEventTypes: [String!]!\n inboundCommandTypes: [String!]!\n targetName: String\n externalSystem: String\n chapter: String\n consumedSources: [String!]\n}`,
|
|
35
35
|
`type Platform_InboundTranslationSliceDef {\n name: String!\n commandTypes: [String!]!\n targetName: String\n externalSystem: String\n chapter: String\n}`,
|
|
@@ -120,6 +120,8 @@ let encodeReadSideDef = (r: readSideDef): JSON.t =>
|
|
|
120
120
|
("visibility", r.visibility->Option.mapOr(JSON.Encode.null, JSON.Encode.string)),
|
|
121
121
|
("chapter", r.chapter->Option.mapOr(JSON.Encode.null, JSON.Encode.string)),
|
|
122
122
|
("singleQueryField", r.singleQueryField->Option.mapOr(JSON.Encode.null, JSON.Encode.string)),
|
|
123
|
+
("plural", r.plural->Option.mapOr(JSON.Encode.null, JSON.Encode.string)),
|
|
124
|
+
("pluralSource", r.pluralSource->Option.mapOr(JSON.Encode.null, JSON.Encode.string)),
|
|
123
125
|
("idField", r.idField->Option.mapOr(JSON.Encode.null, JSON.Encode.string)),
|
|
124
126
|
("idFieldSource", r.idFieldSource->Option.mapOr(JSON.Encode.null, JSON.Encode.string)),
|
|
125
127
|
("requiredAccess", r.requiredAccess->Option.mapOr(JSON.Encode.null, encodeStrings)),
|
|
@@ -10,7 +10,7 @@ let sdlTypes = [
|
|
|
10
10
|
`type Platform_EventDef {\n name: String!\n schema: String!\n references: [Platform_FieldReference!]!\n}`,
|
|
11
11
|
`type Platform_ErrorDef {\n name: String!\n schema: String!\n references: [Platform_FieldReference!]!\n}`,
|
|
12
12
|
`type Platform_WriteSideDef {\n name: String!\n commands: [Platform_CommandDef!]!\n linkedViews: [String!]!\n consistencyRead: String\n producedEventTypes: [String!]!\n consumedEventTypes: [String!]!\n events: [Platform_EventDef!]!\n errors: [Platform_ErrorDef!]!\n chapter: String\n}`,
|
|
13
|
-
`type Platform_ReadSideDef {\n name: String!\n queryField: String!\n schema: String!\n consumedEventTypes: [String!]!\n linkedWriteSide: [String!]!\n labelField: String!\n searchableFields: [String!]!\n labelFieldSource: String\n lifecycleField: String\n visibility: String\n chapter: String\n singleQueryField: String\n idField: String\n idFieldSource: String\n requiredAccess: [String!]\n ownerField: String\n retiredField: String\n retiredValues: [String!]\n namedWhenRetired: Boolean!\n}`,
|
|
13
|
+
`type Platform_ReadSideDef {\n name: String!\n queryField: String!\n schema: String!\n consumedEventTypes: [String!]!\n linkedWriteSide: [String!]!\n labelField: String!\n searchableFields: [String!]!\n labelFieldSource: String\n lifecycleField: String\n visibility: String\n chapter: String\n singleQueryField: String\n plural: String\n pluralSource: String\n idField: String\n idFieldSource: String\n requiredAccess: [String!]\n ownerField: String\n retiredField: String\n retiredValues: [String!]\n namedWhenRetired: Boolean!\n}`,
|
|
14
14
|
`type Platform_AutomationSliceDef {\n name: String!\n consumedEventTypes: [String!]!\n producedCommandTypes: [String!]!\n targetName: String\n chapter: String\n schedule: String\n}`,
|
|
15
15
|
`type Platform_OutboundTranslationSliceDef {\n name: String!\n consumedEventTypes: [String!]!\n inboundCommandTypes: [String!]!\n targetName: String\n externalSystem: String\n chapter: String\n consumedSources: [String!]\n}`,
|
|
16
16
|
`type Platform_InboundTranslationSliceDef {\n name: String!\n commandTypes: [String!]!\n targetName: String\n externalSystem: String\n chapter: String\n}`,
|
|
@@ -151,6 +151,14 @@ function encodeReadSideDef(r) {
|
|
|
151
151
|
"singleQueryField",
|
|
152
152
|
Stdlib_Option.mapOr(r.singleQueryField, null, prim => prim)
|
|
153
153
|
],
|
|
154
|
+
[
|
|
155
|
+
"plural",
|
|
156
|
+
Stdlib_Option.mapOr(r.plural, null, prim => prim)
|
|
157
|
+
],
|
|
158
|
+
[
|
|
159
|
+
"pluralSource",
|
|
160
|
+
Stdlib_Option.mapOr(r.pluralSource, null, prim => prim)
|
|
161
|
+
],
|
|
154
162
|
[
|
|
155
163
|
"idField",
|
|
156
164
|
Stdlib_Option.mapOr(r.idField, null, prim => prim)
|
|
@@ -95,6 +95,65 @@ let merged = (i18n: ReventlessInfra.Platform.i18n, ~language: string, ~read: rea
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
// ── The release gate ──────────────────────────────────────────────────────────
|
|
99
|
+
|
|
100
|
+
/** A source directory's JSON files as `(file name, text)`; none for a directory that is not. */
|
|
101
|
+
let filesIn = (dir: string): array<(string, string)> =>
|
|
102
|
+
switch NodeFs.readdirSyncNames(dir, {}) {
|
|
103
|
+
| names =>
|
|
104
|
+
names
|
|
105
|
+
->Array.filter(f => f->String.endsWith(".json"))
|
|
106
|
+
->Array.toSorted(String.compare)
|
|
107
|
+
->Array.map(f => (f, NodeFs.readFileSync(NodePath.join([dir, f]))))
|
|
108
|
+
| exception _ => []
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A source's name in a message: the package its `i18n/` sits in. */
|
|
112
|
+
let sourceName = (dir: string): string => {
|
|
113
|
+
let base = NodePath.basename(dir)
|
|
114
|
+
base == "i18n" ? NodePath.basename(NodePath.dirname(dir)) : base
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
What `generate-catalogue check` checks, before a deployment serves its catalogues: in any
|
|
119
|
+
language a text that does not parse or names other placeholders than the English, and in a
|
|
120
|
+
language the last source's `languages.json` releases also a key missing or stale.
|
|
121
|
+
*/
|
|
122
|
+
let gate = (
|
|
123
|
+
i18n: ReventlessInfra.Platform.i18n,
|
|
124
|
+
~files: string => array<(string, string)>,
|
|
125
|
+
~hash: string => string,
|
|
126
|
+
): result<unit, string> => {
|
|
127
|
+
module Status = Reventless.CatalogueStatus
|
|
128
|
+
let layers =
|
|
129
|
+
i18n.sources->Array.reduce(Ok([]), (acc, dir) =>
|
|
130
|
+
acc->Result.flatMap(done =>
|
|
131
|
+
Status.layerOf(~name=sourceName(dir), files(dir))->Result.map(l => Array.concat(done, [l]))
|
|
132
|
+
)
|
|
133
|
+
)
|
|
134
|
+
let releases =
|
|
135
|
+
i18n.sources
|
|
136
|
+
->Array.at(-1)
|
|
137
|
+
->Option.flatMap(dir =>
|
|
138
|
+
files(dir)->Array.find(((f, _)) => f == "languages.json")->Option.map(Pair.second)
|
|
139
|
+
)
|
|
140
|
+
->Option.mapOr(Ok(Dict.make()), Status.readReleases)
|
|
141
|
+
switch (layers, releases) {
|
|
142
|
+
| (Error(e), _) | (_, Error(e)) => Error("i18n: " ++ e)
|
|
143
|
+
| (Ok(layers), Ok(releases)) =>
|
|
144
|
+
switch Status.problems(layers, ~releases, ~hash) {
|
|
145
|
+
| [] => Ok()
|
|
146
|
+
| found =>
|
|
147
|
+
Error(
|
|
148
|
+
`i18n: ${found->Array.length->Int.toString} problem(s) in the catalogues:\n` ++
|
|
149
|
+
found
|
|
150
|
+
->Array.map(p => ` ${p.language} ${p.layer} ${p.key}: ${p.reason}`)
|
|
151
|
+
->Array.join("\n"),
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
98
157
|
/** Every offered language's merged catalogue, as `(file name, text)`, or the first mistake. */
|
|
99
158
|
let files = (i18n: ReventlessInfra.Platform.i18n, ~read: read): result<
|
|
100
159
|
array<(string, string)>,
|
|
@@ -110,3 +169,73 @@ let files = (i18n: ReventlessInfra.Platform.i18n, ~read: read): result<
|
|
|
110
169
|
)
|
|
111
170
|
)
|
|
112
171
|
)
|
|
172
|
+
|
|
173
|
+
// ── The server's words ────────────────────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
/** A served catalogue's text as its keys and texts; a value that is not a string is skipped. */
|
|
176
|
+
let parseCatalogue = (text: string): result<dict<string>, string> =>
|
|
177
|
+
switch text->JSON.parseOrThrow->JSON.Decode.object {
|
|
178
|
+
| Some(entries) =>
|
|
179
|
+
Ok(
|
|
180
|
+
entries
|
|
181
|
+
->Dict.toArray
|
|
182
|
+
->Array.filterMap(((k, v)) => v->JSON.Decode.string->Option.map(s => (k, s)))
|
|
183
|
+
->Dict.fromArray,
|
|
184
|
+
)
|
|
185
|
+
| None => Error("a catalogue is not a JSON object")
|
|
186
|
+
| exception _ => Error("a catalogue is not JSON")
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** A person's `locale` matched to what the deployment offers. See `Text.offeredFor`. */
|
|
190
|
+
let offeredFor = (i18n: ReventlessInfra.Platform.i18n, locale: string): option<string> =>
|
|
191
|
+
Reventless.Text.offeredFor(~offered=Array.concat([i18n.default], i18n.offered), locale)
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
What a slice formats a message with on a deployment that declared its languages: a recipient
|
|
195
|
+
in their own `locale` where `localeOf` knows it and the deployment offers it, else in the
|
|
196
|
+
language their request was made in where that is offered, else the declared default; and a language's catalogue as `catalogue` fetches it. A language that is not offered
|
|
197
|
+
has none.
|
|
198
|
+
*/
|
|
199
|
+
let text = (
|
|
200
|
+
i18n: ReventlessInfra.Platform.i18n,
|
|
201
|
+
~catalogue: string => promise<result<option<dict<string>>, string>>,
|
|
202
|
+
~localeOf: Reventless.Messaging.recipient => promise<option<string>>=async _ => None,
|
|
203
|
+
): Reventless.Text.t => {
|
|
204
|
+
default: i18n.default,
|
|
205
|
+
languageFor: async (recipient, ~requested=?) =>
|
|
206
|
+
Reventless.Text.choose(
|
|
207
|
+
~offered=Array.concat([i18n.default], i18n.offered),
|
|
208
|
+
~default=i18n.default,
|
|
209
|
+
~own=await localeOf(recipient),
|
|
210
|
+
~requested,
|
|
211
|
+
),
|
|
212
|
+
catalogue: async language =>
|
|
213
|
+
Array.concat([i18n.default], i18n.offered)->Array.includes(language)
|
|
214
|
+
? await catalogue(language)
|
|
215
|
+
: Ok(None),
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** The languages as a sending Lambda reads them, `{"default", "offered"}`. */
|
|
219
|
+
let languagesJson = (i18n: ReventlessInfra.Platform.i18n): string =>
|
|
220
|
+
JSON.stringify(
|
|
221
|
+
dict{
|
|
222
|
+
"default": JSON.Encode.string(i18n.default),
|
|
223
|
+
"offered": i18n.offered->Array.map(JSON.Encode.string)->JSON.Encode.array,
|
|
224
|
+
}->JSON.Encode.object,
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
/** The languages `languagesJson` wrote, as a declaration with no sources: what a Lambda knows. */
|
|
228
|
+
let languagesOfJson = (text: string): option<ReventlessInfra.Platform.i18n> =>
|
|
229
|
+
switch text->JSON.parseOrThrow->JSON.Decode.object {
|
|
230
|
+
| Some(o) =>
|
|
231
|
+
switch (
|
|
232
|
+
o->Dict.get("default")->Option.flatMap(JSON.Decode.string),
|
|
233
|
+
o->Dict.get("offered")->Option.flatMap(JSON.Decode.array),
|
|
234
|
+
) {
|
|
235
|
+
| (Some(default), Some(offered)) =>
|
|
236
|
+
Some({default, offered: offered->Array.filterMap(JSON.Decode.string), sources: []})
|
|
237
|
+
| _ => None
|
|
238
|
+
}
|
|
239
|
+
| None => None
|
|
240
|
+
| exception _ => None
|
|
241
|
+
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Nodefs from "node:fs";
|
|
4
|
+
import * as Nodepath from "node:path";
|
|
3
5
|
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
4
6
|
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
5
7
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
6
8
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
9
|
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
10
|
+
import * as Text$Reventless from "@reventlessdev/reventless-spec/src/i18n/Text.res.mjs";
|
|
8
11
|
import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
|
|
12
|
+
import * as CatalogueStatus$Reventless from "@reventlessdev/reventless-spec/src/i18n/CatalogueStatus.res.mjs";
|
|
9
13
|
|
|
10
14
|
let configKey = "languages";
|
|
11
15
|
|
|
@@ -93,6 +97,63 @@ function merged(i18n, language, read) {
|
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
|
|
100
|
+
function filesIn(dir) {
|
|
101
|
+
let names;
|
|
102
|
+
try {
|
|
103
|
+
names = Nodefs.readdirSync(dir, {});
|
|
104
|
+
} catch (exn) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
return names.filter(f => f.endsWith(".json")).toSorted(Primitive_string.compare).map(f => [
|
|
108
|
+
f,
|
|
109
|
+
Nodefs.readFileSync(Nodepath.join(dir, f), "utf8")
|
|
110
|
+
]);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function sourceName(dir) {
|
|
114
|
+
let base = Nodepath.basename(dir);
|
|
115
|
+
if (base === "i18n") {
|
|
116
|
+
return Nodepath.basename(Nodepath.dirname(dir));
|
|
117
|
+
} else {
|
|
118
|
+
return base;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function gate(i18n, files, hash) {
|
|
123
|
+
let layers = Stdlib_Array.reduce(i18n.sources, {
|
|
124
|
+
TAG: "Ok",
|
|
125
|
+
_0: []
|
|
126
|
+
}, (acc, dir) => Stdlib_Result.flatMap(acc, done => Stdlib_Result.map(CatalogueStatus$Reventless.layerOf(sourceName(dir), files(dir)), l => done.concat([l]))));
|
|
127
|
+
let releases = Stdlib_Option.mapOr(Stdlib_Option.flatMap(i18n.sources.at(-1), dir => Stdlib_Option.map(files(dir).find(param => param[0] === "languages.json"), prim => prim[1])), {
|
|
128
|
+
TAG: "Ok",
|
|
129
|
+
_0: {}
|
|
130
|
+
}, CatalogueStatus$Reventless.readReleases);
|
|
131
|
+
if (layers.TAG !== "Ok") {
|
|
132
|
+
return {
|
|
133
|
+
TAG: "Error",
|
|
134
|
+
_0: "i18n: " + layers._0
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (releases.TAG !== "Ok") {
|
|
138
|
+
return {
|
|
139
|
+
TAG: "Error",
|
|
140
|
+
_0: "i18n: " + releases._0
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
let found = CatalogueStatus$Reventless.problems(layers._0, releases._0, hash);
|
|
144
|
+
if (found.length !== 0) {
|
|
145
|
+
return {
|
|
146
|
+
TAG: "Error",
|
|
147
|
+
_0: `i18n: ` + found.length.toString() + ` problem(s) in the catalogues:\n` + found.map(p => ` ` + p.language + ` ` + p.layer + ` ` + p.key + `: ` + p.reason).join("\n")
|
|
148
|
+
};
|
|
149
|
+
} else {
|
|
150
|
+
return {
|
|
151
|
+
TAG: "Ok",
|
|
152
|
+
_0: undefined
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
96
157
|
function files(i18n, read) {
|
|
97
158
|
return Stdlib_Result.flatMap(validate(i18n), i18n => Stdlib_Array.reduce(i18n.offered, {
|
|
98
159
|
TAG: "Ok",
|
|
@@ -103,6 +164,85 @@ function files(i18n, read) {
|
|
|
103
164
|
]])))));
|
|
104
165
|
}
|
|
105
166
|
|
|
167
|
+
function parseCatalogue(text) {
|
|
168
|
+
let entries;
|
|
169
|
+
try {
|
|
170
|
+
entries = Stdlib_JSON.Decode.object(JSON.parse(text));
|
|
171
|
+
} catch (exn) {
|
|
172
|
+
return {
|
|
173
|
+
TAG: "Error",
|
|
174
|
+
_0: "a catalogue is not JSON"
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (entries !== undefined) {
|
|
178
|
+
return {
|
|
179
|
+
TAG: "Ok",
|
|
180
|
+
_0: Object.fromEntries(Stdlib_Array.filterMap(Object.entries(entries), param => {
|
|
181
|
+
let k = param[0];
|
|
182
|
+
return Stdlib_Option.map(Stdlib_JSON.Decode.string(param[1]), s => [
|
|
183
|
+
k,
|
|
184
|
+
s
|
|
185
|
+
]);
|
|
186
|
+
}))
|
|
187
|
+
};
|
|
188
|
+
} else {
|
|
189
|
+
return {
|
|
190
|
+
TAG: "Error",
|
|
191
|
+
_0: "a catalogue is not a JSON object"
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function offeredFor(i18n, locale) {
|
|
197
|
+
return Text$Reventless.offeredFor([i18n.default].concat(i18n.offered), locale);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function text(i18n, catalogue, localeOfOpt) {
|
|
201
|
+
let localeOf = localeOfOpt !== undefined ? localeOfOpt : async param => {};
|
|
202
|
+
return {
|
|
203
|
+
default: i18n.default,
|
|
204
|
+
languageFor: async (recipient, requested) => Text$Reventless.choose([i18n.default].concat(i18n.offered), i18n.default, await localeOf(recipient), requested),
|
|
205
|
+
catalogue: async language => {
|
|
206
|
+
if ([i18n.default].concat(i18n.offered).includes(language)) {
|
|
207
|
+
return await catalogue(language);
|
|
208
|
+
} else {
|
|
209
|
+
return {
|
|
210
|
+
TAG: "Ok",
|
|
211
|
+
_0: undefined
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function languagesJson(i18n) {
|
|
219
|
+
return JSON.stringify({
|
|
220
|
+
default: i18n.default,
|
|
221
|
+
offered: i18n.offered.map(prim => prim)
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function languagesOfJson(text) {
|
|
226
|
+
let o;
|
|
227
|
+
try {
|
|
228
|
+
o = Stdlib_JSON.Decode.object(JSON.parse(text));
|
|
229
|
+
} catch (exn) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (o === undefined) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
let match = Stdlib_Option.flatMap(o["default"], Stdlib_JSON.Decode.string);
|
|
236
|
+
let match$1 = Stdlib_Option.flatMap(o["offered"], Stdlib_JSON.Decode.array);
|
|
237
|
+
if (match !== undefined && match$1 !== undefined) {
|
|
238
|
+
return {
|
|
239
|
+
default: match,
|
|
240
|
+
offered: Stdlib_Array.filterMap(match$1, Stdlib_JSON.Decode.string),
|
|
241
|
+
sources: []
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
106
246
|
export {
|
|
107
247
|
configKey,
|
|
108
248
|
fileName,
|
|
@@ -110,6 +250,14 @@ export {
|
|
|
110
250
|
validate,
|
|
111
251
|
configEntry,
|
|
112
252
|
merged,
|
|
253
|
+
filesIn,
|
|
254
|
+
sourceName,
|
|
255
|
+
gate,
|
|
113
256
|
files,
|
|
257
|
+
parseCatalogue,
|
|
258
|
+
offeredFor,
|
|
259
|
+
text,
|
|
260
|
+
languagesJson,
|
|
261
|
+
languagesOfJson,
|
|
114
262
|
}
|
|
115
|
-
/*
|
|
263
|
+
/* node:fs Not a pure module */
|
|
@@ -39,7 +39,14 @@ let openRolesField = (structures: array<(string, Reventless.Plugin.pluginStructu
|
|
|
39
39
|
string,
|
|
40
40
|
> =>
|
|
41
41
|
marked(structures, OpenRoles)->Option.map(((plugin, d)) =>
|
|
42
|
-
|
|
42
|
+
// The view's own published field, so a `@plural` on it is honored.
|
|
43
|
+
structures
|
|
44
|
+
->Array.findMap(((p, s)) => p == plugin ? Some(s) : None)
|
|
45
|
+
->Option.flatMap(s => s.stateViewSlices->Array.find(v => v.name == d.component))
|
|
46
|
+
->Option.mapOr(
|
|
47
|
+
Api_Naming.queryFieldNamesForStateView(~plugin, ~viewName=d.component).listFieldName,
|
|
48
|
+
v => v.queryField,
|
|
49
|
+
)
|
|
43
50
|
)
|
|
44
51
|
|
|
45
52
|
let selfServiceGroups = (structures: array<(string, Reventless.Plugin.pluginStructure)>) =>
|
|
@@ -23,7 +23,15 @@ function doorField(structures, part) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function openRolesField(structures) {
|
|
26
|
-
return Stdlib_Option.map(marked(structures, "OpenRoles"), param =>
|
|
26
|
+
return Stdlib_Option.map(marked(structures, "OpenRoles"), param => {
|
|
27
|
+
let d = param[1];
|
|
28
|
+
let plugin = param[0];
|
|
29
|
+
return Stdlib_Option.mapOr(Stdlib_Option.flatMap(Stdlib_Array.findMap(structures, param => {
|
|
30
|
+
if (param[0] === plugin) {
|
|
31
|
+
return param[1];
|
|
32
|
+
}
|
|
33
|
+
}), s => s.stateViewSlices.find(v => v.name === d.component)), Api_Naming$ReventlessCore.queryFieldNamesForStateView(plugin, d.component, undefined, undefined, undefined).listFieldName, v => v.queryField);
|
|
34
|
+
});
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
function selfServiceGroups(structures) {
|
|
@@ -9,6 +9,11 @@ type queryNames = {
|
|
|
9
9
|
labelField?: string,
|
|
10
10
|
includeIdParam: bool,
|
|
11
11
|
connectionSpec: bool,
|
|
12
|
+
/** The plural `listFieldName` and `pluralTypeName` are built from; absent on a
|
|
13
|
+
record built by hand. */
|
|
14
|
+
plural?: string,
|
|
15
|
+
/** Whether `plural` is a `@plural` declaration rather than the English rule's. */
|
|
16
|
+
pluralDeclared?: bool,
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
let pluralize = (n: string) =>
|
|
@@ -128,13 +133,33 @@ let sliceMutationFieldFor = (
|
|
|
128
133
|
// "ProductDemand" the singularize is a no-op and pluralize behaves as usual.
|
|
129
134
|
let canonicalPlural = (n: string) => pluralize(singularize(n))
|
|
130
135
|
|
|
136
|
+
// The plural a view's `@plural("…")` declares, read off its state schema.
|
|
137
|
+
let declaredPlural = (stateSchema: S.t<unknown>): option<string> =>
|
|
138
|
+
Reventless.StateAnnotations.getSpec(stateSchema)->Option.flatMap(s => s.plural)
|
|
139
|
+
|
|
140
|
+
// The singular a view's `@singular("…")` declares, read off its state schema.
|
|
141
|
+
let declaredSingular = (stateSchema: S.t<unknown>): option<string> =>
|
|
142
|
+
Reventless.StateAnnotations.getSpec(stateSchema)->Option.flatMap(s => s.singular)
|
|
143
|
+
|
|
144
|
+
// The declared singulars of a plugin's views, by `<plugin>.<spec name>`: a `@resolves` field
|
|
145
|
+
// names its target by spec name only, and has to land on the type that view is exposed as.
|
|
146
|
+
// Recorded by the plugin builder before it builds any query entry.
|
|
147
|
+
let declaredSingulars: dict<string> = Dict.make()
|
|
148
|
+
|
|
149
|
+
let registerSingular = (~plugin: string, ~name: string, stateSchema: S.t<unknown>) =>
|
|
150
|
+
declaredSingular(stateSchema)->Option.forEach(singular =>
|
|
151
|
+
declaredSingulars->Dict.set(`${plugin}.${name}`, singular)
|
|
152
|
+
)
|
|
153
|
+
|
|
131
154
|
let queryFieldNamesForReadModel = (
|
|
132
155
|
~plugin: string,
|
|
133
156
|
~name: string,
|
|
157
|
+
~plural as declared: option<string>=?,
|
|
158
|
+
~singular as declaredOne: option<string>=?,
|
|
134
159
|
~connectionSpec: bool=true,
|
|
135
160
|
): queryNames => {
|
|
136
|
-
let singular = singularize(name)
|
|
137
|
-
let plural = canonicalPlural(name)
|
|
161
|
+
let singular = declaredOne->Option.getOr(singularize(name))
|
|
162
|
+
let plural = declared->Option.getOr(canonicalPlural(name))
|
|
138
163
|
{
|
|
139
164
|
singleFieldName: `${plugin}_${singular}`,
|
|
140
165
|
listFieldName: `${plugin}_${plural}`,
|
|
@@ -142,6 +167,8 @@ let queryFieldNamesForReadModel = (
|
|
|
142
167
|
pluralTypeName: `${plugin}_${plural}`,
|
|
143
168
|
includeIdParam: true,
|
|
144
169
|
connectionSpec,
|
|
170
|
+
plural,
|
|
171
|
+
pluralDeclared: declared->Option.isSome,
|
|
145
172
|
}
|
|
146
173
|
}
|
|
147
174
|
|
|
@@ -149,7 +176,9 @@ let queryFieldNamesForReadModel = (
|
|
|
149
176
|
// `queryFieldNamesFor*` above name it this way, so a `@resolves` target reached
|
|
150
177
|
// by spec name lands on the same type whichever kind declares it.
|
|
151
178
|
let returnTypeNameFor = (~plugin: string, ~name: string) =>
|
|
152
|
-
`${plugin}_${
|
|
179
|
+
`${plugin}_${declaredSingulars
|
|
180
|
+
->Dict.get(`${plugin}.${name}`)
|
|
181
|
+
->Option.getOr(singularize(stripViewSuffix(name)))}`
|
|
153
182
|
|
|
154
183
|
/**
|
|
155
184
|
The cross-table fields `@resolves` / `@resolvesMany` add to a queryable's object
|
|
@@ -204,11 +233,13 @@ let resolvedFieldsOfConfig = (~plugin: string, config: Reventless.ReadModel.conf
|
|
|
204
233
|
let queryFieldNamesForStateView = (
|
|
205
234
|
~plugin: string,
|
|
206
235
|
~viewName: string,
|
|
236
|
+
~plural as declared: option<string>=?,
|
|
237
|
+
~singular as declaredOne: option<string>=?,
|
|
207
238
|
~connectionSpec: bool=true,
|
|
208
239
|
): queryNames => {
|
|
209
240
|
let entity = stripViewSuffix(viewName)
|
|
210
|
-
let singular = singularize(entity)
|
|
211
|
-
let plural = canonicalPlural(entity)
|
|
241
|
+
let singular = declaredOne->Option.getOr(singularize(entity))
|
|
242
|
+
let plural = declared->Option.getOr(canonicalPlural(entity))
|
|
212
243
|
{
|
|
213
244
|
singleFieldName: `${plugin}_${singular}`,
|
|
214
245
|
listFieldName: `${plugin}_${plural}`,
|
|
@@ -216,6 +247,8 @@ let queryFieldNamesForStateView = (
|
|
|
216
247
|
pluralTypeName: `${plugin}_${plural}`,
|
|
217
248
|
includeIdParam: true,
|
|
218
249
|
connectionSpec,
|
|
250
|
+
plural,
|
|
251
|
+
pluralDeclared: declared->Option.isSome,
|
|
219
252
|
}
|
|
220
253
|
}
|
|
221
254
|
|
|
@@ -230,13 +263,16 @@ let queryFieldNamesForSliceQueryDb = (
|
|
|
230
263
|
~queryDbName: string,
|
|
231
264
|
~connectionSpec: bool=true,
|
|
232
265
|
): queryNames => {
|
|
266
|
+
let plural = canonicalPlural(queryDbName)
|
|
233
267
|
{
|
|
234
268
|
singleFieldName: `${plugin}_${queryDbName}`,
|
|
235
|
-
listFieldName: `${plugin}_${
|
|
269
|
+
listFieldName: `${plugin}_${plural}`,
|
|
236
270
|
returnTypeName: `${plugin}_${queryDbName}`,
|
|
237
|
-
pluralTypeName: `${plugin}_${
|
|
271
|
+
pluralTypeName: `${plugin}_${plural}`,
|
|
238
272
|
includeIdParam: true,
|
|
239
273
|
connectionSpec,
|
|
274
|
+
plural,
|
|
275
|
+
pluralDeclared: false,
|
|
240
276
|
}
|
|
241
277
|
}
|
|
242
278
|
|