@open-dpp/dto 7.5.1 → 7.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aas/submodel-base/annotated-relationship-element-json-schema.d.ts +2 -2
- package/dist/aas/submodel-base/create-group-from-column-schema.d.ts +1 -1
- package/dist/aas/submodel-base/entity-type-json-schema.d.ts +2 -2
- package/dist/aas/submodel-base/submodel-element-collection-json-schema.d.ts +2 -2
- package/dist/aas/submodel-base/submodel-element-list-json-schema.d.ts +2 -2
- package/dist/aas/submodel-base/submodel-element-schema.d.ts +5 -5
- package/dist/aas/submodel-base/submodel-json-schema.d.ts +3 -3
- package/dist/permalinks/permalink.dto.d.ts +2 -2
- package/dist/presentation-configurations/presentation-configuration.dto.d.ts +6 -6
- package/dist/unique-product-identifiers/gs1/gs1-data-attributes.dto.d.ts +9 -8
- package/dist/unique-product-identifiers/gs1/gs1-data-attributes.dto.d.ts.map +1 -1
- package/dist/unique-product-identifiers/gs1/gs1-data-attributes.dto.js +25 -28
- package/package.json +3 -3
- package/src/unique-product-identifiers/gs1/gs1-data-attributes.dto.spec.ts +44 -0
- package/src/unique-product-identifiers/gs1/gs1-data-attributes.dto.ts +26 -28
|
@@ -41,7 +41,7 @@ export declare const AnnotatedRelationshipElementJsonSchema: z.ZodLazy<z.ZodObje
|
|
|
41
41
|
value: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
42
|
refersTo: z.ZodDefault<z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>;
|
|
43
43
|
}, z.core.$strip>>>;
|
|
44
|
-
annotations: z.ZodDefault<z.ZodArray<z.
|
|
44
|
+
annotations: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
45
45
|
[x: string]: unknown;
|
|
46
46
|
modelType: string;
|
|
47
47
|
idShort: string;
|
|
@@ -258,7 +258,7 @@ export declare function AnnotatedRelationshipElementJsonSchemaImpl(): z.ZodObjec
|
|
|
258
258
|
value: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
259
259
|
refersTo: z.ZodDefault<z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>;
|
|
260
260
|
}, z.core.$strip>>>;
|
|
261
|
-
annotations: z.ZodDefault<z.ZodArray<z.
|
|
261
|
+
annotations: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
262
262
|
[x: string]: unknown;
|
|
263
263
|
modelType: string;
|
|
264
264
|
idShort: string;
|
|
@@ -43,7 +43,7 @@ export declare const EntityTypeJsonSchema: z.ZodLazy<z.ZodObject<{
|
|
|
43
43
|
value: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
44
44
|
refersTo: z.ZodDefault<z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>;
|
|
45
45
|
}, z.core.$strip>>>;
|
|
46
|
-
statements: z.ZodDefault<z.ZodArray<z.
|
|
46
|
+
statements: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
47
47
|
[x: string]: unknown;
|
|
48
48
|
modelType: string;
|
|
49
49
|
idShort: string;
|
|
@@ -270,7 +270,7 @@ export declare function EntityTypeJsonSchemaImpl(): z.ZodObject<{
|
|
|
270
270
|
value: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
271
271
|
refersTo: z.ZodDefault<z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>;
|
|
272
272
|
}, z.core.$strip>>>;
|
|
273
|
-
statements: z.ZodDefault<z.ZodArray<z.
|
|
273
|
+
statements: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
274
274
|
[x: string]: unknown;
|
|
275
275
|
modelType: string;
|
|
276
276
|
idShort: string;
|
|
@@ -39,7 +39,7 @@ export declare const SubmodelElementCollectionJsonSchema: z.ZodLazy<z.ZodObject<
|
|
|
39
39
|
value: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
40
|
refersTo: z.ZodDefault<z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>;
|
|
41
41
|
}, z.core.$strip>>>;
|
|
42
|
-
value: z.ZodDefault<z.ZodArray<z.
|
|
42
|
+
value: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
43
43
|
[x: string]: unknown;
|
|
44
44
|
modelType: string;
|
|
45
45
|
idShort: string;
|
|
@@ -254,7 +254,7 @@ export declare function SubmodelElementCollectionJsonSchemaImpl(): z.ZodObject<{
|
|
|
254
254
|
value: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
255
255
|
refersTo: z.ZodDefault<z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>;
|
|
256
256
|
}, z.core.$strip>>>;
|
|
257
|
-
value: z.ZodDefault<z.ZodArray<z.
|
|
257
|
+
value: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
258
258
|
[x: string]: unknown;
|
|
259
259
|
modelType: string;
|
|
260
260
|
idShort: string;
|
|
@@ -93,7 +93,7 @@ export declare const SubmodelElementListJsonSchema: z.ZodLazy<z.ZodObject<{
|
|
|
93
93
|
readonly UnsignedLong: "UnsignedLong";
|
|
94
94
|
readonly UnsignedShort: "UnsignedShort";
|
|
95
95
|
}>>>>;
|
|
96
|
-
value: z.ZodDefault<z.ZodArray<z.
|
|
96
|
+
value: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
97
97
|
[x: string]: unknown;
|
|
98
98
|
modelType: string;
|
|
99
99
|
idShort: string;
|
|
@@ -362,7 +362,7 @@ export declare function SubmodelElementListJsonSchemaImpl(): z.ZodObject<{
|
|
|
362
362
|
readonly UnsignedLong: "UnsignedLong";
|
|
363
363
|
readonly UnsignedShort: "UnsignedShort";
|
|
364
364
|
}>>>>;
|
|
365
|
-
value: z.ZodDefault<z.ZodArray<z.
|
|
365
|
+
value: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
366
366
|
[x: string]: unknown;
|
|
367
367
|
modelType: string;
|
|
368
368
|
idShort: string;
|
|
@@ -166,7 +166,7 @@ export declare function SubmodelElementSchemaJsonImpl(): z.ZodDiscriminatedUnion
|
|
|
166
166
|
value: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
167
167
|
refersTo: z.ZodDefault<z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>;
|
|
168
168
|
}, z.core.$strip>>>;
|
|
169
|
-
annotations: z.ZodDefault<z.ZodArray<z.
|
|
169
|
+
annotations: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
170
170
|
[x: string]: unknown;
|
|
171
171
|
modelType: string;
|
|
172
172
|
idShort: string;
|
|
@@ -547,7 +547,7 @@ export declare function SubmodelElementSchemaJsonImpl(): z.ZodDiscriminatedUnion
|
|
|
547
547
|
value: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
548
548
|
refersTo: z.ZodDefault<z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>;
|
|
549
549
|
}, z.core.$strip>>>;
|
|
550
|
-
statements: z.ZodDefault<z.ZodArray<z.
|
|
550
|
+
statements: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
551
551
|
[x: string]: unknown;
|
|
552
552
|
modelType: string;
|
|
553
553
|
idShort: string;
|
|
@@ -1838,7 +1838,7 @@ export declare function SubmodelElementSchemaJsonImpl(): z.ZodDiscriminatedUnion
|
|
|
1838
1838
|
value: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1839
1839
|
refersTo: z.ZodDefault<z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>;
|
|
1840
1840
|
}, z.core.$strip>>>;
|
|
1841
|
-
value: z.ZodDefault<z.ZodArray<z.
|
|
1841
|
+
value: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
1842
1842
|
[x: string]: unknown;
|
|
1843
1843
|
modelType: string;
|
|
1844
1844
|
idShort: string;
|
|
@@ -2107,7 +2107,7 @@ export declare function SubmodelElementSchemaJsonImpl(): z.ZodDiscriminatedUnion
|
|
|
2107
2107
|
readonly UnsignedLong: "UnsignedLong";
|
|
2108
2108
|
readonly UnsignedShort: "UnsignedShort";
|
|
2109
2109
|
}>>>>;
|
|
2110
|
-
value: z.ZodDefault<z.ZodArray<z.
|
|
2110
|
+
value: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
2111
2111
|
[x: string]: unknown;
|
|
2112
2112
|
modelType: string;
|
|
2113
2113
|
idShort: string;
|
|
@@ -2284,7 +2284,7 @@ export declare function SubmodelElementSchemaJsonImpl(): z.ZodDiscriminatedUnion
|
|
|
2284
2284
|
modelType: z.ZodLiteral<"SubmodelElementList">;
|
|
2285
2285
|
}, z.core.$strip>], "modelType">;
|
|
2286
2286
|
export declare const SubmodelElementPaginationResponseDtoSchema: z.ZodObject<{
|
|
2287
|
-
result: z.ZodArray<z.
|
|
2287
|
+
result: z.ZodArray<z.ZodTypeAny<{
|
|
2288
2288
|
[x: string]: unknown;
|
|
2289
2289
|
modelType: string;
|
|
2290
2290
|
idShort: string;
|
|
@@ -48,7 +48,7 @@ export declare const SubmodelJsonSchema: z.ZodObject<{
|
|
|
48
48
|
readonly Template: "Template";
|
|
49
49
|
readonly Instance: "Instance";
|
|
50
50
|
}>>>;
|
|
51
|
-
submodelElements: z.ZodDefault<z.ZodArray<z.
|
|
51
|
+
submodelElements: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
52
52
|
[x: string]: unknown;
|
|
53
53
|
modelType: string;
|
|
54
54
|
idShort: string;
|
|
@@ -273,7 +273,7 @@ export declare const SubmodelPaginationResponseDtoSchema: z.ZodObject<{
|
|
|
273
273
|
readonly Template: "Template";
|
|
274
274
|
readonly Instance: "Instance";
|
|
275
275
|
}>>>;
|
|
276
|
-
submodelElements: z.ZodDefault<z.ZodArray<z.
|
|
276
|
+
submodelElements: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
277
277
|
[x: string]: unknown;
|
|
278
278
|
modelType: string;
|
|
279
279
|
idShort: string;
|
|
@@ -502,7 +502,7 @@ export declare const SubmodelRequestDtoSchema: z.ZodObject<{
|
|
|
502
502
|
readonly Template: "Template";
|
|
503
503
|
readonly Instance: "Instance";
|
|
504
504
|
}>>>;
|
|
505
|
-
submodelElements: z.ZodDefault<z.ZodArray<z.
|
|
505
|
+
submodelElements: z.ZodDefault<z.ZodArray<z.ZodTypeAny<{
|
|
506
506
|
[x: string]: unknown;
|
|
507
507
|
modelType: string;
|
|
508
508
|
idShort: string;
|
|
@@ -3835,7 +3835,7 @@ export declare const PassportPermalinkBundleDtoSchema: z.ZodObject<{
|
|
|
3835
3835
|
label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
3836
3836
|
elementDesign: z.ZodDefault<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
3837
3837
|
readonly BigNumber: "BigNumber";
|
|
3838
|
-
}
|
|
3838
|
+
}>>, unknown>>;
|
|
3839
3839
|
defaultComponents: z.ZodDefault<z.ZodPreprocess<z.ZodRecord<z.ZodEnum<{
|
|
3840
3840
|
readonly AnnotatedRelationshipElement: "AnnotatedRelationshipElement";
|
|
3841
3841
|
readonly AssetAdministrationShell: "AssetAdministrationShell";
|
|
@@ -3863,7 +3863,7 @@ export declare const PassportPermalinkBundleDtoSchema: z.ZodObject<{
|
|
|
3863
3863
|
readonly SubmodelElementList: "SubmodelElementList";
|
|
3864
3864
|
}> & z.core.$partial, z.ZodEnum<{
|
|
3865
3865
|
readonly BigNumber: "BigNumber";
|
|
3866
|
-
}
|
|
3866
|
+
}>>, unknown>>;
|
|
3867
3867
|
createdAt: z.ZodUnion<readonly [z.ZodISODateTime, z.ZodDate]>;
|
|
3868
3868
|
updatedAt: z.ZodUnion<readonly [z.ZodISODateTime, z.ZodDate]>;
|
|
3869
3869
|
}, z.core.$strip>>;
|
|
@@ -17,7 +17,7 @@ export declare const PresentationConfigurationDtoSchema: z.ZodObject<{
|
|
|
17
17
|
label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
18
18
|
elementDesign: z.ZodDefault<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
19
19
|
readonly BigNumber: "BigNumber";
|
|
20
|
-
}
|
|
20
|
+
}>>, unknown>>;
|
|
21
21
|
defaultComponents: z.ZodDefault<z.ZodPreprocess<z.ZodRecord<z.ZodEnum<{
|
|
22
22
|
readonly AnnotatedRelationshipElement: "AnnotatedRelationshipElement";
|
|
23
23
|
readonly AssetAdministrationShell: "AssetAdministrationShell";
|
|
@@ -45,7 +45,7 @@ export declare const PresentationConfigurationDtoSchema: z.ZodObject<{
|
|
|
45
45
|
readonly SubmodelElementList: "SubmodelElementList";
|
|
46
46
|
}> & z.core.$partial, z.ZodEnum<{
|
|
47
47
|
readonly BigNumber: "BigNumber";
|
|
48
|
-
}
|
|
48
|
+
}>>, unknown>>;
|
|
49
49
|
createdAt: z.ZodUnion<readonly [z.ZodISODateTime, z.ZodDate]>;
|
|
50
50
|
updatedAt: z.ZodUnion<readonly [z.ZodISODateTime, z.ZodDate]>;
|
|
51
51
|
}, z.core.$strip>;
|
|
@@ -62,7 +62,7 @@ export declare const PresentationConfigurationInvariantsSchema: z.ZodObject<{
|
|
|
62
62
|
export declare const PresentationConfigurationExportSchema: z.ZodObject<{
|
|
63
63
|
elementDesign: z.ZodDefault<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
64
64
|
readonly BigNumber: "BigNumber";
|
|
65
|
-
}
|
|
65
|
+
}>>, unknown>>;
|
|
66
66
|
defaultComponents: z.ZodDefault<z.ZodPreprocess<z.ZodRecord<z.ZodEnum<{
|
|
67
67
|
readonly AnnotatedRelationshipElement: "AnnotatedRelationshipElement";
|
|
68
68
|
readonly AssetAdministrationShell: "AssetAdministrationShell";
|
|
@@ -90,7 +90,7 @@ export declare const PresentationConfigurationExportSchema: z.ZodObject<{
|
|
|
90
90
|
readonly SubmodelElementList: "SubmodelElementList";
|
|
91
91
|
}> & z.core.$partial, z.ZodEnum<{
|
|
92
92
|
readonly BigNumber: "BigNumber";
|
|
93
|
-
}
|
|
93
|
+
}>>, unknown>>;
|
|
94
94
|
}, z.core.$strip>;
|
|
95
95
|
export type PresentationConfigurationExportDto = z.infer<typeof PresentationConfigurationExportSchema>;
|
|
96
96
|
export declare const PresentationConfigurationCreateRequestSchema: z.ZodObject<{
|
|
@@ -108,7 +108,7 @@ export declare const PresentationConfigurationListResponseSchema: z.ZodArray<z.Z
|
|
|
108
108
|
label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
109
109
|
elementDesign: z.ZodDefault<z.ZodPreprocess<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
110
110
|
readonly BigNumber: "BigNumber";
|
|
111
|
-
}
|
|
111
|
+
}>>, unknown>>;
|
|
112
112
|
defaultComponents: z.ZodDefault<z.ZodPreprocess<z.ZodRecord<z.ZodEnum<{
|
|
113
113
|
readonly AnnotatedRelationshipElement: "AnnotatedRelationshipElement";
|
|
114
114
|
readonly AssetAdministrationShell: "AssetAdministrationShell";
|
|
@@ -136,7 +136,7 @@ export declare const PresentationConfigurationListResponseSchema: z.ZodArray<z.Z
|
|
|
136
136
|
readonly SubmodelElementList: "SubmodelElementList";
|
|
137
137
|
}> & z.core.$partial, z.ZodEnum<{
|
|
138
138
|
readonly BigNumber: "BigNumber";
|
|
139
|
-
}
|
|
139
|
+
}>>, unknown>>;
|
|
140
140
|
createdAt: z.ZodUnion<readonly [z.ZodISODateTime, z.ZodDate]>;
|
|
141
141
|
updatedAt: z.ZodUnion<readonly [z.ZodISODateTime, z.ZodDate]>;
|
|
142
142
|
}, z.core.$strip>>;
|
|
@@ -9,15 +9,16 @@ import { z } from "zod";
|
|
|
9
9
|
* satisfy the format/length rules for the corresponding AI.
|
|
10
10
|
*
|
|
11
11
|
* An empty map `{}` is accepted.
|
|
12
|
-
* Non-object input (array, string, null, undefined)
|
|
13
|
-
* `z.partialRecord` schema
|
|
12
|
+
* Non-object input (array, string, null, undefined) and non-string values are
|
|
13
|
+
* rejected by the base `z.partialRecord` schema; the value check does not run
|
|
14
|
+
* for them.
|
|
14
15
|
*
|
|
15
|
-
* Error reporting
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
16
|
+
* Error reporting: all unknown AIs share one issue on the map itself. The
|
|
17
|
+
* values of the known AIs are checked as well, so a map with an unknown AI and
|
|
18
|
+
* an invalid value reports both. Among invalid values, only the first (in key
|
|
19
|
+
* order) is reported: a single value check can cost ~100ms on adversarial
|
|
20
|
+
* input (see GS1_DATA_ATTRIBUTE_MAX_LENGTH), so checking every entry would let
|
|
21
|
+
* one request multiply that by the number of entries.
|
|
21
22
|
*
|
|
22
23
|
* Pure module: no DOM or Node-only globals required at import time.
|
|
23
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gs1-data-attributes.dto.d.ts","sourceRoot":"","sources":["../../../src/unique-product-identifiers/gs1/gs1-data-attributes.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"gs1-data-attributes.dto.d.ts","sourceRoot":"","sources":["../../../src/unique-product-identifiers/gs1/gs1-data-attributes.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA4BxB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAUA,CAAC;AAErC,4EAA4E;AAC5E,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|
|
@@ -6,20 +6,23 @@ const gs1_ai_constants_1 = require("./gs1-ai-constants");
|
|
|
6
6
|
const gs1_digital_link_1 = require("./gs1-digital-link");
|
|
7
7
|
/** Cap on how much of an unknown AI key is echoed back in an error message. */
|
|
8
8
|
const MAX_ECHOED_KEY_LENGTH = 50;
|
|
9
|
-
const unknownAiMessage = (
|
|
10
|
-
const
|
|
11
|
-
const echoed =
|
|
9
|
+
const unknownAiMessage = (key) => {
|
|
10
|
+
const text = String(key);
|
|
11
|
+
const echoed = text.length > MAX_ECHOED_KEY_LENGTH ? `${text.slice(0, MAX_ECHOED_KEY_LENGTH)}…` : text;
|
|
12
12
|
return `"${echoed}" is not a known GS1 data-attribute AI`;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Error map for the map itself: names every key that is no GS1 data-attribute
|
|
16
|
+
* AI, and leaves all other issues to zod's default message.
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
18
|
+
* zod reports those keys as one `unrecognized_keys` issue on the record, with
|
|
19
|
+
* the keys in `issue.keys`. Its default message is replaced because it echoes
|
|
20
|
+
* each key in full. zod's typings for a record's issues do not list that code,
|
|
21
|
+
* hence the loose parameter type.
|
|
19
22
|
*/
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const unknownAiKeysErrorMap = (issue) => issue.code === "unrecognized_keys" && Array.isArray(issue.keys)
|
|
24
|
+
? issue.keys.map(unknownAiMessage).join("; ")
|
|
25
|
+
: undefined;
|
|
23
26
|
/**
|
|
24
27
|
* Zod schema for a map of GS1 data-attribute Application Identifiers to their values.
|
|
25
28
|
*
|
|
@@ -30,31 +33,25 @@ const Gs1DataAttributeAiSchema = zod_1.z.enum(gs1_ai_constants_1.Gs1DataAttribut
|
|
|
30
33
|
* satisfy the format/length rules for the corresponding AI.
|
|
31
34
|
*
|
|
32
35
|
* An empty map `{}` is accepted.
|
|
33
|
-
* Non-object input (array, string, null, undefined)
|
|
34
|
-
* `z.partialRecord` schema
|
|
36
|
+
* Non-object input (array, string, null, undefined) and non-string values are
|
|
37
|
+
* rejected by the base `z.partialRecord` schema; the value check does not run
|
|
38
|
+
* for them.
|
|
35
39
|
*
|
|
36
|
-
* Error reporting
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* Error reporting: all unknown AIs share one issue on the map itself. The
|
|
41
|
+
* values of the known AIs are checked as well, so a map with an unknown AI and
|
|
42
|
+
* an invalid value reports both. Among invalid values, only the first (in key
|
|
43
|
+
* order) is reported: a single value check can cost ~100ms on adversarial
|
|
44
|
+
* input (see GS1_DATA_ATTRIBUTE_MAX_LENGTH), so checking every entry would let
|
|
45
|
+
* one request multiply that by the number of entries.
|
|
42
46
|
*
|
|
43
47
|
* Pure module: no DOM or Node-only globals required at import time.
|
|
44
48
|
*/
|
|
45
49
|
exports.Gs1DataAttributesSchema = zod_1.z
|
|
46
|
-
.partialRecord(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.check((ctx) => {
|
|
50
|
-
for (const [ai, value] of Object.entries(ctx.value)) {
|
|
50
|
+
.partialRecord(zod_1.z.enum(gs1_ai_constants_1.Gs1DataAttributeAi), zod_1.z.string(), { error: unknownAiKeysErrorMap })
|
|
51
|
+
.superRefine((attributes, ctx) => {
|
|
52
|
+
for (const [ai, value] of Object.entries(attributes)) {
|
|
51
53
|
if (!(0, gs1_digital_link_1.isValidGs1DataAttributeValue)(ai, value)) {
|
|
52
|
-
ctx.
|
|
53
|
-
code: "custom",
|
|
54
|
-
input: ctx.value,
|
|
55
|
-
message: `value for AI "${ai}" is invalid`,
|
|
56
|
-
path: [ai],
|
|
57
|
-
});
|
|
54
|
+
ctx.addIssue({ code: "custom", message: `value for AI "${ai}" is invalid`, path: [ai] });
|
|
58
55
|
return;
|
|
59
56
|
}
|
|
60
57
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-dpp/dto",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/open-dpp/open-dpp#readme",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"uuid": "^13.0.2",
|
|
36
|
-
"zod": "^4.
|
|
36
|
+
"zod": "^4.6.7"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@tsconfig/node-lts": "^24.0.1",
|
|
40
40
|
"@tsconfig/node-ts": "^23.6.5",
|
|
41
|
-
"@types/node": "^26.6.
|
|
41
|
+
"@types/node": "^26.6.11",
|
|
42
42
|
"typescript": "~6.0.3"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { Gs1DataAttributesSchema } from "./gs1-data-attributes.dto";
|
|
3
3
|
|
|
4
|
+
const messagesFor = (input: unknown): string[] => {
|
|
5
|
+
const result = Gs1DataAttributesSchema.safeParse(input);
|
|
6
|
+
return result.success ? [] : result.error.issues.map((issue) => issue.message);
|
|
7
|
+
};
|
|
8
|
+
|
|
4
9
|
describe("Gs1DataAttributesSchema", () => {
|
|
5
10
|
it("accepts a valid map and the empty map", () => {
|
|
6
11
|
expect(Gs1DataAttributesSchema.safeParse({ "17": "251231", "90": "ABC" }).success).toBe(true);
|
|
@@ -15,6 +20,45 @@ describe("Gs1DataAttributesSchema", () => {
|
|
|
15
20
|
}
|
|
16
21
|
});
|
|
17
22
|
|
|
23
|
+
it("rejects an AI that exists but is no data attribute with the same message", () => {
|
|
24
|
+
// "01" (GTIN) is a primary identifier, not a data attribute.
|
|
25
|
+
expect(messagesFor({ "01": "09506000134352" })).toEqual([
|
|
26
|
+
'"01" is not a known GS1 data-attribute AI',
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("echoes at most 50 characters of an unknown AI key", () => {
|
|
31
|
+
const key = "k".repeat(80);
|
|
32
|
+
expect(messagesFor({ [key]: "x" })).toEqual([
|
|
33
|
+
`"${"k".repeat(50)}…" is not a known GS1 data-attribute AI`,
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("names every unknown AI key", () => {
|
|
38
|
+
expect(messagesFor({ "8888": "x", "9999": "y" })).toEqual([
|
|
39
|
+
'"8888" is not a known GS1 data-attribute AI; "9999" is not a known GS1 data-attribute AI',
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("reports an unknown AI key and an invalid value together", () => {
|
|
44
|
+
// "999999" is no valid YYMMDD date for AI 11 (see the next spec).
|
|
45
|
+
const result = Gs1DataAttributesSchema.safeParse({ "9999": "x", "11": "999999" });
|
|
46
|
+
expect(result.success).toBe(false);
|
|
47
|
+
if (!result.success) {
|
|
48
|
+
expect(result.error.issues.map(({ path, message }) => ({ path, message }))).toEqual([
|
|
49
|
+
{ path: [], message: '"9999" is not a known GS1 data-attribute AI' },
|
|
50
|
+
{ path: ["11"], message: 'value for AI "11" is invalid' },
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("reports only the first invalid value next to an unknown AI key", () => {
|
|
56
|
+
expect(messagesFor({ "9999": "x", "11": "999999", "17": "999999" })).toEqual([
|
|
57
|
+
'"9999" is not a known GS1 data-attribute AI',
|
|
58
|
+
'value for AI "11" is invalid',
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
18
62
|
it("reports only the first invalid value (bounds worst-case validation cost)", () => {
|
|
19
63
|
// Each value check may cost ~100ms on adversarial input (see
|
|
20
64
|
// GS1_DATA_ATTRIBUTE_MAX_LENGTH); reporting every failure would let one
|
|
@@ -5,22 +5,26 @@ import { isValidGs1DataAttributeValue } from "./gs1-digital-link";
|
|
|
5
5
|
/** Cap on how much of an unknown AI key is echoed back in an error message. */
|
|
6
6
|
const MAX_ECHOED_KEY_LENGTH = 50;
|
|
7
7
|
|
|
8
|
-
const unknownAiMessage = (
|
|
9
|
-
const
|
|
8
|
+
const unknownAiMessage = (key: unknown): string => {
|
|
9
|
+
const text = String(key);
|
|
10
10
|
const echoed =
|
|
11
|
-
|
|
11
|
+
text.length > MAX_ECHOED_KEY_LENGTH ? `${text.slice(0, MAX_ECHOED_KEY_LENGTH)}…` : text;
|
|
12
12
|
return `"${echoed}" is not a known GS1 data-attribute AI`;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Error map for the map itself: names every key that is no GS1 data-attribute
|
|
17
|
+
* AI, and leaves all other issues to zod's default message.
|
|
17
18
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* zod reports those keys as one `unrecognized_keys` issue on the record, with
|
|
20
|
+
* the keys in `issue.keys`. Its default message is replaced because it echoes
|
|
21
|
+
* each key in full. zod's typings for a record's issues do not list that code,
|
|
22
|
+
* hence the loose parameter type.
|
|
20
23
|
*/
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
const unknownAiKeysErrorMap = (issue: { code?: string; keys?: unknown }): string | undefined =>
|
|
25
|
+
issue.code === "unrecognized_keys" && Array.isArray(issue.keys)
|
|
26
|
+
? issue.keys.map(unknownAiMessage).join("; ")
|
|
27
|
+
: undefined;
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
30
|
* Zod schema for a map of GS1 data-attribute Application Identifiers to their values.
|
|
@@ -32,31 +36,25 @@ const Gs1DataAttributeAiSchema = z.enum(Gs1DataAttributeAi, {
|
|
|
32
36
|
* satisfy the format/length rules for the corresponding AI.
|
|
33
37
|
*
|
|
34
38
|
* An empty map `{}` is accepted.
|
|
35
|
-
* Non-object input (array, string, null, undefined)
|
|
36
|
-
* `z.partialRecord` schema
|
|
39
|
+
* Non-object input (array, string, null, undefined) and non-string values are
|
|
40
|
+
* rejected by the base `z.partialRecord` schema; the value check does not run
|
|
41
|
+
* for them.
|
|
37
42
|
*
|
|
38
|
-
* Error reporting
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
43
|
+
* Error reporting: all unknown AIs share one issue on the map itself. The
|
|
44
|
+
* values of the known AIs are checked as well, so a map with an unknown AI and
|
|
45
|
+
* an invalid value reports both. Among invalid values, only the first (in key
|
|
46
|
+
* order) is reported: a single value check can cost ~100ms on adversarial
|
|
47
|
+
* input (see GS1_DATA_ATTRIBUTE_MAX_LENGTH), so checking every entry would let
|
|
48
|
+
* one request multiply that by the number of entries.
|
|
44
49
|
*
|
|
45
50
|
* Pure module: no DOM or Node-only globals required at import time.
|
|
46
51
|
*/
|
|
47
52
|
export const Gs1DataAttributesSchema = z
|
|
48
|
-
.partialRecord(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.check((ctx) => {
|
|
52
|
-
for (const [ai, value] of Object.entries(ctx.value)) {
|
|
53
|
+
.partialRecord(z.enum(Gs1DataAttributeAi), z.string(), { error: unknownAiKeysErrorMap })
|
|
54
|
+
.superRefine((attributes, ctx) => {
|
|
55
|
+
for (const [ai, value] of Object.entries(attributes)) {
|
|
53
56
|
if (!isValidGs1DataAttributeValue(ai, value)) {
|
|
54
|
-
ctx.
|
|
55
|
-
code: "custom",
|
|
56
|
-
input: ctx.value,
|
|
57
|
-
message: `value for AI "${ai}" is invalid`,
|
|
58
|
-
path: [ai],
|
|
59
|
-
});
|
|
57
|
+
ctx.addIssue({ code: "custom", message: `value for AI "${ai}" is invalid`, path: [ai] });
|
|
60
58
|
return;
|
|
61
59
|
}
|
|
62
60
|
}
|