@aidc-toolkit/app-extension 1.0.33-beta → 1.0.35-beta

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.
Files changed (162) hide show
  1. package/README.md +1 -5
  2. package/dist/app-extension.d.ts +194 -0
  3. package/dist/app-extension.d.ts.map +1 -0
  4. package/dist/app-extension.js +133 -0
  5. package/dist/app-extension.js.map +1 -0
  6. package/dist/app-helper-proxy.d.ts +61 -0
  7. package/dist/app-helper-proxy.d.ts.map +1 -0
  8. package/dist/app-helper-proxy.js +332 -0
  9. package/dist/app-helper-proxy.js.map +1 -0
  10. package/dist/descriptor.d.ts +189 -0
  11. package/dist/descriptor.d.ts.map +1 -0
  12. package/dist/descriptor.js +44 -0
  13. package/dist/descriptor.js.map +1 -0
  14. package/dist/generator/generator.d.ts +117 -0
  15. package/dist/generator/generator.d.ts.map +1 -0
  16. package/dist/generator/generator.js +187 -0
  17. package/dist/generator/generator.js.map +1 -0
  18. package/dist/generator/index.d.ts +2 -0
  19. package/dist/generator/index.d.ts.map +1 -0
  20. package/dist/generator/index.js +2 -0
  21. package/dist/generator/index.js.map +1 -0
  22. package/dist/generator/locale-resources-generator.d.ts +2 -0
  23. package/dist/generator/locale-resources-generator.d.ts.map +1 -0
  24. package/dist/generator/locale-resources-generator.js +311 -0
  25. package/dist/generator/locale-resources-generator.js.map +1 -0
  26. package/dist/gs1/character-set-proxy.d.ts +13 -0
  27. package/dist/gs1/character-set-proxy.d.ts.map +1 -0
  28. package/dist/gs1/character-set-proxy.js +126 -0
  29. package/dist/gs1/character-set-proxy.js.map +1 -0
  30. package/dist/gs1/check-proxy.d.ts +11 -0
  31. package/dist/gs1/check-proxy.d.ts.map +1 -0
  32. package/dist/gs1/check-proxy.js +163 -0
  33. package/dist/gs1/check-proxy.js.map +1 -0
  34. package/dist/gs1/gtin-creator-proxy.d.ts +10 -0
  35. package/dist/gs1/gtin-creator-proxy.d.ts.map +1 -0
  36. package/dist/gs1/gtin-creator-proxy.js +85 -0
  37. package/dist/gs1/gtin-creator-proxy.js.map +1 -0
  38. package/dist/gs1/gtin-descriptor.d.ts +3 -0
  39. package/dist/gs1/gtin-descriptor.d.ts.map +1 -0
  40. package/dist/gs1/gtin-descriptor.js +8 -0
  41. package/dist/gs1/gtin-descriptor.js.map +1 -0
  42. package/dist/gs1/gtin-validator-proxy.d.ts +26 -0
  43. package/dist/gs1/gtin-validator-proxy.d.ts.map +1 -0
  44. package/dist/gs1/gtin-validator-proxy.js +256 -0
  45. package/dist/gs1/gtin-validator-proxy.js.map +1 -0
  46. package/dist/gs1/identifier-creator-proxy.d.ts +30 -0
  47. package/dist/gs1/identifier-creator-proxy.d.ts.map +1 -0
  48. package/dist/gs1/identifier-creator-proxy.js +302 -0
  49. package/dist/gs1/identifier-creator-proxy.js.map +1 -0
  50. package/dist/gs1/identifier-descriptor.d.ts +4 -0
  51. package/dist/gs1/identifier-descriptor.d.ts.map +1 -0
  52. package/dist/gs1/identifier-descriptor.js +14 -0
  53. package/dist/gs1/identifier-descriptor.js.map +1 -0
  54. package/dist/gs1/identifier-type.d.ts +22 -0
  55. package/dist/gs1/identifier-type.d.ts.map +1 -0
  56. package/dist/gs1/identifier-type.js +34 -0
  57. package/dist/gs1/identifier-type.js.map +1 -0
  58. package/dist/gs1/identifier-validator-proxy.d.ts +29 -0
  59. package/dist/gs1/identifier-validator-proxy.d.ts.map +1 -0
  60. package/dist/gs1/identifier-validator-proxy.js +212 -0
  61. package/dist/gs1/identifier-validator-proxy.js.map +1 -0
  62. package/dist/gs1/index.d.ts +10 -0
  63. package/dist/gs1/index.d.ts.map +1 -0
  64. package/dist/gs1/index.js +10 -0
  65. package/dist/gs1/index.js.map +1 -0
  66. package/dist/gs1/non-gtin-creator-proxy.d.ts +38 -0
  67. package/dist/gs1/non-gtin-creator-proxy.d.ts.map +1 -0
  68. package/dist/gs1/non-gtin-creator-proxy.js +301 -0
  69. package/dist/gs1/non-gtin-creator-proxy.js.map +1 -0
  70. package/dist/gs1/non-gtin-validator-proxy.d.ts +37 -0
  71. package/dist/gs1/non-gtin-validator-proxy.d.ts.map +1 -0
  72. package/dist/gs1/non-gtin-validator-proxy.js +302 -0
  73. package/dist/gs1/non-gtin-validator-proxy.js.map +1 -0
  74. package/dist/gs1/prefix-definition-descriptor.d.ts +4 -0
  75. package/dist/gs1/prefix-definition-descriptor.d.ts.map +1 -0
  76. package/dist/gs1/prefix-definition-descriptor.js +16 -0
  77. package/dist/gs1/prefix-definition-descriptor.js.map +1 -0
  78. package/dist/gs1/prefix-manager-proxy.d.ts +14 -0
  79. package/dist/gs1/prefix-manager-proxy.d.ts.map +1 -0
  80. package/dist/gs1/prefix-manager-proxy.js +213 -0
  81. package/dist/gs1/prefix-manager-proxy.js.map +1 -0
  82. package/dist/gs1/service-proxy.d.ts +7 -0
  83. package/dist/gs1/service-proxy.d.ts.map +1 -0
  84. package/dist/gs1/service-proxy.js +105 -0
  85. package/dist/gs1/service-proxy.js.map +1 -0
  86. package/dist/gs1/variable-measure-proxy.d.ts +7 -0
  87. package/dist/gs1/variable-measure-proxy.d.ts.map +1 -0
  88. package/dist/gs1/variable-measure-proxy.js +114 -0
  89. package/dist/gs1/variable-measure-proxy.js.map +1 -0
  90. package/dist/index.d.ts +28 -1865
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +11 -2
  93. package/dist/index.js.map +1 -0
  94. package/dist/lib-proxy.d.ts +135 -0
  95. package/dist/lib-proxy.d.ts.map +1 -0
  96. package/dist/lib-proxy.js +276 -0
  97. package/dist/lib-proxy.js.map +1 -0
  98. package/dist/locale/en/locale-resources.d.ts +752 -0
  99. package/dist/locale/en/locale-resources.d.ts.map +1 -0
  100. package/dist/locale/en/locale-resources.js +751 -0
  101. package/dist/locale/en/locale-resources.js.map +1 -0
  102. package/dist/locale/fr/locale-resources.d.ts +752 -0
  103. package/dist/locale/fr/locale-resources.d.ts.map +1 -0
  104. package/dist/locale/fr/locale-resources.js +751 -0
  105. package/dist/locale/fr/locale-resources.js.map +1 -0
  106. package/dist/locale/i18n.d.ts +27 -0
  107. package/dist/locale/i18n.d.ts.map +1 -0
  108. package/dist/locale/i18n.js +36 -0
  109. package/dist/locale/i18n.js.map +1 -0
  110. package/dist/proxy.d.ts +136 -0
  111. package/dist/proxy.d.ts.map +1 -0
  112. package/dist/proxy.js +295 -0
  113. package/dist/proxy.js.map +1 -0
  114. package/dist/streaming.d.ts +10 -0
  115. package/dist/streaming.d.ts.map +1 -0
  116. package/dist/streaming.js +2 -0
  117. package/dist/streaming.js.map +1 -0
  118. package/dist/type.d.ts +91 -0
  119. package/dist/type.d.ts.map +1 -0
  120. package/dist/type.js +2 -0
  121. package/dist/type.js.map +1 -0
  122. package/dist/utility/character-set-descriptor.d.ts +6 -0
  123. package/dist/utility/character-set-descriptor.d.ts.map +1 -0
  124. package/dist/utility/character-set-descriptor.js +28 -0
  125. package/dist/utility/character-set-descriptor.js.map +1 -0
  126. package/dist/utility/character-set-proxy.d.ts +31 -0
  127. package/dist/utility/character-set-proxy.d.ts.map +1 -0
  128. package/dist/utility/character-set-proxy.js +278 -0
  129. package/dist/utility/character-set-proxy.js.map +1 -0
  130. package/dist/utility/index.d.ts +4 -0
  131. package/dist/utility/index.d.ts.map +1 -0
  132. package/dist/utility/index.js +4 -0
  133. package/dist/utility/index.js.map +1 -0
  134. package/dist/utility/reg-exp-proxy.d.ts +8 -0
  135. package/dist/utility/reg-exp-proxy.d.ts.map +1 -0
  136. package/dist/utility/reg-exp-proxy.js +103 -0
  137. package/dist/utility/reg-exp-proxy.js.map +1 -0
  138. package/dist/utility/string-descriptor.d.ts +4 -0
  139. package/dist/utility/string-descriptor.d.ts.map +1 -0
  140. package/dist/utility/string-descriptor.js +12 -0
  141. package/dist/utility/string-descriptor.js.map +1 -0
  142. package/dist/utility/string-proxy.d.ts +7 -0
  143. package/dist/utility/string-proxy.d.ts.map +1 -0
  144. package/dist/utility/string-proxy.js +63 -0
  145. package/dist/utility/string-proxy.js.map +1 -0
  146. package/dist/utility/transformer-descriptor.d.ts +6 -0
  147. package/dist/utility/transformer-descriptor.d.ts.map +1 -0
  148. package/dist/utility/transformer-descriptor.js +24 -0
  149. package/dist/utility/transformer-descriptor.js.map +1 -0
  150. package/dist/utility/transformer-proxy.d.ts +9 -0
  151. package/dist/utility/transformer-proxy.d.ts.map +1 -0
  152. package/dist/utility/transformer-proxy.js +111 -0
  153. package/dist/utility/transformer-proxy.js.map +1 -0
  154. package/package.json +11 -10
  155. package/src/descriptor.ts +0 -5
  156. package/src/generator/generator.ts +59 -9
  157. package/src/index.ts +2 -1
  158. package/src/proxy.ts +0 -29
  159. package/tsconfig-src.json +7 -1
  160. package/tsconfig-src.tsbuildinfo +1 -0
  161. package/dist/index.cjs +0 -17
  162. package/dist/index.d.cts +0 -1865
