@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/src/lib-proxy.ts
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { mapIterable } from "@aidc-toolkit/utility";
|
|
2
|
-
import type { AppExtension } from "./app-extension";
|
|
3
|
-
import { i18nextAppExtension } from "./locale/i18n";
|
|
4
|
-
import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "./type";
|
|
2
|
+
import type { AppExtension } from "./app-extension.js";
|
|
3
|
+
import { i18nextAppExtension } from "./locale/i18n.js";
|
|
4
|
+
import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "./type.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Library proxy.
|
|
8
8
|
*
|
|
9
|
-
* @template TBigInt
|
|
10
|
-
* Type to which big integer is mapped.
|
|
11
|
-
*
|
|
12
9
|
* @template ThrowError
|
|
13
10
|
* If true, errors are reported through the throw/catch mechanism.
|
|
14
11
|
*
|
|
15
12
|
* @template TError
|
|
16
13
|
* Error type.
|
|
14
|
+
*
|
|
15
|
+
* @template TInvocationContext
|
|
16
|
+
* Application-specific invocation context type.
|
|
17
|
+
*
|
|
18
|
+
* @template TBigInt
|
|
19
|
+
* Type to which big integer is mapped.
|
|
17
20
|
*/
|
|
18
21
|
export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> {
|
|
19
22
|
/**
|
|
20
23
|
* Application extension.
|
|
21
24
|
*/
|
|
22
|
-
|
|
25
|
+
readonly #appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>;
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* Constructor.
|
|
@@ -28,14 +31,14 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
|
|
|
28
31
|
* Application extension.
|
|
29
32
|
*/
|
|
30
33
|
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
|
|
31
|
-
this
|
|
34
|
+
this.#appExtension = appExtension;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
38
|
* Get the application extension.
|
|
36
39
|
*/
|
|
37
40
|
protected get appExtension(): AppExtension<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
38
|
-
return this
|
|
41
|
+
return this.#appExtension;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/**
|
|
@@ -48,7 +51,7 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
|
|
|
48
51
|
* Mapped big integer value.
|
|
49
52
|
*/
|
|
50
53
|
mapBigInt(value: bigint): ResultError<TBigInt, ThrowError, TError> {
|
|
51
|
-
return this.
|
|
54
|
+
return this.#appExtension.mapBigInt(value);
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
/**
|
|
@@ -60,13 +63,13 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
|
|
|
60
63
|
* @returns
|
|
61
64
|
* Error if errors are not thrown.
|
|
62
65
|
*/
|
|
63
|
-
|
|
66
|
+
#handleError<TResult>(e: unknown): ResultError<TResult, ThrowError, TError> {
|
|
64
67
|
let result: ResultError<TResult, ThrowError, TError>;
|
|
65
68
|
|
|
66
69
|
if (e instanceof RangeError) {
|
|
67
|
-
const error = this.
|
|
70
|
+
const error = this.#appExtension.mapRangeError(e);
|
|
68
71
|
|
|
69
|
-
if (this.
|
|
72
|
+
if (this.#appExtension.throwError) {
|
|
70
73
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is determined by application mapping.
|
|
71
74
|
throw error as Error;
|
|
72
75
|
}
|
|
@@ -94,13 +97,13 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
|
|
|
94
97
|
* @returns
|
|
95
98
|
* Callback result or error if errors are not thrown.
|
|
96
99
|
*/
|
|
97
|
-
|
|
100
|
+
#doCallback<TValue, TResult>(value: TValue, callback: (value: TValue) => TResult): ResultError<TResult, ThrowError, TError> {
|
|
98
101
|
let result: ResultError<TResult, ThrowError, TError>;
|
|
99
102
|
|
|
100
103
|
try {
|
|
101
104
|
result = callback(value);
|
|
102
105
|
} catch (e: unknown) {
|
|
103
|
-
result = this
|
|
106
|
+
result = this.#handleError(e);
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
return result;
|
|
@@ -119,7 +122,7 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
|
|
|
119
122
|
* Matrix of callback results and errors if errors are not thrown.
|
|
120
123
|
*/
|
|
121
124
|
protected mapMatrix<TValue, TResult>(matrixValues: Matrix<TValue>, callback: (value: TValue) => TResult): MatrixResultError<TResult, ThrowError, TError> {
|
|
122
|
-
return matrixValues.map(rowValues => rowValues.map(value => this
|
|
125
|
+
return matrixValues.map(rowValues => rowValues.map(value => this.#doCallback(value, callback)));
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
/**
|
|
@@ -134,8 +137,8 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
|
|
|
134
137
|
* @returns
|
|
135
138
|
* Callback result or error as array if errors are not thrown.
|
|
136
139
|
*/
|
|
137
|
-
|
|
138
|
-
const result = this
|
|
140
|
+
#doArrayCallback<TValue, TResult>(value: TValue, callback: (value: TValue) => TResult[]): Array<ResultError<TResult, ThrowError, TError>> {
|
|
141
|
+
const result = this.#doCallback(value, callback);
|
|
139
142
|
|
|
140
143
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type determination is handled.
|
|
141
144
|
return result instanceof Array ? result : [result as ResultError<TResult, ThrowError, TError>];
|
|
@@ -163,7 +166,7 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
|
|
|
163
166
|
matrixResultError = [];
|
|
164
167
|
|
|
165
168
|
matrixValues[0].forEach((value, columnIndex) => {
|
|
166
|
-
const arrayResultError = this
|
|
169
|
+
const arrayResultError = this.#doArrayCallback(value, callback);
|
|
167
170
|
|
|
168
171
|
arrayResultError.forEach((resultError, rowIndex) => {
|
|
169
172
|
if (matrixResultError.length <= rowIndex) {
|
|
@@ -182,9 +185,9 @@ export abstract class LibProxy<ThrowError extends boolean, TError extends ErrorE
|
|
|
182
185
|
// Special case; unlikely to occur.
|
|
183
186
|
arrayResultError = [];
|
|
184
187
|
} else if (rowValue.length === 1) {
|
|
185
|
-
arrayResultError = this
|
|
188
|
+
arrayResultError = this.#doArrayCallback(rowValue[0], callback);
|
|
186
189
|
} else {
|
|
187
|
-
arrayResultError = [this
|
|
190
|
+
arrayResultError = [this.#handleError(new RangeError(i18nextAppExtension.t("Proxy.matrixMustBeArray")))];
|
|
188
191
|
}
|
|
189
192
|
|
|
190
193
|
return arrayResultError;
|
package/src/locale/i18n.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { i18nCoreInit, type I18nEnvironment } from "@aidc-toolkit/core";
|
|
|
2
2
|
import { gs1Resources, i18nGS1Init } from "@aidc-toolkit/gs1";
|
|
3
3
|
import { i18nUtilityInit, utilityResources } from "@aidc-toolkit/utility";
|
|
4
4
|
import i18next, { type i18n, type Resource } from "i18next";
|
|
5
|
-
import enLocaleResources from "./en/locale-resources";
|
|
6
|
-
import frLocaleResources from "./fr/locale-resources";
|
|
5
|
+
import enLocaleResources from "./en/locale-resources.js";
|
|
6
|
+
import frLocaleResources from "./fr/locale-resources.js";
|
|
7
7
|
|
|
8
8
|
export const appExtensionNS = "aidct_app_extension";
|
|
9
9
|
|
|
@@ -24,7 +24,7 @@ export const appExtensionResources: Resource = {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
// Explicit type is necessary
|
|
27
|
+
// Explicit type is necessary because type can't be inferred without additional references.
|
|
28
28
|
export const i18nextAppExtension: i18n = i18next.createInstance();
|
|
29
29
|
|
|
30
30
|
/**
|
package/src/locale/i18next.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GS1LocaleResources } from "@aidc-toolkit/gs1";
|
|
2
2
|
import type { UtilityLocaleResources } from "@aidc-toolkit/utility";
|
|
3
|
-
import type { AppExtensionLocaleResources } from "./i18n";
|
|
3
|
+
import type { AppExtensionLocaleResources } from "./i18n.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Internationalization module.
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
NUMERIC_CREATOR,
|
|
11
11
|
Sequence
|
|
12
12
|
} from "@aidc-toolkit/utility";
|
|
13
|
-
import type { AppExtension } from "../app-extension";
|
|
13
|
+
import type { AppExtension } from "../app-extension.js";
|
|
14
14
|
import {
|
|
15
15
|
expandParameterDescriptor,
|
|
16
16
|
type ParameterDescriptor,
|
|
@@ -18,22 +18,22 @@ import {
|
|
|
18
18
|
ProxyMethod,
|
|
19
19
|
ProxyParameter,
|
|
20
20
|
Types
|
|
21
|
-
} from "../descriptor";
|
|
22
|
-
import { LibProxy } from "../lib-proxy";
|
|
23
|
-
import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "../type";
|
|
21
|
+
} from "../descriptor.js";
|
|
22
|
+
import { LibProxy } from "../lib-proxy.js";
|
|
23
|
+
import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "../type.js";
|
|
24
24
|
import {
|
|
25
25
|
exclusionAnyParameterDescriptor,
|
|
26
26
|
exclusionFirstZeroParameterDescriptor,
|
|
27
27
|
exclusionNoneParameterDescriptor
|
|
28
|
-
} from "./character-set-descriptor";
|
|
29
|
-
import { sParameterDescriptor, validateSParameterDescriptor } from "./string-descriptor";
|
|
30
|
-
import { StringProxy } from "./string-proxy";
|
|
28
|
+
} from "./character-set-descriptor.js";
|
|
29
|
+
import { sParameterDescriptor, validateSParameterDescriptor } from "./string-descriptor.js";
|
|
30
|
+
import { StringProxy } from "./string-proxy.js";
|
|
31
31
|
import {
|
|
32
32
|
countParameterDescriptor,
|
|
33
33
|
startValueParameterDescriptor,
|
|
34
34
|
tweakParameterDescriptor,
|
|
35
35
|
valueParameterDescriptor
|
|
36
|
-
} from "./transformer-descriptor";
|
|
36
|
+
} from "./transformer-descriptor.js";
|
|
37
37
|
|
|
38
38
|
const lengthParameterDescriptor: ParameterDescriptor = {
|
|
39
39
|
name: "length",
|
|
@@ -48,12 +48,12 @@ const valueForSParameterDescriptor: ParameterDescriptor = {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
export abstract class CharacterSetValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends StringProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
51
|
-
|
|
51
|
+
readonly #characterSetValidator: CharacterSetValidator;
|
|
52
52
|
|
|
53
53
|
protected constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, characterSetValidator: CharacterSetValidator) {
|
|
54
54
|
super(appExtension);
|
|
55
55
|
|
|
56
|
-
this
|
|
56
|
+
this.#characterSetValidator = characterSetValidator;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
@ProxyMethod({
|
|
@@ -64,7 +64,7 @@ export abstract class CharacterSetValidatorProxy<ThrowError extends boolean, TEr
|
|
|
64
64
|
@ProxyParameter(validateSParameterDescriptor) matrixSs: Matrix<string>,
|
|
65
65
|
@ProxyParameter(exclusionNoneParameterDescriptor) exclusion: Nullishable<Exclusion>
|
|
66
66
|
): MatrixResultError<string, ThrowError, TError> {
|
|
67
|
-
return this.validateString(this
|
|
67
|
+
return this.validateString(this.#characterSetValidator, matrixSs, {
|
|
68
68
|
exclusion: exclusion ?? undefined
|
|
69
69
|
} satisfies CharacterSetValidation);
|
|
70
70
|
}
|
|
@@ -82,12 +82,12 @@ export abstract class CharacterSetValidatorProxy<ThrowError extends boolean, TEr
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends CharacterSetValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
85
|
-
|
|
85
|
+
readonly #characterSetCreator: CharacterSetCreator;
|
|
86
86
|
|
|
87
87
|
protected constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, characterSetCreator: CharacterSetCreator) {
|
|
88
88
|
super(appExtension, characterSetCreator);
|
|
89
89
|
|
|
90
|
-
this
|
|
90
|
+
this.#characterSetCreator = characterSetCreator;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
@ProxyMethod({
|
|
@@ -103,7 +103,7 @@ export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TErro
|
|
|
103
103
|
const exclusionOrUndefined = exclusion ?? undefined;
|
|
104
104
|
const tweakOrUndefined = tweak ?? undefined;
|
|
105
105
|
|
|
106
|
-
return this.mapMatrix(matrixValues, value => this.
|
|
106
|
+
return this.mapMatrix(matrixValues, value => this.#characterSetCreator.create(length, value, exclusionOrUndefined, tweakOrUndefined));
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
@ProxyMethod({
|
|
@@ -123,7 +123,7 @@ export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TErro
|
|
|
123
123
|
const exclusionOrUndefined = exclusion ?? undefined;
|
|
124
124
|
const tweakOrUndefined = tweak ?? undefined;
|
|
125
125
|
|
|
126
|
-
return LibProxy.matrixResult(this.
|
|
126
|
+
return LibProxy.matrixResult(this.#characterSetCreator.create(length, new Sequence(startValue, count), exclusionOrUndefined, tweakOrUndefined));
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
@ProxyMethod({
|
|
@@ -138,7 +138,7 @@ export abstract class CharacterSetCreatorProxy<ThrowError extends boolean, TErro
|
|
|
138
138
|
const exclusionOrUndefined = exclusion ?? undefined;
|
|
139
139
|
const tweakOrUndefined = tweak ?? undefined;
|
|
140
140
|
|
|
141
|
-
return this.mapMatrix(matrixSs, s => this.mapBigInt(this.
|
|
141
|
+
return this.mapMatrix(matrixSs, s => this.mapBigInt(this.#characterSetCreator.valueFor(s, exclusionOrUndefined, tweakOrUndefined)));
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
package/src/utility/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./transformer-proxy";
|
|
2
|
-
export * from "./reg-exp-proxy";
|
|
3
|
-
export * from "./character-set-proxy";
|
|
1
|
+
export * from "./transformer-proxy.js";
|
|
2
|
+
export * from "./reg-exp-proxy.js";
|
|
3
|
+
export * from "./character-set-proxy.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Nullishable } from "@aidc-toolkit/core";
|
|
2
2
|
import { RegExpValidator } from "@aidc-toolkit/utility";
|
|
3
|
-
import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "../descriptor";
|
|
4
|
-
import type { ErrorExtends, Matrix, MatrixResultError } from "../type";
|
|
5
|
-
import { validateSParameterDescriptor } from "./string-descriptor";
|
|
6
|
-
import { StringProxy } from "./string-proxy";
|
|
3
|
+
import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "../descriptor.js";
|
|
4
|
+
import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
|
|
5
|
+
import { validateSParameterDescriptor } from "./string-descriptor.js";
|
|
6
|
+
import { StringProxy } from "./string-proxy.js";
|
|
7
7
|
|
|
8
8
|
const regExpParameterDescriptor: ParameterDescriptor = {
|
|
9
9
|
name: "regExp",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StringValidation, StringValidator } from "@aidc-toolkit/utility";
|
|
2
|
-
import { LibProxy } from "../lib-proxy";
|
|
3
|
-
import type { ErrorExtends, Matrix, MatrixResultError } from "../type";
|
|
2
|
+
import { LibProxy } from "../lib-proxy.js";
|
|
3
|
+
import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
|
|
4
4
|
|
|
5
5
|
export abstract class StringProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
6
6
|
protected validateString<TStringValidation extends StringValidation>(validator: StringValidator<TStringValidation>, matrixSs: Matrix<string>, validation?: TStringValidation): Matrix<string> {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Nullishable } from "@aidc-toolkit/core";
|
|
2
2
|
import { mapIterable, Sequence, Transformer } from "@aidc-toolkit/utility";
|
|
3
|
-
import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "../descriptor";
|
|
4
|
-
import { LibProxy } from "../lib-proxy";
|
|
5
|
-
import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "../type";
|
|
3
|
+
import { type ParameterDescriptor, ProxyClass, ProxyMethod, ProxyParameter, Types } from "../descriptor.js";
|
|
4
|
+
import { LibProxy } from "../lib-proxy.js";
|
|
5
|
+
import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "../type.js";
|
|
6
6
|
import {
|
|
7
7
|
countParameterDescriptor,
|
|
8
8
|
startValueParameterDescriptor,
|
|
9
9
|
tweakParameterDescriptor,
|
|
10
10
|
valueParameterDescriptor
|
|
11
|
-
} from "./transformer-descriptor";
|
|
11
|
+
} from "./transformer-descriptor.js";
|
|
12
12
|
|
|
13
13
|
const domainParameterDescriptor: ParameterDescriptor = {
|
|
14
14
|
name: "domain",
|
package/tsconfig.json
CHANGED
package/tsup.config.ts
CHANGED