@aidc-toolkit/gs1 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/abstract-identifier-creator.d.ts +6 -40
- package/dist/abstract-identifier-creator.d.ts.map +1 -1
- package/dist/abstract-identifier-creator.js +3 -9
- package/dist/abstract-identifier-creator.js.map +1 -1
- package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts +7 -13
- package/dist/abstract-non-gtin-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/abstract-non-gtin-numeric-identifier-creator.js +8 -11
- package/dist/abstract-non-gtin-numeric-identifier-creator.js.map +1 -1
- package/dist/abstract-numeric-identifier-creator.d.ts +7 -16
- package/dist/abstract-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/abstract-numeric-identifier-creator.js +3 -9
- package/dist/abstract-numeric-identifier-creator.js.map +1 -1
- package/dist/gtin-creator.d.ts +2 -2
- package/dist/gtin-creator.d.ts.map +1 -1
- package/dist/gtin-creator.js +1 -1
- package/dist/gtin-creator.js.map +1 -1
- package/dist/identifier-creators.d.ts +32 -4
- package/dist/identifier-creators.d.ts.map +1 -1
- package/dist/identifier-creators.js +18 -0
- package/dist/identifier-creators.js.map +1 -1
- package/dist/identifier-validators.d.ts +28 -3
- package/dist/identifier-validators.d.ts.map +1 -1
- package/dist/identifier-validators.js +15 -1
- package/dist/identifier-validators.js.map +1 -1
- package/dist/non-numeric-identifier-creator.d.ts +1 -1
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/non-numeric-identifier-creator.js.map +1 -1
- package/dist/non-serializable-numeric-identifier-creator.d.ts +1 -1
- package/dist/non-serializable-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/non-serializable-numeric-identifier-creator.js.map +1 -1
- package/dist/non-serializable-numeric-identifier-descriptor.d.ts +5 -0
- package/dist/non-serializable-numeric-identifier-descriptor.d.ts.map +1 -1
- package/dist/prefix-manager.d.ts +19 -4
- package/dist/prefix-manager.d.ts.map +1 -1
- package/dist/prefix-manager.js +27 -69
- package/dist/prefix-manager.js.map +1 -1
- package/dist/serializable-numeric-identifier-creator.d.ts +1 -1
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -1
- package/dist/serializable-numeric-identifier-creator.js.map +1 -1
- package/package.json +4 -4
- package/src/abstract-identifier-creator.ts +18 -70
- package/src/abstract-non-gtin-numeric-identifier-creator.ts +22 -27
- package/src/abstract-numeric-identifier-creator.ts +21 -38
- package/src/gtin-creator.ts +2 -4
- package/src/identifier-creators.ts +54 -4
- package/src/identifier-validators.ts +50 -3
- package/src/non-numeric-identifier-creator.ts +1 -3
- package/src/non-serializable-numeric-identifier-creator.ts +1 -2
- package/src/non-serializable-numeric-identifier-descriptor.ts +5 -0
- package/src/prefix-manager.ts +37 -76
- package/src/serializable-numeric-identifier-creator.ts +1 -2
- package/test/mixin.test.ts +35 -0
- package/test/non-numeric-identifier-validator.ts +2 -2
- package/test/serializable-numeric-identifier-validator.ts +2 -2
- package/test/utility.ts +6 -6
- package/tsconfig.json +1 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AbstractConstructor } from "@aidc-toolkit/core";
|
|
1
2
|
import {
|
|
2
3
|
CharacterSetCreator,
|
|
3
4
|
Exclusions,
|
|
@@ -5,14 +6,9 @@ import {
|
|
|
5
6
|
type TransformerInput,
|
|
6
7
|
type TransformerOutput
|
|
7
8
|
} from "@aidc-toolkit/utility";
|
|
8
|
-
import {
|
|
9
|
-
type IdentifierCreatorConstructor,
|
|
10
|
-
type IdentifierExtensionConstructor,
|
|
11
|
-
type IdentifierValidatorConstructor,
|
|
12
|
-
MixinAbstractIdentifierCreator
|
|
13
|
-
} from "./abstract-identifier-creator.js";
|
|
9
|
+
import { type IdentifierCreatorConstructor, MixinAbstractIdentifierCreator } from "./abstract-identifier-creator.js";
|
|
14
10
|
import { checkDigit, checkDigitSum } from "./check.js";
|
|
15
|
-
import type { IdentifierTypeValidator } from "./identifier-validators.js";
|
|
11
|
+
import type { IdentifierTypeValidator, IdentifierValidatorConstructorsEntry } from "./identifier-validators.js";
|
|
16
12
|
import { LeaderTypes } from "./leader-type.js";
|
|
17
13
|
import type { NumericIdentifierCreator } from "./numeric-identifier-creator.js";
|
|
18
14
|
import type { NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
@@ -22,9 +18,6 @@ import type { PrefixProvider } from "./prefix-provider.js";
|
|
|
22
18
|
/**
|
|
23
19
|
* Numeric identifier creator constructor type, which delegates to a numeric identifier validator constructor.
|
|
24
20
|
*
|
|
25
|
-
* @template TConstructorArguments
|
|
26
|
-
* Constructor arguments types.
|
|
27
|
-
*
|
|
28
21
|
* @template TNumericIdentifierType
|
|
29
22
|
* Numeric identifier type type.
|
|
30
23
|
*
|
|
@@ -32,42 +25,31 @@ import type { PrefixProvider } from "./prefix-provider.js";
|
|
|
32
25
|
* Numeric identifier validator type.
|
|
33
26
|
*/
|
|
34
27
|
export type NumericIdentifierCreatorConstructor<
|
|
35
|
-
TConstructorArguments extends unknown[],
|
|
36
28
|
TNumericIdentifierType extends NumericIdentifierType,
|
|
37
29
|
TNumericIdentifierValidator extends NumericIdentifierValidator<TNumericIdentifierType>
|
|
38
|
-
> =
|
|
39
|
-
[prefixProvider: PrefixProvider, prefix: string, ...args:
|
|
30
|
+
> = AbstractConstructor<
|
|
31
|
+
[prefixProvider: PrefixProvider, prefix: string, ...args: ConstructorParameters<IdentifierValidatorConstructorsEntry<TNumericIdentifierType>>],
|
|
40
32
|
TNumericIdentifierValidator & NumericIdentifierCreator<TNumericIdentifierType>
|
|
41
33
|
>;
|
|
42
34
|
|
|
43
35
|
/**
|
|
44
36
|
* Mixin implementation of {@linkcode NumericIdentifierCreator} with an appropriate numeric identifier validator base.
|
|
45
37
|
*
|
|
46
|
-
* @template TConstructorArguments
|
|
47
|
-
* Constructor arguments types.
|
|
48
|
-
*
|
|
49
38
|
* @template TNumericIdentifierType
|
|
50
39
|
* Numeric identifier type type.
|
|
51
40
|
*
|
|
52
|
-
* @
|
|
53
|
-
* Numeric identifier validator constructor type.
|
|
54
|
-
*
|
|
55
|
-
* @param NumericIdentifierValidatorBase
|
|
41
|
+
* @param NumericIdentifierValidatorConstructor
|
|
56
42
|
* Numeric identifier validator base.
|
|
57
43
|
*
|
|
58
44
|
* @returns
|
|
59
45
|
* Numeric identifier creator class.
|
|
60
46
|
*/
|
|
61
47
|
export function MixinAbstractNumericIdentifierCreator<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
NumericIdentifierValidation
|
|
68
|
-
>
|
|
69
|
-
>(NumericIdentifierValidatorBase: TNumericIdentifierValidatorConstructor): NumericIdentifierCreatorConstructor<
|
|
70
|
-
TConstructorArguments,
|
|
48
|
+
TNumericIdentifierType extends NumericIdentifierType
|
|
49
|
+
>(NumericIdentifierValidatorConstructor: AbstractConstructor<
|
|
50
|
+
ConstructorParameters<IdentifierValidatorConstructorsEntry<TNumericIdentifierType>>,
|
|
51
|
+
IdentifierTypeValidator<TNumericIdentifierType>
|
|
52
|
+
>): NumericIdentifierCreatorConstructor<
|
|
71
53
|
TNumericIdentifierType,
|
|
72
54
|
IdentifierTypeValidator<TNumericIdentifierType>
|
|
73
55
|
> {
|
|
@@ -75,12 +57,13 @@ export function MixinAbstractNumericIdentifierCreator<
|
|
|
75
57
|
* Abstract numeric identifier creator. Implements common functionality for a numeric identifier creator, mixed in
|
|
76
58
|
* with a matching numeric identifier validator.
|
|
77
59
|
*/
|
|
78
|
-
abstract class AbstractNumericIdentifierCreator extends (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
abstract class AbstractNumericIdentifierCreator extends (
|
|
61
|
+
MixinAbstractIdentifierCreator(NumericIdentifierValidatorConstructor) as IdentifierCreatorConstructor<
|
|
62
|
+
TNumericIdentifierType,
|
|
63
|
+
NumericIdentifierValidation,
|
|
64
|
+
NumericIdentifierValidator<TNumericIdentifierType>
|
|
65
|
+
>
|
|
66
|
+
) implements NumericIdentifierCreator<TNumericIdentifierType> {
|
|
84
67
|
/**
|
|
85
68
|
* Capacity.
|
|
86
69
|
*/
|
|
@@ -103,7 +86,7 @@ export function MixinAbstractNumericIdentifierCreator<
|
|
|
103
86
|
* @param args
|
|
104
87
|
* Originating constructor arguments.
|
|
105
88
|
*/
|
|
106
|
-
constructor(prefixProvider: PrefixProvider, prefix: string, ...args:
|
|
89
|
+
constructor(prefixProvider: PrefixProvider, prefix: string, ...args: ConstructorParameters<IdentifierValidatorConstructorsEntry<TNumericIdentifierType>>) {
|
|
107
90
|
super(prefixProvider, prefix, 1, ...args);
|
|
108
91
|
|
|
109
92
|
// Capacity is always in number range.
|
|
@@ -227,10 +210,10 @@ export function MixinAbstractNumericIdentifierCreator<
|
|
|
227
210
|
}
|
|
228
211
|
|
|
229
212
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Base class was upcast to type with statically known members for mixin, downcast result.
|
|
230
|
-
return AbstractNumericIdentifierCreator as
|
|
213
|
+
return AbstractNumericIdentifierCreator as AbstractConstructor<
|
|
231
214
|
ConstructorParameters<typeof AbstractNumericIdentifierCreator>,
|
|
232
215
|
unknown
|
|
233
|
-
> as
|
|
216
|
+
> as AbstractConstructor<
|
|
234
217
|
ConstructorParameters<typeof AbstractNumericIdentifierCreator>,
|
|
235
218
|
IdentifierTypeValidator<TNumericIdentifierType> & AbstractNumericIdentifierCreator
|
|
236
219
|
>;
|
package/src/gtin-creator.ts
CHANGED
|
@@ -14,12 +14,10 @@ import { i18nextGS1 } from "./locale/i18n.js";
|
|
|
14
14
|
import type { PrefixProvider } from "./prefix-provider.js";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* GTIN creator. Applicable to GTIN-13, GTIN-12, and GTIN-8 types;
|
|
17
|
+
* GTIN creator. Applicable to GTIN-13, GTIN-12, and GTIN-8 types; not applicable to GTIN-14 type.
|
|
18
18
|
*/
|
|
19
19
|
export class GTINCreator extends MixinAbstractNumericIdentifierCreator<
|
|
20
|
-
|
|
21
|
-
GTINType,
|
|
22
|
-
typeof GTINValidator
|
|
20
|
+
GTINType
|
|
23
21
|
>(GTINValidator) {
|
|
24
22
|
/**
|
|
25
23
|
* Validation parameters for required indicator digit.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { GTINCreator } from "./gtin-creator.js";
|
|
2
|
+
import type { GTINBaseLength } from "./gtin-length.js";
|
|
3
|
+
import type { GTINType } from "./gtin-type.js";
|
|
2
4
|
import type { IdentifierCreator } from "./identifier-creator.js";
|
|
3
5
|
import {
|
|
4
6
|
type IdentifierTypeExtension,
|
|
@@ -11,10 +13,11 @@ import {
|
|
|
11
13
|
} from "./identifier-extension.js";
|
|
12
14
|
import type { IdentifierType } from "./identifier-type.js";
|
|
13
15
|
import type { NonGTINNumericIdentifierCreator } from "./non-gtin-numeric-identifier-creator.js";
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
+
import { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator.js";
|
|
17
|
+
import { NonSerializableNumericIdentifierCreator } from "./non-serializable-numeric-identifier-creator.js";
|
|
16
18
|
import type { NumericIdentifierCreator } from "./numeric-identifier-creator.js";
|
|
17
|
-
import type {
|
|
19
|
+
import type { PrefixProvider } from "./prefix-provider.js";
|
|
20
|
+
import { SerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator.js";
|
|
18
21
|
|
|
19
22
|
/**
|
|
20
23
|
* Identifier creator type based on identifier type type.
|
|
@@ -48,6 +51,53 @@ export type IdentifierCreatorsRecord = {
|
|
|
48
51
|
[TIdentifierType in IdentifierType]: IdentifierCreatorsEntry<TIdentifierType>;
|
|
49
52
|
};
|
|
50
53
|
|
|
54
|
+
/**
|
|
55
|
+
* GTIN creator constructor type.
|
|
56
|
+
*/
|
|
57
|
+
export type GTINCreatorConstructor =
|
|
58
|
+
new (prefixProvider: PrefixProvider, gtinBaseLength: GTINBaseLength) => GTINCreator;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Non-GTIN creator constructor type.
|
|
62
|
+
*
|
|
63
|
+
* @template TIdentifierType
|
|
64
|
+
* Identifier type type.
|
|
65
|
+
*/
|
|
66
|
+
export type NonGTINCreatorConstructor<TIdentifierType extends Exclude<IdentifierType, GTINType>> =
|
|
67
|
+
new (prefixProvider: PrefixProvider, identifierType: TIdentifierType) => IdentifierCreatorsRecord[TIdentifierType];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Identifier creator constructors entry type based on identifier type type.
|
|
71
|
+
*
|
|
72
|
+
* @template TIdentifierType
|
|
73
|
+
* Identifier type type.
|
|
74
|
+
*/
|
|
75
|
+
export type IdentifierCreatorConstructorsEntry<TIdentifierType extends IdentifierType> = TIdentifierType extends GTINType ?
|
|
76
|
+
GTINCreatorConstructor :
|
|
77
|
+
NonGTINCreatorConstructor<Exclude<TIdentifierType, GTINType>>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Identifier creator constructors record type.
|
|
81
|
+
*/
|
|
82
|
+
export type IdentifierCreatorConstructorsRecord = {
|
|
83
|
+
readonly [TIdentifierType in IdentifierType]: IdentifierCreatorConstructorsEntry<TIdentifierType>;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const IdentifierCreatorConstructors: IdentifierCreatorConstructorsRecord = {
|
|
87
|
+
GTIN: GTINCreator,
|
|
88
|
+
GLN: NonSerializableNumericIdentifierCreator,
|
|
89
|
+
SSCC: NonSerializableNumericIdentifierCreator,
|
|
90
|
+
GRAI: SerializableNumericIdentifierCreator,
|
|
91
|
+
GIAI: NonNumericIdentifierCreator,
|
|
92
|
+
GSRN: NonSerializableNumericIdentifierCreator,
|
|
93
|
+
GDTI: SerializableNumericIdentifierCreator,
|
|
94
|
+
GINC: NonNumericIdentifierCreator,
|
|
95
|
+
GSIN: NonSerializableNumericIdentifierCreator,
|
|
96
|
+
GCN: SerializableNumericIdentifierCreator,
|
|
97
|
+
CPID: NonNumericIdentifierCreator,
|
|
98
|
+
GMN: NonNumericIdentifierCreator
|
|
99
|
+
};
|
|
100
|
+
|
|
51
101
|
/**
|
|
52
102
|
* Determine if identifier creator is a numeric identifier creator.
|
|
53
103
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GTINBaseLength } from "./gtin-length.js";
|
|
2
2
|
import type { GTINType } from "./gtin-type.js";
|
|
3
|
-
import { GTIN_VALIDATORS,
|
|
3
|
+
import { GTIN_VALIDATORS, GTINValidator } from "./gtin-validator.js";
|
|
4
4
|
import { isGTINDescriptors } from "./identifier-descriptors.js";
|
|
5
5
|
import {
|
|
6
6
|
type IdentifierTypeExtension,
|
|
@@ -105,13 +105,13 @@ export type IdentifierValidatorsEntry<TIdentifierType extends IdentifierType> =
|
|
|
105
105
|
* Identifier validators record type.
|
|
106
106
|
*/
|
|
107
107
|
export type IdentifierValidatorsRecord = {
|
|
108
|
-
|
|
108
|
+
[TIdentifierType in IdentifierType]: IdentifierValidatorsEntry<TIdentifierType>;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* Identifier validators for all identifier types.
|
|
113
113
|
*/
|
|
114
|
-
export const IdentifierValidators: IdentifierValidatorsRecord = {
|
|
114
|
+
export const IdentifierValidators: Readonly<IdentifierValidatorsRecord> = {
|
|
115
115
|
[IdentifierTypes.GTIN]: GTIN_VALIDATORS,
|
|
116
116
|
[IdentifierTypes.GLN]: GLN_VALIDATOR,
|
|
117
117
|
[IdentifierTypes.SSCC]: SSCC_VALIDATOR,
|
|
@@ -126,6 +126,53 @@ export const IdentifierValidators: IdentifierValidatorsRecord = {
|
|
|
126
126
|
[IdentifierTypes.GMN]: GMN_VALIDATOR
|
|
127
127
|
};
|
|
128
128
|
|
|
129
|
+
/**
|
|
130
|
+
* GTIN validator constructor type.
|
|
131
|
+
*/
|
|
132
|
+
export type GTINValidatorConstructor =
|
|
133
|
+
new (gtinBaseLength: GTINBaseLength) => GTINValidator;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Non-GTIN validator constructor type.
|
|
137
|
+
*
|
|
138
|
+
* @template TIdentifierType
|
|
139
|
+
* Identifier type type.
|
|
140
|
+
*/
|
|
141
|
+
export type NonGTINValidatorConstructor<TIdentifierType extends Exclude<IdentifierType, GTINType>> =
|
|
142
|
+
new (identifierType: TIdentifierType) => IdentifierValidatorsRecord[TIdentifierType];
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Identifier validator constructors entry type based on identifier type type.
|
|
146
|
+
*
|
|
147
|
+
* @template TIdentifierType
|
|
148
|
+
* Identifier type type.
|
|
149
|
+
*/
|
|
150
|
+
export type IdentifierValidatorConstructorsEntry<TIdentifierType extends IdentifierType> = TIdentifierType extends GTINType ?
|
|
151
|
+
GTINValidatorConstructor :
|
|
152
|
+
NonGTINValidatorConstructor<Exclude<TIdentifierType, GTINType>>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Identifier validator constructors record type.
|
|
156
|
+
*/
|
|
157
|
+
export type IdentifierValidatorConstructorsRecord = {
|
|
158
|
+
readonly [TIdentifierType in IdentifierType]: IdentifierValidatorConstructorsEntry<TIdentifierType>;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const IdentifierValidatorConstructors: IdentifierValidatorConstructorsRecord = {
|
|
162
|
+
GTIN: GTINValidator,
|
|
163
|
+
GLN: NonSerializableNumericIdentifierValidator,
|
|
164
|
+
SSCC: NonSerializableNumericIdentifierValidator,
|
|
165
|
+
GRAI: SerializableNumericIdentifierValidator,
|
|
166
|
+
GIAI: NonNumericIdentifierValidator,
|
|
167
|
+
GSRN: NonSerializableNumericIdentifierValidator,
|
|
168
|
+
GDTI: SerializableNumericIdentifierValidator,
|
|
169
|
+
GINC: NonNumericIdentifierValidator,
|
|
170
|
+
GSIN: NonSerializableNumericIdentifierValidator,
|
|
171
|
+
GCN: SerializableNumericIdentifierValidator,
|
|
172
|
+
CPID: NonNumericIdentifierValidator,
|
|
173
|
+
GMN: NonNumericIdentifierValidator
|
|
174
|
+
};
|
|
175
|
+
|
|
129
176
|
/**
|
|
130
177
|
* Determine if identifier validators or validator is GTIN validators.
|
|
131
178
|
*
|
|
@@ -19,10 +19,8 @@ import type { PrefixProvider } from "./prefix-provider.js";
|
|
|
19
19
|
* Non-numeric identifier creator.
|
|
20
20
|
*/
|
|
21
21
|
export class NonNumericIdentifierCreator extends MixinAbstractIdentifierCreator<
|
|
22
|
-
[NonNumericIdentifierType],
|
|
23
22
|
NonNumericIdentifierType,
|
|
24
|
-
NonNumericIdentifierValidation
|
|
25
|
-
typeof NonNumericIdentifierValidator
|
|
23
|
+
NonNumericIdentifierValidation
|
|
26
24
|
>(NonNumericIdentifierValidator) {
|
|
27
25
|
/**
|
|
28
26
|
* Reference validation parameters.
|
|
@@ -6,7 +6,6 @@ import { NonSerializableNumericIdentifierValidator } from "./non-serializable-nu
|
|
|
6
6
|
* Non-serializable numeric identifier creator.
|
|
7
7
|
*/
|
|
8
8
|
export class NonSerializableNumericIdentifierCreator extends MixinAbstractNonGTINNumericIdentifierCreator<
|
|
9
|
-
NonSerializableNumericIdentifierType
|
|
10
|
-
typeof NonSerializableNumericIdentifierValidator
|
|
9
|
+
NonSerializableNumericIdentifierType
|
|
11
10
|
>(NonSerializableNumericIdentifierValidator) {
|
|
12
11
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type { LeaderTypes } from "./leader-type.js";
|
|
1
2
|
import type { NonGTINNumericIdentifierDescriptor } from "./non-gtin-numeric-identifier-descriptor.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Non-serializable numeric identifier descriptor.
|
|
5
6
|
*/
|
|
6
7
|
export interface NonSerializableNumericIdentifierDescriptor extends NonGTINNumericIdentifierDescriptor {
|
|
8
|
+
/**
|
|
9
|
+
* @inheritDoc
|
|
10
|
+
*/
|
|
11
|
+
readonly leaderType: typeof LeaderTypes.None | typeof LeaderTypes.ExtensionDigit;
|
|
7
12
|
}
|
package/src/prefix-manager.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import { GTINCreator } from "./gtin-creator.js";
|
|
1
|
+
import type { GTINCreator } from "./gtin-creator.js";
|
|
2
2
|
import { GTIN_BASE_TYPES } from "./gtin-length.js";
|
|
3
|
+
import type { GTINType } from "./gtin-type.js";
|
|
3
4
|
import type { IdentifierCreator } from "./identifier-creator.js";
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
IdentifierCreatorConstructors,
|
|
7
|
+
type IdentifierCreatorsRecord,
|
|
8
|
+
isNumericIdentifierCreator,
|
|
9
|
+
type NonGTINCreatorConstructor
|
|
10
|
+
} from "./identifier-creators.js";
|
|
5
11
|
import { type IdentifierType, IdentifierTypes } from "./identifier-type.js";
|
|
6
12
|
import { i18nextGS1 } from "./locale/i18n.js";
|
|
7
|
-
import { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator.js";
|
|
8
|
-
import type {
|
|
9
|
-
import { NonSerializableNumericIdentifierCreator } from "./non-serializable-numeric-identifier-creator.js";
|
|
10
|
-
import type { NonSerializableNumericIdentifierType } from "./non-serializable-numeric-identifier-type.js";
|
|
13
|
+
import type { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator.js";
|
|
14
|
+
import type { NonSerializableNumericIdentifierCreator } from "./non-serializable-numeric-identifier-creator.js";
|
|
11
15
|
import type { NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
12
16
|
import type { PrefixProvider } from "./prefix-provider.js";
|
|
13
17
|
import { type PrefixType, PrefixTypes } from "./prefix-type.js";
|
|
14
18
|
import { PrefixValidator } from "./prefix-validator.js";
|
|
15
|
-
import { SerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator.js";
|
|
16
|
-
import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type.js";
|
|
19
|
+
import type { SerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator.js";
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* Prefix manager. This is the core class for identifier creation.
|
|
@@ -232,33 +235,30 @@ export class PrefixManager implements PrefixProvider {
|
|
|
232
235
|
* @template TIdentifierType
|
|
233
236
|
* Identifier type type.
|
|
234
237
|
*
|
|
235
|
-
* @template TConstructorArgument
|
|
236
|
-
* Second constructor argument type.
|
|
237
|
-
*
|
|
238
238
|
* @param identifierType
|
|
239
|
-
* Identifier type
|
|
240
|
-
*
|
|
241
|
-
* @param constructorArgument
|
|
242
|
-
* Second constructor argument passed to constructor callback alongside this.
|
|
243
|
-
*
|
|
244
|
-
* @param ConstructorCallback
|
|
245
|
-
* Constructor callback.
|
|
239
|
+
* Identifier type for which to retrieve or construct identifier creator.
|
|
246
240
|
*
|
|
247
241
|
* @returns
|
|
248
242
|
* Identifier creator.
|
|
249
243
|
*/
|
|
250
|
-
|
|
244
|
+
getIdentifierCreator<TIdentifierType extends IdentifierType>(identifierType: TIdentifierType): IdentifierCreatorsRecord[TIdentifierType] {
|
|
251
245
|
let creator: IdentifierCreatorsRecord[TIdentifierType] | undefined = this.#identifierCreators[identifierType];
|
|
252
246
|
|
|
253
247
|
if (creator === undefined) {
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
248
|
+
if (identifierType === IdentifierTypes.GTIN) {
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Types are known to match.
|
|
250
|
+
creator = new IdentifierCreatorConstructors.GTIN(this, GTIN_BASE_TYPES[this.prefixType]) as IdentifierCreatorsRecord[TIdentifierType];
|
|
251
|
+
} else {
|
|
252
|
+
if (this.prefixType === PrefixTypes.GS18Prefix) {
|
|
253
|
+
throw new RangeError(i18nextGS1.t("Prefix.identifierTypeNotSupportedByGS18Prefix", {
|
|
254
|
+
identifierType
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Types are known to match.
|
|
259
|
+
creator = new (IdentifierCreatorConstructors[identifierType] as unknown as NonGTINCreatorConstructor<Exclude<TIdentifierType, GTINType>>)(this, identifierType as Exclude<TIdentifierType, GTINType>);
|
|
258
260
|
}
|
|
259
261
|
|
|
260
|
-
creator = new ConstructorCallback(this, constructorArgument);
|
|
261
|
-
|
|
262
262
|
this.#setCreatorTweak(creator);
|
|
263
263
|
|
|
264
264
|
this.#identifierCreators[identifierType] = creator;
|
|
@@ -267,126 +267,87 @@ export class PrefixManager implements PrefixProvider {
|
|
|
267
267
|
return creator;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
/**
|
|
271
|
-
* Get non-GTIN numeric identifier creator.
|
|
272
|
-
*
|
|
273
|
-
* @param identifierType
|
|
274
|
-
* Identifier type used to construct identifier creator.
|
|
275
|
-
*
|
|
276
|
-
* @returns
|
|
277
|
-
* Identifier creator.
|
|
278
|
-
*/
|
|
279
|
-
#getNonGTINNumericIdentifierCreator(identifierType: NonSerializableNumericIdentifierType): NonSerializableNumericIdentifierCreator {
|
|
280
|
-
return this.#getIdentifierCreator(identifierType, identifierType, NonSerializableNumericIdentifierCreator);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Get serialized numeric identifier creator.
|
|
285
|
-
*
|
|
286
|
-
* @param identifierType
|
|
287
|
-
* Identifier type used to construct identifier creator.
|
|
288
|
-
*
|
|
289
|
-
* @returns
|
|
290
|
-
* Identifier creator.
|
|
291
|
-
*/
|
|
292
|
-
#getSerializableNumericIdentifierCreator(identifierType: SerializableNumericIdentifierType): SerializableNumericIdentifierCreator {
|
|
293
|
-
return this.#getIdentifierCreator(identifierType, identifierType, SerializableNumericIdentifierCreator);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Get non-numeric identifier creator.
|
|
298
|
-
*
|
|
299
|
-
* @param identifierType
|
|
300
|
-
* Identifier type used to construct identifier creator.
|
|
301
|
-
*
|
|
302
|
-
* @returns
|
|
303
|
-
* Identifier creator.
|
|
304
|
-
*/
|
|
305
|
-
#getNonNumericIdentifierCreator(identifierType: NonNumericIdentifierType): NonNumericIdentifierCreator {
|
|
306
|
-
return this.#getIdentifierCreator(identifierType, identifierType, NonNumericIdentifierCreator);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
270
|
/**
|
|
310
271
|
* Get GTIN creator.
|
|
311
272
|
*/
|
|
312
273
|
get gtinCreator(): GTINCreator {
|
|
313
|
-
return this
|
|
274
|
+
return this.getIdentifierCreator(IdentifierTypes.GTIN);
|
|
314
275
|
}
|
|
315
276
|
|
|
316
277
|
/**
|
|
317
278
|
* Get GLN creator.
|
|
318
279
|
*/
|
|
319
280
|
get glnCreator(): NonSerializableNumericIdentifierCreator {
|
|
320
|
-
return this
|
|
281
|
+
return this.getIdentifierCreator(IdentifierTypes.GLN);
|
|
321
282
|
}
|
|
322
283
|
|
|
323
284
|
/**
|
|
324
285
|
* Get SSCC creator.
|
|
325
286
|
*/
|
|
326
287
|
get ssccCreator(): NonSerializableNumericIdentifierCreator {
|
|
327
|
-
return this
|
|
288
|
+
return this.getIdentifierCreator(IdentifierTypes.SSCC);
|
|
328
289
|
}
|
|
329
290
|
|
|
330
291
|
/**
|
|
331
292
|
* Get GRAI creator.
|
|
332
293
|
*/
|
|
333
294
|
get graiCreator(): SerializableNumericIdentifierCreator {
|
|
334
|
-
return this
|
|
295
|
+
return this.getIdentifierCreator(IdentifierTypes.GRAI);
|
|
335
296
|
}
|
|
336
297
|
|
|
337
298
|
/**
|
|
338
299
|
* Get GIAI creator.
|
|
339
300
|
*/
|
|
340
301
|
get giaiCreator(): NonNumericIdentifierCreator {
|
|
341
|
-
return this
|
|
302
|
+
return this.getIdentifierCreator(IdentifierTypes.GIAI);
|
|
342
303
|
}
|
|
343
304
|
|
|
344
305
|
/**
|
|
345
306
|
* Get GSRN creator.
|
|
346
307
|
*/
|
|
347
308
|
get gsrnCreator(): NonSerializableNumericIdentifierCreator {
|
|
348
|
-
return this
|
|
309
|
+
return this.getIdentifierCreator(IdentifierTypes.GSRN);
|
|
349
310
|
}
|
|
350
311
|
|
|
351
312
|
/**
|
|
352
313
|
* Get GDTI creator.
|
|
353
314
|
*/
|
|
354
315
|
get gdtiCreator(): SerializableNumericIdentifierCreator {
|
|
355
|
-
return this
|
|
316
|
+
return this.getIdentifierCreator(IdentifierTypes.GDTI);
|
|
356
317
|
}
|
|
357
318
|
|
|
358
319
|
/**
|
|
359
320
|
* Get GINC creator.
|
|
360
321
|
*/
|
|
361
322
|
get gincCreator(): NonNumericIdentifierCreator {
|
|
362
|
-
return this
|
|
323
|
+
return this.getIdentifierCreator(IdentifierTypes.GINC);
|
|
363
324
|
}
|
|
364
325
|
|
|
365
326
|
/**
|
|
366
327
|
* Get GSIN creator.
|
|
367
328
|
*/
|
|
368
329
|
get gsinCreator(): NonSerializableNumericIdentifierCreator {
|
|
369
|
-
return this
|
|
330
|
+
return this.getIdentifierCreator(IdentifierTypes.GSIN);
|
|
370
331
|
}
|
|
371
332
|
|
|
372
333
|
/**
|
|
373
334
|
* Get GCN creator.
|
|
374
335
|
*/
|
|
375
336
|
get gcnCreator(): SerializableNumericIdentifierCreator {
|
|
376
|
-
return this
|
|
337
|
+
return this.getIdentifierCreator(IdentifierTypes.GCN);
|
|
377
338
|
}
|
|
378
339
|
|
|
379
340
|
/**
|
|
380
341
|
* Get CPID creator.
|
|
381
342
|
*/
|
|
382
343
|
get cpidCreator(): NonNumericIdentifierCreator {
|
|
383
|
-
return this
|
|
344
|
+
return this.getIdentifierCreator(IdentifierTypes.CPID);
|
|
384
345
|
}
|
|
385
346
|
|
|
386
347
|
/**
|
|
387
348
|
* Get GMN creator.
|
|
388
349
|
*/
|
|
389
350
|
get gmnCreator(): NonNumericIdentifierCreator {
|
|
390
|
-
return this
|
|
351
|
+
return this.getIdentifierCreator(IdentifierTypes.GMN);
|
|
391
352
|
}
|
|
392
353
|
}
|
|
@@ -8,8 +8,7 @@ import { SerializableNumericIdentifierValidator } from "./serializable-numeric-i
|
|
|
8
8
|
* Serializable numeric identifier creator.
|
|
9
9
|
*/
|
|
10
10
|
export class SerializableNumericIdentifierCreator extends MixinAbstractNonGTINNumericIdentifierCreator<
|
|
11
|
-
SerializableNumericIdentifierType
|
|
12
|
-
typeof SerializableNumericIdentifierValidator
|
|
11
|
+
SerializableNumericIdentifierType
|
|
13
12
|
>(SerializableNumericIdentifierValidator) {
|
|
14
13
|
/**
|
|
15
14
|
* Concatenate a validated base identifier with serial component(s).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
GTINBaseLengths,
|
|
4
|
+
type IdentifierCreator,
|
|
5
|
+
IdentifierTypes,
|
|
6
|
+
IdentifierValidators,
|
|
7
|
+
PrefixManager,
|
|
8
|
+
PrefixTypes
|
|
9
|
+
} from "../src/index.js";
|
|
10
|
+
|
|
11
|
+
describe("Mixins", () => {
|
|
12
|
+
function validate<TValidator extends object, TCreator extends TValidator & IdentifierCreator>(validator: TValidator, creator: TCreator): void {
|
|
13
|
+
for (const key of Object.keys(validator)) {
|
|
14
|
+
expect(key in creator, key).toBe(true);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const prefixManager = PrefixManager.get(PrefixTypes.GS1CompanyPrefix, "9521234");
|
|
19
|
+
|
|
20
|
+
test(IdentifierTypes.GTIN, () => {
|
|
21
|
+
validate(IdentifierValidators.GTIN[GTINBaseLengths.GTIN13], prefixManager.gtinCreator);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("Non-serialized numeric", () => {
|
|
25
|
+
validate(IdentifierValidators.GLN, prefixManager.glnCreator);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("Serialized numeric", () => {
|
|
29
|
+
validate(IdentifierValidators.GRAI, prefixManager.graiCreator);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("Non-numeric", () => {
|
|
33
|
+
validate(IdentifierValidators.GIAI, prefixManager.giaiCreator);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -7,12 +7,12 @@ import {
|
|
|
7
7
|
PrefixTypes
|
|
8
8
|
} from "../src/index.js";
|
|
9
9
|
import { validateIdentifierValidator } from "./identifier-validator.js";
|
|
10
|
-
import {
|
|
10
|
+
import { characterSetCreatorFor } from "./utility.js";
|
|
11
11
|
|
|
12
12
|
export function validateNonNumericIdentifierValidator(validator: NonNumericIdentifierValidator, isCreator: boolean, identifierType: IdentifierType, length: number, referenceCharacterSet: ContentCharacterSet, requiresCheckCharacterPair: boolean): void {
|
|
13
13
|
validateIdentifierValidator(validator, identifierType, PrefixTypes.GS1CompanyPrefix, length);
|
|
14
14
|
|
|
15
|
-
const referenceCreator =
|
|
15
|
+
const referenceCreator = characterSetCreatorFor(referenceCharacterSet);
|
|
16
16
|
|
|
17
17
|
expect(validator.referenceCharacterSet).toBe(referenceCharacterSet);
|
|
18
18
|
expect(validator.referenceCreator).toBe(referenceCreator);
|
|
@@ -7,12 +7,12 @@ import type {
|
|
|
7
7
|
SerializableNumericIdentifierValidator
|
|
8
8
|
} from "../src/index.js";
|
|
9
9
|
import { validateNonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator.js";
|
|
10
|
-
import {
|
|
10
|
+
import { characterSetCreatorFor } from "./utility.js";
|
|
11
11
|
|
|
12
12
|
export function validateSerializableNumericIdentifierValidator(validator: SerializableNumericIdentifierValidator, isCreator: boolean, identifierType: IdentifierType, length: number, leaderType: LeaderType, serialLength: number, serialCharacterSet: ContentCharacterSet): void {
|
|
13
13
|
validateNonGTINNumericIdentifierValidator(validator, isCreator, identifierType, length, leaderType);
|
|
14
14
|
|
|
15
|
-
const serialCreator =
|
|
15
|
+
const serialCreator = characterSetCreatorFor(serialCharacterSet);
|
|
16
16
|
|
|
17
17
|
expect(validator.serialComponentLength).toBe(serialLength);
|
|
18
18
|
expect(validator.serialComponentCharacterSet).toBe(serialCharacterSet);
|
package/test/utility.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { type CharacterSetCreator, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
2
|
import { AI39_CREATOR, AI82_CREATOR, type ContentCharacterSet, ContentCharacterSets } from "../src/index.js";
|
|
3
3
|
|
|
4
|
-
export function
|
|
5
|
-
let
|
|
4
|
+
export function characterSetCreatorFor(characterSet: ContentCharacterSet): CharacterSetCreator {
|
|
5
|
+
let characterSetCreator: CharacterSetCreator;
|
|
6
6
|
|
|
7
7
|
switch (characterSet) {
|
|
8
8
|
case ContentCharacterSets.Numeric:
|
|
9
|
-
|
|
9
|
+
characterSetCreator = NUMERIC_CREATOR;
|
|
10
10
|
break;
|
|
11
11
|
|
|
12
12
|
case ContentCharacterSets.AI82:
|
|
13
|
-
|
|
13
|
+
characterSetCreator = AI82_CREATOR;
|
|
14
14
|
break;
|
|
15
15
|
|
|
16
16
|
case ContentCharacterSets.AI39:
|
|
17
|
-
|
|
17
|
+
characterSetCreator = AI39_CREATOR;
|
|
18
18
|
break;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
return
|
|
21
|
+
return characterSetCreator;
|
|
22
22
|
}
|