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