@aidc-toolkit/app-extension 1.0.31-beta → 1.0.32-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 +3446 -627
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +575 -300
- package/dist/index.d.ts +575 -300
- package/dist/index.js +3435 -610
- package/dist/index.js.map +1 -1
- package/package.json +8 -9
- package/src/app-data.ts +94 -0
- package/src/app-extension.ts +162 -93
- package/src/app-utility-proxy.ts +154 -103
- package/src/descriptor.ts +33 -6
- package/src/generator/generator.ts +3 -6
- package/src/generator/locale-resources-generator.ts +30 -28
- package/src/gs1/character-set-proxy.ts +8 -8
- package/src/gs1/check-proxy.ts +14 -14
- package/src/gs1/gtin-creator-proxy.ts +12 -25
- package/src/gs1/gtin-descriptor.ts +0 -21
- package/src/gs1/gtin-validator-proxy.ts +34 -35
- package/src/gs1/identifier-creator-proxy.ts +44 -32
- package/src/gs1/identifier-descriptor.ts +15 -0
- package/src/gs1/identifier-type.ts +37 -0
- package/src/gs1/identifier-validator-proxy.ts +52 -19
- package/src/gs1/index.ts +8 -0
- package/src/gs1/non-gtin-creator-proxy.ts +22 -22
- package/src/gs1/non-gtin-validator-proxy.ts +22 -22
- package/src/gs1/prefix-manager-proxy.ts +199 -4
- package/src/gs1/service-proxy.ts +56 -0
- package/src/gs1/variable-measure-proxy.ts +61 -0
- package/src/index.ts +6 -0
- package/src/lib-proxy.ts +112 -70
- package/src/locale/en/locale-resources.ts +147 -34
- package/src/locale/fr/locale-resources.ts +147 -34
- package/src/locale/i18n.ts +2 -5
- package/src/proxy.ts +82 -106
- package/src/streaming.ts +13 -0
- package/src/type.ts +8 -7
- package/src/utility/character-set-proxy.ts +33 -32
- package/src/utility/reg-exp-proxy.ts +7 -6
- package/src/utility/string-proxy.ts +3 -7
- package/src/utility/transformer-proxy.ts +19 -13
package/src/gs1/check-proxy.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { type ExtendsParameterDescriptor, type ParameterDescriptor, Types } from "../descriptor.js";
|
|
10
10
|
import { LibProxy } from "../lib-proxy.js";
|
|
11
11
|
import { proxy } from "../proxy.js";
|
|
12
|
-
import type { ErrorExtends, Matrix,
|
|
12
|
+
import type { ErrorExtends, Matrix, MatrixResult, SingletonResult } from "../type.js";
|
|
13
13
|
|
|
14
14
|
const checkSParameterDescriptor: ParameterDescriptor = {
|
|
15
15
|
name: "checkS",
|
|
@@ -55,14 +55,14 @@ const ai82SWithCheckCharacterPairParameterDescriptor: ExtendsParameterDescriptor
|
|
|
55
55
|
@proxy.describeClass(false, {
|
|
56
56
|
namespace: "GS1"
|
|
57
57
|
})
|
|
58
|
-
export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
58
|
+
export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
|
|
59
59
|
@proxy.describeMethod({
|
|
60
60
|
type: Types.String,
|
|
61
61
|
isMatrix: true,
|
|
62
62
|
parameterDescriptors: [numericSParameterDescriptor]
|
|
63
63
|
})
|
|
64
|
-
checkDigit(matrixSs: Matrix<string>):
|
|
65
|
-
return this.
|
|
64
|
+
checkDigit(matrixSs: Matrix<string>): MatrixResult<string, ThrowError, TError> {
|
|
65
|
+
return this.matrixResult(matrixSs, s => checkDigit(s));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
@proxy.describeMethod({
|
|
@@ -70,8 +70,8 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
|
|
|
70
70
|
isMatrix: true,
|
|
71
71
|
parameterDescriptors: [numericSWithCheckDigitParameterDescriptor]
|
|
72
72
|
})
|
|
73
|
-
hasValidCheckDigit(matrixSs: Matrix<string>):
|
|
74
|
-
return this.
|
|
73
|
+
hasValidCheckDigit(matrixSs: Matrix<string>): MatrixResult<boolean, ThrowError, TError> {
|
|
74
|
+
return this.matrixResult(matrixSs, s => hasValidCheckDigit(s));
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
@proxy.describeMethod({
|
|
@@ -79,8 +79,8 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
|
|
|
79
79
|
isMatrix: true,
|
|
80
80
|
parameterDescriptors: [numericSFourOrFiveDigitsParameterDescriptor]
|
|
81
81
|
})
|
|
82
|
-
priceOrWeightCheckDigit(matrixSs: Matrix<string>):
|
|
83
|
-
return this.
|
|
82
|
+
priceOrWeightCheckDigit(matrixSs: Matrix<string>): MatrixResult<string, ThrowError, TError> {
|
|
83
|
+
return this.matrixResult(matrixSs, s => priceOrWeightCheckDigit(s));
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
@proxy.describeMethod({
|
|
@@ -91,8 +91,8 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
|
|
|
91
91
|
isMatrix: false
|
|
92
92
|
}, checkDigitParameterDescriptor]
|
|
93
93
|
})
|
|
94
|
-
isValidPriceOrWeightCheckDigit(s: string, checkDigit: string):
|
|
95
|
-
return isValidPriceOrWeightCheckDigit(s, checkDigit);
|
|
94
|
+
isValidPriceOrWeightCheckDigit(s: string, checkDigit: string): SingletonResult<boolean, ThrowError, TError> {
|
|
95
|
+
return this.singletonResult(() => isValidPriceOrWeightCheckDigit(s, checkDigit));
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
@proxy.describeMethod({
|
|
@@ -100,8 +100,8 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
|
|
|
100
100
|
isMatrix: true,
|
|
101
101
|
parameterDescriptors: [ai82SParameterDescriptor]
|
|
102
102
|
})
|
|
103
|
-
checkCharacterPair(matrixSs: Matrix<string>):
|
|
104
|
-
return this.
|
|
103
|
+
checkCharacterPair(matrixSs: Matrix<string>): MatrixResult<string, ThrowError, TError> {
|
|
104
|
+
return this.matrixResult(matrixSs, s => checkCharacterPair(s));
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
@proxy.describeMethod({
|
|
@@ -109,7 +109,7 @@ export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<
|
|
|
109
109
|
isMatrix: true,
|
|
110
110
|
parameterDescriptors: [ai82SWithCheckCharacterPairParameterDescriptor]
|
|
111
111
|
})
|
|
112
|
-
hasValidCheckCharacterPair(matrixSs: Matrix<string>):
|
|
113
|
-
return this.
|
|
112
|
+
hasValidCheckCharacterPair(matrixSs: Matrix<string>): MatrixResult<boolean, ThrowError, TError> {
|
|
113
|
+
return this.matrixResult(matrixSs, s => hasValidCheckCharacterPair(s));
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import type { Nullishable } from "@aidc-toolkit/core";
|
|
2
|
-
import { GTINCreator,
|
|
2
|
+
import type { GTINCreator, GTINType } from "@aidc-toolkit/gs1";
|
|
3
3
|
import type { AppExtension } from "../app-extension.js";
|
|
4
4
|
import { Types } from "../descriptor.js";
|
|
5
5
|
import { expandParameterDescriptor, proxy } from "../proxy.js";
|
|
6
|
-
import type { ErrorExtends, Matrix,
|
|
6
|
+
import type { ErrorExtends, Matrix, MatrixResult } from "../type.js";
|
|
7
7
|
import { valueParameterDescriptor } from "../utility/transformer-descriptor.js";
|
|
8
|
-
import {
|
|
9
|
-
indicatorDigitParameterDescriptor,
|
|
10
|
-
rcnFormatParameterDescriptor,
|
|
11
|
-
rcnItemReferenceParameterDescriptor,
|
|
12
|
-
rcnPriceOrWeightParameterDescriptor
|
|
13
|
-
} from "./gtin-descriptor.js";
|
|
8
|
+
import { indicatorDigitParameterDescriptor } from "./gtin-descriptor.js";
|
|
14
9
|
import { NumericIdentifierCreatorProxy, sparseParameterDescriptor } from "./identifier-creator-proxy.js";
|
|
15
10
|
import {
|
|
16
11
|
prefixDefinitionAnyParameterDescriptor,
|
|
@@ -20,15 +15,15 @@ import {
|
|
|
20
15
|
@proxy.describeClass(false, {
|
|
21
16
|
namespace: "GS1",
|
|
22
17
|
methodInfix: "GTIN",
|
|
23
|
-
|
|
18
|
+
replacementParameterDescriptors: [
|
|
24
19
|
{
|
|
25
20
|
name: expandParameterDescriptor(prefixDefinitionGS1UPCParameterDescriptor).name,
|
|
26
21
|
replacement: prefixDefinitionAnyParameterDescriptor
|
|
27
22
|
}
|
|
28
23
|
]
|
|
29
24
|
})
|
|
30
|
-
export class GTINCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, GTINType, GTINCreator> {
|
|
31
|
-
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
|
|
25
|
+
export class GTINCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends NumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt, GTINType, GTINCreator> {
|
|
26
|
+
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
|
|
32
27
|
super(appExtension, prefixManager => prefixManager.gtinCreator);
|
|
33
28
|
}
|
|
34
29
|
|
|
@@ -38,21 +33,13 @@ export class GTINCreatorProxy<ThrowError extends boolean, TError extends ErrorEx
|
|
|
38
33
|
ignoreInfix: true,
|
|
39
34
|
parameterDescriptors: [indicatorDigitParameterDescriptor, prefixDefinitionAnyParameterDescriptor, valueParameterDescriptor, sparseParameterDescriptor]
|
|
40
35
|
})
|
|
41
|
-
createGTIN14(indicatorDigit: string, prefixDefinition: Matrix<unknown>, matrixValues: Matrix<number | bigint>, sparse: Nullishable<boolean>):
|
|
42
|
-
const creator = this.getCreator(prefixDefinition);
|
|
43
|
-
|
|
36
|
+
createGTIN14(indicatorDigit: string, prefixDefinition: Matrix<unknown>, matrixValues: Matrix<number | bigint>, sparse: Nullishable<boolean>): MatrixResult<string, ThrowError, TError> {
|
|
44
37
|
const sparseOrUndefined = sparse ?? undefined;
|
|
45
38
|
|
|
46
|
-
return this.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
isMatrix: true,
|
|
52
|
-
ignoreInfix: true,
|
|
53
|
-
parameterDescriptors: [rcnFormatParameterDescriptor, rcnItemReferenceParameterDescriptor, rcnPriceOrWeightParameterDescriptor]
|
|
54
|
-
})
|
|
55
|
-
createVariableMeasureRCN(format: string, itemReference: number, matrixPricesOrWeights: Matrix<number>): MatrixResultError<string, ThrowError, TError> {
|
|
56
|
-
return this.mapMatrix(matrixPricesOrWeights, priceOrWeight => GTINCreator.createVariableMeasureRCN(format, itemReference, priceOrWeight));
|
|
39
|
+
return this.setUpMatrixResult(() =>
|
|
40
|
+
this.getCreator(prefixDefinition),
|
|
41
|
+
matrixValues, (creator, value) =>
|
|
42
|
+
creator.createGTIN14(indicatorDigit, value, sparseOrUndefined)
|
|
43
|
+
);
|
|
57
44
|
}
|
|
58
45
|
}
|
|
@@ -6,24 +6,3 @@ export const indicatorDigitParameterDescriptor: ParameterDescriptor = {
|
|
|
6
6
|
isMatrix: false,
|
|
7
7
|
isRequired: true
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
export const rcnFormatParameterDescriptor: ParameterDescriptor = {
|
|
11
|
-
name: "rcnFormat",
|
|
12
|
-
type: Types.String,
|
|
13
|
-
isMatrix: false,
|
|
14
|
-
isRequired: true
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const rcnItemReferenceParameterDescriptor: ParameterDescriptor = {
|
|
18
|
-
name: "rcnItemReference",
|
|
19
|
-
type: Types.Number,
|
|
20
|
-
isMatrix: false,
|
|
21
|
-
isRequired: true
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const rcnPriceOrWeightParameterDescriptor: ParameterDescriptor = {
|
|
25
|
-
name: "rcnPriceOrWeight",
|
|
26
|
-
type: Types.Number,
|
|
27
|
-
isMatrix: true,
|
|
28
|
-
isRequired: true
|
|
29
|
-
};
|
|
@@ -4,16 +4,17 @@ import type { AppExtension } from "../app-extension.js";
|
|
|
4
4
|
import { type ExtendsParameterDescriptor, type ParameterDescriptor, Types } from "../descriptor.js";
|
|
5
5
|
import { LibProxy } from "../lib-proxy.js";
|
|
6
6
|
import { proxy } from "../proxy.js";
|
|
7
|
-
import type { ErrorExtends, Matrix,
|
|
8
|
-
import { indicatorDigitParameterDescriptor
|
|
9
|
-
import {
|
|
7
|
+
import type { ErrorExtends, Matrix, MatrixResult } from "../type.js";
|
|
8
|
+
import { indicatorDigitParameterDescriptor } from "./gtin-descriptor.js";
|
|
9
|
+
import { identifierParameterDescriptor } from "./identifier-descriptor.js";
|
|
10
|
+
import { GTINValidatorProxy } from "./identifier-validator-proxy.js";
|
|
10
11
|
|
|
11
12
|
@proxy.describeClass(false, {
|
|
12
13
|
namespace: "GS1",
|
|
13
14
|
methodInfix: "GTIN13"
|
|
14
15
|
})
|
|
15
|
-
export class GTIN13ValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends GTINValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
16
|
-
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
|
|
16
|
+
export class GTIN13ValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends GTINValidatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
|
|
17
|
+
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
|
|
17
18
|
super(appExtension, IdentifierValidators.GTIN[GTINLengths.GTIN13]);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -22,8 +23,8 @@ export class GTIN13ValidatorProxy<ThrowError extends boolean, TError extends Err
|
|
|
22
23
|
namespace: "GS1",
|
|
23
24
|
methodInfix: "GTIN12"
|
|
24
25
|
})
|
|
25
|
-
export class GTIN12ValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends GTINValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
26
|
-
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
|
|
26
|
+
export class GTIN12ValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends GTINValidatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
|
|
27
|
+
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
|
|
27
28
|
super(appExtension, IdentifierValidators.GTIN[GTINLengths.GTIN12]);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
@@ -32,8 +33,8 @@ export class GTIN12ValidatorProxy<ThrowError extends boolean, TError extends Err
|
|
|
32
33
|
namespace: "GS1",
|
|
33
34
|
methodInfix: "GTIN8"
|
|
34
35
|
})
|
|
35
|
-
export class GTIN8ValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends GTINValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
36
|
-
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
|
|
36
|
+
export class GTIN8ValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends GTINValidatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
|
|
37
|
+
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>) {
|
|
37
38
|
super(appExtension, IdentifierValidators.GTIN[GTINLengths.GTIN8]);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -75,24 +76,17 @@ const validateGTIN14ParameterDescriptor: ExtendsParameterDescriptor = {
|
|
|
75
76
|
name: "validateGTIN14"
|
|
76
77
|
};
|
|
77
78
|
|
|
78
|
-
const rcnParameterDescriptor: ParameterDescriptor = {
|
|
79
|
-
name: "rcn",
|
|
80
|
-
type: Types.String,
|
|
81
|
-
isMatrix: true,
|
|
82
|
-
isRequired: true
|
|
83
|
-
};
|
|
84
|
-
|
|
85
79
|
@proxy.describeClass(false, {
|
|
86
80
|
namespace: "GS1"
|
|
87
81
|
})
|
|
88
|
-
export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
82
|
+
export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
|
|
89
83
|
@proxy.describeMethod({
|
|
90
84
|
type: Types.String,
|
|
91
85
|
isMatrix: true,
|
|
92
86
|
parameterDescriptors: [zeroSuppressibleGTIN12ParameterDescriptor]
|
|
93
87
|
})
|
|
94
|
-
zeroSuppressGTIN12(matrixGTIN12s: Matrix<string>):
|
|
95
|
-
return this.
|
|
88
|
+
zeroSuppressGTIN12(matrixGTIN12s: Matrix<string>): MatrixResult<string, ThrowError, TError> {
|
|
89
|
+
return this.matrixResult(matrixGTIN12s, gtin12 => GTINValidator.zeroSuppress(gtin12));
|
|
96
90
|
}
|
|
97
91
|
|
|
98
92
|
@proxy.describeMethod({
|
|
@@ -100,8 +94,8 @@ export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends
|
|
|
100
94
|
isMatrix: true,
|
|
101
95
|
parameterDescriptors: [zeroSuppressedGTIN12ParameterDescriptor]
|
|
102
96
|
})
|
|
103
|
-
zeroExpandGTIN12(matrixZeroSuppressedGTIN12s: Matrix<string>):
|
|
104
|
-
return this.
|
|
97
|
+
zeroExpandGTIN12(matrixZeroSuppressedGTIN12s: Matrix<string>): MatrixResult<string, ThrowError, TError> {
|
|
98
|
+
return this.matrixResult(matrixZeroSuppressedGTIN12s, zeroSuppressedGTIN12 => GTINValidator.zeroExpand(zeroSuppressedGTIN12));
|
|
105
99
|
}
|
|
106
100
|
|
|
107
101
|
@proxy.describeMethod({
|
|
@@ -109,8 +103,8 @@ export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends
|
|
|
109
103
|
isMatrix: true,
|
|
110
104
|
parameterDescriptors: [indicatorDigitParameterDescriptor, convertGTINParameterDescriptor]
|
|
111
105
|
})
|
|
112
|
-
convertToGTIN14(indicatorDigit: string, matrixGTINs: Matrix<string>):
|
|
113
|
-
return this.
|
|
106
|
+
convertToGTIN14(indicatorDigit: string, matrixGTINs: Matrix<string>): MatrixResult<string, ThrowError, TError> {
|
|
107
|
+
return this.matrixResult(matrixGTINs, gtin => GTINValidator.convertToGTIN14(indicatorDigit, gtin));
|
|
114
108
|
}
|
|
115
109
|
|
|
116
110
|
@proxy.describeMethod({
|
|
@@ -118,8 +112,8 @@ export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends
|
|
|
118
112
|
isMatrix: true,
|
|
119
113
|
parameterDescriptors: [normalizeGTINParameterDescriptor]
|
|
120
114
|
})
|
|
121
|
-
normalizeGTIN(matrixGTINs: Matrix<string>):
|
|
122
|
-
return this.
|
|
115
|
+
normalizeGTIN(matrixGTINs: Matrix<string>): MatrixResult<string, ThrowError, TError> {
|
|
116
|
+
return this.matrixResult(matrixGTINs, gtin => GTINValidator.normalize(gtin));
|
|
123
117
|
}
|
|
124
118
|
|
|
125
119
|
@proxy.describeMethod({
|
|
@@ -130,32 +124,37 @@ export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends
|
|
|
130
124
|
validateGTIN(matrixGTINs: Matrix<string>, gtinLevel: Nullishable<GTINLevel>): Matrix<string> {
|
|
131
125
|
const gtinLevelOrUndefined = gtinLevel ?? undefined;
|
|
132
126
|
|
|
133
|
-
return
|
|
127
|
+
return this.matrixErrorResult(matrixGTINs, (gtin) => {
|
|
134
128
|
GTINValidator.validateAny(gtin, gtinLevelOrUndefined);
|
|
135
129
|
});
|
|
136
130
|
}
|
|
137
131
|
|
|
132
|
+
@proxy.describeMethod({
|
|
133
|
+
type: Types.String,
|
|
134
|
+
isMatrix: true,
|
|
135
|
+
parameterDescriptors: [validateGTINParameterDescriptor, gtinLevelParameterDescriptor]
|
|
136
|
+
})
|
|
137
|
+
isValidGTIN(matrixGTINs: Matrix<string>, gtinLevel: Nullishable<GTINLevel>): Matrix<boolean> {
|
|
138
|
+
return this.isValidString(this.validateGTIN(matrixGTINs, gtinLevel));
|
|
139
|
+
}
|
|
140
|
+
|
|
138
141
|
@proxy.describeMethod({
|
|
139
142
|
type: Types.String,
|
|
140
143
|
isMatrix: true,
|
|
141
144
|
parameterDescriptors: [validateGTIN14ParameterDescriptor]
|
|
142
145
|
})
|
|
143
146
|
validateGTIN14(matrixGTIN14s: Matrix<string>): Matrix<string> {
|
|
144
|
-
return
|
|
147
|
+
return this.matrixErrorResult(matrixGTIN14s, (gtin14) => {
|
|
145
148
|
GTINValidator.validateGTIN14(gtin14);
|
|
146
149
|
});
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
@proxy.describeMethod({
|
|
150
|
-
type: Types.
|
|
153
|
+
type: Types.String,
|
|
151
154
|
isMatrix: true,
|
|
152
|
-
parameterDescriptors: [
|
|
155
|
+
parameterDescriptors: [validateGTIN14ParameterDescriptor]
|
|
153
156
|
})
|
|
154
|
-
|
|
155
|
-
return this.
|
|
156
|
-
const rcnReference = GTINValidator.parseVariableMeasureRCN(format, rcn);
|
|
157
|
-
|
|
158
|
-
return [rcnReference.itemReference, rcnReference.priceOrWeight];
|
|
159
|
-
});
|
|
157
|
+
isValidGTIN14(matrixGTIN14s: Matrix<string>): Matrix<boolean> {
|
|
158
|
+
return this.isValidString(this.validateGTIN14(matrixGTIN14s));
|
|
160
159
|
}
|
|
161
160
|
}
|
|
@@ -25,21 +25,21 @@ import { type ExtendsParameterDescriptor, type ParameterDescriptor, Types } from
|
|
|
25
25
|
import { LibProxy } from "../lib-proxy.js";
|
|
26
26
|
import { i18nextAppExtension } from "../locale/i18n.js";
|
|
27
27
|
import { proxy } from "../proxy.js";
|
|
28
|
-
import type { ErrorExtends, Matrix,
|
|
28
|
+
import type { ErrorExtends, Matrix, MatrixResult } from "../type.js";
|
|
29
29
|
import {
|
|
30
30
|
countParameterDescriptor,
|
|
31
31
|
startValueParameterDescriptor,
|
|
32
32
|
valueParameterDescriptor
|
|
33
33
|
} from "../utility/transformer-descriptor.js";
|
|
34
|
-
import { identifierParameterDescriptor } from "./identifier-
|
|
34
|
+
import { identifierParameterDescriptor } from "./identifier-descriptor.js";
|
|
35
35
|
import { prefixDefinitionGS1UPCParameterDescriptor } from "./prefix-definition-descriptor.js";
|
|
36
36
|
|
|
37
|
-
abstract class IdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TIdentifierType extends IdentifierType, TIdentifierValidation extends IdentifierValidation, TIdentifierCreator extends IdentifierCreator<TIdentifierType, TIdentifierValidation>> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
37
|
+
abstract class IdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt, TIdentifierType extends IdentifierType, TIdentifierValidation extends IdentifierValidation, TIdentifierCreator extends IdentifierCreator<TIdentifierType, TIdentifierValidation>> extends LibProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt> {
|
|
38
38
|
static readonly #PREFIX_TYPES: Array<PrefixType | undefined> = [PrefixTypes.GS1CompanyPrefix, PrefixTypes.UPCCompanyPrefix, PrefixTypes.GS18Prefix];
|
|
39
39
|
|
|
40
40
|
readonly #getCreator: (prefixManager: PrefixManager) => TIdentifierCreator;
|
|
41
41
|
|
|
42
|
-
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, getCreator: (prefixManager: PrefixManager) => TIdentifierCreator) {
|
|
42
|
+
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt>, getCreator: (prefixManager: PrefixManager) => TIdentifierCreator) {
|
|
43
43
|
super(appExtension);
|
|
44
44
|
|
|
45
45
|
this.#getCreator = getCreator;
|
|
@@ -110,18 +110,20 @@ export const sparseParameterDescriptor: ParameterDescriptor = {
|
|
|
110
110
|
@proxy.describeClass(true, {
|
|
111
111
|
namespace: "GS1"
|
|
112
112
|
})
|
|
113
|
-
export abstract class NumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TNumericIdentifierType extends NumericIdentifierType, TNumericIdentifierCreator extends NumericIdentifierCreator<TNumericIdentifierType>> extends IdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, TNumericIdentifierType, NumericIdentifierValidation, TNumericIdentifierCreator> {
|
|
113
|
+
export abstract class NumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt, TNumericIdentifierType extends NumericIdentifierType, TNumericIdentifierCreator extends NumericIdentifierCreator<TNumericIdentifierType>> extends IdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt, TNumericIdentifierType, NumericIdentifierValidation, TNumericIdentifierCreator> {
|
|
114
114
|
@proxy.describeMethod({
|
|
115
115
|
type: Types.String,
|
|
116
116
|
isMatrix: true,
|
|
117
117
|
parameterDescriptors: [prefixDefinitionGS1UPCParameterDescriptor, valueParameterDescriptor, sparseParameterDescriptor]
|
|
118
118
|
})
|
|
119
|
-
create(prefixDefinition: Matrix<unknown>, matrixValues: Matrix<number | bigint>, sparse: Nullishable<boolean>):
|
|
120
|
-
const creator = this.getCreator(prefixDefinition);
|
|
121
|
-
|
|
119
|
+
create(prefixDefinition: Matrix<unknown>, matrixValues: Matrix<number | bigint>, sparse: Nullishable<boolean>): MatrixResult<string, ThrowError, TError> {
|
|
122
120
|
const sparseOrUndefined = sparse ?? undefined;
|
|
123
121
|
|
|
124
|
-
return this.
|
|
122
|
+
return this.setUpMatrixResult(() =>
|
|
123
|
+
this.getCreator(prefixDefinition),
|
|
124
|
+
matrixValues, (creator, value) =>
|
|
125
|
+
creator.create(value, sparseOrUndefined)
|
|
126
|
+
);
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
@proxy.describeMethod({
|
|
@@ -130,10 +132,12 @@ export abstract class NumericIdentifierCreatorProxy<ThrowError extends boolean,
|
|
|
130
132
|
isMatrix: true,
|
|
131
133
|
parameterDescriptors: [prefixDefinitionGS1UPCParameterDescriptor, startValueParameterDescriptor, countParameterDescriptor, sparseParameterDescriptor]
|
|
132
134
|
})
|
|
133
|
-
createSequence(prefixDefinition: Matrix<unknown>, startValue: number, count: number, sparse: Nullishable<boolean>):
|
|
134
|
-
this.
|
|
135
|
+
createSequence(prefixDefinition: Matrix<unknown>, startValue: number, count: number, sparse: Nullishable<boolean>): MatrixResult<string, ThrowError, TError> {
|
|
136
|
+
return this.iterableResult(() => {
|
|
137
|
+
this.appExtension.validateSequenceCount(count);
|
|
135
138
|
|
|
136
|
-
|
|
139
|
+
return this.getCreator(prefixDefinition).create(new Sequence(startValue, count), sparse ?? undefined);
|
|
140
|
+
});
|
|
137
141
|
}
|
|
138
142
|
|
|
139
143
|
@proxy.describeMethod({
|
|
@@ -141,19 +145,21 @@ export abstract class NumericIdentifierCreatorProxy<ThrowError extends boolean,
|
|
|
141
145
|
isMatrix: true,
|
|
142
146
|
parameterDescriptors: [prefixDefinitionGS1UPCParameterDescriptor]
|
|
143
147
|
})
|
|
144
|
-
createAll(prefixDefinition: Matrix<unknown>):
|
|
145
|
-
|
|
148
|
+
createAll(prefixDefinition: Matrix<unknown>): MatrixResult<string, ThrowError, TError> {
|
|
149
|
+
return this.iterableResult(() => {
|
|
150
|
+
const creator = this.getCreator(prefixDefinition);
|
|
146
151
|
|
|
147
|
-
|
|
152
|
+
this.appExtension.validateSequenceCount(creator.capacity);
|
|
148
153
|
|
|
149
|
-
|
|
154
|
+
return creator.createAll();
|
|
155
|
+
});
|
|
150
156
|
}
|
|
151
157
|
}
|
|
152
158
|
|
|
153
|
-
abstract class NonGTINNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TNonGTINNumericIdentifierType extends NonGTINNumericIdentifierType, TNonGTINNumericIdentifierCreator extends NonGTINNumericIdentifierCreator> extends NumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, TNonGTINNumericIdentifierType, TNonGTINNumericIdentifierCreator> {
|
|
159
|
+
abstract class NonGTINNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt, TNonGTINNumericIdentifierType extends NonGTINNumericIdentifierType, TNonGTINNumericIdentifierCreator extends NonGTINNumericIdentifierCreator> extends NumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt, TNonGTINNumericIdentifierType, TNonGTINNumericIdentifierCreator> {
|
|
154
160
|
}
|
|
155
161
|
|
|
156
|
-
export abstract class NonSerializableNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TNonSerializableNumericIdentifierType extends NonSerializableNumericIdentifierType, TNonGTINNumericIdentifierCreator extends NonGTINNumericIdentifierCreator> extends NonGTINNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, TNonSerializableNumericIdentifierType, TNonGTINNumericIdentifierCreator> {
|
|
162
|
+
export abstract class NonSerializableNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt, TNonSerializableNumericIdentifierType extends NonSerializableNumericIdentifierType, TNonGTINNumericIdentifierCreator extends NonGTINNumericIdentifierCreator> extends NonGTINNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt, TNonSerializableNumericIdentifierType, TNonGTINNumericIdentifierCreator> {
|
|
157
163
|
}
|
|
158
164
|
|
|
159
165
|
const singleValueParameterDescriptor: ExtendsParameterDescriptor = {
|
|
@@ -177,18 +183,20 @@ const serialComponentParameterDescriptor: ParameterDescriptor = {
|
|
|
177
183
|
@proxy.describeClass(true, {
|
|
178
184
|
namespace: "GS1"
|
|
179
185
|
})
|
|
180
|
-
export abstract class SerializableNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, SerializableNumericIdentifierType, SerializableNumericIdentifierCreator> {
|
|
186
|
+
export abstract class SerializableNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends NonGTINNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt, SerializableNumericIdentifierType, SerializableNumericIdentifierCreator> {
|
|
181
187
|
@proxy.describeMethod({
|
|
182
188
|
type: Types.String,
|
|
183
189
|
isMatrix: true,
|
|
184
190
|
parameterDescriptors: [prefixDefinitionGS1UPCParameterDescriptor, singleValueParameterDescriptor, serialComponentParameterDescriptor, sparseParameterDescriptor]
|
|
185
191
|
})
|
|
186
|
-
createSerialized(prefixDefinition: Matrix<unknown>, value: number, matrixSerialComponents: Matrix<string>, sparse: Nullishable<boolean>):
|
|
187
|
-
const creator = this.getCreator(prefixDefinition);
|
|
188
|
-
|
|
192
|
+
createSerialized(prefixDefinition: Matrix<unknown>, value: number, matrixSerialComponents: Matrix<string>, sparse: Nullishable<boolean>): MatrixResult<string, ThrowError, TError> {
|
|
189
193
|
const sparseOrUndefined = sparse ?? undefined;
|
|
190
194
|
|
|
191
|
-
return this.
|
|
195
|
+
return this.setUpMatrixResult(() =>
|
|
196
|
+
this.getCreator(prefixDefinition),
|
|
197
|
+
matrixSerialComponents, (creator, serialComponent) =>
|
|
198
|
+
creator.createSerialized(value, serialComponent, sparseOrUndefined)
|
|
199
|
+
);
|
|
192
200
|
}
|
|
193
201
|
|
|
194
202
|
@proxy.describeMethod({
|
|
@@ -196,10 +204,12 @@ export abstract class SerializableNumericIdentifierCreatorProxy<ThrowError exten
|
|
|
196
204
|
isMatrix: true,
|
|
197
205
|
parameterDescriptors: [baseIdentifierParameterDescriptor, serialComponentParameterDescriptor]
|
|
198
206
|
})
|
|
199
|
-
concatenate(baseIdentifier: string, matrixSerialComponents: Matrix<string>):
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
207
|
+
concatenate(baseIdentifier: string, matrixSerialComponents: Matrix<string>): MatrixResult<string, ThrowError, TError> {
|
|
208
|
+
return this.setUpMatrixResult(() =>
|
|
209
|
+
this.getCreator([[baseIdentifier.substring(0, !baseIdentifier.startsWith("0") ? PrefixValidator.GS1_COMPANY_PREFIX_MINIMUM_LENGTH : PrefixValidator.UPC_COMPANY_PREFIX_MINIMUM_LENGTH + 1), PrefixTypes.GS1CompanyPrefix]]),
|
|
210
|
+
matrixSerialComponents, (creator, serialComponent) =>
|
|
211
|
+
creator.concatenate(baseIdentifier, serialComponent)
|
|
212
|
+
);
|
|
203
213
|
}
|
|
204
214
|
}
|
|
205
215
|
|
|
@@ -213,15 +223,17 @@ const referenceParameterDescriptor: ParameterDescriptor = {
|
|
|
213
223
|
@proxy.describeClass(true, {
|
|
214
224
|
namespace: "GS1"
|
|
215
225
|
})
|
|
216
|
-
export abstract class NonNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends IdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, NonNumericIdentifierType, NonNumericIdentifierValidation, NonNumericIdentifierCreator> {
|
|
226
|
+
export abstract class NonNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TStreamingInvocationContext, TBigInt> extends IdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TStreamingInvocationContext, TBigInt, NonNumericIdentifierType, NonNumericIdentifierValidation, NonNumericIdentifierCreator> {
|
|
217
227
|
@proxy.describeMethod({
|
|
218
228
|
type: Types.String,
|
|
219
229
|
isMatrix: true,
|
|
220
230
|
parameterDescriptors: [prefixDefinitionGS1UPCParameterDescriptor, referenceParameterDescriptor]
|
|
221
231
|
})
|
|
222
|
-
create(prefixDefinition: Matrix<unknown>, matrixReferences: Matrix<string>):
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
232
|
+
create(prefixDefinition: Matrix<unknown>, matrixReferences: Matrix<string>): MatrixResult<string, ThrowError, TError> {
|
|
233
|
+
return this.setUpMatrixResult(() =>
|
|
234
|
+
this.getCreator(prefixDefinition),
|
|
235
|
+
matrixReferences, (creator, reference) =>
|
|
236
|
+
creator.create(reference)
|
|
237
|
+
);
|
|
226
238
|
}
|
|
227
239
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ParameterDescriptor, Types } from "../descriptor.js";
|
|
2
|
+
|
|
3
|
+
export const identifierTypeParameterDescriptor: ParameterDescriptor = {
|
|
4
|
+
name: "identifierType",
|
|
5
|
+
type: Types.String,
|
|
6
|
+
isMatrix: false,
|
|
7
|
+
isRequired: true
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const identifierParameterDescriptor: ParameterDescriptor = {
|
|
11
|
+
name: "identifier",
|
|
12
|
+
type: Types.String,
|
|
13
|
+
isMatrix: true,
|
|
14
|
+
isRequired: true
|
|
15
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type IdentifierType, IdentifierTypes } from "@aidc-toolkit/gs1";
|
|
2
|
+
import { i18nextAppExtension } from "../locale/i18n.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Determine if an identifier type is valid.
|
|
6
|
+
*
|
|
7
|
+
* @param identifierType
|
|
8
|
+
* Identifier type.
|
|
9
|
+
*
|
|
10
|
+
* @returns
|
|
11
|
+
* True if identifier type is valid.
|
|
12
|
+
*/
|
|
13
|
+
export function isIdentifierType(identifierType: string): identifierType is IdentifierType {
|
|
14
|
+
return identifierType in IdentifierTypes;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Validate an identifier type and return it normalized.
|
|
19
|
+
*
|
|
20
|
+
* @param identifierType
|
|
21
|
+
* Identifier type.
|
|
22
|
+
*
|
|
23
|
+
* @returns
|
|
24
|
+
* Normalized identifier type.
|
|
25
|
+
*/
|
|
26
|
+
export function validateIdentifierType(identifierType: string): IdentifierType {
|
|
27
|
+
// Ignore case.
|
|
28
|
+
const upperIdentifierType = identifierType.toUpperCase();
|
|
29
|
+
|
|
30
|
+
if (!isIdentifierType(upperIdentifierType)) {
|
|
31
|
+
throw new RangeError(i18nextAppExtension.t("ServiceProxy.invalidIdentifierType", {
|
|
32
|
+
identifierType
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return upperIdentifierType;
|
|
37
|
+
}
|