@aidc-toolkit/app-extension 1.0.47-beta → 1.0.49-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/app-extension.d.ts +12 -0
- package/dist/app-extension.d.ts.map +1 -1
- package/dist/app-extension.js +23 -0
- package/dist/app-extension.js.map +1 -1
- package/dist/app-helper-proxy.d.ts +11 -1
- package/dist/app-helper-proxy.d.ts.map +1 -1
- package/dist/app-helper-proxy.js +42 -7
- package/dist/app-helper-proxy.js.map +1 -1
- package/dist/descriptor.d.ts +0 -12
- package/dist/descriptor.d.ts.map +1 -1
- package/dist/generator/functions-generator.d.ts +119 -0
- package/dist/generator/functions-generator.d.ts.map +1 -0
- package/dist/generator/functions-generator.js +206 -0
- package/dist/generator/functions-generator.js.map +1 -0
- package/dist/generator/generator.d.ts +6 -9
- package/dist/generator/generator.d.ts.map +1 -1
- package/dist/generator/generator.js +22 -29
- package/dist/generator/generator.js.map +1 -1
- package/dist/generator/index.d.ts +1 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +1 -0
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/locale-resources-generator.js +8 -7
- package/dist/generator/locale-resources-generator.js.map +1 -1
- package/dist/gs1/check-proxy.js +3 -3
- package/dist/gs1/check-proxy.js.map +1 -1
- package/dist/gs1/gcp-length-proxy.d.ts.map +1 -1
- package/dist/gs1/gcp-length-proxy.js +0 -3
- package/dist/gs1/gcp-length-proxy.js.map +1 -1
- package/dist/gs1/gtin-validator-proxy.js +2 -2
- package/dist/gs1/gtin-validator-proxy.js.map +1 -1
- package/dist/gs1/identifier-validator-proxy.js +2 -2
- package/dist/gs1/identifier-validator-proxy.js.map +1 -1
- package/dist/locale/en/locale-resources.d.ts +3 -0
- package/dist/locale/en/locale-resources.d.ts.map +1 -1
- package/dist/locale/en/locale-resources.js +3 -0
- package/dist/locale/en/locale-resources.js.map +1 -1
- package/dist/locale/fr/locale-resources.d.ts +3 -0
- package/dist/locale/fr/locale-resources.d.ts.map +1 -1
- package/dist/locale/fr/locale-resources.js +5 -2
- package/dist/locale/fr/locale-resources.js.map +1 -1
- package/dist/locale/i18n.d.ts +4 -4
- package/dist/locale/i18n.d.ts.map +1 -1
- package/dist/locale/i18n.js +4 -4
- package/dist/locale/i18n.js.map +1 -1
- package/dist/proxy.d.ts +2 -2
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +3 -7
- package/dist/proxy.js.map +1 -1
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +5 -5
- package/src/app-extension.ts +29 -0
- package/src/app-helper-proxy.ts +45 -7
- package/src/descriptor.ts +0 -15
- package/src/generator/functions-generator.ts +292 -0
- package/src/generator/generator.ts +37 -46
- package/src/generator/index.ts +1 -0
- package/src/generator/locale-resources-generator.ts +9 -7
- package/src/gs1/check-proxy.ts +3 -3
- package/src/gs1/gcp-length-proxy.ts +0 -3
- package/src/gs1/gtin-validator-proxy.ts +2 -2
- package/src/gs1/identifier-validator-proxy.ts +2 -2
- package/src/locale/en/locale-resources.ts +3 -0
- package/src/locale/fr/locale-resources.ts +5 -2
- package/src/locale/i18n.ts +5 -5
- package/src/proxy.ts +5 -11
- package/src/version.ts +4 -0
- package/tsconfig-src.tsbuildinfo +1 -1
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ClassDescriptor,
|
|
3
|
+
type MethodDescriptor,
|
|
4
|
+
type ParameterDescriptor,
|
|
5
|
+
type Type,
|
|
6
|
+
Types
|
|
7
|
+
} from "../descriptor.js";
|
|
8
|
+
import { type FunctionLocalization, Generator, type Localization } from "./generator.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Class type alias.
|
|
12
|
+
*/
|
|
13
|
+
export interface ClassTypeAlias {
|
|
14
|
+
/**
|
|
15
|
+
* Name.
|
|
16
|
+
*/
|
|
17
|
+
readonly name: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Getter function.
|
|
21
|
+
*/
|
|
22
|
+
readonly getter: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Declaration associating name with implementation type and creating getter function.
|
|
26
|
+
*/
|
|
27
|
+
readonly declaration: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Function implementation.
|
|
32
|
+
*/
|
|
33
|
+
export interface FunctionImplementation {
|
|
34
|
+
/**
|
|
35
|
+
* Function name.
|
|
36
|
+
*/
|
|
37
|
+
readonly functionName: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Parameter localizations with JavaScript type and parameter descriptor.
|
|
41
|
+
*/
|
|
42
|
+
readonly parameterLocalizations: ReadonlyArray<Localization & {
|
|
43
|
+
/**
|
|
44
|
+
* JavaScript type.
|
|
45
|
+
*/
|
|
46
|
+
javaScriptType: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Parameter descriptor.
|
|
50
|
+
*/
|
|
51
|
+
parameterDescriptor?: ParameterDescriptor;
|
|
52
|
+
}>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Declaration.
|
|
56
|
+
*/
|
|
57
|
+
readonly declaration: string[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Generator with helpers for writing TypeScript functions file.
|
|
62
|
+
*/
|
|
63
|
+
export abstract class FunctionsGenerator extends Generator {
|
|
64
|
+
/**
|
|
65
|
+
* Mapping of descriptor types to JavaScript types.
|
|
66
|
+
*/
|
|
67
|
+
static readonly #DESCRIPTOR_TYPE_STRINGS: Readonly<Record<Type, string>> = {
|
|
68
|
+
[Types.String]: "string",
|
|
69
|
+
[Types.Number]: "number",
|
|
70
|
+
[Types.Boolean]: "boolean",
|
|
71
|
+
[Types.Any]: "any"
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
protected static readonly BASE_IMPORTS = [
|
|
75
|
+
"import * as AppExtension from \"@aidc-toolkit/app-extension\";",
|
|
76
|
+
"import { appExtension } from \"./app-extension.js\";"
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* If true, functions are declared inline rather than using `function`.
|
|
81
|
+
*/
|
|
82
|
+
readonly #inline: boolean;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* If true, application extension supports context.
|
|
86
|
+
*/
|
|
87
|
+
readonly #supportsContext: boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Invocation context type name.
|
|
91
|
+
*/
|
|
92
|
+
readonly #invocationContextTypeName: string;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Streaming invocation context type name.
|
|
96
|
+
*/
|
|
97
|
+
readonly #streamingInvocationContextTypeName: string;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Template declaration for type alias.
|
|
101
|
+
*/
|
|
102
|
+
readonly #templateDeclaration: string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Current class type alias.
|
|
106
|
+
*/
|
|
107
|
+
#classTypeAlias!: ClassTypeAlias;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Constructor.
|
|
111
|
+
*
|
|
112
|
+
* @param version
|
|
113
|
+
* Package version.
|
|
114
|
+
*
|
|
115
|
+
* @param inline
|
|
116
|
+
* If true, functions are declared inline rather than using `function`.
|
|
117
|
+
*
|
|
118
|
+
* @param throwError
|
|
119
|
+
* If true, errors are reported through the throw/catch mechanism.
|
|
120
|
+
*
|
|
121
|
+
* @param errorTypeName
|
|
122
|
+
* Error type name.
|
|
123
|
+
*
|
|
124
|
+
* @param supportsContext
|
|
125
|
+
* If true, application extension supports context.
|
|
126
|
+
*
|
|
127
|
+
* Big integer type name.
|
|
128
|
+
* @param invocationContextTypeName
|
|
129
|
+
* Invocation context type name.
|
|
130
|
+
*
|
|
131
|
+
* @param streamingInvocationContextTypeName
|
|
132
|
+
* Streaming invocation context type name.
|
|
133
|
+
*
|
|
134
|
+
* @param bigIntTypeName
|
|
135
|
+
* Big integer type name.
|
|
136
|
+
*/
|
|
137
|
+
constructor(version: string, inline: boolean, throwError: boolean, errorTypeName: string, supportsContext: boolean, invocationContextTypeName: string, streamingInvocationContextTypeName: string, bigIntTypeName: string) {
|
|
138
|
+
super(version, true);
|
|
139
|
+
|
|
140
|
+
this.#inline = inline;
|
|
141
|
+
|
|
142
|
+
this.#supportsContext = supportsContext;
|
|
143
|
+
this.#invocationContextTypeName = invocationContextTypeName;
|
|
144
|
+
this.#streamingInvocationContextTypeName = streamingInvocationContextTypeName;
|
|
145
|
+
|
|
146
|
+
this.#templateDeclaration = `<${throwError}, ${errorTypeName}, ${invocationContextTypeName}, ${streamingInvocationContextTypeName}, ${bigIntTypeName}>`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Get the class type alias.
|
|
151
|
+
*/
|
|
152
|
+
get classTypeAlias(): ClassTypeAlias {
|
|
153
|
+
return this.#classTypeAlias;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Get the import statement for a namespace.
|
|
158
|
+
*
|
|
159
|
+
* @param namespace
|
|
160
|
+
* Namespace.
|
|
161
|
+
*
|
|
162
|
+
* @returns
|
|
163
|
+
* Import statement.
|
|
164
|
+
*/
|
|
165
|
+
protected getNamespaceImport(namespace: string): string {
|
|
166
|
+
return `import * as AppExtension${namespace} from "@aidc-toolkit/app-extension/${namespace.toLowerCase()}";`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @inheritDoc
|
|
171
|
+
*/
|
|
172
|
+
protected override createClassProxy(classDescriptor: ClassDescriptor): void {
|
|
173
|
+
const classDescriptorNamespace = classDescriptor.namespace ?? "";
|
|
174
|
+
const name = `${classDescriptorNamespace}${classDescriptor.name}`;
|
|
175
|
+
const getter = `get${name}()`;
|
|
176
|
+
const implementation = `AppExtension${classDescriptorNamespace}.${classDescriptor.name}${this.#templateDeclaration}`;
|
|
177
|
+
|
|
178
|
+
this.#classTypeAlias = {
|
|
179
|
+
name,
|
|
180
|
+
getter,
|
|
181
|
+
declaration: [
|
|
182
|
+
"",
|
|
183
|
+
"/**",
|
|
184
|
+
" * Class type alias name.",
|
|
185
|
+
" */",
|
|
186
|
+
`type ${name} = ${implementation};`,
|
|
187
|
+
"",
|
|
188
|
+
"/**",
|
|
189
|
+
" * Getter function to get an instance of the class.",
|
|
190
|
+
" *",
|
|
191
|
+
" * @returns",
|
|
192
|
+
" * Class instance.",
|
|
193
|
+
" */",
|
|
194
|
+
`function ${getter}: ${name} {`,
|
|
195
|
+
` return appExtension.getProxy(${implementation});`,
|
|
196
|
+
"}"
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Get a function implementation.
|
|
203
|
+
*
|
|
204
|
+
* @param methodDescriptor
|
|
205
|
+
* Method descriptor.
|
|
206
|
+
*
|
|
207
|
+
* @param functionNamePrefix
|
|
208
|
+
* Function name prefix.
|
|
209
|
+
*
|
|
210
|
+
* @param functionLocalization
|
|
211
|
+
* Function localization. May be undefined for hidden functions, in which case generated
|
|
212
|
+
*
|
|
213
|
+
* @param parameterCallback
|
|
214
|
+
* Callback to modify parameter in implementation function call.
|
|
215
|
+
*
|
|
216
|
+
* @returns
|
|
217
|
+
* Function implementation.
|
|
218
|
+
*/
|
|
219
|
+
protected getFunctionImplementation(methodDescriptor: MethodDescriptor, functionNamePrefix: string, functionLocalization: FunctionLocalization | undefined, parameterCallback?: (name: string, parameterDescriptor: ParameterDescriptor) => string): FunctionImplementation {
|
|
220
|
+
const methodType = `${this.classTypeAlias.name}["${methodDescriptor.name}"]`;
|
|
221
|
+
|
|
222
|
+
const parameterDescriptors = methodDescriptor.parameterDescriptors;
|
|
223
|
+
|
|
224
|
+
const parameterLocalizations: Array<FunctionImplementation["parameterLocalizations"][number]> = parameterDescriptors.map((parameterDescriptor) => {
|
|
225
|
+
const parameterLocalization = functionLocalization?.parametersMap.get(parameterDescriptor.name) ?? {
|
|
226
|
+
name: parameterDescriptor.name,
|
|
227
|
+
description: "*** NO LOCALIZATION ***"
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
...parameterLocalization,
|
|
232
|
+
javaScriptType: FunctionsGenerator.#DESCRIPTOR_TYPE_STRINGS[parameterDescriptor.type],
|
|
233
|
+
parameterDescriptor
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const dummyParameters: string[] = [];
|
|
238
|
+
|
|
239
|
+
if (this.#supportsContext) {
|
|
240
|
+
if (methodDescriptor.requiresContext === true) {
|
|
241
|
+
parameterLocalizations.push({
|
|
242
|
+
name: "invocationContext",
|
|
243
|
+
description: "Invocation context.",
|
|
244
|
+
javaScriptType: this.#invocationContextTypeName
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (methodDescriptor.isStream === true) {
|
|
249
|
+
parameterLocalizations.push({
|
|
250
|
+
name: "streamingInvocationContext",
|
|
251
|
+
description: "Streaming invocation context.",
|
|
252
|
+
javaScriptType: this.#streamingInvocationContextTypeName
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
if (methodDescriptor.requiresContext === true) {
|
|
257
|
+
// Invocation context type name represents a literal dummy value.
|
|
258
|
+
dummyParameters.push(this.#invocationContextTypeName);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (methodDescriptor.isStream === true) {
|
|
262
|
+
// Streaming invocation context type name represents a literal dummy value.
|
|
263
|
+
dummyParameters.push(this.#streamingInvocationContextTypeName);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const asyncQualifier = methodDescriptor.isAsync === true ? "async " : "";
|
|
268
|
+
const functionName = functionNamePrefix === "" ?
|
|
269
|
+
functionLocalization?.name ?? methodDescriptor.name :
|
|
270
|
+
`${functionNamePrefix}${functionLocalization?.titleCaseName ?? methodDescriptor.name.replace(/^[a-z]/u, c => c.toUpperCase())}`;
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
functionName,
|
|
274
|
+
parameterLocalizations,
|
|
275
|
+
declaration: [
|
|
276
|
+
`${
|
|
277
|
+
!this.#inline ?
|
|
278
|
+
`export ${asyncQualifier}function ${functionName}` :
|
|
279
|
+
asyncQualifier
|
|
280
|
+
}(${parameterLocalizations.map((parameterLocalization, index) =>
|
|
281
|
+
`${parameterLocalization.name}: Parameters<${methodType}>[${index}]`
|
|
282
|
+
).join(", ")}): ReturnType<${methodType}> ${!this.#inline ? "{" : "=>"}`,
|
|
283
|
+
` ${!this.#inline ? "return " : ""}${(this.classTypeAlias.getter)}.${methodDescriptor.name}(${[...parameterLocalizations.map(parameterLocalization =>
|
|
284
|
+
parameterCallback === undefined || parameterLocalization.parameterDescriptor === undefined ?
|
|
285
|
+
parameterLocalization.name :
|
|
286
|
+
parameterCallback(parameterLocalization.name, parameterLocalization.parameterDescriptor)
|
|
287
|
+
), ...dummyParameters].join(", ")})${(!this.#inline ? ";" : "")}`,
|
|
288
|
+
...!this.#inline ? ["}"] : []
|
|
289
|
+
]
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ALPHA_URL, getLogger,
|
|
1
|
+
import { ALPHA_URL, getLogger, I18nLanguageDetectors, type Promisable, websiteURL } from "@aidc-toolkit/core";
|
|
2
2
|
import type { DefaultNamespace, ParseKeys } from "i18next";
|
|
3
3
|
import type { Logger } from "tslog";
|
|
4
4
|
import { AppHelperProxy } from "../app-helper-proxy.js";
|
|
@@ -39,9 +39,9 @@ export interface Localization {
|
|
|
39
39
|
*/
|
|
40
40
|
export interface FunctionLocalization extends Localization {
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Name in title case.
|
|
43
43
|
*/
|
|
44
|
-
readonly
|
|
44
|
+
readonly titleCaseName: string;
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Documentation URL.
|
|
@@ -155,18 +155,15 @@ export abstract class Generator {
|
|
|
155
155
|
protected abstract createCategory(namespace: string | undefined, category: string, categoryLocalizationsMap: ReadonlyMap<string, string>): void;
|
|
156
156
|
|
|
157
157
|
/**
|
|
158
|
-
* Create a proxy
|
|
159
|
-
*
|
|
160
|
-
* @param objectName
|
|
161
|
-
* Object name, derived from namespace and class name.
|
|
158
|
+
* Create a proxy for a class.
|
|
162
159
|
*
|
|
163
160
|
* @param classDescriptor
|
|
164
161
|
* Class descriptor.
|
|
165
162
|
*/
|
|
166
|
-
protected abstract
|
|
163
|
+
protected abstract createClassProxy(classDescriptor: ClassDescriptor): void;
|
|
167
164
|
|
|
168
165
|
/**
|
|
169
|
-
* Create a proxy
|
|
166
|
+
* Create a proxy for a method.
|
|
170
167
|
*
|
|
171
168
|
* @param classDescriptor
|
|
172
169
|
* Class descriptor.
|
|
@@ -177,7 +174,7 @@ export abstract class Generator {
|
|
|
177
174
|
* @param functionLocalizationsMap
|
|
178
175
|
* Function localizations map.
|
|
179
176
|
*/
|
|
180
|
-
protected abstract
|
|
177
|
+
protected abstract createMethodProxy(classDescriptor: ClassDescriptor, methodDescriptor: MethodDescriptor, functionLocalizationsMap: ReadonlyMap<string, FunctionLocalization>): void;
|
|
181
178
|
|
|
182
179
|
/**
|
|
183
180
|
* Finalize the generation of the output.
|
|
@@ -205,14 +202,21 @@ export abstract class Generator {
|
|
|
205
202
|
* @returns
|
|
206
203
|
* Localization.
|
|
207
204
|
*/
|
|
208
|
-
static #generateLocalization<TLocalization extends Localization>(locale: string, key: string, localizationCallback: (locale: string, localization: Localization) => TLocalization): TLocalization {
|
|
205
|
+
static #generateLocalization<TLocalization extends Localization>(locale: string, key: string, localizationCallback: (locale: string, localization: Localization & Partial<TLocalization>) => TLocalization): TLocalization {
|
|
209
206
|
const lngReturnObjectsOption = {
|
|
210
207
|
lng: locale,
|
|
211
208
|
returnObjects: true
|
|
212
209
|
} as const;
|
|
213
210
|
|
|
214
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion --
|
|
215
|
-
|
|
211
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Assume localized key exists.
|
|
212
|
+
const parseKey = key as ParseKeys<DefaultNamespace, typeof lngReturnObjectsOption>;
|
|
213
|
+
|
|
214
|
+
if (!i18nextAppExtension.exists(parseKey, lngReturnObjectsOption)) {
|
|
215
|
+
throw new Error(`Missing localization for ${key} in ${locale}`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Localized key exists and return type is Localization & Partial<TLocalization>.
|
|
219
|
+
return localizationCallback(locale, i18nextAppExtension.t(key as ParseKeys<DefaultNamespace, typeof lngReturnObjectsOption>, lngReturnObjectsOption) as Localization & Partial<TLocalization>);
|
|
216
220
|
}
|
|
217
221
|
|
|
218
222
|
/**
|
|
@@ -221,7 +225,7 @@ export abstract class Generator {
|
|
|
221
225
|
async generate(): Promise<void> {
|
|
222
226
|
let success = false;
|
|
223
227
|
|
|
224
|
-
await i18nAppExtensionInit(
|
|
228
|
+
await i18nAppExtensionInit(I18nLanguageDetectors.CLI);
|
|
225
229
|
|
|
226
230
|
const documentationBaseURL = websiteURL(this.version, true, await ALPHA_URL);
|
|
227
231
|
|
|
@@ -278,7 +282,7 @@ export abstract class Generator {
|
|
|
278
282
|
const namespaceClassNamesSet = new Set<string>();
|
|
279
283
|
|
|
280
284
|
for (const classDescriptor of classDescriptors) {
|
|
281
|
-
const namespaceClassName = classDescriptor.
|
|
285
|
+
const namespaceClassName = `${namespacePrefix}${classDescriptor.name}`;
|
|
282
286
|
|
|
283
287
|
if (namespaceClassNamesSet.has(namespaceClassName)) {
|
|
284
288
|
throw new Error(`Duplicate class ${namespaceClassName}`);
|
|
@@ -286,39 +290,26 @@ export abstract class Generator {
|
|
|
286
290
|
|
|
287
291
|
namespaceClassNamesSet.add(namespaceClassName);
|
|
288
292
|
|
|
289
|
-
|
|
290
|
-
// - one or more uppercase letters followed by zero or more numbers; or
|
|
291
|
-
// - single uppercase letter followed by zero or more characters except uppercase letters or period.
|
|
292
|
-
//
|
|
293
|
-
// Second capture group is:
|
|
294
|
-
// - single uppercase letter followed by zero or more characters except period; or
|
|
295
|
-
// - zero characters (empty string).
|
|
296
|
-
//
|
|
297
|
-
// Third capture group, separated by optional period, is:
|
|
298
|
-
// - single uppercase letter followed by zero or more characters (remainder of string); or
|
|
299
|
-
// - zero characters (empty string).
|
|
300
|
-
const objectNameGroups = /^(?<namespaceFirstWord>[A-Z]+[0-9]*|[A-Z][^A-Z.]*)(?<namespaceRemaining>[A-Z][^.]*|)\.?(?<className>[A-Z].*|)$/u.exec(namespaceClassName)?.groups;
|
|
301
|
-
|
|
302
|
-
if (objectNameGroups === undefined) {
|
|
303
|
-
throw new Error(`${namespaceClassName} is not a valid namespace-qualified class name`);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
this.createProxyObject(`${objectNameGroups["namespaceFirstWord"].toLowerCase()}${objectNameGroups["namespaceRemaining"]}${objectNameGroups["className"]}`, classDescriptor);
|
|
293
|
+
this.createClassProxy(classDescriptor);
|
|
307
294
|
|
|
308
295
|
for (const methodDescriptor of classDescriptor.methodDescriptors) {
|
|
309
|
-
const functionLocalizationsMap = new Map(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
296
|
+
const functionLocalizationsMap = new Map(methodDescriptor.isHidden !== true ?
|
|
297
|
+
this.locales.map(locale =>
|
|
298
|
+
[locale, Generator.#generateLocalization<FunctionLocalization>(locale, `Functions.${namespacePrefix}${methodDescriptor.functionName}`, (locale, localization) => ({
|
|
299
|
+
...localization,
|
|
300
|
+
titleCaseName: localization.titleCaseName ?? localization.name.replace(/^[a-z]/u, c => c.toUpperCase()),
|
|
301
|
+
documentationURL: `${documentationBaseURL}/${locale === this.defaultLocale ? "" : `${locale}/`}${Generator.#DOCUMENTATION_PATH}${namespacePath}${localization.name}.html`,
|
|
302
|
+
parametersMap: new Map(methodDescriptor.parameterDescriptors.map(parameterDescriptor =>
|
|
303
|
+
// eslint-disable-next-line max-nested-callbacks -- Callback is empty.
|
|
304
|
+
[parameterDescriptor.name, Generator.#generateLocalization(locale, `Parameters.${parameterDescriptor.name}`, (_locale, localization) => localization)]
|
|
305
|
+
))
|
|
306
|
+
}))]
|
|
307
|
+
) :
|
|
308
|
+
// Hidden methods are not localized.
|
|
309
|
+
[]
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
this.createMethodProxy(classDescriptor, methodDescriptor, functionLocalizationsMap);
|
|
322
313
|
}
|
|
323
314
|
}
|
|
324
315
|
}
|
package/src/generator/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
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
|
-
import packageConfiguration from "../../package.json" with { type: "json" };
|
|
5
4
|
import type {
|
|
6
5
|
ClassDescriptor,
|
|
7
6
|
ExtendsParameterDescriptor,
|
|
8
7
|
MethodDescriptor,
|
|
9
8
|
ParameterDescriptor
|
|
10
9
|
} from "../descriptor.js";
|
|
10
|
+
import { VERSION } from "../version.js";
|
|
11
11
|
import { Generator } from "./generator.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -91,7 +91,7 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
91
91
|
* Constructor.
|
|
92
92
|
*/
|
|
93
93
|
constructor() {
|
|
94
|
-
super(
|
|
94
|
+
super(VERSION, false);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|
|
@@ -115,7 +115,7 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
115
115
|
/**
|
|
116
116
|
* @inheritDoc
|
|
117
117
|
*/
|
|
118
|
-
protected override
|
|
118
|
+
protected override createClassProxy(): void {
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
@@ -193,7 +193,7 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
193
193
|
/**
|
|
194
194
|
* @inheritDoc
|
|
195
195
|
*/
|
|
196
|
-
protected override
|
|
196
|
+
protected override createMethodProxy(classDescriptor: ClassDescriptor, methodDescriptor: MethodDescriptor): void {
|
|
197
197
|
// Hidden functions aren't localized.
|
|
198
198
|
if (methodDescriptor.isHidden !== true) {
|
|
199
199
|
// Add any parameters that are not already known.
|
|
@@ -255,15 +255,17 @@ class LocaleResourcesGenerator extends Generator {
|
|
|
255
255
|
* Merged locale resources.
|
|
256
256
|
*/
|
|
257
257
|
#merge(logChanges: boolean, parentKey: string, sourceLocaleResources: LocaleResources, destinationLocaleResources: LocaleResources, addMissing: boolean): LocaleResources {
|
|
258
|
-
// Some entries at the
|
|
259
|
-
const
|
|
258
|
+
// Some entries at the root are not part of the generator output.
|
|
259
|
+
const atRoot = parentKey === "";
|
|
260
|
+
|
|
261
|
+
const atFunction = parentKey.startsWith("Functions.");
|
|
260
262
|
|
|
261
263
|
const newDestinationLocaleResources: LocaleResources = {};
|
|
262
264
|
|
|
263
265
|
// Copy over or delete any destination keys that are not in source.
|
|
264
266
|
for (const [key, destinationValue] of Object.entries(destinationLocaleResources)) {
|
|
265
267
|
if (!(key in sourceLocaleResources)) {
|
|
266
|
-
if (
|
|
268
|
+
if (atRoot || (atFunction && key === "titleCaseName")) {
|
|
267
269
|
newDestinationLocaleResources[key] = destinationValue;
|
|
268
270
|
} else if (logChanges) {
|
|
269
271
|
this.logger.info(`Deleting ${parentKey}${key}...`);
|
package/src/gs1/check-proxy.ts
CHANGED
|
@@ -67,7 +67,7 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
@proxy.describeMethod({
|
|
70
|
-
type: Types.
|
|
70
|
+
type: Types.Boolean,
|
|
71
71
|
multiplicity: Multiplicities.Matrix,
|
|
72
72
|
parameterDescriptors: [numericSWithCheckDigitParameterDescriptor]
|
|
73
73
|
})
|
|
@@ -85,7 +85,7 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
@proxy.describeMethod({
|
|
88
|
-
type: Types.
|
|
88
|
+
type: Types.Boolean,
|
|
89
89
|
multiplicity: Multiplicities.Singleton,
|
|
90
90
|
parameterDescriptors: [{
|
|
91
91
|
...numericSFourOrFiveDigitsParameterDescriptor,
|
|
@@ -106,7 +106,7 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
@proxy.describeMethod({
|
|
109
|
-
type: Types.
|
|
109
|
+
type: Types.Boolean,
|
|
110
110
|
multiplicity: Multiplicities.Matrix,
|
|
111
111
|
parameterDescriptors: [ai82SWithCheckCharacterPairParameterDescriptor]
|
|
112
112
|
})
|
|
@@ -126,7 +126,6 @@ export class GCPLengthProxy<ThrowError extends boolean, TError extends ErrorExte
|
|
|
126
126
|
type: Types.Number,
|
|
127
127
|
multiplicity: Multiplicities.Matrix,
|
|
128
128
|
isAsync: true,
|
|
129
|
-
titleCaseStart: 3,
|
|
130
129
|
parameterDescriptors: [identifierTypeParameterDescriptor, gcpLengthIdentifierParameterDescriptor]
|
|
131
130
|
})
|
|
132
131
|
async gcpLengthOf(identifierType: string, matrixIdentifiers: Matrix<string>): Promise<MatrixResult<number, ThrowError, TError>> {
|
|
@@ -141,7 +140,6 @@ export class GCPLengthProxy<ThrowError extends boolean, TError extends ErrorExte
|
|
|
141
140
|
type: Types.String,
|
|
142
141
|
multiplicity: Multiplicities.Singleton,
|
|
143
142
|
isAsync: true,
|
|
144
|
-
titleCaseStart: 3,
|
|
145
143
|
parameterDescriptors: []
|
|
146
144
|
})
|
|
147
145
|
async gcpLengthDateTime(): Promise<SingletonResult<string, ThrowError, TError>> {
|
|
@@ -154,7 +152,6 @@ export class GCPLengthProxy<ThrowError extends boolean, TError extends ErrorExte
|
|
|
154
152
|
type: Types.String,
|
|
155
153
|
multiplicity: Multiplicities.Singleton,
|
|
156
154
|
isAsync: true,
|
|
157
|
-
titleCaseStart: 3,
|
|
158
155
|
parameterDescriptors: []
|
|
159
156
|
})
|
|
160
157
|
async gcpLengthDisclaimer(): Promise<SingletonResult<string, ThrowError, TError>> {
|
|
@@ -128,7 +128,7 @@ export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
@proxy.describeMethod({
|
|
131
|
-
type: Types.
|
|
131
|
+
type: Types.Boolean,
|
|
132
132
|
multiplicity: Multiplicities.Matrix,
|
|
133
133
|
parameterDescriptors: [validateGTINParameterDescriptor, gtinLevelParameterDescriptor]
|
|
134
134
|
})
|
|
@@ -148,7 +148,7 @@ export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
@proxy.describeMethod({
|
|
151
|
-
type: Types.
|
|
151
|
+
type: Types.Boolean,
|
|
152
152
|
multiplicity: Multiplicities.Matrix,
|
|
153
153
|
parameterDescriptors: [validateGTIN14ParameterDescriptor]
|
|
154
154
|
})
|
|
@@ -61,7 +61,7 @@ abstract class NumericIdentifierValidatorProxy<ThrowError extends boolean, TErro
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
@proxy.describeMethod({
|
|
64
|
-
type: Types.
|
|
64
|
+
type: Types.Boolean,
|
|
65
65
|
multiplicity: Multiplicities.Matrix,
|
|
66
66
|
parameterDescriptors: [validateIdentifierParameterDescriptor]
|
|
67
67
|
})
|
|
@@ -109,7 +109,7 @@ export abstract class NonNumericIdentifierValidatorProxy<ThrowError extends bool
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
@proxy.describeMethod({
|
|
112
|
-
type: Types.
|
|
112
|
+
type: Types.Boolean,
|
|
113
113
|
multiplicity: Multiplicities.Matrix,
|
|
114
114
|
parameterDescriptors: [validateIdentifierParameterDescriptor, exclusionAllNumericParameterDescriptor]
|
|
115
115
|
})
|
|
@@ -735,14 +735,17 @@ export default {
|
|
|
735
735
|
},
|
|
736
736
|
gcpLengthOf: {
|
|
737
737
|
name: "gcpLengthOf",
|
|
738
|
+
titleCaseName: "GCPLengthOf",
|
|
738
739
|
description: "Get the length of a GS1 Company Prefix for an identifier."
|
|
739
740
|
},
|
|
740
741
|
gcpLengthDateTime: {
|
|
741
742
|
name: "gcpLengthDateTime",
|
|
743
|
+
titleCaseName: "GCPLengthDateTime",
|
|
742
744
|
description: "Get the date and time the GS1 Company Prefix length data was last updated."
|
|
743
745
|
},
|
|
744
746
|
gcpLengthDisclaimer: {
|
|
745
747
|
name: "gcpLengthDisclaimer",
|
|
748
|
+
titleCaseName: "GCPLengthDisclaimer",
|
|
746
749
|
description: "Get the disclaimer for the GS1 Company Prefix length data."
|
|
747
750
|
}
|
|
748
751
|
}
|
|
@@ -27,7 +27,7 @@ export default {
|
|
|
27
27
|
tweakFactorMustBeNumber: "Le facteur de réglage doit être un nombre"
|
|
28
28
|
},
|
|
29
29
|
ServiceProxy: {
|
|
30
|
-
invalidIdentifierType: "Type d'identifiant invalide «{{identifierType}}»"
|
|
30
|
+
invalidIdentifierType: "Type d'identifiant invalide « {{identifierType}} »"
|
|
31
31
|
},
|
|
32
32
|
Parameters: {
|
|
33
33
|
spillArray: {
|
|
@@ -731,18 +731,21 @@ export default {
|
|
|
731
731
|
},
|
|
732
732
|
verifiedByGS1: {
|
|
733
733
|
name: "verifiedByGS1",
|
|
734
|
-
description: "Créer un lien hypertexte «
|
|
734
|
+
description: "Créer un lien hypertexte « Verified by GS1 »."
|
|
735
735
|
},
|
|
736
736
|
gcpLengthOf: {
|
|
737
737
|
name: "longueurGCPDe",
|
|
738
|
+
titleCaseName: undefined,
|
|
738
739
|
description: "Obtenez la longueur du préfixe d'entreprise GS1 pour un identifiant."
|
|
739
740
|
},
|
|
740
741
|
gcpLengthDateTime: {
|
|
741
742
|
name: "dateHeureLongueurGCP",
|
|
743
|
+
titleCaseName: undefined,
|
|
742
744
|
description: "Obtenez la date et l'heure de la dernière mise à jour des données relatives à la longueur du préfixe d'entreprise GS1."
|
|
743
745
|
},
|
|
744
746
|
gcpLengthDisclaimer: {
|
|
745
747
|
name: "avertissementLongueurGCP",
|
|
748
|
+
titleCaseName: undefined,
|
|
746
749
|
description: "Obtenez l'avertissement relatif aux données sur la longueur des préfixes d'entreprise GS1."
|
|
747
750
|
}
|
|
748
751
|
}
|