@digitraffic/common 2026.1.9-1 → 2026.1.9-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/utils/zod-utils.d.ts +16 -0
- package/dist/utils/zod-utils.js +31 -0
- package/package.json +2 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Functions for validating and parsing e.g. path and query parameters with zod.
|
|
4
|
+
* The value of the message parameter will appear in the zod error object resulting from failed validation.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* const mySchema = z
|
|
8
|
+
* .object({
|
|
9
|
+
* myParameter: z
|
|
10
|
+
* .zStringToDate("Invalid value of myParameter")
|
|
11
|
+
* .optional()
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export declare function zStringToNumber(message?: string): z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>;
|
|
16
|
+
export declare function zStringToDate(message?: string): z.ZodPipe<z.ZodString, z.ZodTransform<Date | undefined, string>>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Functions for validating and parsing e.g. path and query parameters with zod.
|
|
4
|
+
* The value of the message parameter will appear in the zod error object resulting from failed validation.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* const mySchema = z
|
|
8
|
+
* .object({
|
|
9
|
+
* myParameter: z
|
|
10
|
+
* .zStringToDate("Invalid value of myParameter")
|
|
11
|
+
* .optional()
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export function zStringToNumber(message) {
|
|
16
|
+
return z
|
|
17
|
+
.string()
|
|
18
|
+
.transform(Number)
|
|
19
|
+
.refine((vesselId) => !Number.isNaN(vesselId), {
|
|
20
|
+
message: message ? message : "Not a number",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function zStringToDate(message) {
|
|
24
|
+
return z
|
|
25
|
+
.string()
|
|
26
|
+
.transform((val) => (val ? new Date(val) : undefined))
|
|
27
|
+
.refine((date) => !date || !Number.isNaN(date.getTime()), {
|
|
28
|
+
message: message ? message : "Invalid date format",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=zod-utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitraffic/common",
|
|
3
|
-
"version": "2026.01.09-
|
|
3
|
+
"version": "2026.01.09-3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"repository": {
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
"@types/jest": "30.0.0",
|
|
129
129
|
"@types/lodash-es": "4.17.12",
|
|
130
130
|
"@types/madge": "5.0.3",
|
|
131
|
-
"@types/node": "22.19.
|
|
131
|
+
"@types/node": "22.19.3",
|
|
132
132
|
"aws-cdk-lib": "2.234.0",
|
|
133
133
|
"change-case": "5.4.4",
|
|
134
134
|
"constructs": "10.4.4",
|