@reventlessdev/reventless-core 3.0.0-alpha.335 → 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 +19 -0
- package/package.json +5 -5
- 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 +241 -0
- package/src/admin/Platform_I18n.res.mjs +263 -0
- 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,25 @@
|
|
|
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
|
+
|
|
18
|
+
# 3.0.0-alpha.336 (2026-11-09)
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **core:** a deployment serves its catalogues beside config.json ([299f6eb](https://github.com/ReventlessDev/reventless-core/commit/299f6eb50fdcb8ae2fdd76a32cfc264004088075))
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
# 3.0.0-alpha.335 (2026-11-08)
|
|
7
26
|
|
|
8
27
|
* feat(core)!: an automation or outbound translation hears that its command was refused ([8c9b4b6](https://github.com/ReventlessDev/reventless-core/commit/8c9b4b6c643a5a9e95c85f823fbc333638224346))
|
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-effect": "1.0.0-alpha.3",
|
|
32
|
-
"@reventlessdev/rescript-fast-csv": "2.0.0-alpha.26",
|
|
33
31
|
"@reventlessdev/rescript-jest": "1.0.0-alpha.13",
|
|
34
32
|
"@reventlessdev/rescript-node": "2.0.0-alpha.26",
|
|
33
|
+
"@reventlessdev/rescript-effect": "1.0.0-alpha.3",
|
|
34
|
+
"@reventlessdev/rescript-fast-csv": "2.0.0-alpha.26",
|
|
35
35
|
"@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
|
|
36
36
|
"@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
|
|
37
37
|
"@reventlessdev/rescript-ssh2": "2.0.0-alpha.27",
|
|
38
38
|
"@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
|
|
39
39
|
"@reventlessdev/reventless-interop": "3.0.0-alpha.43",
|
|
40
|
-
"@reventlessdev/reventless-spec": "3.0.0-alpha.
|
|
41
|
-
"@reventlessdev/reventless-infra": "3.0.0-alpha.
|
|
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)
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// Where a deployment's catalogues go, how they are merged, and what the shell is told about its
|
|
2
|
+
// languages.
|
|
3
|
+
//
|
|
4
|
+
// Stated once, in core, for the reason `Platform_UiSlots` gives: the AWS deploy and the local
|
|
5
|
+
// platform both write `i18n/<lang>.json` beside `config.json` and both write the `languages`
|
|
6
|
+
// key, and a platform that spelled either differently would serve catalogues nothing reads.
|
|
7
|
+
//
|
|
8
|
+
// The merge is per language and key: each source's `<lang>.json` in the order declared, a later
|
|
9
|
+
// source winning a key. A deployment lists each plugin's `i18n/` first and its own overrides
|
|
10
|
+
// last, so an app can reword a plugin's text without editing the plugin.
|
|
11
|
+
|
|
12
|
+
/** The `config.json` key naming the languages. */
|
|
13
|
+
let configKey = "languages"
|
|
14
|
+
|
|
15
|
+
/** Where a language's catalogue is served, relative to `config.json`. */
|
|
16
|
+
let fileName = (language: string): string => `i18n/${language}.json`
|
|
17
|
+
|
|
18
|
+
let isTag = (tag: string): bool => {
|
|
19
|
+
let parts = tag->String.split("-")
|
|
20
|
+
parts->Array.length > 0 &&
|
|
21
|
+
parts->Array.every(p => /^[A-Za-z0-9]{1,8}$/->RegExp.test(p)) &&
|
|
22
|
+
/^[A-Za-z]{2,3}$/->RegExp.test(parts->Array.getUnsafe(0))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The declaration checked, with the default among the offered languages. A mistake is the
|
|
26
|
+
deployment's own and is stated, never repaired silently: a catalogue that is quietly not
|
|
27
|
+
served reads as a translation that does nothing. */
|
|
28
|
+
let validate = (i18n: ReventlessInfra.Platform.i18n): result<
|
|
29
|
+
ReventlessInfra.Platform.i18n,
|
|
30
|
+
string,
|
|
31
|
+
> =>
|
|
32
|
+
switch Array.concat([i18n.default], i18n.offered)->Array.filter(t => !isTag(t)) {
|
|
33
|
+
| [] =>
|
|
34
|
+
switch i18n.register {
|
|
35
|
+
| Some(r) if r != "Sie" && r != "du" =>
|
|
36
|
+
Error(`i18n: register must be "Sie" or "du", got "${r}"`)
|
|
37
|
+
| _ =>
|
|
38
|
+
Ok({
|
|
39
|
+
...i18n,
|
|
40
|
+
offered: i18n.offered->Array.includes(i18n.default)
|
|
41
|
+
? i18n.offered
|
|
42
|
+
: Array.concat([i18n.default], i18n.offered),
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
| bad => Error(`i18n: not a language tag: ${bad->Array.join(", ")}`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `config.json`'s `languages`, in the shape the shell reads. */
|
|
49
|
+
let configEntry = (i18n: ReventlessInfra.Platform.i18n): (string, JSON.t) => {
|
|
50
|
+
let fields = dict{
|
|
51
|
+
"default": JSON.Encode.string(i18n.default),
|
|
52
|
+
"offered": i18n.offered->Array.map(JSON.Encode.string)->JSON.Encode.array,
|
|
53
|
+
}
|
|
54
|
+
i18n.register->Option.forEach(r => fields->Dict.set("register", JSON.Encode.string(r)))
|
|
55
|
+
(configKey, JSON.Encode.object(fields))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A source's catalogue for a language, as text: `None` where the source has no file for it. */
|
|
59
|
+
type read = (~dir: string, ~language: string) => option<string>
|
|
60
|
+
|
|
61
|
+
/** One language's merged catalogue as written: keys sorted, two-space indent, a final newline. */
|
|
62
|
+
let merged = (i18n: ReventlessInfra.Platform.i18n, ~language: string, ~read: read): result<
|
|
63
|
+
string,
|
|
64
|
+
string,
|
|
65
|
+
> => {
|
|
66
|
+
let out = Dict.make()
|
|
67
|
+
let problem = i18n.sources->Array.findMap(dir =>
|
|
68
|
+
switch read(~dir, ~language) {
|
|
69
|
+
| None => None
|
|
70
|
+
| Some(text) =>
|
|
71
|
+
switch text->JSON.parseOrThrow->JSON.Decode.object {
|
|
72
|
+
| Some(entries) =>
|
|
73
|
+
entries->Dict.forEachWithKey((value, key) =>
|
|
74
|
+
value->JSON.Decode.string->Option.forEach(s => out->Dict.set(key, JSON.Encode.string(s)))
|
|
75
|
+
)
|
|
76
|
+
None
|
|
77
|
+
| None => Some(`i18n: ${dir}/${language}.json is not a JSON object`)
|
|
78
|
+
| exception _ => Some(`i18n: ${dir}/${language}.json is not JSON`)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
switch problem {
|
|
83
|
+
| Some(message) => Error(message)
|
|
84
|
+
| None =>
|
|
85
|
+
Ok(
|
|
86
|
+
JSON.stringify(
|
|
87
|
+
out
|
|
88
|
+
->Dict.toArray
|
|
89
|
+
->Array.toSorted(((a, _), (b, _)) => String.compare(a, b))
|
|
90
|
+
->Dict.fromArray
|
|
91
|
+
->JSON.Encode.object,
|
|
92
|
+
~space=2,
|
|
93
|
+
) ++ "\n",
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
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
|
+
|
|
157
|
+
/** Every offered language's merged catalogue, as `(file name, text)`, or the first mistake. */
|
|
158
|
+
let files = (i18n: ReventlessInfra.Platform.i18n, ~read: read): result<
|
|
159
|
+
array<(string, string)>,
|
|
160
|
+
string,
|
|
161
|
+
> =>
|
|
162
|
+
validate(i18n)->Result.flatMap(i18n =>
|
|
163
|
+
i18n.offered->Array.reduce(Ok([]), (acc, language) =>
|
|
164
|
+
acc->Result.flatMap(
|
|
165
|
+
done =>
|
|
166
|
+
merged(i18n, ~language, ~read)->Result.map(
|
|
167
|
+
text => Array.concat(done, [(fileName(language), text)]),
|
|
168
|
+
),
|
|
169
|
+
)
|
|
170
|
+
)
|
|
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
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Nodefs from "node:fs";
|
|
4
|
+
import * as Nodepath from "node:path";
|
|
5
|
+
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
6
|
+
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
7
|
+
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
8
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
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";
|
|
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";
|
|
13
|
+
|
|
14
|
+
let configKey = "languages";
|
|
15
|
+
|
|
16
|
+
function fileName(language) {
|
|
17
|
+
return `i18n/` + language + `.json`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isTag(tag) {
|
|
21
|
+
let parts = tag.split("-");
|
|
22
|
+
if (parts.length !== 0 && parts.every(p => /^[A-Za-z0-9]{1,8}$/.test(p))) {
|
|
23
|
+
return /^[A-Za-z]{2,3}$/.test(parts[0]);
|
|
24
|
+
} else {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function validate(i18n) {
|
|
30
|
+
let bad = [i18n.default].concat(i18n.offered).filter(t => !isTag(t));
|
|
31
|
+
if (bad.length !== 0) {
|
|
32
|
+
return {
|
|
33
|
+
TAG: "Error",
|
|
34
|
+
_0: `i18n: not a language tag: ` + bad.join(", ")
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
let r = i18n.register;
|
|
38
|
+
if (r !== undefined && r !== "Sie" && r !== "du") {
|
|
39
|
+
return {
|
|
40
|
+
TAG: "Error",
|
|
41
|
+
_0: `i18n: register must be "Sie" or "du", got "` + r + `"`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
let newrecord = {...i18n};
|
|
45
|
+
return {
|
|
46
|
+
TAG: "Ok",
|
|
47
|
+
_0: (newrecord.offered = i18n.offered.includes(i18n.default) ? i18n.offered : [i18n.default].concat(i18n.offered), newrecord)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function configEntry(i18n) {
|
|
52
|
+
let fields = {
|
|
53
|
+
default: i18n.default,
|
|
54
|
+
offered: i18n.offered.map(prim => prim)
|
|
55
|
+
};
|
|
56
|
+
Stdlib_Option.forEach(i18n.register, r => {
|
|
57
|
+
fields["register"] = r;
|
|
58
|
+
});
|
|
59
|
+
return [
|
|
60
|
+
configKey,
|
|
61
|
+
fields
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function merged(i18n, language, read) {
|
|
66
|
+
let out = {};
|
|
67
|
+
let problem = Stdlib_Array.findMap(i18n.sources, dir => {
|
|
68
|
+
let text = read(dir, language);
|
|
69
|
+
if (text === undefined) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
let entries;
|
|
73
|
+
try {
|
|
74
|
+
entries = Stdlib_JSON.Decode.object(JSON.parse(text));
|
|
75
|
+
} catch (exn) {
|
|
76
|
+
return `i18n: ` + dir + `/` + language + `.json is not JSON`;
|
|
77
|
+
}
|
|
78
|
+
if (entries !== undefined) {
|
|
79
|
+
Stdlib_Dict.forEachWithKey(entries, (value, key) => Stdlib_Option.forEach(Stdlib_JSON.Decode.string(value), s => {
|
|
80
|
+
out[key] = s;
|
|
81
|
+
}));
|
|
82
|
+
return;
|
|
83
|
+
} else {
|
|
84
|
+
return `i18n: ` + dir + `/` + language + `.json is not a JSON object`;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
if (problem !== undefined) {
|
|
88
|
+
return {
|
|
89
|
+
TAG: "Error",
|
|
90
|
+
_0: problem
|
|
91
|
+
};
|
|
92
|
+
} else {
|
|
93
|
+
return {
|
|
94
|
+
TAG: "Ok",
|
|
95
|
+
_0: JSON.stringify(Object.fromEntries(Object.entries(out).toSorted((param, param$1) => Primitive_string.compare(param[0], param$1[0]))), undefined, 2) + "\n"
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
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
|
+
|
|
157
|
+
function files(i18n, read) {
|
|
158
|
+
return Stdlib_Result.flatMap(validate(i18n), i18n => Stdlib_Array.reduce(i18n.offered, {
|
|
159
|
+
TAG: "Ok",
|
|
160
|
+
_0: []
|
|
161
|
+
}, (acc, language) => Stdlib_Result.flatMap(acc, done => Stdlib_Result.map(merged(i18n, language, read), text => done.concat([[
|
|
162
|
+
fileName(language),
|
|
163
|
+
text
|
|
164
|
+
]])))));
|
|
165
|
+
}
|
|
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
|
+
|
|
246
|
+
export {
|
|
247
|
+
configKey,
|
|
248
|
+
fileName,
|
|
249
|
+
isTag,
|
|
250
|
+
validate,
|
|
251
|
+
configEntry,
|
|
252
|
+
merged,
|
|
253
|
+
filesIn,
|
|
254
|
+
sourceName,
|
|
255
|
+
gate,
|
|
256
|
+
files,
|
|
257
|
+
parseCatalogue,
|
|
258
|
+
offeredFor,
|
|
259
|
+
text,
|
|
260
|
+
languagesJson,
|
|
261
|
+
languagesOfJson,
|
|
262
|
+
}
|
|
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)>) =>
|