@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.
Files changed (37) hide show
  1. package/dist/index.cjs +1205 -967
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +134 -312
  4. package/dist/index.d.ts +134 -312
  5. package/dist/index.js +1207 -964
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -6
  8. package/src/app-extension.ts +33 -24
  9. package/src/app-utility-proxy.ts +33 -27
  10. package/src/descriptor.ts +29 -199
  11. package/src/generator/generator.ts +102 -145
  12. package/src/generator/index.ts +0 -1
  13. package/src/generator/locale-resources-generator.ts +67 -42
  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 +22 -19
  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 +39 -55
  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 -122
  37. package/src/gs1/identifier-proxy.ts +0 -825
@@ -1,825 +0,0 @@
1
- import { isNullish, type Nullishable } from "@aidc-toolkit/core";
2
- import {
3
- GTINCreator,
4
- type GTINDescriptor,
5
- type GTINLevel,
6
- GTINTypes,
7
- GTINValidator,
8
- type IdentifierCreator,
9
- type IdentifierDescriptor,
10
- type IdentifierType,
11
- type IdentifierTypes,
12
- type IdentifierTypeValidator,
13
- type IdentifierValidation,
14
- IdentifierValidators,
15
- type NonGTINNumericIdentifierCreator,
16
- type NonGTINNumericIdentifierDescriptor,
17
- type NonGTINNumericIdentifierType,
18
- type NonNumericIdentifierCreator,
19
- type NonNumericIdentifierDescriptor,
20
- type NonNumericIdentifierType,
21
- type NonNumericIdentifierValidation,
22
- type NumericIdentifierCreator,
23
- type NumericIdentifierDescriptor,
24
- type NumericIdentifierType,
25
- type NumericIdentifierValidation,
26
- PrefixManager,
27
- type PrefixType,
28
- PrefixTypes,
29
- PrefixValidator,
30
- type SerializableNumericIdentifierCreator,
31
- type SerializableNumericIdentifierDescriptor,
32
- type SerializableNumericIdentifierType
33
- } from "@aidc-toolkit/gs1";
34
- import { Sequence } from "@aidc-toolkit/utility";
35
- import type { AppExtension } from "../app-extension.js";
36
- import {
37
- expandParameterDescriptor,
38
- type ParameterDescriptor,
39
- ProxyClass,
40
- ProxyMethod,
41
- ProxyParameter,
42
- Types
43
- } from "../descriptor.js";
44
- import { LibProxy } from "../lib-proxy.js";
45
- import { i18nextAppExtension } from "../locale/i18n.js";
46
- import type { ErrorExtends, Matrix, MatrixResultError } from "../type.js";
47
- import { exclusionAllNumericParameterDescriptor } from "../utility/character-set-descriptor.js";
48
- import { StringProxy } from "../utility/string-proxy.js";
49
- import {
50
- countParameterDescriptor,
51
- startValueParameterDescriptor,
52
- valueParameterDescriptor
53
- } from "../utility/transformer-descriptor.js";
54
-
55
- const identifierParameterDescriptor: ParameterDescriptor = {
56
- name: "identifier",
57
- type: Types.String,
58
- isMatrix: true,
59
- isRequired: true
60
- };
61
-
62
- const validateIdentifierParameterDescriptor: ParameterDescriptor = {
63
- extendsDescriptor: identifierParameterDescriptor,
64
- sortOrder: 0,
65
- name: "validateIdentifier"
66
- };
67
-
68
- abstract class IdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TIdentifierType extends IdentifierType> extends StringProxy<ThrowError, TError, TInvocationContext, TBigInt> {
69
- private readonly _validator: IdentifierTypeValidator<TIdentifierType>;
70
-
71
- protected constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, validator: IdentifierTypeValidator<TIdentifierType>) {
72
- super(appExtension);
73
-
74
- this._validator = validator;
75
- }
76
-
77
- protected get validator(): IdentifierTypeValidator<TIdentifierType> {
78
- return this._validator;
79
- }
80
- }
81
-
82
- abstract class NumericIdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TNumericIdentifierType extends NumericIdentifierType> extends IdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, TNumericIdentifierType> {
83
- @ProxyMethod({
84
- type: Types.String,
85
- isMatrix: true
86
- })
87
- validate(
88
- @ProxyParameter(validateIdentifierParameterDescriptor) matrixIdentifiers: Matrix<string>
89
- ): MatrixResultError<string, ThrowError, TError> {
90
- return this.validateString(this.validator, matrixIdentifiers);
91
- }
92
- }
93
-
94
- abstract class GTINValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, typeof IdentifierTypes.GTIN> {
95
- }
96
-
97
- abstract class NonGTINNumericIdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TNonGTINNumericIdentifierType extends NonGTINNumericIdentifierType = NonGTINNumericIdentifierType> extends NumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, TNonGTINNumericIdentifierType> {
98
- }
99
-
100
- abstract class SerializableNumericIdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, SerializableNumericIdentifierType> {
101
- }
102
-
103
- abstract class NonNumericIdentifierValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends IdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt, NonNumericIdentifierType> {
104
- @ProxyMethod({
105
- type: Types.String,
106
- isMatrix: true
107
- })
108
- validate(
109
- @ProxyParameter(validateIdentifierParameterDescriptor) matrixIdentifiers: Matrix<string>,
110
- @ProxyParameter(exclusionAllNumericParameterDescriptor) exclusion: Nullishable<NonNumericIdentifierValidation["exclusion"]>
111
- ): MatrixResultError<string, ThrowError, TError> {
112
- return this.validateString(this.validator, matrixIdentifiers, {
113
- exclusion: exclusion ?? undefined
114
- } satisfies NonNumericIdentifierValidation);
115
- }
116
- }
117
-
118
- @ProxyClass({
119
- namespace: "GS1",
120
- methodInfix: "GTIN13"
121
- })
122
- export class GTIN13ValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends GTINValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
123
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
124
- super(appExtension, IdentifierValidators.GTIN[GTINTypes.GTIN13]);
125
- }
126
- }
127
-
128
- @ProxyClass({
129
- namespace: "GS1",
130
- methodInfix: "GTIN12"
131
- })
132
- export class GTIN12ValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends GTINValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
133
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
134
- super(appExtension, IdentifierValidators.GTIN[GTINTypes.GTIN12]);
135
- }
136
- }
137
-
138
- @ProxyClass({
139
- namespace: "GS1",
140
- methodInfix: "GTIN8"
141
- })
142
- export class GTIN8ValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends GTINValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
143
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
144
- super(appExtension, IdentifierValidators.GTIN[GTINTypes.GTIN8]);
145
- }
146
- }
147
-
148
- const zeroSuppressibleGTIN12ParameterDescriptor: ParameterDescriptor = {
149
- extendsDescriptor: identifierParameterDescriptor,
150
- name: "zeroSuppressibleGTIN12"
151
- };
152
-
153
- const zeroSuppressedGTIN12ParameterDescriptor: ParameterDescriptor = {
154
- extendsDescriptor: identifierParameterDescriptor,
155
- name: "zeroSuppressedGTIN12"
156
- };
157
-
158
- const indicatorDigitParameterDescriptor: ParameterDescriptor = {
159
- name: "indicatorDigit",
160
- type: Types.String,
161
- isMatrix: false,
162
- isRequired: true
163
- };
164
-
165
- const convertGTINParameterDescriptor: ParameterDescriptor = {
166
- extendsDescriptor: identifierParameterDescriptor,
167
- name: "convertGTIN"
168
- };
169
-
170
- const normalizeGTINParameterDescriptor: ParameterDescriptor = {
171
- extendsDescriptor: identifierParameterDescriptor,
172
- name: "normalizeGTIN"
173
- };
174
-
175
- const validateGTINParameterDescriptor: ParameterDescriptor = {
176
- extendsDescriptor: identifierParameterDescriptor,
177
- name: "validateGTIN"
178
- };
179
-
180
- const gtinLevelParameterDescriptor: ParameterDescriptor = {
181
- name: "gtinLevel",
182
- type: Types.Number,
183
- isMatrix: false,
184
- isRequired: false
185
- };
186
-
187
- const validateGTIN14ParameterDescriptor: ParameterDescriptor = {
188
- extendsDescriptor: identifierParameterDescriptor,
189
- name: "validateGTIN14"
190
- };
191
-
192
- const rcnFormatParameterDescriptor: ParameterDescriptor = {
193
- name: "rcnFormat",
194
- type: Types.String,
195
- isMatrix: false,
196
- isRequired: true
197
- };
198
-
199
- const rcnParameterDescriptor: ParameterDescriptor = {
200
- name: "rcn",
201
- type: Types.String,
202
- isMatrix: true,
203
- isRequired: true
204
- };
205
-
206
- const rcnItemReferenceParameterDescriptor: ParameterDescriptor = {
207
- name: "rcnItemReference",
208
- type: Types.Number,
209
- isMatrix: false,
210
- isRequired: true
211
- };
212
-
213
- const rcnPriceOrWeightParameterDescriptor: ParameterDescriptor = {
214
- name: "rcnPriceOrWeight",
215
- type: Types.Number,
216
- isMatrix: true,
217
- isRequired: true
218
- };
219
-
220
- @ProxyClass({
221
- namespace: "GS1"
222
- })
223
- export class GTINValidatorStaticProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
224
- @ProxyMethod({
225
- type: Types.String,
226
- isMatrix: true
227
- })
228
- zeroSuppressGTIN12(
229
- @ProxyParameter(zeroSuppressibleGTIN12ParameterDescriptor) matrixGTIN12s: Matrix<string>
230
- ): MatrixResultError<string, ThrowError, TError> {
231
- return this.mapMatrix(matrixGTIN12s, gtin12 => GTINValidator.zeroSuppress(gtin12));
232
- }
233
-
234
- @ProxyMethod({
235
- type: Types.String,
236
- isMatrix: true
237
- })
238
- zeroExpandGTIN12(
239
- @ProxyParameter(zeroSuppressedGTIN12ParameterDescriptor) matrixZeroSuppressedGTIN12s: Matrix<string>
240
- ): MatrixResultError<string, ThrowError, TError> {
241
- return this.mapMatrix(matrixZeroSuppressedGTIN12s, zeroSuppressedGTIN12 => GTINValidator.zeroExpand(zeroSuppressedGTIN12));
242
- }
243
-
244
- @ProxyMethod({
245
- type: Types.String,
246
- isMatrix: true
247
- })
248
- convertToGTIN14(
249
- @ProxyParameter(indicatorDigitParameterDescriptor) indicatorDigit: string,
250
- @ProxyParameter(convertGTINParameterDescriptor) matrixGTINs: Matrix<string>
251
- ): MatrixResultError<string, ThrowError, TError> {
252
- return this.mapMatrix(matrixGTINs, gtin => GTINValidator.convertToGTIN14(indicatorDigit, gtin));
253
- }
254
-
255
- @ProxyMethod({
256
- type: Types.String,
257
- isMatrix: true
258
- })
259
- normalizeGTIN(
260
- @ProxyParameter(normalizeGTINParameterDescriptor) matrixGTINs: Matrix<string>
261
- ): MatrixResultError<string, ThrowError, TError> {
262
- return this.mapMatrix(matrixGTINs, gtin => GTINValidator.normalize(gtin));
263
- }
264
-
265
- @ProxyMethod({
266
- type: Types.String,
267
- isMatrix: true
268
- })
269
- validateGTIN(
270
- @ProxyParameter(validateGTINParameterDescriptor) matrixGTINs: Matrix<string>,
271
- @ProxyParameter(gtinLevelParameterDescriptor) gtinLevel: Nullishable<GTINLevel>
272
- ): Matrix<string> {
273
- const gtinLevelOrUndefined = gtinLevel ?? undefined;
274
-
275
- return LibProxy.mapMatrixRangeError(matrixGTINs, (gtin) => {
276
- GTINValidator.validateAny(gtin, gtinLevelOrUndefined);
277
- });
278
- }
279
-
280
- @ProxyMethod({
281
- type: Types.String,
282
- isMatrix: true
283
- })
284
- validateGTIN14(
285
- @ProxyParameter(validateGTIN14ParameterDescriptor) matrixGTIN14s: Matrix<string>
286
- ): Matrix<string> {
287
- return LibProxy.mapMatrixRangeError(matrixGTIN14s, (gtin14) => {
288
- GTINValidator.validateGTIN14(gtin14);
289
- });
290
- }
291
-
292
- @ProxyMethod({
293
- type: Types.Number,
294
- isMatrix: true
295
- })
296
- parseVariableMeasureRCN(
297
- @ProxyParameter(rcnFormatParameterDescriptor) format: string,
298
- @ProxyParameter(rcnParameterDescriptor) matrixRCNs: Matrix<string>
299
- ): MatrixResultError<number, ThrowError, TError> {
300
- return this.mapArray(matrixRCNs, (rcn) => {
301
- const rcnReference = GTINValidator.parseVariableMeasureRCN(format, rcn);
302
-
303
- return [rcnReference.itemReference, rcnReference.priceOrWeight];
304
- });
305
- }
306
- }
307
-
308
- @ProxyClass({
309
- namespace: "GS1",
310
- methodInfix: "GLN"
311
- })
312
- export class GLNValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
313
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
314
- super(appExtension, IdentifierValidators.GLN);
315
- }
316
- }
317
-
318
- @ProxyClass({
319
- namespace: "GS1",
320
- methodInfix: "SSCC"
321
- })
322
- export class SSCCValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
323
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
324
- super(appExtension, IdentifierValidators.SSCC);
325
- }
326
- }
327
-
328
- @ProxyClass({
329
- namespace: "GS1",
330
- methodInfix: "GRAI"
331
- })
332
- export class GRAIValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends SerializableNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
333
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
334
- super(appExtension, IdentifierValidators.GRAI);
335
- }
336
- }
337
-
338
- @ProxyClass({
339
- namespace: "GS1",
340
- methodInfix: "GIAI"
341
- })
342
- export class GIAIValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
343
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
344
- super(appExtension, IdentifierValidators.GIAI);
345
- }
346
- }
347
-
348
- @ProxyClass({
349
- namespace: "GS1",
350
- methodInfix: "GSRN"
351
- })
352
- export class GSRNValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
353
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
354
- super(appExtension, IdentifierValidators.GSRN);
355
- }
356
- }
357
-
358
- @ProxyClass({
359
- namespace: "GS1",
360
- methodInfix: "GDTI"
361
- })
362
- export class GDTIValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends SerializableNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
363
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
364
- super(appExtension, IdentifierValidators.GDTI);
365
- }
366
- }
367
-
368
- @ProxyClass({
369
- namespace: "GS1",
370
- methodInfix: "GINC"
371
- })
372
- export class GINCValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
373
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
374
- super(appExtension, IdentifierValidators.GINC);
375
- }
376
- }
377
-
378
- @ProxyClass({
379
- namespace: "GS1",
380
- methodInfix: "GSIN"
381
- })
382
- export class GSINValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
383
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
384
- super(appExtension, IdentifierValidators.GSIN);
385
- }
386
- }
387
-
388
- @ProxyClass({
389
- namespace: "GS1",
390
- methodInfix: "GCN"
391
- })
392
- export class GCNValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends SerializableNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
393
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
394
- super(appExtension, IdentifierValidators.GCN);
395
- }
396
- }
397
-
398
- @ProxyClass({
399
- namespace: "GS1",
400
- methodInfix: "CPID"
401
- })
402
- export class CPIDValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
403
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
404
- super(appExtension, IdentifierValidators.CPID);
405
- }
406
- }
407
-
408
- @ProxyClass({
409
- namespace: "GS1",
410
- methodInfix: "GMN"
411
- })
412
- export class GMNValidatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonNumericIdentifierValidatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
413
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
414
- super(appExtension, IdentifierValidators.GMN);
415
- }
416
- }
417
-
418
- const prefixParameterDescriptor: ParameterDescriptor = {
419
- name: "prefix",
420
- type: Types.String,
421
- isMatrix: false,
422
- isRequired: true
423
- };
424
-
425
- const prefixTypeParameterDescriptor: ParameterDescriptor = {
426
- name: "prefixType",
427
- type: Types.Number,
428
- isMatrix: false,
429
- isRequired: false
430
- };
431
-
432
- const tweakFactorParameterDescriptor: ParameterDescriptor = {
433
- name: "tweakFactor",
434
- type: Types.Number,
435
- isMatrix: false,
436
- isRequired: false
437
- };
438
-
439
- const prefixDefinitionParameterDescriptor: ParameterDescriptor = {
440
- name: "prefixDefinition",
441
- type: Types.Any,
442
- isMatrix: true,
443
- isRequired: true
444
- };
445
-
446
- const prefixDefinitionGS1UPCParameterDescriptor: ParameterDescriptor = {
447
- extendsDescriptor: prefixDefinitionParameterDescriptor,
448
- name: "prefixDefinitionGS1UPC"
449
- };
450
-
451
- const prefixDefinitionAnyParameterDescriptor: ParameterDescriptor = {
452
- extendsDescriptor: prefixDefinitionParameterDescriptor,
453
- name: "prefixDefinitionAny"
454
- };
455
-
456
- @ProxyClass({
457
- namespace: "GS1"
458
- })
459
- export class PrefixManagerProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
460
- @ProxyMethod({
461
- type: Types.Any,
462
- isMatrix: true
463
- })
464
- definePrefix(
465
- @ProxyParameter(prefixParameterDescriptor) prefix: string,
466
- @ProxyParameter(prefixTypeParameterDescriptor) prefixType: Nullishable<PrefixType>,
467
- @ProxyParameter(tweakFactorParameterDescriptor) tweakFactor: Nullishable<number>
468
- ): Matrix<unknown> {
469
- // Parameters will be validated by IdentifierCreatorProxy.getCreator().
470
- return [[prefix, prefixType, tweakFactor]];
471
- }
472
- }
473
-
474
- abstract class IdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TIdentifierDescriptor extends IdentifierDescriptor, TIdentifierValidation extends IdentifierValidation, TIdentifierCreator extends IdentifierCreator<TIdentifierDescriptor, TIdentifierValidation>> extends LibProxy<ThrowError, TError, TInvocationContext, TBigInt> {
475
- private static readonly PREFIX_TYPES: Array<PrefixType | undefined> = [PrefixTypes.GS1CompanyPrefix, PrefixTypes.UPCCompanyPrefix, PrefixTypes.GS18Prefix];
476
-
477
- private readonly _getCreator: (prefixManager: PrefixManager) => TIdentifierCreator;
478
-
479
- protected constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>, getCreator: (prefixManager: PrefixManager) => TIdentifierCreator) {
480
- super(appExtension);
481
-
482
- this._getCreator = getCreator;
483
- }
484
-
485
- protected getCreator(prefixDefinition: Matrix<unknown>): TIdentifierCreator {
486
- const reducedPrefixDefinition = prefixDefinition.length === 1 ?
487
- // Prefix definition is horizontal.
488
- prefixDefinition[0] :
489
- // Prefix definition is vertical.
490
- prefixDefinition.map((prefixDefinitionRow) => {
491
- if (prefixDefinitionRow.length !== 1) {
492
- throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.prefixDefinitionMustBeOneDimensional"));
493
- }
494
-
495
- return prefixDefinitionRow[0];
496
- });
497
-
498
- if (reducedPrefixDefinition.length > 3) {
499
- throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.prefixDefinitionMustHaveMaximumThreeElements"));
500
- }
501
- const prefix = reducedPrefixDefinition[0];
502
-
503
- if (typeof prefix !== "string") {
504
- throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.prefixMustBeString"));
505
- }
506
-
507
- const prefixTypeIndex = reducedPrefixDefinition[1] ?? 0;
508
-
509
- if (typeof prefixTypeIndex !== "number" || prefixTypeIndex < 0 || prefixTypeIndex >= IdentifierCreatorProxy.PREFIX_TYPES.length) {
510
- throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.prefixTypeMustBeNumber", {
511
- maximumPrefixType: IdentifierCreatorProxy.PREFIX_TYPES.length - 1
512
- }));
513
- }
514
-
515
- const prefixType = IdentifierCreatorProxy.PREFIX_TYPES[prefixTypeIndex];
516
-
517
- // Undefined is included in type in case of invalid input.
518
- if (prefixType === undefined) {
519
- throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.invalidPrefixType"));
520
- }
521
-
522
- const prefixManager = PrefixManager.get(prefixType, prefix);
523
-
524
- const tweakFactor = reducedPrefixDefinition[2];
525
-
526
- if (!isNullish(tweakFactor)) {
527
- if (typeof tweakFactor !== "number") {
528
- throw new RangeError(i18nextAppExtension.t("IdentifierCreatorProxy.tweakFactorMustBeNumber"));
529
- }
530
-
531
- prefixManager.tweakFactor = tweakFactor;
532
- } else {
533
- prefixManager.resetTweakFactor();
534
- }
535
-
536
- return this._getCreator(prefixManager);
537
- }
538
- }
539
-
540
- const sparseParameterDescriptor: ParameterDescriptor = {
541
- name: "sparse",
542
- type: Types.Boolean,
543
- isMatrix: false,
544
- isRequired: false
545
- };
546
-
547
- abstract class NumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TNumericIdentifierDescriptor extends NumericIdentifierDescriptor, TNumericIdentifierCreator extends NumericIdentifierCreator<TNumericIdentifierDescriptor>> extends IdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, TNumericIdentifierDescriptor, NumericIdentifierValidation, TNumericIdentifierCreator> {
548
- @ProxyMethod({
549
- type: Types.String,
550
- isMatrix: true
551
- })
552
- create(
553
- @ProxyParameter(prefixDefinitionGS1UPCParameterDescriptor) prefixDefinition: Matrix<unknown>,
554
- @ProxyParameter(valueParameterDescriptor) matrixValues: Matrix<number | bigint>,
555
- @ProxyParameter(sparseParameterDescriptor) sparse: Nullishable<boolean>
556
- ): MatrixResultError<string, ThrowError, TError> {
557
- const creator = this.getCreator(prefixDefinition);
558
-
559
- const sparseOrUndefined = sparse ?? undefined;
560
-
561
- return this.mapMatrix(matrixValues, value => creator.create(value, sparseOrUndefined));
562
- }
563
-
564
- @ProxyMethod({
565
- infixBefore: "Sequence",
566
- type: Types.String,
567
- isMatrix: true
568
- })
569
- createSequence(
570
- @ProxyParameter(prefixDefinitionGS1UPCParameterDescriptor) prefixDefinition: Matrix<unknown>,
571
- @ProxyParameter(startValueParameterDescriptor) startValue: number,
572
- @ProxyParameter(countParameterDescriptor) count: number,
573
- @ProxyParameter(sparseParameterDescriptor) sparse: Nullishable<boolean>
574
- ): Matrix<string> {
575
- this.appExtension.validateSequenceCount(count);
576
-
577
- return LibProxy.matrixResult(this.getCreator(prefixDefinition).create(new Sequence(startValue, count), sparse ?? undefined));
578
- }
579
-
580
- @ProxyMethod({
581
- type: Types.String,
582
- isMatrix: true
583
- })
584
- createAll(
585
- @ProxyParameter(prefixDefinitionGS1UPCParameterDescriptor) prefixDefinition: Matrix<unknown>
586
- ): Matrix<string> {
587
- const creator = this.getCreator(prefixDefinition);
588
-
589
- this.appExtension.validateSequenceCount(creator.capacity);
590
-
591
- return LibProxy.matrixResult(creator.createAll());
592
- }
593
- }
594
-
595
- abstract class NonGTINNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt, TNonGTINNumericIdentifierDescriptor extends NonGTINNumericIdentifierDescriptor, TNonGTINNumericIdentifierCreator extends NonGTINNumericIdentifierCreator> extends NumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, TNonGTINNumericIdentifierDescriptor, TNonGTINNumericIdentifierCreator> {
596
- }
597
-
598
- const singleValueParameterDescriptor: ParameterDescriptor = {
599
- extendsDescriptor: valueParameterDescriptor,
600
- isMatrix: false
601
- };
602
-
603
- const baseIdentifierParameterDescriptor: ParameterDescriptor = {
604
- extendsDescriptor: identifierParameterDescriptor,
605
- name: "baseIdentifier",
606
- isMatrix: false
607
- };
608
-
609
- const serialComponentParameterDescriptor: ParameterDescriptor = {
610
- name: "serialComponent",
611
- type: Types.String,
612
- isMatrix: true,
613
- isRequired: true
614
- };
615
-
616
- abstract class SerializableNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, SerializableNumericIdentifierDescriptor, SerializableNumericIdentifierCreator> {
617
- @ProxyMethod({
618
- type: Types.String,
619
- isMatrix: true
620
- })
621
- createSerialized(
622
- @ProxyParameter(prefixDefinitionGS1UPCParameterDescriptor) prefixDefinition: Matrix<unknown>,
623
- @ProxyParameter(singleValueParameterDescriptor) value: number,
624
- @ProxyParameter(serialComponentParameterDescriptor) matrixSerialComponents: Matrix<string>,
625
- @ProxyParameter(sparseParameterDescriptor) sparse: Nullishable<boolean>
626
- ): MatrixResultError<string, ThrowError, TError> {
627
- const creator = this.getCreator(prefixDefinition);
628
-
629
- const sparseOrUndefined = sparse ?? undefined;
630
-
631
- return this.mapMatrix(matrixSerialComponents, serialComponent => creator.createSerialized(value, serialComponent, sparseOrUndefined));
632
- }
633
-
634
- @ProxyMethod({
635
- type: Types.String,
636
- isMatrix: true
637
- })
638
- concatenate(
639
- @ProxyParameter(baseIdentifierParameterDescriptor) baseIdentifier: string,
640
- @ProxyParameter(serialComponentParameterDescriptor) matrixSerialComponents: Matrix<string>
641
- ): MatrixResultError<string, ThrowError, TError> {
642
- 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]]);
643
-
644
- return this.mapMatrix(matrixSerialComponents, serialComponent => creator.concatenate(baseIdentifier, serialComponent));
645
- }
646
- }
647
-
648
- const referenceParameterDescriptor: ParameterDescriptor = {
649
- name: "reference",
650
- type: Types.String,
651
- isMatrix: true,
652
- isRequired: true
653
- };
654
-
655
- abstract class NonNumericIdentifierCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends IdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, NonNumericIdentifierDescriptor, NonNumericIdentifierValidation, NonNumericIdentifierCreator> {
656
- @ProxyMethod({
657
- type: Types.String,
658
- isMatrix: true
659
- })
660
- create(
661
- @ProxyParameter(prefixDefinitionGS1UPCParameterDescriptor) prefixDefinition: Matrix<unknown>,
662
- @ProxyParameter(referenceParameterDescriptor) matrixReferences: Matrix<string>
663
- ): MatrixResultError<string, ThrowError, TError> {
664
- const creator = this.getCreator(prefixDefinition);
665
-
666
- return this.mapMatrix(matrixReferences, reference => creator.create(reference));
667
- }
668
- }
669
-
670
- @ProxyClass({
671
- namespace: "GS1",
672
- methodInfix: "GTIN",
673
- replaceParameterDescriptors: [
674
- {
675
- name: expandParameterDescriptor(prefixDefinitionGS1UPCParameterDescriptor).name,
676
- replacement: prefixDefinitionAnyParameterDescriptor
677
- }
678
- ]
679
- })
680
- export class GTINCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, GTINDescriptor, GTINCreator> {
681
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
682
- super(appExtension, prefixManager => prefixManager.gtinCreator);
683
- }
684
-
685
- @ProxyMethod({
686
- type: Types.String,
687
- isMatrix: true,
688
- ignoreInfix: true
689
- })
690
- createGTIN14(
691
- @ProxyParameter(indicatorDigitParameterDescriptor) indicatorDigit: string,
692
- @ProxyParameter(prefixDefinitionAnyParameterDescriptor) prefixDefinition: Matrix<unknown>,
693
- @ProxyParameter(valueParameterDescriptor) matrixValues: Matrix<number | bigint>,
694
- @ProxyParameter(sparseParameterDescriptor) sparse: Nullishable<boolean>
695
- ): MatrixResultError<string, ThrowError, TError> {
696
- const creator = this.getCreator(prefixDefinition);
697
-
698
- const sparseOrUndefined = sparse ?? undefined;
699
-
700
- return this.mapMatrix(matrixValues, value => creator.createGTIN14(indicatorDigit, value, sparseOrUndefined));
701
- }
702
-
703
- @ProxyMethod({
704
- type: Types.String,
705
- isMatrix: true,
706
- ignoreInfix: true
707
- })
708
- createVariableMeasureRCN(
709
- @ProxyParameter(rcnFormatParameterDescriptor) format: string,
710
- @ProxyParameter(rcnItemReferenceParameterDescriptor) itemReference: number,
711
- @ProxyParameter(rcnPriceOrWeightParameterDescriptor) matrixPricesOrWeights: Matrix<number>
712
- ): MatrixResultError<string, ThrowError, TError> {
713
- return this.mapMatrix(matrixPricesOrWeights, priceOrWeight => GTINCreator.createVariableMeasureRCN(format, itemReference, priceOrWeight));
714
- }
715
- }
716
-
717
- @ProxyClass({
718
- namespace: "GS1",
719
- methodInfix: "GLN"
720
- })
721
- export class GLNCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, NonGTINNumericIdentifierDescriptor, NonGTINNumericIdentifierCreator> {
722
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
723
- super(appExtension, prefixManager => prefixManager.glnCreator);
724
- }
725
- }
726
-
727
- @ProxyClass({
728
- namespace: "GS1",
729
- methodInfix: "SSCC"
730
- })
731
- export class SSCCCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, NonGTINNumericIdentifierDescriptor, NonGTINNumericIdentifierCreator> {
732
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
733
- super(appExtension, prefixManager => prefixManager.ssccCreator);
734
- }
735
- }
736
-
737
- @ProxyClass({
738
- namespace: "GS1",
739
- methodInfix: "GRAI"
740
- })
741
- export class GRAICreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends SerializableNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
742
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
743
- super(appExtension, prefixManager => prefixManager.graiCreator);
744
- }
745
- }
746
-
747
- @ProxyClass({
748
- namespace: "GS1",
749
- methodInfix: "GIAI"
750
- })
751
- export class GIAICreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
752
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
753
- super(appExtension, prefixManager => prefixManager.giaiCreator);
754
- }
755
- }
756
-
757
- @ProxyClass({
758
- namespace: "GS1",
759
- methodInfix: "GSRN"
760
- })
761
- export class GSRNCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, NonGTINNumericIdentifierDescriptor, NonGTINNumericIdentifierCreator> {
762
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
763
- super(appExtension, prefixManager => prefixManager.gsrnCreator);
764
- }
765
- }
766
-
767
- @ProxyClass({
768
- namespace: "GS1",
769
- methodInfix: "GDTI"
770
- })
771
- export class GDTICreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends SerializableNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
772
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
773
- super(appExtension, prefixManager => prefixManager.gdtiCreator);
774
- }
775
- }
776
-
777
- @ProxyClass({
778
- namespace: "GS1",
779
- methodInfix: "GINC"
780
- })
781
- export class GINCCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
782
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
783
- super(appExtension, prefixManager => prefixManager.gincCreator);
784
- }
785
- }
786
-
787
- @ProxyClass({
788
- namespace: "GS1",
789
- methodInfix: "GSIN"
790
- })
791
- export class GSINCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonGTINNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt, NonGTINNumericIdentifierDescriptor, NonGTINNumericIdentifierCreator> {
792
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
793
- super(appExtension, prefixManager => prefixManager.gsinCreator);
794
- }
795
- }
796
-
797
- @ProxyClass({
798
- namespace: "GS1",
799
- methodInfix: "GCN"
800
- })
801
- export class GCNCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends SerializableNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
802
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
803
- super(appExtension, prefixManager => prefixManager.gcnCreator);
804
- }
805
- }
806
-
807
- @ProxyClass({
808
- namespace: "GS1",
809
- methodInfix: "CPID"
810
- })
811
- export class CPIDCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
812
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
813
- super(appExtension, prefixManager => prefixManager.cpidCreator);
814
- }
815
- }
816
-
817
- @ProxyClass({
818
- namespace: "GS1",
819
- methodInfix: "GMN"
820
- })
821
- export class GMNCreatorProxy<ThrowError extends boolean, TError extends ErrorExtends<ThrowError>, TInvocationContext, TBigInt> extends NonNumericIdentifierCreatorProxy<ThrowError, TError, TInvocationContext, TBigInt> {
822
- constructor(appExtension: AppExtension<ThrowError, TError, TInvocationContext, TBigInt>) {
823
- super(appExtension, prefixManager => prefixManager.gmnCreator);
824
- }
825
- }