@@ -0,0 +1,117 @@
1
+ import { type Promisable } from "@aidc-toolkit/core";
2
+ import type { Logger } from "tslog";
3
+ import type { ClassDescriptor, MethodDescriptor } from "../descriptor.js";
4
+ /**
5
+ * Localization.
6
+ */
7
+ export interface Localization {
8
+ /**
9
+ * Name.
10
+ */
11
+ readonly name: string;
12
+ /**
13
+ * Description.
14
+ */
15
+ readonly description: string;
16
+ }
17
+ /**
18
+ * Function localization.
19
+ */
20
+ export interface FunctionLocalization extends Localization {
21
+ /**
22
+ * Namespace function name.
23
+ */
24
+ readonly namespaceFunctionName: string;
25
+ /**
26
+ * Documentation URL.
27
+ */
28
+ readonly documentationURL: string;
29
+ /**
30
+ * Parameters map.
31
+ */
32
+ readonly parametersMap: ReadonlyMap<string, Localization>;
33
+ }
34
+ /**
35
+ * Abstract generator.
36
+ */
37
+ export declare abstract class Generator {
38
+ #private;
39
+ /**
40
+ * Constructor.
41
+ *
42
+ * @param includeLocalizations
43
+ * Include localizations if true.
44
+ */
45
+ constructor(includeLocalizations?: boolean);
46
+ /**
47
+ * Get the logger.
48
+ */
49
+ get logger(): Logger<object>;
50
+ /**
51
+ * Get the locales.
52
+ */
53
+ protected get locales(): readonly string[];
54
+ /**
55
+ * Get the default locale.
56
+ */
57
+ protected get defaultLocale(): string;
58
+ /**
59
+ * Initialize the generation of the output.
60
+ */
61
+ protected abstract initialize(): void;
62
+ /**
63
+ * Create a namespace.
64
+ *
65
+ * @param namespace
66
+ * Namespace.
67
+ */
68
+ protected abstract createNamespace(namespace: string | undefined): void;
69
+ /**
70
+ * Create a category.
71
+ *
72
+ * @param namespace
73
+ * Namespace.
74
+ *
75
+ * @param category
76
+ * Category.
77
+ *
78
+ * @param categoryLocalizationsMap
79
+ * Category localizations map.
80
+ */
81
+ protected abstract createCategory(namespace: string | undefined, category: string, categoryLocalizationsMap: ReadonlyMap<string, string>): void;
82
+ /**
83
+ * Create a proxy object for a class.
84
+ *
85
+ * @param objectName
86
+ * Object name, derived from namespace and class name.
87
+ *
88
+ * @param classDescriptor
89
+ * Class descriptor.
90
+ */
91
+ protected abstract createProxyObject(objectName: string, classDescriptor: ClassDescriptor): void;
92
+ /**
93
+ * Create a proxy function for a class and method.
94
+ *
95
+ * @param classDescriptor
96
+ * Class descriptor.
97
+ *
98
+ * @param methodDescriptor
99
+ * Method descriptor.
100
+ *
101
+ * @param functionLocalizationsMap
102
+ * Function localizations map.
103
+ */
104
+ protected abstract createProxyFunction(classDescriptor: ClassDescriptor, methodDescriptor: MethodDescriptor, functionLocalizationsMap: ReadonlyMap<string, FunctionLocalization>): void;
105
+ /**
106
+ * Finalize the generation of the output.
107
+ *
108
+ * @param success
109
+ * True if successful.
110
+ */
111
+ protected abstract finalize(success: boolean): Promisable<void>;
112
+ /**
113
+ * Generate by processing individual imports.
114
+ */
115
+ generate(): Promise<void>;
116
+ }
117
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/generator/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8D,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEjH,OAAO,KAAK,EAAE,MA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eAAe,GAAG,IAAI;IAEhG;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,QAAQ,CAAC,mBAAmB,CAAC,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,WAAW,CAAC,MAAM,EAAE,oBAAoB,CAAC,GAAG,IAAI;IAEvL;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC;IA8B/D;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAoHlC"}
@@ -0,0 +1,187 @@
1
+ import { getLogger, I18nEnvironments, LocalAppDataStorage, phaseURL } from "@aidc-toolkit/core";
2
+ import packageConfiguration from "../../package.json" with { type: "json" };
3
+ import { AppHelperProxy } from "../app-helper-proxy.js";
4
+ import * as GS1 from "../gs1/index.js";
5
+ import { appExtensionResourceBundle, i18nAppExtensionInit, i18nextAppExtension } from "../locale/i18n.js";
6
+ import { proxy } from "../proxy.js";
7
+ import * as Utility from "../utility/index.js";
8
+ /**
9
+ * Dummy method to force proxies to register their decorators.
10
+ *
11
+ * @param _proxies
12
+ * Proxies.
13
+ */
14
+ function registerProxies(..._proxies) {
15
+ }
16
+ registerProxies(AppHelperProxy, Utility, GS1);
17
+ /**
18
+ * Configuration directory, expected to be present in all repositories that use the generator.
19
+ */
20
+ const CONFIGURATION_DIRECTORY = "config";
21
+ /**
22
+ * Local resources file, expected to be present in all repositories that use the generator.
23
+ */
24
+ const LOCAL_RESOURCES_KEY = "resources.local";
25
+ /**
26
+ * Abstract generator.
27
+ */
28
+ export class Generator {
29
+ /**
30
+ * Documentation path, optionally preceded by locale.
31
+ */
32
+ static #DOCUMENTATION_PATH = "app-extension/";
33
+ /**
34
+ * Logger.
35
+ */
36
+ #logger = getLogger();
37
+ /**
38
+ * Locales.
39
+ */
40
+ #locales;
41
+ /**
42
+ * Default locale.
43
+ */
44
+ #defaultLocale;
45
+ /**
46
+ * Constructor.
47
+ *
48
+ * @param includeLocalizations
49
+ * Include localizations if true.
50
+ */
51
+ constructor(includeLocalizations = true) {
52
+ this.#locales = includeLocalizations ? Object.keys(appExtensionResourceBundle) : [];
53
+ this.#defaultLocale = this.#locales[0] ?? "";
54
+ }
55
+ /**
56
+ * Get the logger.
57
+ */
58
+ get logger() {
59
+ return this.#logger;
60
+ }
61
+ /**
62
+ * Get the locales.
63
+ */
64
+ get locales() {
65
+ return this.#locales;
66
+ }
67
+ /**
68
+ * Get the default locale.
69
+ */
70
+ get defaultLocale() {
71
+ return this.#defaultLocale;
72
+ }
73
+ /**
74
+ * Generate a localization.
75
+ *
76
+ * @template TLocalization
77
+ * Localization type.
78
+ *
79
+ * @param locale
80
+ * Locale.
81
+ *
82
+ * @param key
83
+ * Key.
84
+ *
85
+ * @param localizationCallback
86
+ * Callback to finalize localization.
87
+ *
88
+ * @returns
89
+ * Localization.
90
+ */
91
+ static #generateLocalization(locale, key, localizationCallback) {
92
+ const lngReturnObjectsOption = {
93
+ lng: locale,
94
+ returnObjects: true
95
+ };
96
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Localized key exists and return type is Localization.
97
+ return localizationCallback(locale, i18nextAppExtension.t(key, lngReturnObjectsOption));
98
+ }
99
+ /**
100
+ * Generate by processing individual imports.
101
+ */
102
+ async generate() {
103
+ let success = false;
104
+ await i18nAppExtensionInit(I18nEnvironments.CLI);
105
+ const baseURL = await LocalAppDataStorage.then(async (LocalAppDataStorage) => new LocalAppDataStorage(CONFIGURATION_DIRECTORY).read(LOCAL_RESOURCES_KEY)).then(resources =>
106
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- File must exist and have this type.
107
+ phaseURL(packageConfiguration.version, resources.alphaURL));
108
+ this.initialize();
109
+ const namespaceHierarchy = new Map();
110
+ // Organize class descriptors by namespace and category.
111
+ for (const classDescriptor of proxy.classDescriptors) {
112
+ const namespace = classDescriptor.namespace;
113
+ const category = classDescriptor.category;
114
+ let categoryHierarchy = namespaceHierarchy.get(namespace);
115
+ if (categoryHierarchy === undefined) {
116
+ categoryHierarchy = new Map();
117
+ namespaceHierarchy.set(namespace, categoryHierarchy);
118
+ }
119
+ let classDescriptors = categoryHierarchy.get(category);
120
+ if (classDescriptors === undefined) {
121
+ classDescriptors = [];
122
+ categoryHierarchy.set(category, classDescriptors);
123
+ }
124
+ classDescriptors.push(classDescriptor);
125
+ }
126
+ try {
127
+ for (const [namespace, categoryHierarchy] of namespaceHierarchy) {
128
+ const namespacePrefix = namespace === undefined ? "" : `${namespace}.`;
129
+ const namespacePath = namespace === undefined ? "" : `${namespace}/`;
130
+ this.createNamespace(namespace);
131
+ for (const [category, classDescriptors] of categoryHierarchy) {
132
+ const namespaceCategory = `${namespacePrefix}${category}`;
133
+ const categoriesKey = `Categories.${category}`;
134
+ const namespaceCategoriesKey = `Categories.${namespaceCategory}`;
135
+ const categoryLocalizationsMap = new Map(this.locales.map((locale) => {
136
+ const lngOption = {
137
+ lng: locale
138
+ };
139
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Localized key exists.
140
+ return [locale, i18nextAppExtension.t((i18nextAppExtension.exists(namespaceCategoriesKey, lngOption) ? namespaceCategoriesKey : categoriesKey), lngOption)];
141
+ }));
142
+ this.createCategory(namespace, category, categoryLocalizationsMap);
143
+ const namespaceClassNamesSet = new Set();
144
+ for (const classDescriptor of classDescriptors) {
145
+ const namespaceClassName = classDescriptor.namespaceClassName;
146
+ if (namespaceClassNamesSet.has(namespaceClassName)) {
147
+ throw new Error(`Duplicate class ${namespaceClassName}`);
148
+ }
149
+ namespaceClassNamesSet.add(namespaceClassName);
150
+ // First capture group is:
151
+ // - one or more uppercase letters followed by zero or more numbers; or
152
+ // - single uppercase letter followed by zero or more characters except uppercase letters or period.
153
+ //
154
+ // Second capture group is:
155
+ // - single uppercase letter followed by zero or more characters except period; or
156
+ // - zero characters (empty string).
157
+ //
158
+ // Third capture group, separated by optional period, is:
159
+ // - single uppercase letter followed by zero or more characters (remainder of string); or
160
+ // - zero characters (empty string).
161
+ const objectNameGroups = /^(?<namespaceFirstWord>[A-Z]+[0-9]*|[A-Z][^A-Z.]*)(?<namespaceRemaining>[A-Z][^.]*|)\.?(?<className>[A-Z].*|)$/u.exec(namespaceClassName)?.groups;
162
+ if (objectNameGroups === undefined) {
163
+ throw new Error(`${namespaceClassName} is not a valid namespace-qualified class name`);
164
+ }
165
+ this.createProxyObject(`${objectNameGroups["namespaceFirstWord"].toLowerCase()}${objectNameGroups["namespaceRemaining"]}${objectNameGroups["className"]}`, classDescriptor);
166
+ for (const methodDescriptor of classDescriptor.methodDescriptors) {
167
+ const functionLocalizationsMap = new Map(this.locales.map(locale => [locale, Generator.#generateLocalization(locale, `Functions.${methodDescriptor.namespaceFunctionName}`, (locale, localization) => ({
168
+ ...localization,
169
+ namespaceFunctionName: `${namespacePrefix}${localization.name}`,
170
+ documentationURL: `${baseURL}/${locale === this.defaultLocale ? "" : `${locale}/`}${Generator.#DOCUMENTATION_PATH}${namespacePath}${localization.name}.html`,
171
+ parametersMap: new Map(methodDescriptor.parameterDescriptors.map(parameterDescriptor =>
172
+ // eslint-disable-next-line max-nested-callbacks -- Callback is empty.
173
+ [parameterDescriptor.name, Generator.#generateLocalization(locale, `Parameters.${parameterDescriptor.name}`, (_locale, localization) => localization)]))
174
+ }))]));
175
+ this.createProxyFunction(classDescriptor, methodDescriptor, functionLocalizationsMap);
176
+ }
177
+ }
178
+ }
179
+ }
180
+ success = true;
181
+ }
182
+ finally {
183
+ await this.finalize(success);
184
+ }
185
+ }
186
+ }
187
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/generator/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,QAAQ,EAAmB,MAAM,oBAAoB,CAAC;AAGjH,OAAO,oBAAoB,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./generator.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=locale-resources-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-resources-generator.d.ts","sourceRoot":"","sources":["../../src/generator/locale-resources-generator.ts"],"names":[],"mappings":""}
@@ -0,0 +1,311 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import { Generator } from "./generator.js";
4
+ /**
5
+ * Locale resources generator.
6
+ */
7
+ class LocaleResourcesGenerator extends Generator {
8
+ /**
9
+ * Locale resources import path.
10
+ */
11
+ static #IMPORT_PATH = "../app-extension/src/locale";
12
+ /**
13
+ * Parameters sequencer.
14
+ */
15
+ #parametersSequencer = {};
16
+ /**
17
+ * Parameters locale resources.
18
+ */
19
+ #parametersLocaleResources = {};
20
+ /**
21
+ * Functions locale resources.
22
+ */
23
+ #functionsLocaleResources = {};
24
+ /**
25
+ * Locale resources.
26
+ */
27
+ #LocaleResources = {
28
+ Parameters: this.#parametersLocaleResources,
29
+ Functions: this.#functionsLocaleResources
30
+ };
31
+ /**
32
+ * Constructor.
33
+ */
34
+ constructor() {
35
+ super(false);
36
+ }
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ initialize() {
41
+ }
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ createNamespace() {
46
+ }
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ createCategory() {
51
+ }
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ createProxyObject() {
56
+ }
57
+ /**
58
+ * Save a parameter descriptor in the appropriate spot in the sequence.
59
+ *
60
+ * @param parameterDescriptor
61
+ * Parameter descriptor.
62
+ *
63
+ * @param isUsed
64
+ * True if parameter descriptor is actually used and not just a base.
65
+ *
66
+ * @returns
67
+ * Parameters sequencer entry.
68
+ */
69
+ #saveParameterSequence(parameterDescriptor, isUsed) {
70
+ let parametersSequencerEntry;
71
+ if (!("extendsDescriptor" in parameterDescriptor)) {
72
+ const parameterName = parameterDescriptor.name;
73
+ // Create entry if it doesn't exist, otherwise pick up where last call left off.
74
+ if (!(parameterName in this.#parametersSequencer)) {
75
+ parametersSequencerEntry = {
76
+ parametersSequencerOrNull: null,
77
+ parameterDescriptor,
78
+ parameterName,
79
+ baseParameterName: parameterName,
80
+ isUsed
81
+ };
82
+ this.#parametersSequencer[parameterName] = parametersSequencerEntry;
83
+ }
84
+ else {
85
+ parametersSequencerEntry = this.#parametersSequencer[parameterName];
86
+ }
87
+ }
88
+ else {
89
+ const baseParametersSequencerEntry = this.#saveParameterSequence(parameterDescriptor.extendsDescriptor, false);
90
+ let parameterName;
91
+ let baseParameterName;
92
+ if (parameterDescriptor.name !== undefined) {
93
+ parameterName = parameterDescriptor.name;
94
+ baseParameterName = baseParametersSequencerEntry.parameterName;
95
+ }
96
+ else {
97
+ parameterName = baseParametersSequencerEntry.parameterName;
98
+ baseParameterName = baseParametersSequencerEntry.baseParameterName;
99
+ }
100
+ if (parameterName !== baseParameterName) {
101
+ // Make sure that base parameters sequencer entry refers to a record type.
102
+ baseParametersSequencerEntry.parametersSequencerOrNull ??= {};
103
+ if (!(parameterName in baseParametersSequencerEntry.parametersSequencerOrNull)) {
104
+ parametersSequencerEntry = {
105
+ parametersSequencerOrNull: null,
106
+ parameterDescriptor,
107
+ parameterName,
108
+ baseParameterName,
109
+ isUsed
110
+ };
111
+ baseParametersSequencerEntry.parametersSequencerOrNull[parameterName] = parametersSequencerEntry;
112
+ }
113
+ else {
114
+ parametersSequencerEntry = baseParametersSequencerEntry.parametersSequencerOrNull[parameterName];
115
+ }
116
+ }
117
+ else {
118
+ // If name is the same, which means that parameter descriptor modified type information only.
119
+ parametersSequencerEntry = baseParametersSequencerEntry;
120
+ }
121
+ }
122
+ return parametersSequencerEntry;
123
+ }
124
+ /**
125
+ * @inheritDoc
126
+ */
127
+ createProxyFunction(classDescriptor, methodDescriptor) {
128
+ // Hidden functions aren't localized.
129
+ if (!(methodDescriptor.isHidden ?? false)) {
130
+ // Add any parameters that are not already known.
131
+ for (const parameterDescriptor of methodDescriptor.parameterDescriptors) {
132
+ this.#saveParameterSequence(parameterDescriptor, true);
133
+ }
134
+ let functionsLocaleResources = this.#functionsLocaleResources;
135
+ const namespace = classDescriptor.namespace;
136
+ if (namespace !== undefined) {
137
+ if (!(namespace in functionsLocaleResources)) {
138
+ const namespaceFunctionsLocaleResources = {};
139
+ // Add namespace and navigate to it.
140
+ functionsLocaleResources[namespace] = namespaceFunctionsLocaleResources;
141
+ functionsLocaleResources = namespaceFunctionsLocaleResources;
142
+ }
143
+ else {
144
+ // Navigate to namespace.
145
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Entry is never a string.
146
+ functionsLocaleResources = functionsLocaleResources[namespace];
147
+ }
148
+ }
149
+ const functionName = methodDescriptor.functionName;
150
+ if (functionName in functionsLocaleResources) {
151
+ throw new Error(`Duplicate function ${functionName}`);
152
+ }
153
+ // Add function.
154
+ functionsLocaleResources[functionName] = {
155
+ name: functionName,
156
+ description: "*** LOCALIZATION REQUIRED ***"
157
+ };
158
+ }
159
+ }
160
+ /**
161
+ * Merge source locale resources into existing destination locale resources.
162
+ *
163
+ * @param logChanges
164
+ * If true, changes are logged. Limits output when processing multiple sources.
165
+ *
166
+ * @param parentKey
167
+ * Parent key for logging purposes.
168
+ *
169
+ * @param sourceLocaleResources
170
+ * Source locale resources.
171
+ *
172
+ * @param destinationLocaleResources
173
+ * Destination locale resources.
174
+ *
175
+ * @param addMissing
176
+ * Add missing if true; applies to locale resources that are not regional.
177
+ *
178
+ * @returns
179
+ * Merged locale resources.
180
+ */
181
+ #merge(logChanges, parentKey, sourceLocaleResources, destinationLocaleResources, addMissing) {
182
+ // Some entries at the top are not part of the generator output.
183
+ const deleteMissing = parentKey.length !== 0;
184
+ const newDestinationLocaleResources = {};
185
+ // Copy over or delete any destination keys that are not in source.
186
+ for (const [key, destinationValue] of Object.entries(destinationLocaleResources)) {
187
+ if (!(key in sourceLocaleResources)) {
188
+ if (!deleteMissing) {
189
+ newDestinationLocaleResources[key] = destinationValue;
190
+ }
191
+ else if (logChanges) {
192
+ this.logger.info(`Deleting ${parentKey}${key}...`);
193
+ }
194
+ }
195
+ }
196
+ for (const [key, sourceValue] of Object.entries(sourceLocaleResources)) {
197
+ if (!(key in destinationLocaleResources)) {
198
+ if (addMissing) {
199
+ if (logChanges) {
200
+ this.logger.info(`Adding ${parentKey}${key}...`);
201
+ }
202
+ newDestinationLocaleResources[key] = sourceValue;
203
+ }
204
+ }
205
+ else {
206
+ const destinationValue = destinationLocaleResources[key];
207
+ if (typeof sourceValue === "object" && typeof destinationValue === "object") {
208
+ newDestinationLocaleResources[key] = this.#merge(logChanges, `${parentKey}${key}.`, sourceValue, destinationValue, addMissing);
209
+ }
210
+ else if (typeof sourceValue === "string" && typeof destinationValue === "string") {
211
+ newDestinationLocaleResources[key] = destinationValue;
212
+ }
213
+ else {
214
+ throw new Error(`Mismatched types at ${parentKey}${key}`);
215
+ }
216
+ }
217
+ }
218
+ return newDestinationLocaleResources;
219
+ }
220
+ /**
221
+ * Build parameters locale resources by going through parameters sequencer.
222
+ *
223
+ * @param parametersSequencer
224
+ * Parameters sequencer.
225
+ */
226
+ #buildParametersLocaleResources(parametersSequencer) {
227
+ const entries = Object.entries(parametersSequencer);
228
+ // Sort the entries as defined by the descriptors.
229
+ entries.sort((entry1, entry2) => {
230
+ let result;
231
+ const parameterDescriptor1 = entry1[1].parameterDescriptor;
232
+ const parameterDescriptor2 = entry2[1].parameterDescriptor;
233
+ if ("sortOrder" in parameterDescriptor1) {
234
+ if ("sortOrder" in parameterDescriptor2) {
235
+ result = parameterDescriptor1.sortOrder - parameterDescriptor2.sortOrder;
236
+ }
237
+ else {
238
+ // Parameter descriptors with undefined sort order to go the end.
239
+ result = -parameterDescriptor1.sortOrder;
240
+ }
241
+ }
242
+ else {
243
+ // eslint-disable-next-line no-lonely-if -- Matches structure in "then" clause.
244
+ if ("sortOrder" in parameterDescriptor2) {
245
+ // Parameter descriptors with undefined sort order to go the end.
246
+ result = parameterDescriptor2.sortOrder;
247
+ }
248
+ else {
249
+ result = 0;
250
+ }
251
+ }
252
+ return result;
253
+ });
254
+ for (const [parameterName, parametersSequencerEntry] of entries) {
255
+ if (parametersSequencerEntry.isUsed) {
256
+ this.#parametersLocaleResources[parameterName] = {
257
+ name: parameterName,
258
+ description: "*** LOCALIZATION REQUIRED ***"
259
+ };
260
+ }
261
+ if (parametersSequencerEntry.parametersSequencerOrNull !== null) {
262
+ this.#buildParametersLocaleResources(parametersSequencerEntry.parametersSequencerOrNull);
263
+ }
264
+ }
265
+ }
266
+ /**
267
+ * Build output to be written back to source file.
268
+ *
269
+ * @param prefix
270
+ * Line prefix.
271
+ *
272
+ * @param value
273
+ * Line value.
274
+ *
275
+ * @param indentLevel
276
+ * Indent level.
277
+ *
278
+ * @returns
279
+ * Output string.
280
+ */
281
+ static #buildOutput(prefix, value, indentLevel) {
282
+ return `${" ".repeat(indentLevel)}${prefix} ${typeof value === "object" ?
283
+ `{\n${Object.entries(value).map(entry => LocaleResourcesGenerator.#buildOutput(`${entry[0]}:`, entry[1], indentLevel + 1)).join(",\n")}\n${" ".repeat(indentLevel)}}` :
284
+ // JSON.stringify() will apply quotes as appropriate.
285
+ JSON.stringify(value)}`;
286
+ }
287
+ /**
288
+ * @inheritDoc
289
+ */
290
+ async finalize(success) {
291
+ if (success) {
292
+ this.#buildParametersLocaleResources(this.#parametersSequencer);
293
+ await Promise.all(fs.readdirSync(LocaleResourcesGenerator.#IMPORT_PATH, {
294
+ withFileTypes: true
295
+ }).filter(entry => entry.isDirectory()).map(async (entry) => {
296
+ const localeResourcesSource = path.resolve(LocaleResourcesGenerator.#IMPORT_PATH, entry.name, "locale-resources.ts");
297
+ return import(localeResourcesSource).then((module) => {
298
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Module format is known.
299
+ const localeResources = this.#merge(entry.name === "en", "", this.#LocaleResources, module.default, !entry.name.includes("-"));
300
+ fs.writeFileSync(localeResourcesSource, `${LocaleResourcesGenerator.#buildOutput("export default", localeResources, 0)};\n`);
301
+ });
302
+ }));
303
+ }
304
+ }
305
+ }
306
+ const generator = new LocaleResourcesGenerator();
307
+ generator.generate().catch((e) => {
308
+ generator.logger.error(e);
309
+ process.exit(1);
310
+ });
311
+ //# sourceMappingURL=locale-resources-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-resources-generator.js","sourceRoot":"","sources":["../../src/generator/locale-resources-generator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAOlC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA+C3C;;GAEG;AACH,MAAM,wBAAyB,SAAQ,SAAS;IAC5C;;OAEG;IACH,MAAM,CAAU,YAAY,GAAG,6BAA6B,CAAC;IAE7D;;OAEG;IACM,oBAAoB,GAAwB,EAAE,CAAC;IAExD;;OAEG;IACM,0BAA0B,GAAoB,EAAE,CAAC;IAE1D;;OAEG;IACM,yBAAyB,GAAoB,EAAE,CAAC;IAEzD;;OAEG;IACM,gBAAgB,GAAoB;QACzC,UAAU,EAAE,IAAI,CAAC,0BAA0B;QAC3C,SAAS,EAAE,IAAI,CAAC,yBAAyB;KAC5C,CAAC;IAEF;;OAEG;IACH;QACI,KAAK,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAED;;OAEG;IACgB,UAAU;IAC7B,CAAC;IAED;;OAEG;IACgB,eAAe;IA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