@aidc-toolkit/app-extension 1.0.27-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 +1115 -876
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -241
- package/dist/index.d.ts +79 -241
- package/dist/index.js +1113 -869
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/app-extension.ts +5 -5
- package/src/app-utility-proxy.ts +18 -24
- package/src/descriptor.ts +29 -259
- package/src/generator/generator.ts +89 -131
- package/src/generator/index.ts +0 -1
- package/src/generator/locale-resources-generator.ts +39 -14
- package/src/gs1/character-set-proxy.ts +5 -5
- package/src/gs1/check-proxy.ts +35 -42
- package/src/gs1/gtin-creator-proxy.ts +58 -0
- package/src/gs1/gtin-descriptor.ts +29 -0
- package/src/gs1/gtin-validator-proxy.ts +161 -0
- package/src/gs1/identifier-creator-proxy.ts +227 -0
- package/src/gs1/identifier-validator-proxy.ts +87 -0
- package/src/gs1/index.ts +5 -1
- package/src/gs1/non-gtin-creator-proxy.ts +119 -0
- package/src/gs1/non-gtin-validator-proxy.ts +119 -0
- package/src/gs1/prefix-definition-descriptor.ts +18 -0
- package/src/gs1/prefix-manager-proxy.ts +42 -0
- package/src/index.ts +1 -0
- package/src/lib-proxy.ts +1 -1
- package/src/proxy.ts +526 -0
- package/src/utility/character-set-descriptor.ts +5 -5
- package/src/utility/character-set-proxy.ts +31 -47
- package/src/utility/reg-exp-proxy.ts +11 -15
- package/src/utility/string-descriptor.ts +2 -2
- package/src/utility/transformer-descriptor.ts +3 -3
- package/src/utility/transformer-proxy.ts +16 -26
- package/tsconfig-src.json +1 -4
- package/tsconfig.json +1 -0
- package/src/generator/descriptor.ts +0 -125
- package/src/gs1/identifier-proxy.ts +0 -826
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
|
}
|
package/src/app-extension.ts
CHANGED
|
@@ -55,7 +55,7 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
55
55
|
* @param throwError
|
|
56
56
|
* If true, errors are reported through the throw/catch mechanism.
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
constructor(version: string, maximumSequenceCount: number, throwError: ThrowError) {
|
|
59
59
|
this.#version = version;
|
|
60
60
|
this.#maximumSequenceCount = maximumSequenceCount;
|
|
61
61
|
this.#throwError = throwError;
|
|
@@ -96,7 +96,7 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
96
96
|
* @returns
|
|
97
97
|
* Maximum width supported by the application.
|
|
98
98
|
*/
|
|
99
|
-
protected abstract getMaximumWidth(): Promise<number>;
|
|
99
|
+
protected abstract getMaximumWidth(): number | Promise<number>;
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Get the maximum height supported by the application.
|
|
@@ -116,7 +116,7 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
116
116
|
* @returns
|
|
117
117
|
* Maximum height supported by the application.
|
|
118
118
|
*/
|
|
119
|
-
protected abstract getMaximumHeight(): Promise<number>;
|
|
119
|
+
protected abstract getMaximumHeight(): number | Promise<number>;
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* Get the sheet address from an invocation context.
|
|
@@ -127,7 +127,7 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
127
127
|
* @returns
|
|
128
128
|
* Sheet address.
|
|
129
129
|
*/
|
|
130
|
-
abstract getSheetAddress(invocationContext: TInvocationContext): Promise<SheetAddress>;
|
|
130
|
+
abstract getSheetAddress(invocationContext: TInvocationContext): SheetAddress | Promise<SheetAddress>;
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
133
|
* Get a parameter range from an invocation context.
|
|
@@ -141,7 +141,7 @@ export abstract class AppExtension<ThrowError extends boolean, TError extends Er
|
|
|
141
141
|
* @returns
|
|
142
142
|
* Sheet range or null if parameter is not a range.
|
|
143
143
|
*/
|
|
144
|
-
abstract getParameterSheetRange(invocationContext: TInvocationContext, parameterNumber: number): Promise<SheetRange | null>;
|
|
144
|
+
abstract getParameterSheetRange(invocationContext: TInvocationContext, parameterNumber: number): SheetRange | null | Promise<SheetRange | null>;
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
147
|
* Validate a sequence count against the maximum supported by application.
|
package/src/app-utility-proxy.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isNullish, type NonNullishable, type Nullishable } from "@aidc-toolkit/core";
|
|
2
|
-
import { type
|
|
2
|
+
import { type ExtendsParameterDescriptor, type ParameterDescriptor, Types } from "./descriptor.js";
|
|
3
3
|
import { LibProxy } from "./lib-proxy.js";
|
|
4
4
|
import { i18nextAppExtension } from "./locale/i18n.js";
|
|
5
|
+
import { proxy } from "./proxy.js";
|
|
5
6
|
import type { ErrorExtends, Matrix } from "./type.js";
|
|
6
7
|
|
|
7
8
|
const spillMatrix: ParameterDescriptor = {
|
|
@@ -18,13 +19,13 @@ const spillMaximumParameterDescriptor: ParameterDescriptor = {
|
|
|
18
19
|
isRequired: false
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
const spillMaximumWidthParameterDescriptor:
|
|
22
|
+
const spillMaximumWidthParameterDescriptor: ExtendsParameterDescriptor = {
|
|
22
23
|
extendsDescriptor: spillMaximumParameterDescriptor,
|
|
23
24
|
sortOrder: 0,
|
|
24
25
|
name: "spillMaximumWidth"
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
const spillMaximumHeightParameterDescriptor:
|
|
28
|
+
const spillMaximumHeightParameterDescriptor: ExtendsParameterDescriptor = {
|
|
28
29
|
extendsDescriptor: spillMaximumParameterDescriptor,
|
|
29
30
|
sortOrder: 1,
|
|
30
31
|
name: "spillMaximumHeight"
|
|
@@ -60,7 +61,7 @@ interface MaximumDimensions {
|
|
|
60
61
|
* @template TBigInt
|
|
61
62
|
* Type to which big integer is mapped.
|
|
62
63
|
*/
|
|
63
|
-
@
|
|
64
|
+
@proxy.describeClass(false)
|
|
64
65
|
export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
65
66
|
/**
|
|
66
67
|
* Get the version.
|
|
@@ -68,9 +69,10 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
68
69
|
* @returns
|
|
69
70
|
* Version.
|
|
70
71
|
*/
|
|
71
|
-
@
|
|
72
|
+
@proxy.describeMethod({
|
|
72
73
|
type: Types.String,
|
|
73
|
-
isMatrix: false
|
|
74
|
+
isMatrix: false,
|
|
75
|
+
parameterDescriptors: []
|
|
74
76
|
})
|
|
75
77
|
version(): string {
|
|
76
78
|
return this.appExtension.version;
|
|
@@ -135,17 +137,13 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
135
137
|
* @returns
|
|
136
138
|
* Matrix spilled within maximum width and maximum height.
|
|
137
139
|
*/
|
|
138
|
-
@
|
|
140
|
+
@proxy.describeMethod({
|
|
139
141
|
requiresContext: true,
|
|
140
142
|
type: Types.Any,
|
|
141
|
-
isMatrix: true
|
|
143
|
+
isMatrix: true,
|
|
144
|
+
parameterDescriptors: [spillMatrix, spillMaximumWidthParameterDescriptor, spillMaximumHeightParameterDescriptor]
|
|
142
145
|
})
|
|
143
|
-
async vSpill(
|
|
144
|
-
@ProxyParameter(spillMatrix) hMatrixValues: Matrix<unknown>,
|
|
145
|
-
@ProxyParameter(spillMaximumWidthParameterDescriptor) maximumWidth: Nullishable<number>,
|
|
146
|
-
@ProxyParameter(spillMaximumHeightParameterDescriptor) maximumHeight: Nullishable<number>,
|
|
147
|
-
invocationContext: Nullishable<TInvocationContext>
|
|
148
|
-
): Promise<Matrix<unknown>> {
|
|
146
|
+
async vSpill(hMatrixValues: Matrix<unknown>, maximumWidth: Nullishable<number>, maximumHeight: Nullishable<number>, invocationContext: Nullishable<TInvocationContext>): Promise<Matrix<unknown>> {
|
|
149
147
|
let result: Matrix<unknown>;
|
|
150
148
|
|
|
151
149
|
if (hMatrixValues.length !== 1) {
|
|
@@ -169,7 +167,7 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
169
167
|
// Array that has a length of a power of 10 is treated specially.
|
|
170
168
|
if (Number.isInteger(Math.log10(hLength))) {
|
|
171
169
|
// Try spill width that is a power of 10.
|
|
172
|
-
const spillWidth10 =
|
|
170
|
+
const spillWidth10 = 10 ** Math.floor(Math.log10(spillWidth));
|
|
173
171
|
|
|
174
172
|
// Keep default if not enough space for power of 10 matrix.
|
|
175
173
|
if (hLength / spillWidth10 <= maximumDimensions.height) {
|
|
@@ -214,17 +212,13 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
214
212
|
* @returns
|
|
215
213
|
* Matrix spilled within maximum height and maximum width.
|
|
216
214
|
*/
|
|
217
|
-
@
|
|
215
|
+
@proxy.describeMethod({
|
|
218
216
|
requiresContext: true,
|
|
219
217
|
type: Types.Any,
|
|
220
|
-
isMatrix: true
|
|
218
|
+
isMatrix: true,
|
|
219
|
+
parameterDescriptors: [spillMatrix, spillMaximumHeightParameterDescriptor, spillMaximumWidthParameterDescriptor]
|
|
221
220
|
})
|
|
222
|
-
async hSpill(
|
|
223
|
-
@ProxyParameter(spillMatrix) vMatrixValues: Matrix<unknown>,
|
|
224
|
-
@ProxyParameter(spillMaximumHeightParameterDescriptor) maximumHeight: Nullishable<number>,
|
|
225
|
-
@ProxyParameter(spillMaximumWidthParameterDescriptor) maximumWidth: Nullishable<number>,
|
|
226
|
-
invocationContext: Nullishable<TInvocationContext>
|
|
227
|
-
): Promise<Matrix<unknown>> {
|
|
221
|
+
async hSpill(vMatrixValues: Matrix<unknown>, maximumHeight: Nullishable<number>, maximumWidth: Nullishable<number>, invocationContext: Nullishable<TInvocationContext>): Promise<Matrix<unknown>> {
|
|
228
222
|
let result: Matrix<unknown>;
|
|
229
223
|
|
|
230
224
|
for (const hArrayValues of vMatrixValues) {
|
|
@@ -250,7 +244,7 @@ export class AppUtilityProxy<ThrowError extends boolean, TError extends ErrorExt
|
|
|
250
244
|
// Array that has a length of a power of 10 is treated specially.
|
|
251
245
|
if (Number.isInteger(Math.log10(vLength))) {
|
|
252
246
|
// Try spill height that is a power of 10.
|
|
253
|
-
const spillHeight10 =
|
|
247
|
+
const spillHeight10 = 10 ** Math.floor(Math.log10(spillHeight));
|
|
254
248
|
|
|
255
249
|
// Keep default if not enough space for power of 10 matrix.
|
|
256
250
|
if (vLength / spillHeight10 <= maximumDimensions.width) {
|
package/src/descriptor.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import type { TypedFunction } from "@aidc-toolkit/core";
|
|
2
|
-
import type { AppExtension } from "./app-extension.js";
|
|
3
|
-
import { LibProxy } from "./lib-proxy.js";
|
|
4
|
-
import type { ErrorExtends } from "./type.js";
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* Core descriptor.
|
|
8
3
|
*/
|
|
@@ -64,9 +59,9 @@ interface TypeDescriptor extends Descriptor {
|
|
|
64
59
|
}
|
|
65
60
|
|
|
66
61
|
/**
|
|
67
|
-
*
|
|
62
|
+
* Parameter descriptor.
|
|
68
63
|
*/
|
|
69
|
-
export interface
|
|
64
|
+
export interface ParameterDescriptor extends TypeDescriptor {
|
|
70
65
|
/**
|
|
71
66
|
* True if required.
|
|
72
67
|
*/
|
|
@@ -74,43 +69,20 @@ export interface BaseParameterDescriptor extends TypeDescriptor {
|
|
|
74
69
|
}
|
|
75
70
|
|
|
76
71
|
/**
|
|
77
|
-
* Extends parameter descriptor
|
|
72
|
+
* Extends parameter descriptor.
|
|
78
73
|
*/
|
|
79
|
-
export interface ExtendsParameterDescriptor extends Partial<
|
|
74
|
+
export interface ExtendsParameterDescriptor extends Partial<ParameterDescriptor> {
|
|
80
75
|
/**
|
|
81
|
-
*
|
|
76
|
+
* Parameter descriptor that this one extends.
|
|
82
77
|
*/
|
|
83
|
-
readonly extendsDescriptor: ParameterDescriptor;
|
|
78
|
+
readonly extendsDescriptor: ParameterDescriptor | ExtendsParameterDescriptor;
|
|
84
79
|
|
|
85
80
|
/**
|
|
86
|
-
* Sort order within
|
|
81
|
+
* Sort order within extended parameter descriptor.
|
|
87
82
|
*/
|
|
88
83
|
readonly sortOrder?: number;
|
|
89
84
|
}
|
|
90
85
|
|
|
91
|
-
/**
|
|
92
|
-
* Parameter descriptor, either base or extends.
|
|
93
|
-
*/
|
|
94
|
-
export type ParameterDescriptor = BaseParameterDescriptor | ExtendsParameterDescriptor;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Expand a parameter descriptor to its full form with all required attributes.
|
|
98
|
-
*
|
|
99
|
-
* @param parameterDescriptor
|
|
100
|
-
* Parameter descriptor.
|
|
101
|
-
*
|
|
102
|
-
* @returns
|
|
103
|
-
* Parameter descriptor in its full form.
|
|
104
|
-
*/
|
|
105
|
-
export function expandParameterDescriptor(parameterDescriptor: ParameterDescriptor): BaseParameterDescriptor {
|
|
106
|
-
return !("extendsDescriptor" in parameterDescriptor) ?
|
|
107
|
-
parameterDescriptor :
|
|
108
|
-
{
|
|
109
|
-
...expandParameterDescriptor(parameterDescriptor.extendsDescriptor),
|
|
110
|
-
...parameterDescriptor
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
86
|
/**
|
|
115
87
|
* Method descriptor.
|
|
116
88
|
*/
|
|
@@ -135,6 +107,16 @@ export interface MethodDescriptor extends TypeDescriptor {
|
|
|
135
107
|
* Parameter descriptors.
|
|
136
108
|
*/
|
|
137
109
|
readonly parameterDescriptors: readonly ParameterDescriptor[];
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Function name with optional infix.
|
|
113
|
+
*/
|
|
114
|
+
readonly functionName: string;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Function name in optional namespace with optional infix.
|
|
118
|
+
*/
|
|
119
|
+
readonly namespaceFunctionName: string;
|
|
138
120
|
}
|
|
139
121
|
|
|
140
122
|
/**
|
|
@@ -144,12 +126,12 @@ export interface ClassDescriptor extends Descriptor {
|
|
|
144
126
|
/**
|
|
145
127
|
* Class namespace. If not provided, class is at the top level.
|
|
146
128
|
*/
|
|
147
|
-
readonly namespace?: string;
|
|
129
|
+
readonly namespace?: string | undefined;
|
|
148
130
|
|
|
149
131
|
/**
|
|
150
132
|
* Method infix. If undefined, method name is generated verbatim.
|
|
151
133
|
*/
|
|
152
|
-
readonly methodInfix?: string;
|
|
134
|
+
readonly methodInfix?: string | undefined;
|
|
153
135
|
|
|
154
136
|
/**
|
|
155
137
|
* Replace parameter descriptors for class hierarchies where enumeration parameter descriptors can change.
|
|
@@ -160,229 +142,17 @@ export interface ClassDescriptor extends Descriptor {
|
|
|
160
142
|
}>;
|
|
161
143
|
|
|
162
144
|
/**
|
|
163
|
-
*
|
|
145
|
+
* Class name in optional namespace.
|
|
164
146
|
*/
|
|
165
|
-
readonly
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
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.
|
|
185
|
-
*/
|
|
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;
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Pending parameter descriptors, consumed and reset when method is described.
|
|
190
|
-
*/
|
|
191
|
-
let pendingParameterDescriptors: ParameterDescriptor[] = [];
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Class method descriptors map, keyed on declaration class name and method name.
|
|
195
|
-
*/
|
|
196
|
-
const classMethodsDescriptorsMap = new Map<string, MethodDescriptor[]>();
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Class descriptors map, keyed on declaration class name.
|
|
200
|
-
*/
|
|
201
|
-
const classDescriptorsMap = new Map<string, ClassDescriptor>();
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Proxy parameter decorator.
|
|
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
|
-
*
|
|
221
|
-
* @param parameterDescriptor
|
|
222
|
-
* Parameter descriptor.
|
|
223
|
-
*
|
|
224
|
-
* @returns
|
|
225
|
-
* Function defining metadata for the parameter.
|
|
226
|
-
*/
|
|
227
|
-
export function ProxyParameter<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, T extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt>>(parameterDescriptor: ParameterDescriptor): ((target: T, propertyKey: string, parameterIndex: number) => void) {
|
|
228
|
-
return (_target: T, _propertyKey: string, parameterIndex: number) => {
|
|
229
|
-
pendingParameterDescriptors[parameterIndex] = parameterDescriptor;
|
|
230
|
-
};
|
|
231
|
-
}
|
|
147
|
+
readonly namespaceClassName: string;
|
|
232
148
|
|
|
233
|
-
/**
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
*
|
|
251
|
-
* @param methodDescriptor
|
|
252
|
-
* Method descriptor.
|
|
253
|
-
*
|
|
254
|
-
* @returns
|
|
255
|
-
* Function defining metadata for the method.
|
|
256
|
-
*/
|
|
257
|
-
export function ProxyMethod<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, T extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt>>(methodDescriptor: Omit<MethodDescriptor, "name" | "parameterDescriptors">): ((target: T, propertyKey: string, propertyDescriptor: PropertyDescriptor) => void) {
|
|
258
|
-
return (target: T, propertyKey: string, propertyDescriptor: PropertyDescriptor) => {
|
|
259
|
-
const declarationClassName = target.constructor.name;
|
|
260
|
-
|
|
261
|
-
// Validate that method descriptor is applied to a function.
|
|
262
|
-
if (typeof propertyDescriptor.value !== "function") {
|
|
263
|
-
throw new Error(`${declarationClassName}.${propertyKey} is not a method`);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Known to be a method.
|
|
267
|
-
const parameterCount = (propertyDescriptor.value as TypedFunction<(...args: unknown[]) => unknown>).length - (!(methodDescriptor.requiresContext ?? false) ? 0 : 1);
|
|
268
|
-
|
|
269
|
-
let anyOptional = false;
|
|
270
|
-
|
|
271
|
-
// Validate that all parameters have descriptors.
|
|
272
|
-
for (let index = 0; index < parameterCount; index++) {
|
|
273
|
-
const parameterDescriptor = expandParameterDescriptor(pendingParameterDescriptors[index]);
|
|
274
|
-
|
|
275
|
-
if (typeof parameterDescriptor === "undefined") {
|
|
276
|
-
throw new Error(`Missing parameter descriptor at index ${index} of ${declarationClassName}.${propertyKey}`);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (!parameterDescriptor.isRequired) {
|
|
280
|
-
anyOptional = true;
|
|
281
|
-
} else if (anyOptional) {
|
|
282
|
-
throw new Error(`Parameter descriptor ${parameterDescriptor.name} at index ${index} of ${declarationClassName}.${propertyKey} is required but prior parameter descriptor ${pendingParameterDescriptors[index - 1].name} is optional`);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
let methodDescriptors = classMethodsDescriptorsMap.get(declarationClassName);
|
|
287
|
-
if (methodDescriptors === undefined) {
|
|
288
|
-
methodDescriptors = [];
|
|
289
|
-
classMethodsDescriptorsMap.set(declarationClassName, methodDescriptors);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// Method descriptors array is constructed in reverse order so that final result is in the correct order.
|
|
293
|
-
methodDescriptors.push({
|
|
294
|
-
name: propertyKey,
|
|
295
|
-
...methodDescriptor,
|
|
296
|
-
parameterDescriptors: pendingParameterDescriptors
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
pendingParameterDescriptors = [];
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Proxy class decorator.
|
|
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
|
-
*
|
|
321
|
-
* @param classDescriptor
|
|
322
|
-
* Class descriptor.
|
|
323
|
-
*
|
|
324
|
-
* @returns
|
|
325
|
-
* Function defining metadata for the class.
|
|
326
|
-
*/
|
|
327
|
-
export function ProxyClass<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, T extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt>>(classDescriptor: Omit<ClassDescriptor, "name" | "methodDescriptors"> = {}): ((classType: ProxyClassType<ThrowError, TError, TInvocationContext, TBigInt, T>) => void) {
|
|
328
|
-
return (classType: ProxyClassType<ThrowError, TError, TInvocationContext, TBigInt, T>) => {
|
|
329
|
-
const methodDescriptorsMap = new Map<string, MethodDescriptor>();
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Build method descriptors map from every class in hierarchy until LibProxy class is reached.
|
|
333
|
-
*
|
|
334
|
-
* @param classType
|
|
335
|
-
* Class type.
|
|
336
|
-
*/
|
|
337
|
-
function buildMethodDescriptorsMap(classType: typeof LibProxy): void {
|
|
338
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Class hierarchy is known.
|
|
339
|
-
const baseClassType = Object.getPrototypeOf(classType) as typeof LibProxy;
|
|
340
|
-
|
|
341
|
-
// Start with class furthest up the hierarchy.
|
|
342
|
-
if (baseClassType !== LibProxy) {
|
|
343
|
-
buildMethodDescriptorsMap(baseClassType);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const classMethodDescriptors = classMethodsDescriptorsMap.get(classType.name);
|
|
347
|
-
|
|
348
|
-
if (classMethodDescriptors !== undefined) {
|
|
349
|
-
for (const classMethodDescriptor of classMethodDescriptors) {
|
|
350
|
-
// If any class overrides a base class method, it will appear in the same position as the base class method.
|
|
351
|
-
methodDescriptorsMap.set(classMethodDescriptor.name, classMethodDescriptor);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
buildMethodDescriptorsMap(classType);
|
|
357
|
-
|
|
358
|
-
let methodDescriptors: MethodDescriptor[];
|
|
359
|
-
|
|
360
|
-
if (classDescriptor.replaceParameterDescriptors !== undefined) {
|
|
361
|
-
const replacementParameterDescriptorsMap = new Map(classDescriptor.replaceParameterDescriptors.map(replaceParameterDescriptor => [replaceParameterDescriptor.name, replaceParameterDescriptor.replacement]));
|
|
362
|
-
|
|
363
|
-
// Method descriptors for class have to be built as copies due to possible mutation of parameter descriptors.
|
|
364
|
-
methodDescriptors = Array.from(methodDescriptorsMap.values()).map(methodDescriptor => ({
|
|
365
|
-
...methodDescriptor,
|
|
366
|
-
parameterDescriptors: methodDescriptor.parameterDescriptors.map(parameterDescriptor => replacementParameterDescriptorsMap.get(expandParameterDescriptor(parameterDescriptor).name) ?? parameterDescriptor)
|
|
367
|
-
}));
|
|
368
|
-
} else {
|
|
369
|
-
methodDescriptors = Array.from(methodDescriptorsMap.values());
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
classDescriptorsMap.set(classType.name, {
|
|
373
|
-
name: classType.name,
|
|
374
|
-
...classDescriptor,
|
|
375
|
-
methodDescriptors
|
|
376
|
-
});
|
|
377
|
-
};
|
|
378
|
-
}
|
|
149
|
+
/**
|
|
150
|
+
* Object name.
|
|
151
|
+
*/
|
|
152
|
+
readonly objectName: string;
|
|
379
153
|
|
|
380
|
-
/**
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
* Class descriptors map.
|
|
385
|
-
*/
|
|
386
|
-
export function getClassDescriptorsMap(): ReadonlyMap<string, ClassDescriptor> {
|
|
387
|
-
return classDescriptorsMap;
|
|
154
|
+
/**
|
|
155
|
+
* Method descriptors.
|
|
156
|
+
*/
|
|
157
|
+
readonly methodDescriptors: readonly MethodDescriptor[];
|
|
388
158
|
}
|