@aidc-toolkit/app-extension 1.0.27-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.
Files changed (37) hide show
  1. package/dist/index.cjs +1102 -877
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +79 -241
  4. package/dist/index.d.ts +79 -241
  5. package/dist/index.js +1100 -870
  6. package/dist/index.js.map +1 -1
  7. package/package.json +5 -5
  8. package/src/app-extension.ts +5 -5
  9. package/src/app-utility-proxy.ts +18 -24
  10. package/src/descriptor.ts +29 -259
  11. package/src/generator/generator.ts +86 -132
  12. package/src/generator/index.ts +0 -1
  13. package/src/generator/locale-resources-generator.ts +39 -14
  14. package/src/gs1/character-set-proxy.ts +5 -5
  15. package/src/gs1/check-proxy.ts +35 -42
  16. package/src/gs1/gtin-creator-proxy.ts +58 -0
  17. package/src/gs1/gtin-descriptor.ts +29 -0
  18. package/src/gs1/gtin-validator-proxy.ts +161 -0
  19. package/src/gs1/identifier-creator-proxy.ts +227 -0
  20. package/src/gs1/identifier-validator-proxy.ts +87 -0
  21. package/src/gs1/index.ts +5 -1
  22. package/src/gs1/non-gtin-creator-proxy.ts +119 -0
  23. package/src/gs1/non-gtin-validator-proxy.ts +119 -0
  24. package/src/gs1/prefix-definition-descriptor.ts +18 -0
  25. package/src/gs1/prefix-manager-proxy.ts +42 -0
  26. package/src/index.ts +1 -0
  27. package/src/lib-proxy.ts +1 -1
  28. package/src/proxy.ts +509 -0
  29. package/src/utility/character-set-descriptor.ts +5 -5
  30. package/src/utility/character-set-proxy.ts +31 -47
  31. package/src/utility/reg-exp-proxy.ts +11 -15
  32. package/src/utility/string-descriptor.ts +2 -2
  33. package/src/utility/transformer-descriptor.ts +3 -3
  34. package/src/utility/transformer-proxy.ts +16 -26
  35. package/tsconfig-src.json +1 -4
  36. package/src/generator/descriptor.ts +0 -125
  37. package/src/gs1/identifier-proxy.ts +0 -826
@@ -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
+ }
@@ -0,0 +1,87 @@
1
+ import type { Nullishable } from "@aidc-toolkit/core";
2
+ import type {
3
+ GTINType,
4
+ IdentifierType,
5
+ IdentifierTypeValidator,
6
+ NonGTINNumericIdentifierType,
7
+ NonNumericIdentifierType,
8
+ NonNumericIdentifierValidation,
9
+ NonSerializableNumericIdentifierType,
10
+ NumericIdentifierType,
11
+ SerializableNumericIdentifierType
12
+ } from "@aidc-toolkit/gs1";
13
+ import type { AppExtension } from "../app-extension.js";
14
+ import { type ExtendsParameterDescriptor, type ParameterDescriptor, Types } from "../descriptor.js";
15
+ import { proxy } from "../proxy.js";
16
+ import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
17
+ import { exclusionAllNumericParameterDescriptor } from "../utility/character-set-descriptor.js";
18
+ import { StringProxy } from "../utility/string-proxy.js";
19
+
20
+ export const identifierParameterDescriptor: ParameterDescriptor = {
21
+ name: "identifier",
22
+ type: Types.String,
23
+ isMatrix: true,
24
+ isRequired: true
25
+ };
26
+
27
+ const validateIdentifierParameterDescriptor: ExtendsParameterDescriptor = {
28
+ extendsDescriptor: identifierParameterDescriptor,
29
+ sortOrder: 0,
30
+ name: "validateIdentifier"
31
+ };
32
+
33
+ abstract class IdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TIdentifierType extends IdentifierType> extends StringProxy<ThrowError, TError, TInvocationContext, TBigInt> {
34
+ readonly #validator: IdentifierTypeValidator<TIdentifierType>;
35
+
36
+ constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, validator: IdentifierTypeValidator<TIdentifierType>) {
37
+ super(appExtension);
38
+
39
+ this.#validator = validator;
40
+ }
41
+
42
+ protected get validator(): IdentifierTypeValidator<TIdentifierType> {
43
+ return this.#validator;
44
+ }
45
+ }
46
+
47
+ @proxy.describeClass(true, {
48
+ namespace: "GS1"
49
+ })
50
+ abstract class NumericIdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TNumericIdentifierType extends NumericIdentifierType> extends IdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, TNumericIdentifierType> {
51
+ @proxy.describeMethod({
52
+ type: Types.String,
53
+ isMatrix: true,
54
+ parameterDescriptors: [validateIdentifierParameterDescriptor]
55
+ })
56
+ validate(matrixIdentifiers: Matrix<string>): MatrixResultError<string, ThrowError, TError> {
57
+ return this.validateString(this.validator, matrixIdentifiers);
58
+ }
59
+ }
60
+
61
+ export abstract class GTINValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, GTINType> {
62
+ }
63
+
64
+ abstract class NonGTINNumericIdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TNonGTINNumericIdentifierType extends NonGTINNumericIdentifierType = NonGTINNumericIdentifierType> extends NumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, TNonGTINNumericIdentifierType> {
65
+ }
66
+
67
+ export abstract class NonSerializableNumericIdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, NonSerializableNumericIdentifierType> {
68
+ }
69
+
70
+ export abstract class SerializableNumericIdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, SerializableNumericIdentifierType> {
71
+ }
72
+
73
+ @proxy.describeClass(true, {
74
+ namespace: "GS1"
75
+ })
76
+ export abstract class NonNumericIdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends IdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, NonNumericIdentifierType> {
77
+ @proxy.describeMethod({
78
+ type: Types.String,
79
+ isMatrix: true,
80
+ parameterDescriptors: [validateIdentifierParameterDescriptor, exclusionAllNumericParameterDescriptor]
81
+ })
82
+ validate(matrixIdentifiers: Matrix<string>, exclusion: Nullishable<NonNumericIdentifierValidation["exclusion"]>): MatrixResultError<string, ThrowError, TError> {
83
+ return this.validateString(this.validator, matrixIdentifiers, {
84
+ exclusion: exclusion ?? undefined
85
+ } satisfies NonNumericIdentifierValidation);
86
+ }
87
+ }
package/src/gs1/index.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  export * from "./character-set-proxy.js";
2
2
  export * from "./check-proxy.js";
3
- export * from "./identifier-proxy.js";
3
+ export * from "./gtin-validator-proxy.js";
4
+ export * from "./non-gtin-validator-proxy.js";
5
+ export * from "./prefix-manager-proxy.js";
6
+ export * from "./gtin-creator-proxy.js";
7
+ export * from "./non-gtin-creator-proxy.js";