@reventlessdev/reventless-core 3.0.0-alpha.335 → 3.0.0-alpha.336

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,13 @@
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.336 (2026-11-09)
7
+
8
+ ### Features
9
+
10
+ * **core:** a deployment serves its catalogues beside config.json ([299f6eb](https://github.com/ReventlessDev/reventless-core/commit/299f6eb50fdcb8ae2fdd76a32cfc264004088075))
11
+
12
+
6
13
  # 3.0.0-alpha.335 (2026-11-08)
7
14
 
8
15
  * 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.335",
3
+ "version": "3.0.0-alpha.336",
4
4
  "description": "Core package for Reventless framework",
5
5
  "license": "Apache-2.0",
6
6
  "jest": {
@@ -29,16 +29,16 @@
29
29
  "sury": "11.1.0",
30
30
  "uuid": "^13.0.0",
31
31
  "@reventlessdev/rescript-effect": "1.0.0-alpha.3",
32
+ "@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
32
33
  "@reventlessdev/rescript-fast-csv": "2.0.0-alpha.26",
33
- "@reventlessdev/rescript-jest": "1.0.0-alpha.13",
34
34
  "@reventlessdev/rescript-node": "2.0.0-alpha.26",
35
- "@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
35
+ "@reventlessdev/rescript-jest": "1.0.0-alpha.13",
36
36
  "@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
37
- "@reventlessdev/rescript-ssh2": "2.0.0-alpha.27",
38
37
  "@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
39
38
  "@reventlessdev/reventless-interop": "3.0.0-alpha.43",
40
- "@reventlessdev/reventless-spec": "3.0.0-alpha.197",
41
- "@reventlessdev/reventless-infra": "3.0.0-alpha.228"
39
+ "@reventlessdev/rescript-ssh2": "2.0.0-alpha.27",
40
+ "@reventlessdev/reventless-infra": "3.0.0-alpha.229",
41
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.198"
42
42
  },
43
43
  "devDependencies": {
44
44
  "rescript": "12.3.1",
@@ -0,0 +1,112 @@
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
+ /** Every offered language's merged catalogue, as `(file name, text)`, or the first mistake. */
99
+ let files = (i18n: ReventlessInfra.Platform.i18n, ~read: read): result<
100
+ array<(string, string)>,
101
+ string,
102
+ > =>
103
+ validate(i18n)->Result.flatMap(i18n =>
104
+ i18n.offered->Array.reduce(Ok([]), (acc, language) =>
105
+ acc->Result.flatMap(
106
+ done =>
107
+ merged(i18n, ~language, ~read)->Result.map(
108
+ text => Array.concat(done, [(fileName(language), text)]),
109
+ ),
110
+ )
111
+ )
112
+ )
@@ -0,0 +1,115 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
4
+ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
5
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
6
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
7
+ import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
8
+ import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
9
+
10
+ let configKey = "languages";
11
+
12
+ function fileName(language) {
13
+ return `i18n/` + language + `.json`;
14
+ }
15
+
16
+ function isTag(tag) {
17
+ let parts = tag.split("-");
18
+ if (parts.length !== 0 && parts.every(p => /^[A-Za-z0-9]{1,8}$/.test(p))) {
19
+ return /^[A-Za-z]{2,3}$/.test(parts[0]);
20
+ } else {
21
+ return false;
22
+ }
23
+ }
24
+
25
+ function validate(i18n) {
26
+ let bad = [i18n.default].concat(i18n.offered).filter(t => !isTag(t));
27
+ if (bad.length !== 0) {
28
+ return {
29
+ TAG: "Error",
30
+ _0: `i18n: not a language tag: ` + bad.join(", ")
31
+ };
32
+ }
33
+ let r = i18n.register;
34
+ if (r !== undefined && r !== "Sie" && r !== "du") {
35
+ return {
36
+ TAG: "Error",
37
+ _0: `i18n: register must be "Sie" or "du", got "` + r + `"`
38
+ };
39
+ }
40
+ let newrecord = {...i18n};
41
+ return {
42
+ TAG: "Ok",
43
+ _0: (newrecord.offered = i18n.offered.includes(i18n.default) ? i18n.offered : [i18n.default].concat(i18n.offered), newrecord)
44
+ };
45
+ }
46
+
47
+ function configEntry(i18n) {
48
+ let fields = {
49
+ default: i18n.default,
50
+ offered: i18n.offered.map(prim => prim)
51
+ };
52
+ Stdlib_Option.forEach(i18n.register, r => {
53
+ fields["register"] = r;
54
+ });
55
+ return [
56
+ configKey,
57
+ fields
58
+ ];
59
+ }
60
+
61
+ function merged(i18n, language, read) {
62
+ let out = {};
63
+ let problem = Stdlib_Array.findMap(i18n.sources, dir => {
64
+ let text = read(dir, language);
65
+ if (text === undefined) {
66
+ return;
67
+ }
68
+ let entries;
69
+ try {
70
+ entries = Stdlib_JSON.Decode.object(JSON.parse(text));
71
+ } catch (exn) {
72
+ return `i18n: ` + dir + `/` + language + `.json is not JSON`;
73
+ }
74
+ if (entries !== undefined) {
75
+ Stdlib_Dict.forEachWithKey(entries, (value, key) => Stdlib_Option.forEach(Stdlib_JSON.Decode.string(value), s => {
76
+ out[key] = s;
77
+ }));
78
+ return;
79
+ } else {
80
+ return `i18n: ` + dir + `/` + language + `.json is not a JSON object`;
81
+ }
82
+ });
83
+ if (problem !== undefined) {
84
+ return {
85
+ TAG: "Error",
86
+ _0: problem
87
+ };
88
+ } else {
89
+ return {
90
+ TAG: "Ok",
91
+ _0: JSON.stringify(Object.fromEntries(Object.entries(out).toSorted((param, param$1) => Primitive_string.compare(param[0], param$1[0]))), undefined, 2) + "\n"
92
+ };
93
+ }
94
+ }
95
+
96
+ function files(i18n, read) {
97
+ return Stdlib_Result.flatMap(validate(i18n), i18n => Stdlib_Array.reduce(i18n.offered, {
98
+ TAG: "Ok",
99
+ _0: []
100
+ }, (acc, language) => Stdlib_Result.flatMap(acc, done => Stdlib_Result.map(merged(i18n, language, read), text => done.concat([[
101
+ fileName(language),
102
+ text
103
+ ]])))));
104
+ }
105
+
106
+ export {
107
+ configKey,
108
+ fileName,
109
+ isTag,
110
+ validate,
111
+ configEntry,
112
+ merged,
113
+ files,
114
+ }
115
+ /* No side effect */