@aidc-toolkit/app-extension 1.0.28-beta → 1.0.31-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 +23 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -9
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/generator/generator.ts +10 -6
- package/src/proxy.ts +23 -6
- package/tsconfig.json +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/app-extension",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31-beta",
|
|
4
4
|
"description": "Application extension framework for AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"build:doc": "npm run build:dev"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@aidc-toolkit/dev": "1.0.
|
|
31
|
+
"@aidc-toolkit/dev": "1.0.31-beta"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@aidc-toolkit/core": "1.0.
|
|
35
|
-
"@aidc-toolkit/gs1": "1.0.
|
|
36
|
-
"@aidc-toolkit/utility": "1.0.
|
|
34
|
+
"@aidc-toolkit/core": "1.0.31-beta",
|
|
35
|
+
"@aidc-toolkit/gs1": "1.0.31-beta",
|
|
36
|
+
"@aidc-toolkit/utility": "1.0.31-beta",
|
|
37
37
|
"i18next": "^25.7.2"
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -195,20 +195,23 @@ export abstract class Generator {
|
|
|
195
195
|
* @param localizedKeyPrefix
|
|
196
196
|
* Localized key prefix.
|
|
197
197
|
*
|
|
198
|
+
* @param namespacePrefix
|
|
199
|
+
* Namespace prefix to be appended to name.
|
|
200
|
+
*
|
|
198
201
|
* @param localizationCallback
|
|
199
202
|
* Callback to finalize localization.
|
|
200
203
|
*
|
|
201
204
|
* @returns
|
|
202
205
|
* Localization.
|
|
203
206
|
*/
|
|
204
|
-
#generateLocalization<TLocalization extends Localization>(locale: string, localizedKeyPrefix: string, localizationCallback: (locale: string, localization: Localization) => TLocalization): TLocalization {
|
|
207
|
+
#generateLocalization<TLocalization extends Localization>(locale: string, localizedKeyPrefix: string, namespacePrefix: string, localizationCallback: (locale: string, localization: Localization) => TLocalization): TLocalization {
|
|
205
208
|
const lngOption = {
|
|
206
209
|
lng: locale
|
|
207
210
|
};
|
|
208
211
|
|
|
209
212
|
return localizationCallback(locale, {
|
|
210
213
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Localized key exists.
|
|
211
|
-
name: i18nextAppExtension.t(`${localizedKeyPrefix}name` as ParseKeys, lngOption)
|
|
214
|
+
name: `${namespacePrefix}${i18nextAppExtension.t(`${localizedKeyPrefix}name` as ParseKeys, lngOption)}`,
|
|
212
215
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Localized key exists.
|
|
213
216
|
description: i18nextAppExtension.t(`${localizedKeyPrefix}description` as ParseKeys, lngOption)
|
|
214
217
|
});
|
|
@@ -231,19 +234,20 @@ export abstract class Generator {
|
|
|
231
234
|
try {
|
|
232
235
|
for (const [_namespaceClassName, classDescriptor] of proxy.classDescriptorsMap.entries()) {
|
|
233
236
|
const namespace = classDescriptor.namespace;
|
|
237
|
+
const namespacePrefix = namespace === undefined ? "" : `${namespace}.`;
|
|
238
|
+
const namespacePath = namespace === undefined ? "" : `${namespace}/`;
|
|
234
239
|
|
|
235
240
|
this.createProxyObject(classDescriptor);
|
|
236
241
|
|
|
237
242
|
for (const methodDescriptor of classDescriptor.methodDescriptors) {
|
|
238
243
|
const namespaceFunctionName = methodDescriptor.namespaceFunctionName;
|
|
239
|
-
|
|
240
244
|
const functionLocalizationsMap = new Map(this.#locales.map(locale =>
|
|
241
|
-
[locale, this.#generateLocalization<FunctionLocalization>(locale, `Functions.${namespaceFunctionName}.`, (locale, localization) => ({
|
|
245
|
+
[locale, this.#generateLocalization<FunctionLocalization>(locale, `Functions.${namespaceFunctionName}.`, namespacePrefix, (locale, localization) => ({
|
|
242
246
|
...localization,
|
|
243
|
-
documentationURL: `${Generator.#DOCUMENTATION_BASE_URL}${locale === this.defaultLocale ? "" : `${locale}/`}${Generator.#DOCUMENTATION_PATH}${
|
|
247
|
+
documentationURL: `${Generator.#DOCUMENTATION_BASE_URL}${locale === this.defaultLocale ? "" : `${locale}/`}${Generator.#DOCUMENTATION_PATH}${namespacePath}${localization.name}.html`,
|
|
244
248
|
parametersMap: new Map(methodDescriptor.parameterDescriptors.map(parameterDescriptor =>
|
|
245
249
|
// eslint-disable-next-line max-nested-callbacks -- Callback is empty.
|
|
246
|
-
[parameterDescriptor.name, this.#generateLocalization(locale, `Parameters.${parameterDescriptor.name}.`, (_locale, localization) => localization)]
|
|
250
|
+
[parameterDescriptor.name, this.#generateLocalization(locale, `Parameters.${parameterDescriptor.name}.`, "", (_locale, localization) => localization)]
|
|
247
251
|
))
|
|
248
252
|
}))]
|
|
249
253
|
));
|
package/src/proxy.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
type AbstractConstructor,
|
|
3
3
|
type Constructor,
|
|
4
4
|
getLogger,
|
|
5
|
+
type LogLevel,
|
|
5
6
|
LogLevels,
|
|
6
7
|
omit,
|
|
7
8
|
type TypedAbstractConstructor
|
|
@@ -146,6 +147,9 @@ interface TargetLogger {
|
|
|
146
147
|
/**
|
|
147
148
|
* Log a method call.
|
|
148
149
|
*
|
|
150
|
+
* @param logLevel
|
|
151
|
+
* Log level.
|
|
152
|
+
*
|
|
149
153
|
* @param methodName
|
|
150
154
|
* Method name.
|
|
151
155
|
*
|
|
@@ -155,7 +159,7 @@ interface TargetLogger {
|
|
|
155
159
|
* @param result
|
|
156
160
|
* Output result.
|
|
157
161
|
*/
|
|
158
|
-
log: (methodName: string, args: unknown[], result: unknown) => void;
|
|
162
|
+
log: (logLevel: LogLevel, methodName: string, args: unknown[], result: unknown) => void;
|
|
159
163
|
}
|
|
160
164
|
|
|
161
165
|
/**
|
|
@@ -165,6 +169,8 @@ export class Proxy {
|
|
|
165
169
|
/**
|
|
166
170
|
* Logger.
|
|
167
171
|
*/
|
|
172
|
+
// TODO Add configuration parameter to output JSON.
|
|
173
|
+
// TODO Change this to LogLevels.Trace when configuration available.
|
|
168
174
|
readonly #logger: Logger<unknown> = getLogger(LogLevels.Info);
|
|
169
175
|
|
|
170
176
|
/**
|
|
@@ -419,14 +425,14 @@ export class Proxy {
|
|
|
419
425
|
/**
|
|
420
426
|
* @inheritDoc
|
|
421
427
|
*/
|
|
422
|
-
log(methodName: string, args: unknown[], result: unknown): void {
|
|
428
|
+
log(logLevel: LogLevel, methodName: string, args: unknown[], result: unknown): void {
|
|
423
429
|
// // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type hierarchy is known.
|
|
424
430
|
// const appExtension = (this as unknown as T).appExtension;
|
|
425
431
|
|
|
426
432
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Method name is known to be valid at this point.
|
|
427
433
|
const methodDescriptor = methodDescriptorsMap.get(methodName)!;
|
|
428
434
|
|
|
429
|
-
logger.
|
|
435
|
+
logger.log(logLevel, "", JSON.stringify({
|
|
430
436
|
namespace: decoratorClassDescriptor.namespace,
|
|
431
437
|
className: name,
|
|
432
438
|
methodName,
|
|
@@ -485,10 +491,21 @@ export class Proxy {
|
|
|
485
491
|
});
|
|
486
492
|
|
|
487
493
|
return function methodProxy(this: TThis, ...args: TArguments): TReturn {
|
|
488
|
-
const result = target.call(this, ...args);
|
|
489
|
-
|
|
490
494
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Class has been modified to add log method.
|
|
491
|
-
|
|
495
|
+
const targetLogger = this as TargetLogger;
|
|
496
|
+
|
|
497
|
+
let result: TReturn;
|
|
498
|
+
|
|
499
|
+
try {
|
|
500
|
+
result = target.call(this, ...args);
|
|
501
|
+
|
|
502
|
+
// TODO Change this to LogLevels.Trace when configuration available.
|
|
503
|
+
targetLogger.log(LogLevels.Info, name, args, result);
|
|
504
|
+
} catch (e: unknown) {
|
|
505
|
+
targetLogger.log(LogLevels.Error, name, args, e instanceof Error ? `${e.name}: ${e.message}` : `Unknown exception: ${String(e)}`);
|
|
506
|
+
|
|
507
|
+
throw e;
|
|
508
|
+
}
|
|
492
509
|
|
|
493
510
|
return result;
|
|
494
511
|
};
|