@aidc-toolkit/app-extension 1.0.26-beta → 1.0.28-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 +1205 -967
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +134 -312
- package/dist/index.d.ts +134 -312
- package/dist/index.js +1207 -964
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/app-extension.ts +33 -24
- package/src/app-utility-proxy.ts +33 -27
- package/src/descriptor.ts +29 -199
- package/src/generator/generator.ts +102 -145
- package/src/generator/index.ts +0 -1
- package/src/generator/locale-resources-generator.ts +67 -42
- 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 +22 -19
- package/src/proxy.ts +509 -0
- package/src/utility/character-set-descriptor.ts +5 -5
- package/src/utility/character-set-proxy.ts +39 -55
- 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/src/generator/descriptor.ts +0 -122
- package/src/gs1/identifier-proxy.ts +0 -825
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { AI39_CREATOR, AI64_VALIDATOR, AI82_CREATOR } from "@aidc-toolkit/gs1";
|
|
2
2
|
import type { AppExtension } from "../app-extension.js";
|
|
3
|
-
import { expandParameterDescriptor,
|
|
3
|
+
import { expandParameterDescriptor, proxy } from "../proxy.js";
|
|
4
4
|
import type { ErrorExtends } from "../type.js";
|
|
5
|
-
import { CharacterSetCreatorProxy, CharacterSetValidatorProxy } from "../utility/index.js";
|
|
6
5
|
import {
|
|
7
6
|
exclusionAllNumericParameterDescriptor,
|
|
8
7
|
exclusionNoneParameterDescriptor
|
|
9
8
|
} from "../utility/character-set-descriptor.js";
|
|
9
|
+
import { CharacterSetCreatorProxy, CharacterSetValidatorProxy } from "../utility/index.js";
|
|
10
10
|
|
|
11
|
-
@
|
|
11
|
+
@proxy.describeClass(false, {
|
|
12
12
|
namespace: "GS1",
|
|
13
13
|
methodInfix: "AI82",
|
|
14
14
|
replaceParameterDescriptors: [
|
|
@@ -24,7 +24,7 @@ export class AI82Proxy<ThrowError extends boolean, TError extends ErrorExtends<T
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
@
|
|
27
|
+
@proxy.describeClass(false, {
|
|
28
28
|
namespace: "GS1",
|
|
29
29
|
methodInfix: "AI39",
|
|
30
30
|
replaceParameterDescriptors: [
|
|
@@ -40,7 +40,7 @@ export class AI39Proxy<ThrowError extends boolean, TError extends ErrorExtends<T
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
@
|
|
43
|
+
@proxy.describeClass(false, {
|
|
44
44
|
namespace: "GS1",
|
|
45
45
|
methodInfix: "AI64"
|
|
46
46
|
})
|
package/src/gs1/check-proxy.ts
CHANGED
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
isValidPriceOrWeightCheckDigit,
|
|
7
7
|
priceOrWeightCheckDigit
|
|
8
8
|
} from "@aidc-toolkit/gs1";
|
|
9
|
-
import { type
|
|
9
|
+
import { type ExtendsParameterDescriptor, type ParameterDescriptor, Types } from "../descriptor.js";
|
|
10
10
|
import { LibProxy } from "../lib-proxy.js";
|
|
11
|
+
import { proxy } from "../proxy.js";
|
|
11
12
|
import type { ErrorExtends, Matrix, MatrixResultError, ResultError } from "../type.js";
|
|
12
13
|
|
|
13
14
|
const checkSParameterDescriptor: ParameterDescriptor = {
|
|
@@ -17,106 +18,98 @@ const checkSParameterDescriptor: ParameterDescriptor = {
|
|
|
17
18
|
isRequired: true
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
const numericSParameterDescriptor:
|
|
21
|
+
const numericSParameterDescriptor: ExtendsParameterDescriptor = {
|
|
21
22
|
extendsDescriptor: checkSParameterDescriptor,
|
|
22
23
|
name: "numericS"
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
const numericSFourOrFiveDigitsParameterDescriptor:
|
|
26
|
+
const numericSFourOrFiveDigitsParameterDescriptor: ExtendsParameterDescriptor = {
|
|
26
27
|
extendsDescriptor: numericSParameterDescriptor,
|
|
27
28
|
sortOrder: 0,
|
|
28
29
|
name: "numericSFourOrFiveDigits"
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
const numericSWithCheckDigitParameterDescriptor:
|
|
32
|
+
const numericSWithCheckDigitParameterDescriptor: ExtendsParameterDescriptor = {
|
|
32
33
|
extendsDescriptor: numericSParameterDescriptor,
|
|
33
34
|
sortOrder: 1,
|
|
34
35
|
name: "numericSWithCheckDigit"
|
|
35
36
|
};
|
|
36
37
|
|
|
37
|
-
const checkDigitParameterDescriptor:
|
|
38
|
+
const checkDigitParameterDescriptor: ExtendsParameterDescriptor = {
|
|
38
39
|
extendsDescriptor: numericSParameterDescriptor,
|
|
39
40
|
sortOrder: 2,
|
|
40
41
|
name: "checkDigit",
|
|
41
42
|
isMatrix: false
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
const ai82SParameterDescriptor:
|
|
45
|
+
const ai82SParameterDescriptor: ExtendsParameterDescriptor = {
|
|
45
46
|
extendsDescriptor: checkSParameterDescriptor,
|
|
46
47
|
name: "ai82S"
|
|
47
48
|
};
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
const ai82SWithCheckCharacterPairParameterDescriptor: ParameterDescriptor = {
|
|
50
|
+
const ai82SWithCheckCharacterPairParameterDescriptor: ExtendsParameterDescriptor = {
|
|
51
51
|
extendsDescriptor: ai82SParameterDescriptor,
|
|
52
52
|
name: "ai82SWithCheckCharacterPair"
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
@
|
|
55
|
+
@proxy.describeClass(false, {
|
|
56
56
|
namespace: "GS1"
|
|
57
57
|
})
|
|
58
58
|
export class CheckProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
59
|
-
@
|
|
59
|
+
@proxy.describeMethod({
|
|
60
60
|
type: Types.String,
|
|
61
|
-
isMatrix: true
|
|
61
|
+
isMatrix: true,
|
|
62
|
+
parameterDescriptors: [numericSParameterDescriptor]
|
|
62
63
|
})
|
|
63
|
-
checkDigit(
|
|
64
|
-
@ProxyParameter(numericSParameterDescriptor) matrixSs: Matrix<string>
|
|
65
|
-
): MatrixResultError<string, ThrowError, TError> {
|
|
64
|
+
checkDigit(matrixSs: Matrix<string>): MatrixResultError<string, ThrowError, TError> {
|
|
66
65
|
return this.mapMatrix(matrixSs, s => checkDigit(s));
|
|
67
66
|
}
|
|
68
67
|
|
|
69
|
-
@
|
|
68
|
+
@proxy.describeMethod({
|
|
70
69
|
type: Types.String,
|
|
71
|
-
isMatrix: true
|
|
70
|
+
isMatrix: true,
|
|
71
|
+
parameterDescriptors: [numericSWithCheckDigitParameterDescriptor]
|
|
72
72
|
})
|
|
73
|
-
hasValidCheckDigit(
|
|
74
|
-
@ProxyParameter(numericSWithCheckDigitParameterDescriptor) matrixSs: Matrix<string>
|
|
75
|
-
): MatrixResultError<boolean, ThrowError, TError> {
|
|
73
|
+
hasValidCheckDigit(matrixSs: Matrix<string>): MatrixResultError<boolean, ThrowError, TError> {
|
|
76
74
|
return this.mapMatrix(matrixSs, s => hasValidCheckDigit(s));
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
@
|
|
77
|
+
@proxy.describeMethod({
|
|
80
78
|
type: Types.String,
|
|
81
|
-
isMatrix: true
|
|
79
|
+
isMatrix: true,
|
|
80
|
+
parameterDescriptors: [numericSFourOrFiveDigitsParameterDescriptor]
|
|
82
81
|
})
|
|
83
|
-
priceOrWeightCheckDigit(
|
|
84
|
-
@ProxyParameter(numericSFourOrFiveDigitsParameterDescriptor) matrixSs: Matrix<string>
|
|
85
|
-
): MatrixResultError<string, ThrowError, TError> {
|
|
82
|
+
priceOrWeightCheckDigit(matrixSs: Matrix<string>): MatrixResultError<string, ThrowError, TError> {
|
|
86
83
|
return this.mapMatrix(matrixSs, s => priceOrWeightCheckDigit(s));
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
@
|
|
86
|
+
@proxy.describeMethod({
|
|
90
87
|
type: Types.String,
|
|
91
|
-
isMatrix: false
|
|
92
|
-
|
|
93
|
-
isValidPriceOrWeightCheckDigit(
|
|
94
|
-
@ProxyParameter({
|
|
88
|
+
isMatrix: false,
|
|
89
|
+
parameterDescriptors: [{
|
|
95
90
|
...numericSFourOrFiveDigitsParameterDescriptor,
|
|
96
91
|
isMatrix: false
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
): ResultError<boolean, ThrowError, TError> {
|
|
92
|
+
}, checkDigitParameterDescriptor]
|
|
93
|
+
})
|
|
94
|
+
isValidPriceOrWeightCheckDigit(s: string, checkDigit: string): ResultError<boolean, ThrowError, TError> {
|
|
100
95
|
return isValidPriceOrWeightCheckDigit(s, checkDigit);
|
|
101
96
|
}
|
|
102
97
|
|
|
103
|
-
@
|
|
98
|
+
@proxy.describeMethod({
|
|
104
99
|
type: Types.String,
|
|
105
|
-
isMatrix: true
|
|
100
|
+
isMatrix: true,
|
|
101
|
+
parameterDescriptors: [ai82SParameterDescriptor]
|
|
106
102
|
})
|
|
107
|
-
checkCharacterPair(
|
|
108
|
-
@ProxyParameter(ai82SParameterDescriptor) matrixSs: Matrix<string>
|
|
109
|
-
): MatrixResultError<string, ThrowError, TError> {
|
|
103
|
+
checkCharacterPair(matrixSs: Matrix<string>): MatrixResultError<string, ThrowError, TError> {
|
|
110
104
|
return this.mapMatrix(matrixSs, s => checkCharacterPair(s));
|
|
111
105
|
}
|
|
112
106
|
|
|
113
|
-
@
|
|
107
|
+
@proxy.describeMethod({
|
|
114
108
|
type: Types.String,
|
|
115
|
-
isMatrix: true
|
|
109
|
+
isMatrix: true,
|
|
110
|
+
parameterDescriptors: [ai82SWithCheckCharacterPairParameterDescriptor]
|
|
116
111
|
})
|
|
117
|
-
hasValidCheckCharacterPair(
|
|
118
|
-
@ProxyParameter(ai82SWithCheckCharacterPairParameterDescriptor) matrixSs: Matrix<string>
|
|
119
|
-
): MatrixResultError<boolean, ThrowError, TError> {
|
|
112
|
+
hasValidCheckCharacterPair(matrixSs: Matrix<string>): MatrixResultError<boolean, ThrowError, TError> {
|
|
120
113
|
return this.mapMatrix(matrixSs, s => hasValidCheckCharacterPair(s));
|
|
121
114
|
}
|
|
122
115
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Nullishable } from "@aidc-toolkit/core";
|
|
2
|
+
import { GTINCreator, type GTINType } from "@aidc-toolkit/gs1";
|
|
3
|
+
import type { AppExtension } from "../app-extension.js";
|
|
4
|
+
import { Types } from "../descriptor.js";
|
|
5
|
+
import { expandParameterDescriptor, proxy } from "../proxy.js";
|
|
6
|
+
import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
|
|
7
|
+
import { valueParameterDescriptor } from "../utility/transformer-descriptor.js";
|
|
8
|
+
import {
|
|
9
|
+
indicatorDigitParameterDescriptor,
|
|
10
|
+
rcnFormatParameterDescriptor,
|
|
11
|
+
rcnItemReferenceParameterDescriptor,
|
|
12
|
+
rcnPriceOrWeightParameterDescriptor
|
|
13
|
+
} from "./gtin-descriptor.js";
|
|
14
|
+
import { NumericIdentifierCreatorProxy, sparseParameterDescriptor } from "./identifier-creator-proxy.js";
|
|
15
|
+
import {
|
|
16
|
+
prefixDefinitionAnyParameterDescriptor,
|
|
17
|
+
prefixDefinitionGS1UPCParameterDescriptor
|
|
18
|
+
} from "./prefix-definition-descriptor.js";
|
|
19
|
+
|
|
20
|
+
@proxy.describeClass(false, {
|
|
21
|
+
namespace: "GS1",
|
|
22
|
+
methodInfix: "GTIN",
|
|
23
|
+
replaceParameterDescriptors: [
|
|
24
|
+
{
|
|
25
|
+
name: expandParameterDescriptor(prefixDefinitionGS1UPCParameterDescriptor).name,
|
|
26
|
+
replacement: prefixDefinitionAnyParameterDescriptor
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
})
|
|
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>) {
|
|
32
|
+
super(appExtension, prefixManager => prefixManager.gtinCreator);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@proxy.describeMethod({
|
|
36
|
+
type: Types.String,
|
|
37
|
+
isMatrix: true,
|
|
38
|
+
ignoreInfix: true,
|
|
39
|
+
parameterDescriptors: [indicatorDigitParameterDescriptor, prefixDefinitionAnyParameterDescriptor, valueParameterDescriptor, sparseParameterDescriptor]
|
|
40
|
+
})
|
|
41
|
+
createGTIN14(indicatorDigit: string, prefixDefinition: Matrix<unknown>, matrixValues: Matrix<number | bigint>, sparse: Nullishable<boolean>): MatrixResultError<string, ThrowError, TError> {
|
|
42
|
+
const creator = this.getCreator(prefixDefinition);
|
|
43
|
+
|
|
44
|
+
const sparseOrUndefined = sparse ?? undefined;
|
|
45
|
+
|
|
46
|
+
return this.mapMatrix(matrixValues, value => creator.createGTIN14(indicatorDigit, value, sparseOrUndefined));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@proxy.describeMethod({
|
|
50
|
+
type: Types.String,
|
|
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));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ParameterDescriptor, Types } from "../descriptor.js";
|
|
2
|
+
|
|
3
|
+
export const indicatorDigitParameterDescriptor: ParameterDescriptor = {
|
|
4
|
+
name: "indicatorDigit",
|
|
5
|
+
type: Types.String,
|
|
6
|
+
isMatrix: false,
|
|
7
|
+
isRequired: true
|
|
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
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { Nullishable } from "@aidc-toolkit/core";
|
|
2
|
+
import { GTINLengths, type GTINLevel, GTINValidator, IdentifierValidators } from "@aidc-toolkit/gs1";
|
|
3
|
+
import type { AppExtension } from "../app-extension.js";
|
|
4
|
+
import { type ExtendsParameterDescriptor, type ParameterDescriptor, Types } from "../descriptor.js";
|
|
5
|
+
import { LibProxy } from "../lib-proxy.js";
|
|
6
|
+
import { proxy } from "../proxy.js";
|
|
7
|
+
import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
|
|
8
|
+
import { indicatorDigitParameterDescriptor, rcnFormatParameterDescriptor } from "./gtin-descriptor.js";
|
|
9
|
+
import { GTINValidatorProxy, identifierParameterDescriptor } from "./identifier-validator-proxy.js";
|
|
10
|
+
|
|
11
|
+
@proxy.describeClass(false, {
|
|
12
|
+
namespace: "GS1",
|
|
13
|
+
methodInfix: "GTIN13"
|
|
14
|
+
})
|
|
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>) {
|
|
17
|
+
super(appExtension, IdentifierValidators.GTIN[GTINLengths.GTIN13]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@proxy.describeClass(false, {
|
|
22
|
+
namespace: "GS1",
|
|
23
|
+
methodInfix: "GTIN12"
|
|
24
|
+
})
|
|
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>) {
|
|
27
|
+
super(appExtension, IdentifierValidators.GTIN[GTINLengths.GTIN12]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@proxy.describeClass(false, {
|
|
32
|
+
namespace: "GS1",
|
|
33
|
+
methodInfix: "GTIN8"
|
|
34
|
+
})
|
|
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>) {
|
|
37
|
+
super(appExtension, IdentifierValidators.GTIN[GTINLengths.GTIN8]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const zeroSuppressibleGTIN12ParameterDescriptor: ExtendsParameterDescriptor = {
|
|
42
|
+
extendsDescriptor: identifierParameterDescriptor,
|
|
43
|
+
name: "zeroSuppressibleGTIN12"
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const zeroSuppressedGTIN12ParameterDescriptor: ExtendsParameterDescriptor = {
|
|
47
|
+
extendsDescriptor: identifierParameterDescriptor,
|
|
48
|
+
name: "zeroSuppressedGTIN12"
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const convertGTINParameterDescriptor: ExtendsParameterDescriptor = {
|
|
52
|
+
extendsDescriptor: identifierParameterDescriptor,
|
|
53
|
+
name: "convertGTIN"
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const normalizeGTINParameterDescriptor: ExtendsParameterDescriptor = {
|
|
57
|
+
extendsDescriptor: identifierParameterDescriptor,
|
|
58
|
+
name: "normalizeGTIN"
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const validateGTINParameterDescriptor: ExtendsParameterDescriptor = {
|
|
62
|
+
extendsDescriptor: identifierParameterDescriptor,
|
|
63
|
+
name: "validateGTIN"
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const gtinLevelParameterDescriptor: ParameterDescriptor = {
|
|
67
|
+
name: "gtinLevel",
|
|
68
|
+
type: Types.Number,
|
|
69
|
+
isMatrix: false,
|
|
70
|
+
isRequired: false
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const validateGTIN14ParameterDescriptor: ExtendsParameterDescriptor = {
|
|
74
|
+
extendsDescriptor: identifierParameterDescriptor,
|
|
75
|
+
name: "validateGTIN14"
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const rcnParameterDescriptor: ParameterDescriptor = {
|
|
79
|
+
name: "rcn",
|
|
80
|
+
type: Types.String,
|
|
81
|
+
isMatrix: true,
|
|
82
|
+
isRequired: true
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
@proxy.describeClass(false, {
|
|
86
|
+
namespace: "GS1"
|
|
87
|
+
})
|
|
88
|
+
export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
|
|
89
|
+
@proxy.describeMethod({
|
|
90
|
+
type: Types.String,
|
|
91
|
+
isMatrix: true,
|
|
92
|
+
parameterDescriptors: [zeroSuppressibleGTIN12ParameterDescriptor]
|
|
93
|
+
})
|
|
94
|
+
zeroSuppressGTIN12(matrixGTIN12s: Matrix<string>): MatrixResultError<string, ThrowError, TError> {
|
|
95
|
+
return this.mapMatrix(matrixGTIN12s, gtin12 => GTINValidator.zeroSuppress(gtin12));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@proxy.describeMethod({
|
|
99
|
+
type: Types.String,
|
|
100
|
+
isMatrix: true,
|
|
101
|
+
parameterDescriptors: [zeroSuppressedGTIN12ParameterDescriptor]
|
|
102
|
+
})
|
|
103
|
+
zeroExpandGTIN12(matrixZeroSuppressedGTIN12s: Matrix<string>): MatrixResultError<string, ThrowError, TError> {
|
|
104
|
+
return this.mapMatrix(matrixZeroSuppressedGTIN12s, zeroSuppressedGTIN12 => GTINValidator.zeroExpand(zeroSuppressedGTIN12));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@proxy.describeMethod({
|
|
108
|
+
type: Types.String,
|
|
109
|
+
isMatrix: true,
|
|
110
|
+
parameterDescriptors: [indicatorDigitParameterDescriptor, convertGTINParameterDescriptor]
|
|
111
|
+
})
|
|
112
|
+
convertToGTIN14(indicatorDigit: string, matrixGTINs: Matrix<string>): MatrixResultError<string, ThrowError, TError> {
|
|
113
|
+
return this.mapMatrix(matrixGTINs, gtin => GTINValidator.convertToGTIN14(indicatorDigit, gtin));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@proxy.describeMethod({
|
|
117
|
+
type: Types.String,
|
|
118
|
+
isMatrix: true,
|
|
119
|
+
parameterDescriptors: [normalizeGTINParameterDescriptor]
|
|
120
|
+
})
|
|
121
|
+
normalizeGTIN(matrixGTINs: Matrix<string>): MatrixResultError<string, ThrowError, TError> {
|
|
122
|
+
return this.mapMatrix(matrixGTINs, gtin => GTINValidator.normalize(gtin));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@proxy.describeMethod({
|
|
126
|
+
type: Types.String,
|
|
127
|
+
isMatrix: true,
|
|
128
|
+
parameterDescriptors: [validateGTINParameterDescriptor, gtinLevelParameterDescriptor]
|
|
129
|
+
})
|
|
130
|
+
validateGTIN(matrixGTINs: Matrix<string>, gtinLevel: Nullishable<GTINLevel>): Matrix<string> {
|
|
131
|
+
const gtinLevelOrUndefined = gtinLevel ?? undefined;
|
|
132
|
+
|
|
133
|
+
return LibProxy.mapMatrixRangeError(matrixGTINs, (gtin) => {
|
|
134
|
+
GTINValidator.validateAny(gtin, gtinLevelOrUndefined);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@proxy.describeMethod({
|
|
139
|
+
type: Types.String,
|
|
140
|
+
isMatrix: true,
|
|
141
|
+
parameterDescriptors: [validateGTIN14ParameterDescriptor]
|
|
142
|
+
})
|
|
143
|
+
validateGTIN14(matrixGTIN14s: Matrix<string>): Matrix<string> {
|
|
144
|
+
return LibProxy.mapMatrixRangeError(matrixGTIN14s, (gtin14) => {
|
|
145
|
+
GTINValidator.validateGTIN14(gtin14);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@proxy.describeMethod({
|
|
150
|
+
type: Types.Number,
|
|
151
|
+
isMatrix: true,
|
|
152
|
+
parameterDescriptors: [rcnFormatParameterDescriptor, rcnParameterDescriptor]
|
|
153
|
+
})
|
|
154
|
+
parseVariableMeasureRCN(format: string, matrixRCNs: Matrix<string>): MatrixResultError<number, ThrowError, TError> {
|
|
155
|
+
return this.mapArray(matrixRCNs, (rcn) => {
|
|
156
|
+
const rcnReference = GTINValidator.parseVariableMeasureRCN(format, rcn);
|
|
157
|
+
|
|
158
|
+
return [rcnReference.itemReference, rcnReference.priceOrWeight];
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { isNullish, type Nullishable } from "@aidc-toolkit/core";
|
|
2
|
+
import {
|
|
3
|
+
type IdentifierCreator,
|
|
4
|
+
type IdentifierType,
|
|
5
|
+
type IdentifierValidation,
|
|
6
|
+
type NonGTINNumericIdentifierCreator,
|
|
7
|
+
type NonGTINNumericIdentifierType,
|
|
8
|
+
type NonNumericIdentifierCreator,
|
|
9
|
+
type NonNumericIdentifierType,
|
|
10
|
+
type NonNumericIdentifierValidation,
|
|
11
|
+
type NonSerializableNumericIdentifierType,
|
|
12
|
+
type NumericIdentifierCreator,
|
|
13
|
+
type NumericIdentifierType,
|
|
14
|
+
type NumericIdentifierValidation,
|
|
15
|
+
PrefixManager,
|
|
16
|
+
type PrefixType,
|
|
17
|
+
PrefixTypes,
|
|
18
|
+
PrefixValidator,
|
|
19
|
+
type SerializableNumericIdentifierCreator,
|
|
20
|
+
type SerializableNumericIdentifierType
|
|
21
|
+
} from "@aidc-toolkit/gs1";
|
|
22
|
+
import { Sequence } from "@aidc-toolkit/utility";
|
|
23
|
+
import type { AppExtension } from "../app-extension.js";
|
|
24
|
+
import { type ExtendsParameterDescriptor, type ParameterDescriptor, Types } from "../descriptor.js";
|
|
25
|
+
import { LibProxy } from "../lib-proxy.js";
|
|
26
|
+
import { i18nextAppExtension } from "../locale/i18n.js";
|
|
27
|
+
import { proxy } from "../proxy.js";
|
|
28
|
+
import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
|
|
29
|
+
import {
|
|
30
|
+
countParameterDescriptor,
|
|
31
|
+
startValueParameterDescriptor,
|
|
32
|
+
valueParameterDescriptor
|
|
33
|
+
} from "../utility/transformer-descriptor.js";
|
|
34
|
+
import { identifierParameterDescriptor } from "./identifier-validator-proxy.js";
|
|
35
|
+
import { prefixDefinitionGS1UPCParameterDescriptor } from "./prefix-definition-descriptor.js";
|
|
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> {
|
|
38
|
+
static readonly #PREFIX_TYPES: Array<PrefixType | undefined> = [PrefixTypes.GS1CompanyPrefix, PrefixTypes.UPCCompanyPrefix, PrefixTypes.GS18Prefix];
|
|
39
|
+
|
|
40
|
+
readonly #getCreator: (prefixManager: PrefixManager) => TIdentifierCreator;
|
|
41
|
+
|
|
42
|
+
constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, getCreator: (prefixManager: PrefixManager) => TIdentifierCreator) {
|
|
43
|
+
super(appExtension);
|
|
44
|
+
|
|
45
|
+
this.#getCreator = getCreator;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected getCreator(prefixDefinition: Matrix<unknown>): TIdentifierCreator {
|
|
49
|
+
const reducedPrefixDefinition = prefixDefinition.length === 1 ?
|
|
50
|
+
// Prefix definition is horizontal.
|
|
51
|
+
prefixDefinition[0] :
|
|
52
|
+
// Prefix definition is vertical.
|
|
53
|
+
prefixDefinition.map((prefixDefinitionRow) => {
|
|
54
|
+
if (prefixDefinitionRow.length !== 1) {
|
|
55
|
+
throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.prefixDefinitionMustBeOneDimensional"));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return prefixDefinitionRow[0];
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (reducedPrefixDefinition.length > 3) {
|
|
62
|
+
throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.prefixDefinitionMustHaveMaximumThreeElements"));
|
|
63
|
+
}
|
|
64
|
+
const prefix = reducedPrefixDefinition[0];
|
|
65
|
+
|
|
66
|
+
if (typeof prefix !== "string") {
|
|
67
|
+
throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.prefixMustBeString"));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const prefixTypeIndex = reducedPrefixDefinition[1] ?? 0;
|
|
71
|
+
|
|
72
|
+
if (typeof prefixTypeIndex !== "number" || prefixTypeIndex < 0 || prefixTypeIndex >= IdentifierCreatorProxy.#PREFIX_TYPES.length) {
|
|
73
|
+
throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.prefixTypeMustBeNumber", {
|
|
74
|
+
maximumPrefixType: IdentifierCreatorProxy.#PREFIX_TYPES.length - 1
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const prefixType = IdentifierCreatorProxy.#PREFIX_TYPES[prefixTypeIndex];
|
|
79
|
+
|
|
80
|
+
// Undefined is included in type in case of invalid input.
|
|
81
|
+
if (prefixType === undefined) {
|
|
82
|
+
throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.invalidPrefixType"));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const prefixManager = PrefixManager.get(prefixType, prefix);
|
|
86
|
+
|
|
87
|
+
const tweakFactor = reducedPrefixDefinition[2];
|
|
88
|
+
|
|
89
|
+
if (!isNullish(tweakFactor)) {
|
|
90
|
+
if (typeof tweakFactor !== "number") {
|
|
91
|
+
throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.tweakFactorMustBeNumber"));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
prefixManager.tweakFactor = tweakFactor;
|
|
95
|
+
} else {
|
|
96
|
+
prefixManager.resetTweakFactor();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return this.#getCreator(prefixManager);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const sparseParameterDescriptor: ParameterDescriptor = {
|
|
104
|
+
name: "sparse",
|
|
105
|
+
type: Types.Boolean,
|
|
106
|
+
isMatrix: false,
|
|
107
|
+
isRequired: false
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
@proxy.describeClass(true, {
|
|
111
|
+
namespace: "GS1"
|
|
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> {
|
|
114
|
+
@proxy.describeMethod({
|
|
115
|
+
type: Types.String,
|
|
116
|
+
isMatrix: true,
|
|
117
|
+
parameterDescriptors: [prefixDefinitionGS1UPCParameterDescriptor, valueParameterDescriptor, sparseParameterDescriptor]
|
|
118
|
+
})
|
|
119
|
+
create(prefixDefinition: Matrix<unknown>, matrixValues: Matrix<number | bigint>, sparse: Nullishable<boolean>): MatrixResultError<string, ThrowError, TError> {
|
|
120
|
+
const creator = this.getCreator(prefixDefinition);
|
|
121
|
+
|
|
122
|
+
const sparseOrUndefined = sparse ?? undefined;
|
|
123
|
+
|
|
124
|
+
return this.mapMatrix(matrixValues, value => creator.create(value, sparseOrUndefined));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@proxy.describeMethod({
|
|
128
|
+
infixBefore: "Sequence",
|
|
129
|
+
type: Types.String,
|
|
130
|
+
isMatrix: true,
|
|
131
|
+
parameterDescriptors: [prefixDefinitionGS1UPCParameterDescriptor, startValueParameterDescriptor, countParameterDescriptor, sparseParameterDescriptor]
|
|
132
|
+
})
|
|
133
|
+
createSequence(prefixDefinition: Matrix<unknown>, startValue: number, count: number, sparse: Nullishable<boolean>): Matrix<string> {
|
|
134
|
+
this.appExtension.validateSequenceCount(count);
|
|
135
|
+
|
|
136
|
+
return LibProxy.matrixResult(this.getCreator(prefixDefinition).create(new Sequence(startValue, count), sparse ?? undefined));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@proxy.describeMethod({
|
|
140
|
+
type: Types.String,
|
|
141
|
+
isMatrix: true,
|
|
142
|
+
parameterDescriptors: [prefixDefinitionGS1UPCParameterDescriptor]
|
|
143
|
+
})
|
|
144
|
+
createAll(prefixDefinition: Matrix<unknown>): Matrix<string> {
|
|
145
|
+
const creator = this.getCreator(prefixDefinition);
|
|
146
|
+
|
|
147
|
+
this.appExtension.validateSequenceCount(creator.capacity);
|
|
148
|
+
|
|
149
|
+
return LibProxy.matrixResult(creator.createAll());
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
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> {
|
|
154
|
+
}
|
|
155
|
+
|
|
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> {
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const singleValueParameterDescriptor: ExtendsParameterDescriptor = {
|
|
160
|
+
extendsDescriptor: valueParameterDescriptor,
|
|
161
|
+
isMatrix: false
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const baseIdentifierParameterDescriptor: ExtendsParameterDescriptor = {
|
|
165
|
+
extendsDescriptor: identifierParameterDescriptor,
|
|
166
|
+
name: "baseIdentifier",
|
|
167
|
+
isMatrix: false
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const serialComponentParameterDescriptor: ParameterDescriptor = {
|
|
171
|
+
name: "serialComponent",
|
|
172
|
+
type: Types.String,
|
|
173
|
+
isMatrix: true,
|
|
174
|
+
isRequired: true
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
@proxy.describeClass(true, {
|
|
178
|
+
namespace: "GS1"
|
|
179
|
+
})
|
|
180
|
+
export abstract class SerializableNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, SerializableNumericIdentifierType, SerializableNumericIdentifierCreator> {
|
|
181
|
+
@proxy.describeMethod({
|
|
182
|
+
type: Types.String,
|
|
183
|
+
isMatrix: true,
|
|
184
|
+
parameterDescriptors: [prefixDefinitionGS1UPCParameterDescriptor, singleValueParameterDescriptor, serialComponentParameterDescriptor, sparseParameterDescriptor]
|
|
185
|
+
})
|
|
186
|
+
createSerialized(prefixDefinition: Matrix<unknown>, value: number, matrixSerialComponents: Matrix<string>, sparse: Nullishable<boolean>): MatrixResultError<string, ThrowError, TError> {
|
|
187
|
+
const creator = this.getCreator(prefixDefinition);
|
|
188
|
+
|
|
189
|
+
const sparseOrUndefined = sparse ?? undefined;
|
|
190
|
+
|
|
191
|
+
return this.mapMatrix(matrixSerialComponents, serialComponent => creator.createSerialized(value, serialComponent, sparseOrUndefined));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@proxy.describeMethod({
|
|
195
|
+
type: Types.String,
|
|
196
|
+
isMatrix: true,
|
|
197
|
+
parameterDescriptors: [baseIdentifierParameterDescriptor, serialComponentParameterDescriptor]
|
|
198
|
+
})
|
|
199
|
+
concatenate(baseIdentifier: string, matrixSerialComponents: Matrix<string>): MatrixResultError<string, ThrowError, TError> {
|
|
200
|
+
const creator = this.getCreator([[baseIdentifier.substring(0, !baseIdentifier.startsWith("0") ? PrefixValidator.GS1_COMPANY_PREFIX_MINIMUM_LENGTH : PrefixValidator.UPC_COMPANY_PREFIX_MINIMUM_LENGTH + 1), PrefixTypes.GS1CompanyPrefix]]);
|
|
201
|
+
|
|
202
|
+
return this.mapMatrix(matrixSerialComponents, serialComponent => creator.concatenate(baseIdentifier, serialComponent));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const referenceParameterDescriptor: ParameterDescriptor = {
|
|
207
|
+
name: "reference",
|
|
208
|
+
type: Types.String,
|
|
209
|
+
isMatrix: true,
|
|
210
|
+
isRequired: true
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
@proxy.describeClass(true, {
|
|
214
|
+
namespace: "GS1"
|
|
215
|
+
})
|
|
216
|
+
export abstract class NonNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends IdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, NonNumericIdentifierType, NonNumericIdentifierValidation, NonNumericIdentifierCreator> {
|
|
217
|
+
@proxy.describeMethod({
|
|
218
|
+
type: Types.String,
|
|
219
|
+
isMatrix: true,
|
|
220
|
+
parameterDescriptors: [prefixDefinitionGS1UPCParameterDescriptor, referenceParameterDescriptor]
|
|
221
|
+
})
|
|
222
|
+
create(prefixDefinition: Matrix<unknown>, matrixReferences: Matrix<string>): MatrixResultError<string, ThrowError, TError> {
|
|
223
|
+
const creator = this.getCreator(prefixDefinition);
|
|
224
|
+
|
|
225
|
+
return this.mapMatrix(matrixReferences, reference => creator.create(reference));
|
|
226
|
+
}
|
|
227
|
+
}
|