@aidc-toolkit/app-extension 1.0.31-beta → 1.0.33-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.
- package/dist/index.cjs +1 -3709
- package/dist/index.d.cts +607 -333
- package/dist/index.d.ts +607 -333
- package/dist/index.js +1 -3683
- package/package.json +12 -13
- package/src/app-extension.ts +141 -93
- package/src/app-helper-proxy.ts +326 -0
- package/src/descriptor.ts +75 -7
- package/src/generator/generator.ts +118 -96
- package/src/generator/locale-resources-generator.ts +56 -42
- package/src/gs1/character-set-proxy.ts +8 -8
- package/src/gs1/check-proxy.ts +26 -25
- package/src/gs1/gtin-creator-proxy.ts +14 -28
- package/src/gs1/gtin-descriptor.ts +2 -23
- package/src/gs1/gtin-validator-proxy.ts +45 -48
- package/src/gs1/identifier-creator-proxy.ts +63 -53
- package/src/gs1/identifier-descriptor.ts +15 -0
- package/src/gs1/identifier-type.ts +37 -0
- package/src/gs1/identifier-validator-proxy.ts +59 -27
- package/src/gs1/index.ts +8 -0
- package/src/gs1/non-gtin-creator-proxy.ts +22 -33
- package/src/gs1/non-gtin-validator-proxy.ts +22 -33
- package/src/gs1/prefix-definition-descriptor.ts +2 -2
- package/src/gs1/prefix-manager-proxy.ts +164 -9
- package/src/gs1/service-proxy.ts +57 -0
- package/src/gs1/variable-measure-proxy.ts +62 -0
- package/src/index.ts +6 -1
- package/src/lib-proxy.ts +112 -70
- package/src/locale/en/locale-resources.ts +173 -47
- package/src/locale/fr/locale-resources.ts +173 -47
- package/src/locale/i18n.ts +8 -10
- package/src/locale/i18next.d.ts +2 -0
- package/src/proxy.ts +140 -140
- package/src/streaming.ts +13 -0
- package/src/type.ts +8 -7
- package/src/utility/character-set-descriptor.ts +2 -2
- package/src/utility/character-set-proxy.ts +39 -38
- package/src/utility/reg-exp-proxy.ts +12 -11
- package/src/utility/string-descriptor.ts +2 -2
- package/src/utility/string-proxy.ts +7 -7
- package/src/utility/transformer-descriptor.ts +5 -5
- package/src/utility/transformer-proxy.ts +25 -18
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/src/app-utility-proxy.ts +0 -273
package/src/descriptor.ts
CHANGED
|
@@ -43,6 +43,42 @@ export type TypeKey = keyof typeof Types;
|
|
|
43
43
|
*/
|
|
44
44
|
export type Type = typeof Types[TypeKey];
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Multiplicities supported by proxy methods.
|
|
48
|
+
*/
|
|
49
|
+
export const Multiplicities = {
|
|
50
|
+
/**
|
|
51
|
+
* Parameter or return value is a singleton.
|
|
52
|
+
*/
|
|
53
|
+
Singleton: 0,
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Parameter or return value is a singleton or an array.
|
|
57
|
+
*/
|
|
58
|
+
Array: 1,
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Parameter or return value is a singleton, an array, or a matrix.
|
|
62
|
+
*/
|
|
63
|
+
Matrix: 2,
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Parameter value is a singleton or array but is treated as a singleton internally and doesn't drive multiplicity
|
|
67
|
+
* of the return value. Return value is an array for use as a singleton array parameter.
|
|
68
|
+
*/
|
|
69
|
+
SingletonArray: 3
|
|
70
|
+
} as const;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Multiplicity key.
|
|
74
|
+
*/
|
|
75
|
+
export type MultiplicityKey = keyof typeof Multiplicities;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Multiplicity.
|
|
79
|
+
*/
|
|
80
|
+
export type Multiplicity = typeof Multiplicities[MultiplicityKey];
|
|
81
|
+
|
|
46
82
|
/**
|
|
47
83
|
* Type descriptor.
|
|
48
84
|
*/
|
|
@@ -53,9 +89,9 @@ interface TypeDescriptor extends Descriptor {
|
|
|
53
89
|
readonly type: Type;
|
|
54
90
|
|
|
55
91
|
/**
|
|
56
|
-
*
|
|
92
|
+
* Multiplicity.
|
|
57
93
|
*/
|
|
58
|
-
readonly
|
|
94
|
+
readonly multiplicity: Multiplicity;
|
|
59
95
|
}
|
|
60
96
|
|
|
61
97
|
/**
|
|
@@ -83,6 +119,21 @@ export interface ExtendsParameterDescriptor extends Partial<ParameterDescriptor>
|
|
|
83
119
|
readonly sortOrder?: number;
|
|
84
120
|
}
|
|
85
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Replacement parameter descriptor.
|
|
124
|
+
*/
|
|
125
|
+
export interface ReplacementParameterDescriptor {
|
|
126
|
+
/**
|
|
127
|
+
* Name to replace.
|
|
128
|
+
*/
|
|
129
|
+
readonly name: string;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Replacement parameter descriptor.
|
|
133
|
+
*/
|
|
134
|
+
readonly replacement: ParameterDescriptor;
|
|
135
|
+
}
|
|
136
|
+
|
|
86
137
|
/**
|
|
87
138
|
* Method descriptor.
|
|
88
139
|
*/
|
|
@@ -92,6 +143,21 @@ export interface MethodDescriptor extends TypeDescriptor {
|
|
|
92
143
|
*/
|
|
93
144
|
readonly requiresContext?: boolean;
|
|
94
145
|
|
|
146
|
+
/**
|
|
147
|
+
* If true, function is hidden from user interface.
|
|
148
|
+
*/
|
|
149
|
+
readonly isHidden?: boolean;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* If true, function is volatile and should be reevaluated regularly.
|
|
153
|
+
*/
|
|
154
|
+
readonly isVolatile?: boolean;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* If true, function opens a stream that updates asynchronously.
|
|
158
|
+
*/
|
|
159
|
+
readonly isStream?: boolean;
|
|
160
|
+
|
|
95
161
|
/**
|
|
96
162
|
* If true, method infix is ignored.
|
|
97
163
|
*/
|
|
@@ -128,18 +194,20 @@ export interface ClassDescriptor extends Descriptor {
|
|
|
128
194
|
*/
|
|
129
195
|
readonly namespace?: string | undefined;
|
|
130
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Category.
|
|
199
|
+
*/
|
|
200
|
+
readonly category: string;
|
|
201
|
+
|
|
131
202
|
/**
|
|
132
203
|
* Method infix. If undefined, method name is generated verbatim.
|
|
133
204
|
*/
|
|
134
205
|
readonly methodInfix?: string | undefined;
|
|
135
206
|
|
|
136
207
|
/**
|
|
137
|
-
*
|
|
208
|
+
* Replacement parameter descriptors for class hierarchies where parameter types can narrow
|
|
138
209
|
*/
|
|
139
|
-
readonly
|
|
140
|
-
readonly name: string;
|
|
141
|
-
readonly replacement: ParameterDescriptor;
|
|
142
|
-
}>;
|
|
210
|
+
readonly replacementParameterDescriptors?: ReplacementParameterDescriptor[];
|
|
143
211
|
|
|
144
212
|
/**
|
|
145
213
|
* Class name in optional namespace.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { I18nEnvironments } from "@aidc-toolkit/core";
|
|
2
|
-
import type { ParseKeys } from "i18next";
|
|
3
|
-
import {
|
|
1
|
+
import { getLogger, I18nEnvironments, type Promisable } from "@aidc-toolkit/core";
|
|
2
|
+
import type { DefaultNamespace, ParseKeys } from "i18next";
|
|
3
|
+
import type { Logger } from "tslog";
|
|
4
|
+
import { AppHelperProxy } from "../app-helper-proxy.js";
|
|
4
5
|
import type { ClassDescriptor, MethodDescriptor } from "../descriptor.js";
|
|
5
6
|
import * as GS1 from "../gs1/index.js";
|
|
6
|
-
import {
|
|
7
|
+
import { appExtensionResourceBundle, i18nAppExtensionInit, i18nextAppExtension } from "../locale/i18n.js";
|
|
7
8
|
import { proxy } from "../proxy.js";
|
|
8
9
|
import * as Utility from "../utility/index.js";
|
|
9
10
|
|
|
@@ -16,7 +17,8 @@ import * as Utility from "../utility/index.js";
|
|
|
16
17
|
function registerProxies(..._proxies: unknown[]): void {
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
registerProxies(
|
|
20
|
+
registerProxies(AppHelperProxy, Utility, GS1);
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* Localization.
|
|
22
24
|
*/
|
|
@@ -24,27 +26,32 @@ export interface Localization {
|
|
|
24
26
|
/**
|
|
25
27
|
* Name.
|
|
26
28
|
*/
|
|
27
|
-
name: string;
|
|
29
|
+
readonly name: string;
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Description.
|
|
31
33
|
*/
|
|
32
|
-
description: string;
|
|
34
|
+
readonly description: string;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* Function localization.
|
|
37
39
|
*/
|
|
38
40
|
export interface FunctionLocalization extends Localization {
|
|
41
|
+
/**
|
|
42
|
+
* Namespace function name.
|
|
43
|
+
*/
|
|
44
|
+
readonly namespaceFunctionName: string;
|
|
45
|
+
|
|
39
46
|
/**
|
|
40
47
|
* Documentation URL.
|
|
41
48
|
*/
|
|
42
|
-
documentationURL: string;
|
|
49
|
+
readonly documentationURL: string;
|
|
43
50
|
|
|
44
51
|
/**
|
|
45
52
|
* Parameters map.
|
|
46
53
|
*/
|
|
47
|
-
parametersMap:
|
|
54
|
+
readonly parametersMap: ReadonlyMap<string, Localization>;
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
/**
|
|
@@ -61,6 +68,11 @@ export abstract class Generator {
|
|
|
61
68
|
*/
|
|
62
69
|
static readonly #DOCUMENTATION_PATH = "app-extension/";
|
|
63
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Logger.
|
|
73
|
+
*/
|
|
74
|
+
readonly #logger = getLogger();
|
|
75
|
+
|
|
64
76
|
/**
|
|
65
77
|
* Locales.
|
|
66
78
|
*/
|
|
@@ -71,11 +83,6 @@ export abstract class Generator {
|
|
|
71
83
|
*/
|
|
72
84
|
readonly #defaultLocale: string;
|
|
73
85
|
|
|
74
|
-
/**
|
|
75
|
-
* Map of function localizations maps by namespace function name.
|
|
76
|
-
*/
|
|
77
|
-
readonly #functionLocalizationsMapsMap = new Map<string, ReadonlyMap<string, FunctionLocalization>>();
|
|
78
|
-
|
|
79
86
|
/**
|
|
80
87
|
* Constructor.
|
|
81
88
|
*
|
|
@@ -83,10 +90,17 @@ export abstract class Generator {
|
|
|
83
90
|
* Include localizations if true.
|
|
84
91
|
*/
|
|
85
92
|
constructor(includeLocalizations = true) {
|
|
86
|
-
this.#locales = includeLocalizations ? Object.keys(
|
|
93
|
+
this.#locales = includeLocalizations ? Object.keys(appExtensionResourceBundle) : [];
|
|
87
94
|
this.#defaultLocale = this.#locales[0] ?? "";
|
|
88
95
|
}
|
|
89
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Get the logger.
|
|
99
|
+
*/
|
|
100
|
+
get logger(): Logger<object> {
|
|
101
|
+
return this.#logger;
|
|
102
|
+
}
|
|
103
|
+
|
|
90
104
|
/**
|
|
91
105
|
* Get the locales.
|
|
92
106
|
*/
|
|
@@ -102,56 +116,31 @@ export abstract class Generator {
|
|
|
102
116
|
}
|
|
103
117
|
|
|
104
118
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @param locale
|
|
108
|
-
* Locale.
|
|
109
|
-
*
|
|
110
|
-
* @param namespaceFunctionName
|
|
111
|
-
* Namespace function name.
|
|
112
|
-
*
|
|
113
|
-
* @returns
|
|
114
|
-
* Function localization.
|
|
119
|
+
* Initialize the generation of the output.
|
|
115
120
|
*/
|
|
116
|
-
protected
|
|
117
|
-
const functionLocalization = this.#functionLocalizationsMapsMap.get(namespaceFunctionName)?.get(locale);
|
|
118
|
-
|
|
119
|
-
if (functionLocalization === undefined) {
|
|
120
|
-
throw new Error(`${locale} localization for function ${namespaceFunctionName} not found`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return functionLocalization;
|
|
124
|
-
}
|
|
121
|
+
protected abstract initialize(): void;
|
|
125
122
|
|
|
126
123
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @param locale
|
|
130
|
-
* Locale.
|
|
124
|
+
* Create a namespace.
|
|
131
125
|
*
|
|
132
|
-
* @param
|
|
133
|
-
* Namespace
|
|
134
|
-
*
|
|
135
|
-
* @param parameterName
|
|
136
|
-
* Parameter name.
|
|
137
|
-
*
|
|
138
|
-
* @returns
|
|
139
|
-
* Parameter localization.
|
|
126
|
+
* @param namespace
|
|
127
|
+
* Namespace.
|
|
140
128
|
*/
|
|
141
|
-
protected
|
|
142
|
-
const parameterLocalization = this.getFunctionLocalization(locale, namespaceFunctionName).parametersMap.get(parameterName);
|
|
143
|
-
|
|
144
|
-
if (parameterLocalization === undefined) {
|
|
145
|
-
throw new Error(`${locale} localization for function ${namespaceFunctionName} parameter ${parameterName} not found`);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return parameterLocalization;
|
|
149
|
-
}
|
|
129
|
+
protected abstract createNamespace(namespace: string | undefined): void;
|
|
150
130
|
|
|
151
131
|
/**
|
|
152
|
-
*
|
|
132
|
+
* Create a category.
|
|
133
|
+
*
|
|
134
|
+
* @param namespace
|
|
135
|
+
* Namespace.
|
|
136
|
+
*
|
|
137
|
+
* @param category
|
|
138
|
+
* Category.
|
|
139
|
+
*
|
|
140
|
+
* @param categoryLocalizationsMap
|
|
141
|
+
* Category localizations map.
|
|
153
142
|
*/
|
|
154
|
-
protected abstract
|
|
143
|
+
protected abstract createCategory(namespace: string | undefined, category: string, categoryLocalizationsMap: ReadonlyMap<string, string>): void;
|
|
155
144
|
|
|
156
145
|
/**
|
|
157
146
|
* Create a proxy object for a class.
|
|
@@ -171,7 +160,7 @@ export abstract class Generator {
|
|
|
171
160
|
* Method descriptor.
|
|
172
161
|
*
|
|
173
162
|
* @param functionLocalizationsMap
|
|
174
|
-
*
|
|
163
|
+
* Function localizations map.
|
|
175
164
|
*/
|
|
176
165
|
protected abstract createProxyFunction(classDescriptor: ClassDescriptor, methodDescriptor: MethodDescriptor, functionLocalizationsMap: ReadonlyMap<string, FunctionLocalization>): void;
|
|
177
166
|
|
|
@@ -181,7 +170,7 @@ export abstract class Generator {
|
|
|
181
170
|
* @param success
|
|
182
171
|
* True if successful.
|
|
183
172
|
*/
|
|
184
|
-
protected abstract finalize(success: boolean):
|
|
173
|
+
protected abstract finalize(success: boolean): Promisable<void>;
|
|
185
174
|
|
|
186
175
|
/**
|
|
187
176
|
* Generate a localization.
|
|
@@ -192,11 +181,8 @@ export abstract class Generator {
|
|
|
192
181
|
* @param locale
|
|
193
182
|
* Locale.
|
|
194
183
|
*
|
|
195
|
-
* @param
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* @param namespacePrefix
|
|
199
|
-
* Namespace prefix to be appended to name.
|
|
184
|
+
* @param key
|
|
185
|
+
* Key.
|
|
200
186
|
*
|
|
201
187
|
* @param localizationCallback
|
|
202
188
|
* Callback to finalize localization.
|
|
@@ -204,17 +190,14 @@ export abstract class Generator {
|
|
|
204
190
|
* @returns
|
|
205
191
|
* Localization.
|
|
206
192
|
*/
|
|
207
|
-
#generateLocalization<TLocalization extends Localization>(locale: string,
|
|
208
|
-
const
|
|
209
|
-
lng: locale
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Localized key exists.
|
|
216
|
-
description: i18nextAppExtension.t(`${localizedKeyPrefix}description` as ParseKeys, lngOption)
|
|
217
|
-
});
|
|
193
|
+
static #generateLocalization<TLocalization extends Localization>(locale: string, key: string, localizationCallback: (locale: string, localization: Localization) => TLocalization): TLocalization {
|
|
194
|
+
const lngReturnObjectsOption = {
|
|
195
|
+
lng: locale,
|
|
196
|
+
returnObjects: true
|
|
197
|
+
} as const;
|
|
198
|
+
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Localized key exists and return type is Localization.
|
|
200
|
+
return localizationCallback(locale, i18nextAppExtension.t(key as ParseKeys<DefaultNamespace, typeof lngReturnObjectsOption>, lngReturnObjectsOption) as Localization);
|
|
218
201
|
}
|
|
219
202
|
|
|
220
203
|
/**
|
|
@@ -225,36 +208,75 @@ export abstract class Generator {
|
|
|
225
208
|
|
|
226
209
|
await i18nAppExtensionInit(I18nEnvironments.CLI);
|
|
227
210
|
|
|
228
|
-
// const LocaleResourcesSource = path.resolve(LocaleResourcesGenerator.IMPORT_PATH, entry.name, "locale-resources.ts");
|
|
229
|
-
//
|
|
230
|
-
// await import(LocaleResourcesSource).then((module) => {
|
|
231
|
-
|
|
232
211
|
this.initialize();
|
|
233
212
|
|
|
213
|
+
const namespaceHierarchy = new Map<string | undefined, Map<string, ClassDescriptor[]>>();
|
|
214
|
+
|
|
215
|
+
// Organize class descriptors by namespace and category.
|
|
216
|
+
for (const classDescriptor of proxy.classDescriptors) {
|
|
217
|
+
const namespace = classDescriptor.namespace;
|
|
218
|
+
const category = classDescriptor.category;
|
|
219
|
+
|
|
220
|
+
let categoryHierarchy = namespaceHierarchy.get(namespace);
|
|
221
|
+
|
|
222
|
+
if (categoryHierarchy === undefined) {
|
|
223
|
+
categoryHierarchy = new Map();
|
|
224
|
+
namespaceHierarchy.set(namespace, categoryHierarchy);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
let classDescriptors = categoryHierarchy.get(category);
|
|
228
|
+
|
|
229
|
+
if (classDescriptors === undefined) {
|
|
230
|
+
classDescriptors = [];
|
|
231
|
+
categoryHierarchy.set(category, classDescriptors);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
classDescriptors.push(classDescriptor);
|
|
235
|
+
}
|
|
236
|
+
|
|
234
237
|
try {
|
|
235
|
-
for (const [
|
|
236
|
-
const namespace = classDescriptor.namespace;
|
|
238
|
+
for (const [namespace, categoryHierarchy] of namespaceHierarchy) {
|
|
237
239
|
const namespacePrefix = namespace === undefined ? "" : `${namespace}.`;
|
|
238
240
|
const namespacePath = namespace === undefined ? "" : `${namespace}/`;
|
|
239
241
|
|
|
240
|
-
this.
|
|
242
|
+
this.createNamespace(namespace);
|
|
243
|
+
|
|
244
|
+
for (const [category, classDescriptors] of categoryHierarchy) {
|
|
245
|
+
const namespaceCategory = `${namespacePrefix}${category}`;
|
|
246
|
+
|
|
247
|
+
const categoriesKey = `Categories.${category}`;
|
|
248
|
+
const namespaceCategoriesKey = `Categories.${namespaceCategory}`;
|
|
249
|
+
|
|
250
|
+
const categoryLocalizationsMap = new Map(this.locales.map((locale) => {
|
|
251
|
+
const lngOption = {
|
|
252
|
+
lng: locale
|
|
253
|
+
} as const;
|
|
254
|
+
|
|
255
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Localized key exists.
|
|
256
|
+
return [locale, i18nextAppExtension.t((i18nextAppExtension.exists(namespaceCategoriesKey, lngOption) ? namespaceCategoriesKey : categoriesKey) as ParseKeys, lngOption)];
|
|
257
|
+
}));
|
|
258
|
+
|
|
259
|
+
this.createCategory(namespace, category, categoryLocalizationsMap);
|
|
241
260
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const functionLocalizationsMap = new Map(this.#locales.map(locale =>
|
|
245
|
-
[locale, this.#generateLocalization<FunctionLocalization>(locale, `Functions.${namespaceFunctionName}.`, namespacePrefix, (locale, localization) => ({
|
|
246
|
-
...localization,
|
|
247
|
-
documentationURL: `${Generator.#DOCUMENTATION_BASE_URL}${locale === this.defaultLocale ? "" : `${locale}/`}${Generator.#DOCUMENTATION_PATH}${namespacePath}${localization.name}.html`,
|
|
248
|
-
parametersMap: new Map(methodDescriptor.parameterDescriptors.map(parameterDescriptor =>
|
|
249
|
-
// eslint-disable-next-line max-nested-callbacks -- Callback is empty.
|
|
250
|
-
[parameterDescriptor.name, this.#generateLocalization(locale, `Parameters.${parameterDescriptor.name}.`, "", (_locale, localization) => localization)]
|
|
251
|
-
))
|
|
252
|
-
}))]
|
|
253
|
-
));
|
|
261
|
+
for (const classDescriptor of classDescriptors) {
|
|
262
|
+
this.createProxyObject(classDescriptor);
|
|
254
263
|
|
|
255
|
-
|
|
264
|
+
for (const methodDescriptor of classDescriptor.methodDescriptors) {
|
|
265
|
+
const functionLocalizationsMap = new Map(this.locales.map(locale =>
|
|
266
|
+
[locale, Generator.#generateLocalization<FunctionLocalization>(locale, `Functions.${methodDescriptor.namespaceFunctionName}`, (locale, localization) => ({
|
|
267
|
+
...localization,
|
|
268
|
+
namespaceFunctionName: `${namespacePrefix}${localization.name}`,
|
|
269
|
+
documentationURL: `${Generator.#DOCUMENTATION_BASE_URL}${locale === this.defaultLocale ? "" : `${locale}/`}${Generator.#DOCUMENTATION_PATH}${namespacePath}${localization.name}.html`,
|
|
270
|
+
parametersMap: new Map(methodDescriptor.parameterDescriptors.map(parameterDescriptor =>
|
|
271
|
+
// eslint-disable-next-line max-nested-callbacks -- Callback is empty.
|
|
272
|
+
[parameterDescriptor.name, Generator.#generateLocalization(locale, `Parameters.${parameterDescriptor.name}`, (_locale, localization) => localization)]
|
|
273
|
+
))
|
|
274
|
+
}))]
|
|
275
|
+
));
|
|
256
276
|
|
|
257
|
-
|
|
277
|
+
this.createProxyFunction(classDescriptor, methodDescriptor, functionLocalizationsMap);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
258
280
|
}
|
|
259
281
|
}
|
|
260
282
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LocaleResources } from "@aidc-toolkit/core";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import type {
|
|
@@ -14,7 +14,7 @@ import { Generator } from "./generator.js";
|
|
|
14
14
|
*/
|
|
15
15
|
interface ParametersSequencerEntry {
|
|
16
16
|
/**
|
|
17
|
-
* Parameters
|
|
17
|
+
* Parameters sequencer or null if automatic.
|
|
18
18
|
*/
|
|
19
19
|
parametersSequencerOrNull: ParametersSequencer | null;
|
|
20
20
|
|
|
@@ -42,7 +42,6 @@ interface ParametersSequencerEntry {
|
|
|
42
42
|
/**
|
|
43
43
|
* Parameters sequencer for keeping similar (extended) parameters together.
|
|
44
44
|
*/
|
|
45
|
-
// TODO Replace with map.
|
|
46
45
|
type ParametersSequencer = Record<string, ParametersSequencerEntry>;
|
|
47
46
|
|
|
48
47
|
/**
|
|
@@ -64,11 +63,6 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
64
63
|
*/
|
|
65
64
|
static readonly #IMPORT_PATH = "../app-extension/src/locale";
|
|
66
65
|
|
|
67
|
-
/**
|
|
68
|
-
* Logger.
|
|
69
|
-
*/
|
|
70
|
-
readonly #logger = getLogger();
|
|
71
|
-
|
|
72
66
|
/**
|
|
73
67
|
* Parameters sequencer.
|
|
74
68
|
*/
|
|
@@ -102,13 +96,25 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
102
96
|
/**
|
|
103
97
|
* @inheritDoc
|
|
104
98
|
*/
|
|
105
|
-
protected initialize(): void {
|
|
99
|
+
protected override initialize(): void {
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @inheritDoc
|
|
104
|
+
*/
|
|
105
|
+
protected override createNamespace(): void {
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* @inheritDoc
|
|
110
110
|
*/
|
|
111
|
-
protected
|
|
111
|
+
protected override createCategory(): void {
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @inheritDoc
|
|
116
|
+
*/
|
|
117
|
+
protected override createProxyObject(): void {
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
/**
|
|
@@ -186,41 +192,44 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
186
192
|
/**
|
|
187
193
|
* @inheritDoc
|
|
188
194
|
*/
|
|
189
|
-
protected createProxyFunction(classDescriptor: ClassDescriptor, methodDescriptor: MethodDescriptor): void {
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
195
|
+
protected override createProxyFunction(classDescriptor: ClassDescriptor, methodDescriptor: MethodDescriptor): void {
|
|
196
|
+
// Hidden functions aren't localized.
|
|
197
|
+
if (!(methodDescriptor.isHidden ?? false)) {
|
|
198
|
+
// Add any parameters that are not already known.
|
|
199
|
+
for (const parameterDescriptor of methodDescriptor.parameterDescriptors) {
|
|
200
|
+
this.#saveParameterSequence(parameterDescriptor, true);
|
|
201
|
+
}
|
|
194
202
|
|
|
195
|
-
|
|
203
|
+
let functionsLocaleResources = this.#functionsLocaleResources;
|
|
196
204
|
|
|
197
|
-
|
|
205
|
+
const namespace = classDescriptor.namespace;
|
|
198
206
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
207
|
+
if (namespace !== undefined) {
|
|
208
|
+
if (!(namespace in functionsLocaleResources)) {
|
|
209
|
+
const namespaceFunctionsLocaleResources: LocaleResources = {};
|
|
202
210
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
211
|
+
// Add namespace and navigate to it.
|
|
212
|
+
functionsLocaleResources[namespace] = namespaceFunctionsLocaleResources;
|
|
213
|
+
functionsLocaleResources = namespaceFunctionsLocaleResources;
|
|
214
|
+
} else {
|
|
215
|
+
// Navigate to namespace.
|
|
216
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Entry is never a string.
|
|
217
|
+
functionsLocaleResources = functionsLocaleResources[namespace] as LocaleResources;
|
|
218
|
+
}
|
|
210
219
|
}
|
|
211
|
-
}
|
|
212
220
|
|
|
213
|
-
|
|
221
|
+
const functionName = methodDescriptor.functionName;
|
|
214
222
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
223
|
+
if (functionName in functionsLocaleResources) {
|
|
224
|
+
throw new Error(`Duplicate function ${functionName}`);
|
|
225
|
+
}
|
|
218
226
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
227
|
+
// Add function.
|
|
228
|
+
functionsLocaleResources[functionName] = {
|
|
229
|
+
name: functionName,
|
|
230
|
+
description: "*** LOCALIZATION REQUIRED ***"
|
|
231
|
+
};
|
|
232
|
+
}
|
|
224
233
|
}
|
|
225
234
|
|
|
226
235
|
/**
|
|
@@ -256,7 +265,7 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
256
265
|
if (!deleteMissing) {
|
|
257
266
|
newDestinationLocaleResources[key] = destinationValue;
|
|
258
267
|
} else if (logChanges) {
|
|
259
|
-
this
|
|
268
|
+
this.logger.info(`Deleting ${parentKey}${key}...`);
|
|
260
269
|
}
|
|
261
270
|
}
|
|
262
271
|
}
|
|
@@ -265,7 +274,7 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
265
274
|
if (!(key in destinationLocaleResources)) {
|
|
266
275
|
if (addMissing) {
|
|
267
276
|
if (logChanges) {
|
|
268
|
-
this
|
|
277
|
+
this.logger.info(`Adding ${parentKey}${key}...`);
|
|
269
278
|
}
|
|
270
279
|
|
|
271
280
|
newDestinationLocaleResources[key] = sourceValue;
|
|
@@ -364,7 +373,7 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
364
373
|
/**
|
|
365
374
|
* @inheritDoc
|
|
366
375
|
*/
|
|
367
|
-
protected async finalize(success: boolean): Promise<void> {
|
|
376
|
+
protected override async finalize(success: boolean): Promise<void> {
|
|
368
377
|
if (success) {
|
|
369
378
|
this.#buildParametersLocaleResources(this.#parametersSequencer);
|
|
370
379
|
|
|
@@ -373,7 +382,7 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
373
382
|
}).filter(entry => entry.isDirectory()).map(async (entry) => {
|
|
374
383
|
const localeResourcesSource = path.resolve(LocaleResourcesGenerator.#IMPORT_PATH, entry.name, "locale-resources.ts");
|
|
375
384
|
|
|
376
|
-
|
|
385
|
+
return import(localeResourcesSource).then((module) => {
|
|
377
386
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Module format is known.
|
|
378
387
|
const localeResources = this.#merge(entry.name === "en", "", this.#LocaleResources, (module as LocaleResourcesModule).default, !entry.name.includes("-"));
|
|
379
388
|
|
|
@@ -384,4 +393,9 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
384
393
|
}
|
|
385
394
|
}
|
|
386
395
|
|
|
387
|
-
|
|
396
|
+
const generator = new LocaleResourcesGenerator();
|
|
397
|
+
|
|
398
|
+
generator.generate().catch((e: unknown) => {
|
|
399
|
+
generator.logger.error(e);
|
|
400
|
+
process.exit(1);
|
|
401
|
+
});
|
|
@@ -11,15 +11,15 @@ import { CharacterSetCreatorProxy, CharacterSetValidatorProxy } from "../utility
|
|
|
11
11
|
@proxy.describeClass(false, {
|
|
12
12
|
namespace: "GS1",
|
|
13
13
|
methodInfix: "AI82",
|
|
14
|
-
|
|
14
|
+
replacementParameterDescriptors: [
|
|
15
15
|
{
|
|
16
16
|
name: expandParameterDescriptor(exclusionNoneParameterDescriptor).name,
|
|
17
17
|
replacement: exclusionAllNumericParameterDescriptor
|
|
18
18
|
}
|
|
19
19
|
]
|
|
20
20
|
})
|
|
21
|
-
export class AI82Proxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
22
|
-
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
|
|
21
|
+
export class AI82Proxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
|
|
22
|
+
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
|
|
23
23
|
super(appExtension, AI82_CREATOR);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -27,15 +27,15 @@ export class AI82Proxy<ThrowError extends boolean, TError extends ErrorExtends<T
|
|
|
27
27
|
@proxy.describeClass(false, {
|
|
28
28
|
namespace: "GS1",
|
|
29
29
|
methodInfix: "AI39",
|
|
30
|
-
|
|
30
|
+
replacementParameterDescriptors: [
|
|
31
31
|
{
|
|
32
32
|
name: expandParameterDescriptor(exclusionNoneParameterDescriptor).name,
|
|
33
33
|
replacement: exclusionAllNumericParameterDescriptor
|
|
34
34
|
}
|
|
35
35
|
]
|
|
36
36
|
})
|
|
37
|
-
export class AI39Proxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
38
|
-
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
|
|
37
|
+
export class AI39Proxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends CharacterSetCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
|
|
38
|
+
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
|
|
39
39
|
super(appExtension, AI39_CREATOR);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -44,8 +44,8 @@ export class AI39Proxy<ThrowError extends boolean, TError extends ErrorExtends<T
|
|
|
44
44
|
namespace: "GS1",
|
|
45
45
|
methodInfix: "AI64"
|
|
46
46
|
})
|
|
47
|
-
export class AI64Proxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends CharacterSetValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
48
|
-
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
|
|
47
|
+
export class AI64Proxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends CharacterSetValidatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
|
|
48
|
+
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
|
|
49
49
|
super(appExtension, AI64_VALIDATOR);
|
|
50
50
|
}
|
|
51
51
|
}
|