@aidc-toolkit/app-extension 1.0.25-beta → 1.0.27-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 +146 -117
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -139
- package/dist/index.d.ts +123 -139
- package/dist/index.js +147 -118
- package/dist/index.js.map +1 -1
- package/package.json +14 -9
- package/src/app-extension.ts +30 -21
- package/src/app-utility-proxy.ts +19 -7
- package/src/descriptor.ts +64 -4
- package/src/generator/descriptor.ts +6 -3
- package/src/generator/generator.ts +46 -25
- package/src/generator/index.ts +2 -2
- package/src/generator/locale-resources-generator.ts +35 -35
- package/src/gs1/character-set-proxy.ts +5 -5
- package/src/gs1/check-proxy.ts +3 -3
- package/src/gs1/identifier-proxy.ts +45 -44
- package/src/gs1/index.ts +3 -3
- package/src/index.ts +9 -9
- package/src/lib-proxy.ts +24 -21
- package/src/locale/i18n.ts +3 -3
- package/src/locale/i18next.d.ts +1 -1
- package/src/utility/character-set-descriptor.ts +1 -1
- package/src/utility/character-set-proxy.ts +16 -16
- package/src/utility/index.ts +3 -3
- package/src/utility/reg-exp-proxy.ts +4 -4
- package/src/utility/string-descriptor.ts +1 -1
- package/src/utility/string-proxy.ts +2 -2
- package/src/utility/transformer-descriptor.ts +1 -1
- package/src/utility/transformer-proxy.ts +4 -4
- package/tsconfig-config.json +4 -0
- package/tsconfig-src.json +11 -0
- package/tsconfig.json +9 -4
- package/tsup.config.ts +3 -2
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/app-extension",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27-beta",
|
|
4
4
|
"description": "Application extension framework for AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"homepage": "https://aidc-toolkit.com/",
|
|
8
|
-
"repository":
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/aidc-toolkit/app-extension.git"
|
|
11
|
+
},
|
|
9
12
|
"bugs": {
|
|
10
13
|
"url": "https://github.com/aidc-toolkit/app-extension/issues"
|
|
11
14
|
},
|
|
@@ -16,19 +19,21 @@
|
|
|
16
19
|
"url": "https://www.linkedin.com/in/kdean"
|
|
17
20
|
},
|
|
18
21
|
"scripts": {
|
|
22
|
+
"locale-resources-generator": "tsx src/generator/locale-resources-generator.ts",
|
|
19
23
|
"lint": "eslint",
|
|
24
|
+
"tsc:core": "tsc --project tsconfig-src.json",
|
|
25
|
+
"build:devx": "rimraf dist && npm run tsc:core -- --declarationMap --sourceMap",
|
|
20
26
|
"build:dev": "tsup --define.mode=dev",
|
|
21
|
-
"build:release": "tsup",
|
|
27
|
+
"build:release": "npm run tsc:core -- --noEmit && tsup",
|
|
22
28
|
"build:doc": "npm run build:dev"
|
|
23
29
|
},
|
|
24
30
|
"devDependencies": {
|
|
25
|
-
"@aidc-toolkit/dev": "1.0.
|
|
26
|
-
"@types/node": "^24.10.1"
|
|
31
|
+
"@aidc-toolkit/dev": "1.0.27-beta"
|
|
27
32
|
},
|
|
28
33
|
"dependencies": {
|
|
29
|
-
"@aidc-toolkit/core": "1.0.
|
|
30
|
-
"@aidc-toolkit/gs1": "1.0.
|
|
31
|
-
"@aidc-toolkit/utility": "1.0.
|
|
32
|
-
"i18next": "^25.7.
|
|
34
|
+
"@aidc-toolkit/core": "1.0.27-beta",
|
|
35
|
+
"@aidc-toolkit/gs1": "1.0.27-beta",
|
|
36
|
+
"@aidc-toolkit/utility": "1.0.27-beta",
|
|
37
|
+
"i18next": "^25.7.2"
|
|
33
38
|
}
|
|
34
39
|
}
|
package/src/app-extension.ts
CHANGED
|
@@ -1,44 +1,47 @@
|
|
|
1
1
|
import type { TypedAsyncFunction, TypedFunction, TypedSyncFunction } from "@aidc-toolkit/core";
|
|
2
|
-
import { i18nextAppExtension } from "./locale/i18n";
|
|
3
|
-
import type { ErrorExtends, ResultError, SheetAddress, SheetRange } from "./type";
|
|
2
|
+
import { i18nextAppExtension } from "./locale/i18n.js";
|
|
3
|
+
import type { ErrorExtends, ResultError, SheetAddress, SheetRange } from "./type.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Application extension.
|
|
7
7
|
*
|
|
8
|
-
* @template TBigInt
|
|
9
|
-
* Type to which big integer is mapped.
|
|
10
|
-
*
|
|
11
8
|
* @template ThrowError
|
|
12
9
|
* If true, errors are reported through the throw/catch mechanism.
|
|
13
10
|
*
|
|
14
11
|
* @template TError
|
|
15
12
|
* Error type.
|
|
13
|
+
*
|
|
14
|
+
* @template TInvocationContext
|
|
15
|
+
* Application-specific invocation context type.
|
|
16
|
+
*
|
|
17
|
+
* @template TBigInt
|
|
18
|
+
* Type to which big integer is mapped.
|
|
16
19
|
*/
|
|
17
20
|
export abstract class AppExtension<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> {
|
|
18
21
|
/**
|
|
19
22
|
* Application version.
|
|
20
23
|
*/
|
|
21
|
-
|
|
24
|
+
readonly #version: string;
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* Maximum sequence count supported by application.
|
|
25
28
|
*/
|
|
26
|
-
|
|
29
|
+
readonly #maximumSequenceCount: number;
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* If true, errors are reported through the throw/catch mechanism.
|
|
30
33
|
*/
|
|
31
|
-
|
|
34
|
+
readonly #throwError: ThrowError;
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* Maximum width supported by application.
|
|
35
38
|
*/
|
|
36
|
-
|
|
39
|
+
#maximumWidth?: number;
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* Maximum height supported by application.
|
|
40
43
|
*/
|
|
41
|
-
|
|
44
|
+
#maximumHeight?: number;
|
|
42
45
|
|
|
43
46
|
/**
|
|
44
47
|
* Constructor.
|
|
@@ -53,9 +56,9 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
53
56
|
* If true, errors are reported through the throw/catch mechanism.
|
|
54
57
|
*/
|
|
55
58
|
protected constructor(version: string, maximumSequenceCount: number, throwError: ThrowError) {
|
|
56
|
-
this
|
|
57
|
-
this
|
|
58
|
-
this
|
|
59
|
+
this.#version = version;
|
|
60
|
+
this.#maximumSequenceCount = maximumSequenceCount;
|
|
61
|
+
this.#throwError = throwError;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
/**
|
|
@@ -65,14 +68,14 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
65
68
|
* Version.
|
|
66
69
|
*/
|
|
67
70
|
get version(): string {
|
|
68
|
-
return this
|
|
71
|
+
return this.#version;
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
/**
|
|
72
75
|
* Determine if errors are reported through the throw/catch mechanism.
|
|
73
76
|
*/
|
|
74
77
|
get throwError(): ThrowError {
|
|
75
|
-
return this
|
|
78
|
+
return this.#throwError;
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
/**
|
|
@@ -82,9 +85,9 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
82
85
|
* Maximum width supported by the application.
|
|
83
86
|
*/
|
|
84
87
|
async maximumWidth(): Promise<number> {
|
|
85
|
-
this
|
|
88
|
+
this.#maximumWidth ??= await this.getMaximumWidth();
|
|
86
89
|
|
|
87
|
-
return this
|
|
90
|
+
return this.#maximumWidth;
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
/**
|
|
@@ -102,9 +105,9 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
102
105
|
* Maximum height supported by the application.
|
|
103
106
|
*/
|
|
104
107
|
async maximumHeight(): Promise<number> {
|
|
105
|
-
this
|
|
108
|
+
this.#maximumHeight ??= await this.getMaximumHeight();
|
|
106
109
|
|
|
107
|
-
return this
|
|
110
|
+
return this.#maximumHeight;
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
/**
|
|
@@ -149,10 +152,10 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
149
152
|
validateSequenceCount(sequenceCount: number): void {
|
|
150
153
|
const absoluteSequenceCount = Math.abs(sequenceCount);
|
|
151
154
|
|
|
152
|
-
if (absoluteSequenceCount > this
|
|
155
|
+
if (absoluteSequenceCount > this.#maximumSequenceCount) {
|
|
153
156
|
throw new RangeError(i18nextAppExtension.t("AppExtension.sequenceCountMustBeLessThanOrEqualTo", {
|
|
154
157
|
sequenceCount: absoluteSequenceCount,
|
|
155
|
-
maximumSequenceCount: this
|
|
158
|
+
maximumSequenceCount: this.#maximumSequenceCount
|
|
156
159
|
}));
|
|
157
160
|
}
|
|
158
161
|
}
|
|
@@ -188,6 +191,9 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
188
191
|
/**
|
|
189
192
|
* Bind a synchronous method and wrap it in a try/catch for comprehensive error handling.
|
|
190
193
|
*
|
|
194
|
+
* @template TMethod
|
|
195
|
+
* Method type.
|
|
196
|
+
*
|
|
191
197
|
* @param thisArg
|
|
192
198
|
* The value to be passed as the `this` parameter to the method.
|
|
193
199
|
*
|
|
@@ -215,6 +221,9 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
215
221
|
/**
|
|
216
222
|
* Bind an asynchronous method and wrap it in a try/catch for comprehensive error handling.
|
|
217
223
|
*
|
|
224
|
+
* @template TMethod
|
|
225
|
+
* Method type.
|
|
226
|
+
*
|
|
218
227
|
* @param thisArg
|
|
219
228
|
* The value to be passed as the `this` parameter to the method.
|
|
220
229
|
*
|
package/src/app-utility-proxy.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isNullish, type NonNullishable, type Nullishable } from "@aidc-toolkit/core";
|
|
2
|
-
import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "./descriptor";
|
|
3
|
-
import { LibProxy } from "./lib-proxy";
|
|
4
|
-
import { i18nextAppExtension } from "./locale/i18n";
|
|
5
|
-
import type { ErrorExtends, Matrix } from "./type";
|
|
2
|
+
import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "./descriptor.js";
|
|
3
|
+
import { LibProxy } from "./lib-proxy.js";
|
|
4
|
+
import { i18nextAppExtension } from "./locale/i18n.js";
|
|
5
|
+
import type { ErrorExtends, Matrix } from "./type.js";
|
|
6
6
|
|
|
7
7
|
const spillMatrix: ParameterDescriptor = {
|
|
8
8
|
name: "spillMatrix",
|
|
@@ -47,6 +47,18 @@ interface MaximumDimensions {
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Application utilities.
|
|
50
|
+
*
|
|
51
|
+
*@template ThrowError
|
|
52
|
+
* If true, errors are reported through the throw/catch mechanism.
|
|
53
|
+
*
|
|
54
|
+
* @template TError
|
|
55
|
+
* Error type.
|
|
56
|
+
*
|
|
57
|
+
* @template TInvocationContext
|
|
58
|
+
* Application-specific invocation context type.
|
|
59
|
+
*
|
|
60
|
+
* @template TBigInt
|
|
61
|
+
* Type to which big integer is mapped.
|
|
50
62
|
*/
|
|
51
63
|
@ProxyClass()
|
|
52
64
|
export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
@@ -76,7 +88,7 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
76
88
|
* @returns
|
|
77
89
|
* Array of maximum width and maximum height.
|
|
78
90
|
*/
|
|
79
|
-
|
|
91
|
+
async #defaultMaximums(maximumDimensions: MaximumDimensions, invocationContext: Nullishable<TInvocationContext>): Promise<NonNullishable<MaximumDimensions>> {
|
|
80
92
|
if (isNullish(invocationContext)) {
|
|
81
93
|
// Application error; no localization necessary.
|
|
82
94
|
throw new Error("Invocation context not provided by application");
|
|
@@ -140,7 +152,7 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
140
152
|
throw new RangeError(i18nextAppExtension.t("Proxy.vSpillMustBeHorizontalArray"));
|
|
141
153
|
}
|
|
142
154
|
|
|
143
|
-
const maximumDimensions = await this
|
|
155
|
+
const maximumDimensions = await this.#defaultMaximums({
|
|
144
156
|
width: maximumWidth,
|
|
145
157
|
height: maximumHeight
|
|
146
158
|
}, invocationContext);
|
|
@@ -222,7 +234,7 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
222
234
|
}
|
|
223
235
|
}
|
|
224
236
|
|
|
225
|
-
const maximumDimensions = await this
|
|
237
|
+
const maximumDimensions = await this.#defaultMaximums({
|
|
226
238
|
width: maximumWidth,
|
|
227
239
|
height: maximumHeight
|
|
228
240
|
}, invocationContext);
|
package/src/descriptor.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TypedFunction } from "@aidc-toolkit/core";
|
|
2
|
-
import type { AppExtension } from "./app-extension";
|
|
3
|
-
import { LibProxy } from "./lib-proxy";
|
|
4
|
-
import type { ErrorExtends } from "./type";
|
|
2
|
+
import type { AppExtension } from "./app-extension.js";
|
|
3
|
+
import { LibProxy } from "./lib-proxy.js";
|
|
4
|
+
import type { ErrorExtends } from "./type.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Core descriptor.
|
|
@@ -167,8 +167,23 @@ export interface ClassDescriptor extends Descriptor {
|
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
169
|
* Proxy class type with fixed constructor.
|
|
170
|
+
*
|
|
171
|
+
* @template ThrowError
|
|
172
|
+
* If true, errors are reported through the throw/catch mechanism.
|
|
173
|
+
*
|
|
174
|
+
* @template TError
|
|
175
|
+
* Error type.
|
|
176
|
+
*
|
|
177
|
+
* @template TInvocationContext
|
|
178
|
+
* Application-specific invocation context type.
|
|
179
|
+
*
|
|
180
|
+
* @template TBigInt
|
|
181
|
+
* Type to which big integer is mapped.
|
|
182
|
+
*
|
|
183
|
+
* @template T
|
|
184
|
+
* Proxy type.
|
|
170
185
|
*/
|
|
171
|
-
type ProxyClassType<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, T extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt>> = (new(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) => T) & typeof LibProxy;
|
|
186
|
+
type ProxyClassType<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, T extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt>> = (new (appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) => T) & typeof LibProxy;
|
|
172
187
|
|
|
173
188
|
/**
|
|
174
189
|
* Pending parameter descriptors, consumed and reset when method is described.
|
|
@@ -188,6 +203,21 @@ const classDescriptorsMap = new Map<string, ClassDescriptor>();
|
|
|
188
203
|
/**
|
|
189
204
|
* Proxy parameter decorator.
|
|
190
205
|
*
|
|
206
|
+
* @template ThrowError
|
|
207
|
+
* If true, errors are reported through the throw/catch mechanism.
|
|
208
|
+
*
|
|
209
|
+
* @template TError
|
|
210
|
+
* Error type.
|
|
211
|
+
*
|
|
212
|
+
* @template TInvocationContext
|
|
213
|
+
* Application-specific invocation context type.
|
|
214
|
+
*
|
|
215
|
+
* @template TBigInt
|
|
216
|
+
* Type to which big integer is mapped.
|
|
217
|
+
*
|
|
218
|
+
* @template T
|
|
219
|
+
* Proxy type.
|
|
220
|
+
*
|
|
191
221
|
* @param parameterDescriptor
|
|
192
222
|
* Parameter descriptor.
|
|
193
223
|
*
|
|
@@ -203,6 +233,21 @@ export function ProxyParameter<ThrowError extends boolean, TError extends ErrorE
|
|
|
203
233
|
/**
|
|
204
234
|
* Proxy method decorator.
|
|
205
235
|
*
|
|
236
|
+
* @template ThrowError
|
|
237
|
+
* If true, errors are reported through the throw/catch mechanism.
|
|
238
|
+
*
|
|
239
|
+
* @template TError
|
|
240
|
+
* Error type.
|
|
241
|
+
*
|
|
242
|
+
* @template TInvocationContext
|
|
243
|
+
* Application-specific invocation context type.
|
|
244
|
+
*
|
|
245
|
+
* @template TBigInt
|
|
246
|
+
* Type to which big integer is mapped.
|
|
247
|
+
*
|
|
248
|
+
* @template T
|
|
249
|
+
* Proxy type.
|
|
250
|
+
*
|
|
206
251
|
* @param methodDescriptor
|
|
207
252
|
* Method descriptor.
|
|
208
253
|
*
|
|
@@ -258,6 +303,21 @@ export function ProxyMethod<ThrowError extends boolean, TError extends ErrorExte
|
|
|
258
303
|
/**
|
|
259
304
|
* Proxy class decorator.
|
|
260
305
|
*
|
|
306
|
+
* @template ThrowError
|
|
307
|
+
* If true, errors are reported through the throw/catch mechanism.
|
|
308
|
+
*
|
|
309
|
+
* @template TError
|
|
310
|
+
* Error type.
|
|
311
|
+
*
|
|
312
|
+
* @template TInvocationContext
|
|
313
|
+
* Application-specific invocation context type.
|
|
314
|
+
*
|
|
315
|
+
* @template TBigInt
|
|
316
|
+
* Type to which big integer is mapped.
|
|
317
|
+
*
|
|
318
|
+
* @template T
|
|
319
|
+
* Proxy type.
|
|
320
|
+
*
|
|
261
321
|
* @param classDescriptor
|
|
262
322
|
* Class descriptor.
|
|
263
323
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseParameterDescriptor, ClassDescriptor, MethodDescriptor } from "../descriptor";
|
|
1
|
+
import type { BaseParameterDescriptor, ClassDescriptor, MethodDescriptor } from "../descriptor.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Localization.
|
|
@@ -33,12 +33,15 @@ export interface ParameterLocalization extends Localization {
|
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Localization descriptor.
|
|
36
|
+
*
|
|
37
|
+
* @param TLocalization
|
|
38
|
+
* Localization type.
|
|
36
39
|
*/
|
|
37
|
-
export interface LocalizationDescriptor<
|
|
40
|
+
export interface LocalizationDescriptor<TLocalization extends Localization> {
|
|
38
41
|
/**
|
|
39
42
|
* Localizations map by locale.
|
|
40
43
|
*/
|
|
41
|
-
readonly localizationsMap: ReadonlyMap<string,
|
|
44
|
+
readonly localizationsMap: ReadonlyMap<string, TLocalization>;
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
/**
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { I18nEnvironments } from "@aidc-toolkit/core";
|
|
2
2
|
import type { ParseKeys } from "i18next";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { AppUtilityProxy } from "../app-utility-proxy.js";
|
|
4
|
+
import { expandParameterDescriptor, getClassDescriptorsMap } from "../descriptor.js";
|
|
5
|
+
import * as GS1 from "../gs1/index.js";
|
|
6
|
+
import { appExtensionResources, i18nAppExtensionInit, i18nextAppExtension } from "../locale/i18n.js";
|
|
7
|
+
import * as Utility from "../utility/index.js";
|
|
5
8
|
import type {
|
|
6
9
|
FunctionLocalization,
|
|
7
10
|
Localization,
|
|
8
11
|
ParameterLocalization,
|
|
9
12
|
ProxyFunctionDescriptor,
|
|
10
13
|
ProxyObjectDescriptor
|
|
11
|
-
} from "./descriptor";
|
|
14
|
+
} from "./descriptor.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Dummy method to force proxies to register their decorators.
|
|
18
|
+
*
|
|
19
|
+
* @param _proxies
|
|
20
|
+
* Proxies.
|
|
21
|
+
*/
|
|
22
|
+
function registerProxies(..._proxies: unknown[]): void {
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
registerProxies(AppUtilityProxy, Utility, GS1);
|
|
12
26
|
|
|
13
27
|
/**
|
|
14
28
|
* Abstract generator.
|
|
@@ -17,32 +31,32 @@ export abstract class Generator {
|
|
|
17
31
|
/**
|
|
18
32
|
* Documentation base URL.
|
|
19
33
|
*/
|
|
20
|
-
|
|
34
|
+
static readonly #DOCUMENTATION_BASE_URL = "https://aidc-toolkit.com/";
|
|
21
35
|
|
|
22
36
|
/**
|
|
23
37
|
* Documentation path, optionally preceded by locale.
|
|
24
38
|
*/
|
|
25
|
-
|
|
39
|
+
static readonly #DOCUMENTATION_PATH = "app-extension/";
|
|
26
40
|
|
|
27
41
|
/**
|
|
28
42
|
* Locales.
|
|
29
43
|
*/
|
|
30
|
-
|
|
44
|
+
readonly #locales: readonly string[];
|
|
31
45
|
|
|
32
46
|
/**
|
|
33
47
|
* Default locale.
|
|
34
48
|
*/
|
|
35
|
-
|
|
49
|
+
readonly #defaultLocale: string;
|
|
36
50
|
|
|
37
51
|
/**
|
|
38
52
|
* Map of function localizations maps by namespace function name.
|
|
39
53
|
*/
|
|
40
|
-
|
|
54
|
+
readonly #functionLocalizationsMapsMap = new Map<string, ReadonlyMap<string, FunctionLocalization>>();
|
|
41
55
|
|
|
42
56
|
/**
|
|
43
57
|
* Map of parameter localizations maps by namespace function parameter name.
|
|
44
58
|
*/
|
|
45
|
-
|
|
59
|
+
readonly #parameterLocalizationsMapsMap = new Map<string, ReadonlyMap<string, ParameterLocalization>>();
|
|
46
60
|
|
|
47
61
|
/**
|
|
48
62
|
*
|
|
@@ -55,22 +69,22 @@ export abstract class Generator {
|
|
|
55
69
|
* Include localizations if true.
|
|
56
70
|
*/
|
|
57
71
|
constructor(includeLocalizations = true) {
|
|
58
|
-
this
|
|
59
|
-
this
|
|
72
|
+
this.#locales = includeLocalizations ? Object.keys(appExtensionResources) : [];
|
|
73
|
+
this.#defaultLocale = this.#locales[0] ?? "";
|
|
60
74
|
}
|
|
61
75
|
|
|
62
76
|
/**
|
|
63
77
|
* Get the locales.
|
|
64
78
|
*/
|
|
65
79
|
protected get locales(): readonly string[] {
|
|
66
|
-
return this
|
|
80
|
+
return this.#locales;
|
|
67
81
|
}
|
|
68
82
|
|
|
69
83
|
/**
|
|
70
84
|
* Get the default locale.
|
|
71
85
|
*/
|
|
72
86
|
protected get defaultLocale(): string {
|
|
73
|
-
return this
|
|
87
|
+
return this.#defaultLocale;
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
/**
|
|
@@ -86,10 +100,10 @@ export abstract class Generator {
|
|
|
86
100
|
* Function localization.
|
|
87
101
|
*/
|
|
88
102
|
protected getFunctionLocalization(namespaceFunctionName: string, locale: string): FunctionLocalization {
|
|
89
|
-
const functionLocalization = this.
|
|
103
|
+
const functionLocalization = this.#functionLocalizationsMapsMap.get(namespaceFunctionName)?.get(locale);
|
|
90
104
|
|
|
91
105
|
if (functionLocalization === undefined) {
|
|
92
|
-
throw new Error(
|
|
106
|
+
throw new Error(`${locale} localization for function ${namespaceFunctionName} not found`);
|
|
93
107
|
}
|
|
94
108
|
|
|
95
109
|
return functionLocalization;
|
|
@@ -111,10 +125,10 @@ export abstract class Generator {
|
|
|
111
125
|
* Function localization.
|
|
112
126
|
*/
|
|
113
127
|
protected getParameterLocalization(namespaceFunctionName: string, parameterName: string, locale: string): ParameterLocalization {
|
|
114
|
-
const parameterLocalization = this.
|
|
128
|
+
const parameterLocalization = this.#parameterLocalizationsMapsMap.get(`${namespaceFunctionName}.${parameterName}`)?.get(locale);
|
|
115
129
|
|
|
116
130
|
if (parameterLocalization === undefined) {
|
|
117
|
-
throw new Error(
|
|
131
|
+
throw new Error(`${locale} localization for function ${namespaceFunctionName} parameter ${parameterName} not found`);
|
|
118
132
|
}
|
|
119
133
|
|
|
120
134
|
return parameterLocalization;
|
|
@@ -152,6 +166,9 @@ export abstract class Generator {
|
|
|
152
166
|
/**
|
|
153
167
|
* Generate localizations map.
|
|
154
168
|
*
|
|
169
|
+
* @template TLocalization
|
|
170
|
+
* Localization type.
|
|
171
|
+
*
|
|
155
172
|
* @param localizedKeyPrefix
|
|
156
173
|
* Localized key prefix.
|
|
157
174
|
*
|
|
@@ -161,8 +178,8 @@ export abstract class Generator {
|
|
|
161
178
|
* @returns
|
|
162
179
|
* Localization map.
|
|
163
180
|
*/
|
|
164
|
-
|
|
165
|
-
return new Map(this.
|
|
181
|
+
#generateLocalizationsMap<TLocalization extends Localization>(localizedKeyPrefix: string, localizationCallback: (locale: string, localization: Localization) => TLocalization): ReadonlyMap<string, TLocalization> {
|
|
182
|
+
return new Map(this.#locales.map((locale) => {
|
|
166
183
|
const lngOption = {
|
|
167
184
|
lng: locale
|
|
168
185
|
};
|
|
@@ -184,6 +201,10 @@ export abstract class Generator {
|
|
|
184
201
|
|
|
185
202
|
await i18nAppExtensionInit(I18nEnvironments.CLI);
|
|
186
203
|
|
|
204
|
+
// const LocaleResourcesSource = path.resolve(LocaleResourcesGenerator.IMPORT_PATH, entry.name, "locale-resources.ts");
|
|
205
|
+
//
|
|
206
|
+
// await import(LocaleResourcesSource).then((module) => {
|
|
207
|
+
|
|
187
208
|
this.initialize();
|
|
188
209
|
|
|
189
210
|
try {
|
|
@@ -237,7 +258,7 @@ export abstract class Generator {
|
|
|
237
258
|
const insertIndex = methodName.indexOf(infixBefore);
|
|
238
259
|
|
|
239
260
|
if (insertIndex === -1) {
|
|
240
|
-
throw new Error(`Cannot find "${infixBefore}" in method
|
|
261
|
+
throw new Error(`Cannot find "${infixBefore}" in method ${methodName}`);
|
|
241
262
|
}
|
|
242
263
|
|
|
243
264
|
// Other classes in the hierarchy and infix is in the middle of the string.
|
|
@@ -246,12 +267,12 @@ export abstract class Generator {
|
|
|
246
267
|
|
|
247
268
|
const namespaceFunctionName = `${namespacePrefix}${functionName}`;
|
|
248
269
|
|
|
249
|
-
const functionLocalizationsMap = this
|
|
270
|
+
const functionLocalizationsMap = this.#generateLocalizationsMap<FunctionLocalization>(`Functions.${namespaceFunctionName}.`, (locale, localization) => ({
|
|
250
271
|
...localization,
|
|
251
|
-
documentationURL: `${Generator
|
|
272
|
+
documentationURL: `${Generator.#DOCUMENTATION_BASE_URL}${locale === this.defaultLocale ? "" : `${locale}/`}${Generator.#DOCUMENTATION_PATH}${namespace === undefined ? "" : `${namespace}/`}${localization.name}.html`
|
|
252
273
|
}));
|
|
253
274
|
|
|
254
|
-
this.
|
|
275
|
+
this.#functionLocalizationsMapsMap.set(namespaceFunctionName, functionLocalizationsMap);
|
|
255
276
|
|
|
256
277
|
this.createProxyFunction({
|
|
257
278
|
...proxyObjectDescriptor,
|
|
@@ -263,9 +284,9 @@ export abstract class Generator {
|
|
|
263
284
|
|
|
264
285
|
const parameterName = expandedParameterDescriptor.name;
|
|
265
286
|
|
|
266
|
-
const parameterLocalizationsMap = this
|
|
287
|
+
const parameterLocalizationsMap = this.#generateLocalizationsMap(`Parameters.${parameterName}.`, (_locale, localization) => localization);
|
|
267
288
|
|
|
268
|
-
this.
|
|
289
|
+
this.#parameterLocalizationsMapsMap.set(`${namespaceFunctionName}.${parameterName}`, parameterLocalizationsMap);
|
|
269
290
|
|
|
270
291
|
return {
|
|
271
292
|
namespace,
|
package/src/generator/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type * from "./descriptor";
|
|
2
|
-
export * from "./generator";
|
|
1
|
+
export type * from "./descriptor.js";
|
|
2
|
+
export * from "./generator.js";
|