@aidc-toolkit/app-extension 0.9.19-beta → 0.9.21-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/README.md +1 -1
- package/app-extension.iml +3 -1
- package/dist/app-utility-proxy.js +6 -6
- package/dist/app-utility-proxy.js.map +1 -1
- package/dist/descriptor.d.ts +10 -6
- package/dist/descriptor.d.ts.map +1 -1
- package/dist/descriptor.js +6 -7
- package/dist/descriptor.js.map +1 -1
- package/dist/generator/descriptor.d.ts +107 -0
- package/dist/generator/descriptor.d.ts.map +1 -0
- package/dist/generator/descriptor.js +2 -0
- package/dist/generator/descriptor.js.map +1 -0
- package/dist/generator/generator.d.ts +120 -0
- package/dist/generator/generator.d.ts.map +1 -0
- package/dist/generator/generator.js +213 -0
- package/dist/generator/generator.js.map +1 -0
- package/dist/generator/index.d.ts +3 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +2 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/gs1/check-proxy.js +8 -8
- package/dist/gs1/check-proxy.js.map +1 -1
- package/dist/gs1/{idkey-proxy.d.ts → identifier-proxy.d.ts} +44 -43
- package/dist/gs1/identifier-proxy.d.ts.map +1 -0
- package/dist/gs1/{idkey-proxy.js → identifier-proxy.js} +113 -110
- package/dist/gs1/identifier-proxy.js.map +1 -0
- package/dist/gs1/index.d.ts +1 -1
- package/dist/gs1/index.d.ts.map +1 -1
- package/dist/gs1/index.js +1 -1
- package/dist/gs1/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/locale/en/locale-strings.d.ts +3 -3
- package/dist/locale/en/locale-strings.js +11 -11
- package/dist/locale/en/locale-strings.js.map +1 -1
- package/dist/locale/fr/locale-strings.d.ts +3 -3
- package/dist/locale/fr/locale-strings.js +4 -4
- package/dist/locale/fr/locale-strings.js.map +1 -1
- package/dist/utility/character-set-descriptor.d.ts.map +1 -1
- package/dist/utility/character-set-descriptor.js +2 -2
- package/dist/utility/character-set-descriptor.js.map +1 -1
- package/dist/utility/character-set-proxy.js +7 -7
- package/dist/utility/character-set-proxy.js.map +1 -1
- package/dist/utility/reg-exp-proxy.js +5 -5
- package/dist/utility/reg-exp-proxy.js.map +1 -1
- package/dist/utility/string-descriptor.d.ts.map +1 -1
- package/dist/utility/string-descriptor.js +2 -2
- package/dist/utility/string-descriptor.js.map +1 -1
- package/dist/utility/transformer-descriptor.d.ts.map +1 -1
- package/dist/utility/transformer-descriptor.js +3 -3
- package/dist/utility/transformer-descriptor.js.map +1 -1
- package/dist/utility/transformer-proxy.js +6 -6
- package/dist/utility/transformer-proxy.js.map +1 -1
- package/package.json +1 -1
- package/src/app-utility-proxy.ts +6 -6
- package/src/descriptor.ts +11 -6
- package/src/generator/descriptor.ts +122 -0
- package/src/generator/generator.ts +287 -0
- package/src/generator/index.ts +2 -0
- package/src/generator/locale-strings-generator.ts +358 -0
- package/src/generator/logger.ts +45 -0
- package/src/gs1/check-proxy.ts +8 -8
- package/src/gs1/{idkey-proxy.ts → identifier-proxy.ts} +125 -120
- package/src/gs1/index.ts +1 -1
- package/src/index.ts +1 -0
- package/src/locale/en/locale-strings.ts +11 -11
- package/src/locale/fr/locale-strings.ts +4 -4
- package/src/utility/character-set-descriptor.ts +2 -2
- package/src/utility/character-set-proxy.ts +7 -7
- package/src/utility/reg-exp-proxy.ts +5 -5
- package/src/utility/string-descriptor.ts +2 -2
- package/src/utility/transformer-descriptor.ts +3 -3
- package/src/utility/transformer-proxy.ts +6 -6
- package/dist/gs1/idkey-proxy.d.ts.map +0 -1
- package/dist/gs1/idkey-proxy.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer-proxy.js","sourceRoot":"","sources":["../../src/utility/transformer-proxy.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"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,CAAC,CAAA;IACnD,WAAA,cAAc,CAAC,wBAAwB,CAAC,CAAA;+CAK5C;AA3CQ,gBAAgB;IAH5B,UAAU,CAAC;QACR,WAAW,EAAE,WAAW;KAC3B,CAAC;GACW,gBAAgB,CA4C5B"}
|
package/package.json
CHANGED
package/src/app-utility-proxy.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter,
|
|
1
|
+
import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "./descriptor.js";
|
|
2
2
|
import { LibProxy } from "./lib-proxy.js";
|
|
3
3
|
import { i18nextAppExtension } from "./locale/i18n.js";
|
|
4
4
|
import { type ErrorExtends, isNullish, type Matrix, type NonNullishable, type Nullishable } from "./types.js";
|
|
5
5
|
|
|
6
6
|
const spillMatrix: ParameterDescriptor = {
|
|
7
7
|
name: "spillMatrix",
|
|
8
|
-
type:
|
|
8
|
+
type: Types.Any,
|
|
9
9
|
isMatrix: true,
|
|
10
10
|
isRequired: true
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const spillMaximumParameterDescriptor: ParameterDescriptor = {
|
|
14
14
|
name: "spillMaximum",
|
|
15
|
-
type:
|
|
15
|
+
type: Types.Number,
|
|
16
16
|
isMatrix: false,
|
|
17
17
|
isRequired: false
|
|
18
18
|
};
|
|
@@ -56,7 +56,7 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
56
56
|
* Version.
|
|
57
57
|
*/
|
|
58
58
|
@ProxyMethod({
|
|
59
|
-
type:
|
|
59
|
+
type: Types.String,
|
|
60
60
|
isMatrix: false
|
|
61
61
|
})
|
|
62
62
|
version(): string {
|
|
@@ -124,7 +124,7 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
124
124
|
*/
|
|
125
125
|
@ProxyMethod({
|
|
126
126
|
requiresContext: true,
|
|
127
|
-
type:
|
|
127
|
+
type: Types.Any,
|
|
128
128
|
isMatrix: true
|
|
129
129
|
})
|
|
130
130
|
async vSpill(
|
|
@@ -203,7 +203,7 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
203
203
|
*/
|
|
204
204
|
@ProxyMethod({
|
|
205
205
|
requiresContext: true,
|
|
206
|
-
type:
|
|
206
|
+
type: Types.Any,
|
|
207
207
|
isMatrix: true
|
|
208
208
|
})
|
|
209
209
|
async hSpill(
|
package/src/descriptor.ts
CHANGED
|
@@ -12,27 +12,32 @@ interface Descriptor {
|
|
|
12
12
|
/**
|
|
13
13
|
* Types supported by proxy methods.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export const Types = {
|
|
16
16
|
/**
|
|
17
17
|
* String.
|
|
18
18
|
*/
|
|
19
|
-
String,
|
|
19
|
+
String: 0,
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Number or enumeration.
|
|
23
23
|
*/
|
|
24
|
-
Number,
|
|
24
|
+
Number: 1,
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Boolean.
|
|
28
28
|
*/
|
|
29
|
-
Boolean,
|
|
29
|
+
Boolean: 2,
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Any.
|
|
33
33
|
*/
|
|
34
|
-
Any
|
|
35
|
-
}
|
|
34
|
+
Any: 3
|
|
35
|
+
} as const;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Type.
|
|
39
|
+
*/
|
|
40
|
+
export type Type = typeof Types[keyof typeof Types];
|
|
36
41
|
|
|
37
42
|
/**
|
|
38
43
|
* Type descriptor.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { BaseParameterDescriptor, ClassDescriptor, MethodDescriptor } from "../descriptor.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Localization.
|
|
5
|
+
*/
|
|
6
|
+
export interface Localization {
|
|
7
|
+
/**
|
|
8
|
+
* Name.
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Description.
|
|
14
|
+
*/
|
|
15
|
+
description: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Function localization.
|
|
20
|
+
*/
|
|
21
|
+
export interface FunctionLocalization extends Localization {
|
|
22
|
+
/**
|
|
23
|
+
* Documentation URL.
|
|
24
|
+
*/
|
|
25
|
+
documentationURL: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parameter localization.
|
|
30
|
+
*/
|
|
31
|
+
export interface ParameterLocalization extends Localization {
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Localization descriptor.
|
|
36
|
+
*/
|
|
37
|
+
export interface LocalizationDescriptor<T extends Localization> {
|
|
38
|
+
/**
|
|
39
|
+
* Localizations map by locale.
|
|
40
|
+
*/
|
|
41
|
+
readonly localizationsMap: ReadonlyMap<string, T>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Proxy namespace descriptor.
|
|
46
|
+
*/
|
|
47
|
+
export interface ProxyNamespaceDescriptor {
|
|
48
|
+
/**
|
|
49
|
+
* Namespace if any.
|
|
50
|
+
*/
|
|
51
|
+
readonly namespace: string | undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Proxy class descriptor.
|
|
56
|
+
*/
|
|
57
|
+
export interface ProxyClassDescriptor extends ProxyNamespaceDescriptor {
|
|
58
|
+
/**
|
|
59
|
+
* Class name.
|
|
60
|
+
*/
|
|
61
|
+
readonly className: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Namespace-qualified class name.
|
|
65
|
+
*/
|
|
66
|
+
readonly namespaceClassName: string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Class descriptor.
|
|
70
|
+
*/
|
|
71
|
+
readonly classDescriptor: ClassDescriptor;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Proxy object descriptor.
|
|
76
|
+
*/
|
|
77
|
+
export interface ProxyObjectDescriptor extends ProxyClassDescriptor {
|
|
78
|
+
/**
|
|
79
|
+
* Object name.
|
|
80
|
+
*/
|
|
81
|
+
readonly objectName: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Proxy parameter descriptor.
|
|
86
|
+
*/
|
|
87
|
+
export interface ProxyParameterDescriptor extends ProxyNamespaceDescriptor, LocalizationDescriptor<ParameterLocalization> {
|
|
88
|
+
/**
|
|
89
|
+
* Function name.
|
|
90
|
+
*/
|
|
91
|
+
readonly parameterName: string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Parameter descriptor.
|
|
95
|
+
*/
|
|
96
|
+
readonly parameterDescriptor: BaseParameterDescriptor;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Proxy function descriptor.
|
|
101
|
+
*/
|
|
102
|
+
export interface ProxyFunctionDescriptor extends ProxyObjectDescriptor, LocalizationDescriptor<FunctionLocalization> {
|
|
103
|
+
/**
|
|
104
|
+
* Function name.
|
|
105
|
+
*/
|
|
106
|
+
readonly functionName: string;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Namespace-qualified function name.
|
|
110
|
+
*/
|
|
111
|
+
readonly namespaceFunctionName: string;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Proxy parameter descriptors
|
|
115
|
+
*/
|
|
116
|
+
readonly proxyParameterDescriptors: ProxyParameterDescriptor[];
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Method descriptor.
|
|
120
|
+
*/
|
|
121
|
+
readonly methodDescriptor: MethodDescriptor;
|
|
122
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { I18nEnvironments } from "@aidc-toolkit/core";
|
|
2
|
+
import type { ParseKeys } from "i18next";
|
|
3
|
+
import { expandParameterDescriptor, getClassDescriptors } from "../descriptor.js";
|
|
4
|
+
import { appExtensionResources, i18nAppExtensionInit, i18nextAppExtension } from "../locale/i18n.js";
|
|
5
|
+
import type {
|
|
6
|
+
FunctionLocalization,
|
|
7
|
+
Localization,
|
|
8
|
+
ParameterLocalization,
|
|
9
|
+
ProxyFunctionDescriptor,
|
|
10
|
+
ProxyObjectDescriptor
|
|
11
|
+
} from "./descriptor.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Abstract generator.
|
|
15
|
+
*/
|
|
16
|
+
export abstract class Generator {
|
|
17
|
+
/**
|
|
18
|
+
* Documentation base URL.
|
|
19
|
+
*/
|
|
20
|
+
private static readonly DOCUMENTATION_BASE_URL = "https://aidc-toolkit.com/";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Documentation path, optionally preceded by locale.
|
|
24
|
+
*/
|
|
25
|
+
private static readonly DOCUMENTATION_PATH = "app-extension/";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Locales.
|
|
29
|
+
*/
|
|
30
|
+
private readonly _locales: readonly string[];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Default locale.
|
|
34
|
+
*/
|
|
35
|
+
private readonly _defaultLocale: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Map of function localizations maps by namespace function name.
|
|
39
|
+
*/
|
|
40
|
+
private readonly _functionLocalizationsMapsMap = new Map<string, ReadonlyMap<string, FunctionLocalization>>();
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Map of parameter localizations maps by namespace function parameter name.
|
|
44
|
+
*/
|
|
45
|
+
private readonly _parameterLocalizationsMapsMap = new Map<string, ReadonlyMap<string, ParameterLocalization>>();
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Constructor.
|
|
53
|
+
*
|
|
54
|
+
* @param includeLocalizations
|
|
55
|
+
* Include localizations if true.
|
|
56
|
+
*/
|
|
57
|
+
constructor(includeLocalizations = true) {
|
|
58
|
+
this._locales = includeLocalizations ? Object.keys(appExtensionResources) : [];
|
|
59
|
+
this._defaultLocale = this._locales[0] ?? "";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get the locales.
|
|
64
|
+
*/
|
|
65
|
+
protected get locales(): readonly string[] {
|
|
66
|
+
return this._locales;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the default locale.
|
|
71
|
+
*/
|
|
72
|
+
protected get defaultLocale(): string {
|
|
73
|
+
return this._defaultLocale;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get function localization.
|
|
78
|
+
*
|
|
79
|
+
* @param namespaceFunctionName
|
|
80
|
+
* Namespace function name.
|
|
81
|
+
*
|
|
82
|
+
* @param locale
|
|
83
|
+
* Locale.
|
|
84
|
+
*
|
|
85
|
+
* @returns
|
|
86
|
+
* Function localization.
|
|
87
|
+
*/
|
|
88
|
+
protected getFunctionLocalization(namespaceFunctionName: string, locale: string): FunctionLocalization {
|
|
89
|
+
const functionLocalization = this._functionLocalizationsMapsMap.get(namespaceFunctionName)?.get(locale);
|
|
90
|
+
|
|
91
|
+
if (functionLocalization === undefined) {
|
|
92
|
+
throw new Error(`Localization for function "${namespaceFunctionName}", locale "${locale}" not found`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return functionLocalization;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Get parameter localization.
|
|
100
|
+
*
|
|
101
|
+
* @param namespaceFunctionName
|
|
102
|
+
* Namespace function name.
|
|
103
|
+
*
|
|
104
|
+
* @param parameterName
|
|
105
|
+
* Parameter name.
|
|
106
|
+
*
|
|
107
|
+
* @param locale
|
|
108
|
+
* Locale.
|
|
109
|
+
*
|
|
110
|
+
* @returns
|
|
111
|
+
* Function localization.
|
|
112
|
+
*/
|
|
113
|
+
protected getParameterLocalization(namespaceFunctionName: string, parameterName: string, locale: string): ParameterLocalization {
|
|
114
|
+
const parameterLocalization = this._parameterLocalizationsMapsMap.get(`${namespaceFunctionName}.${parameterName}`)?.get(locale);
|
|
115
|
+
|
|
116
|
+
if (parameterLocalization === undefined) {
|
|
117
|
+
throw new Error(`Localization for function "${namespaceFunctionName}", parameter "${parameterName}", locale "${locale}" not found`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return parameterLocalization;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Initialize the generation of the output.
|
|
125
|
+
*/
|
|
126
|
+
protected abstract initialize(): void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Create a proxy object.
|
|
130
|
+
*
|
|
131
|
+
* @param proxyObjectDescriptor
|
|
132
|
+
* Proxy object descriptor.
|
|
133
|
+
*/
|
|
134
|
+
protected abstract createProxyObject(proxyObjectDescriptor: ProxyObjectDescriptor): void;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Create a proxy function.
|
|
138
|
+
*
|
|
139
|
+
* @param proxyFunctionDescriptor
|
|
140
|
+
* Proxy function descriptor.
|
|
141
|
+
*/
|
|
142
|
+
protected abstract createProxyFunction(proxyFunctionDescriptor: ProxyFunctionDescriptor): void;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Finalize the generation of the output.
|
|
146
|
+
*
|
|
147
|
+
* @param success
|
|
148
|
+
* True if successful.
|
|
149
|
+
*/
|
|
150
|
+
protected abstract finalize(success: boolean): void | Promise<void>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Generate localizations map.
|
|
154
|
+
*
|
|
155
|
+
* @param localizedKeyPrefix
|
|
156
|
+
* Localized key prefix.
|
|
157
|
+
*
|
|
158
|
+
* @param localizationCallback
|
|
159
|
+
* Callback to finalize localization.
|
|
160
|
+
*
|
|
161
|
+
* @returns
|
|
162
|
+
* Localization map.
|
|
163
|
+
*/
|
|
164
|
+
private generateLocalizationsMap<T extends Localization>(localizedKeyPrefix: string, localizationCallback: (locale: string, localization: Localization) => T): ReadonlyMap<string, T> {
|
|
165
|
+
return new Map(this._locales.map((locale) => {
|
|
166
|
+
const lngOption = {
|
|
167
|
+
lng: locale
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
return [locale, localizationCallback(locale, {
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Localized key exists.
|
|
172
|
+
name: i18nextAppExtension.t(`${localizedKeyPrefix}name` as ParseKeys, lngOption),
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Localized key exists.
|
|
174
|
+
description: i18nextAppExtension.t(`${localizedKeyPrefix}description` as ParseKeys, lngOption)
|
|
175
|
+
})];
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Generate by processing individual imports.
|
|
181
|
+
*/
|
|
182
|
+
async generate(): Promise<void> {
|
|
183
|
+
let success = false;
|
|
184
|
+
|
|
185
|
+
await i18nAppExtensionInit(I18nEnvironments.CLI);
|
|
186
|
+
|
|
187
|
+
this.initialize();
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
for (const classDescriptor of getClassDescriptors().values()) {
|
|
191
|
+
const namespace = classDescriptor.namespace;
|
|
192
|
+
const namespacePrefix = namespace === undefined ? "" : `${namespace}.`;
|
|
193
|
+
const className = classDescriptor.name;
|
|
194
|
+
const methodInfix = classDescriptor.methodInfix;
|
|
195
|
+
|
|
196
|
+
// Namespace-qualified class name is used to construct object name.
|
|
197
|
+
const namespaceClassName = `${namespacePrefix}${className}`;
|
|
198
|
+
|
|
199
|
+
// First capture group is:
|
|
200
|
+
// - one or more uppercase letters followed by zero or more numbers; or
|
|
201
|
+
// - single uppercase letter followed by zero or more characters except uppercase letters or period.
|
|
202
|
+
// Second capture group is:
|
|
203
|
+
// - single uppercase letter followed by zero or more characters except period; or
|
|
204
|
+
// - zero characters (empty string).
|
|
205
|
+
// Third capture group, separated by optional period, is:
|
|
206
|
+
// - single uppercase letter followed by zero or more characters (remainder of string); or
|
|
207
|
+
// - zero characters (empty string).
|
|
208
|
+
const classNameMatch = /^([A-Z]+[0-9]*|[A-Z][^A-Z.]*)([A-Z][^.]*|)\.?([A-Z].*|)$/.exec(namespaceClassName);
|
|
209
|
+
|
|
210
|
+
if (classNameMatch === null) {
|
|
211
|
+
throw new Error(`${namespaceClassName} is not a valid namespace-qualified class name`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const proxyObjectDescriptor: ProxyObjectDescriptor = {
|
|
215
|
+
namespace,
|
|
216
|
+
className,
|
|
217
|
+
namespaceClassName,
|
|
218
|
+
classDescriptor,
|
|
219
|
+
objectName: `${classNameMatch[1].toLowerCase()}${classNameMatch[2]}${classNameMatch[3]}`
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
this.createProxyObject(proxyObjectDescriptor);
|
|
223
|
+
|
|
224
|
+
for (const methodDescriptor of classDescriptor.methodDescriptors) {
|
|
225
|
+
const methodName = methodDescriptor.name;
|
|
226
|
+
const infixBefore = methodDescriptor.infixBefore;
|
|
227
|
+
|
|
228
|
+
let functionName: string;
|
|
229
|
+
|
|
230
|
+
if (methodInfix === undefined || methodDescriptor.ignoreInfix === true) {
|
|
231
|
+
// No other classes in the hierarchy or no infix required.
|
|
232
|
+
functionName = methodName;
|
|
233
|
+
} else if (infixBefore === undefined) {
|
|
234
|
+
// Other classes in the hierarchy and infix is postfix.
|
|
235
|
+
functionName = `${methodName}${methodInfix}`;
|
|
236
|
+
} else {
|
|
237
|
+
const insertIndex = methodName.indexOf(infixBefore);
|
|
238
|
+
|
|
239
|
+
if (insertIndex === -1) {
|
|
240
|
+
throw new Error(`Cannot find "${infixBefore}" in method name ${methodName}`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Other classes in the hierarchy and infix is in the middle of the string.
|
|
244
|
+
functionName = `${methodName.substring(0, insertIndex)}${methodInfix}${methodName.substring(insertIndex)}`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const namespaceFunctionName = `${namespacePrefix}${functionName}`;
|
|
248
|
+
|
|
249
|
+
const functionLocalizationsMap = this.generateLocalizationsMap<FunctionLocalization>(`Functions.${namespaceFunctionName}.`, (locale, localization) => ({
|
|
250
|
+
...localization,
|
|
251
|
+
documentationURL: `${Generator.DOCUMENTATION_BASE_URL}${locale === this.defaultLocale ? "" : `${locale}/`}${Generator.DOCUMENTATION_PATH}${namespace === undefined ? "" : `${namespace}/`}${localization.name}.html`
|
|
252
|
+
}));
|
|
253
|
+
|
|
254
|
+
this._functionLocalizationsMapsMap.set(namespaceFunctionName, functionLocalizationsMap);
|
|
255
|
+
|
|
256
|
+
this.createProxyFunction({
|
|
257
|
+
...proxyObjectDescriptor,
|
|
258
|
+
functionName,
|
|
259
|
+
namespaceFunctionName,
|
|
260
|
+
localizationsMap: functionLocalizationsMap,
|
|
261
|
+
proxyParameterDescriptors: methodDescriptor.parameterDescriptors.map((parameterDescriptor) => {
|
|
262
|
+
const expandedParameterDescriptor = expandParameterDescriptor(parameterDescriptor);
|
|
263
|
+
|
|
264
|
+
const parameterName = expandedParameterDescriptor.name;
|
|
265
|
+
|
|
266
|
+
const parameterLocalizationsMap = this.generateLocalizationsMap(`Parameters.${parameterName}.`, (_locale, localization) => localization);
|
|
267
|
+
|
|
268
|
+
this._parameterLocalizationsMapsMap.set(`${namespaceFunctionName}.${parameterName}`, parameterLocalizationsMap);
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
namespace,
|
|
272
|
+
parameterName,
|
|
273
|
+
localizationsMap: parameterLocalizationsMap,
|
|
274
|
+
parameterDescriptor: expandedParameterDescriptor
|
|
275
|
+
};
|
|
276
|
+
}),
|
|
277
|
+
methodDescriptor
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
success = true;
|
|
283
|
+
} finally {
|
|
284
|
+
await this.finalize(success);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|