@clipboard-health/contract-core 2.3.0 → 2.3.2
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/README.md
CHANGED
|
@@ -96,13 +96,18 @@ try {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// DateTime schema examples
|
|
99
|
-
//
|
|
99
|
+
// Accepts ISO-8601 datetime strings and Date objects, normalizes to Date.
|
|
100
100
|
// Composable with .optional(), .nullable(), etc.
|
|
101
101
|
const createdAt = dateTimeSchema().parse("2026-03-15T10:30:00.000Z");
|
|
102
102
|
// => Date object
|
|
103
103
|
console.log(createdAt instanceof Date); // true
|
|
104
104
|
console.log(createdAt.toISOString()); // "2026-03-15T10:30:00.000Z"
|
|
105
105
|
|
|
106
|
+
// Date objects pass through as-is
|
|
107
|
+
const fromDate = dateTimeSchema().parse(new Date("2026-03-15T10:30:00.000Z"));
|
|
108
|
+
// => Date object
|
|
109
|
+
console.log(fromDate instanceof Date); // true
|
|
110
|
+
|
|
106
111
|
try {
|
|
107
112
|
dateTimeSchema().parse("2026-03-15"); // date-only string
|
|
108
113
|
} catch (error) {
|
|
@@ -114,7 +119,7 @@ try {
|
|
|
114
119
|
dateTimeSchema().parse(1_773_340_050_000); // epoch number
|
|
115
120
|
} catch (error) {
|
|
116
121
|
logError(error);
|
|
117
|
-
// =>
|
|
122
|
+
// => Invalid union
|
|
118
123
|
}
|
|
119
124
|
|
|
120
125
|
// Optional usage — compose at the call site
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/contract-core",
|
|
3
3
|
"description": "Shared Zod schemas for Clipboard's contracts.",
|
|
4
|
-
"version": "2.3.
|
|
4
|
+
"version": "2.3.2",
|
|
5
5
|
"bugs": "https://github.com/ClipboardHealth/core-utils/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"tslib": "2.8.1"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@clipboard-health/testing-core": "2.2.
|
|
10
|
+
"@clipboard-health/testing-core": "2.2.43",
|
|
11
11
|
"zod": "3.25.76"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
/**
|
|
3
|
-
* Validates
|
|
4
|
-
*
|
|
3
|
+
* Validates datetime inputs and normalizes them to Date objects.
|
|
4
|
+
*
|
|
5
|
+
* Accepts:
|
|
6
|
+
* - ISO-8601 datetime strings (validated strictly)
|
|
7
|
+
* - Date objects (passed through as-is)
|
|
8
|
+
*
|
|
9
|
+
* Rejects epoch numbers, date-only strings, and other loose inputs.
|
|
5
10
|
*
|
|
6
11
|
* Composable with `.optional()`, `.nullable()`, etc. at the call site:
|
|
7
12
|
* ```ts
|
|
@@ -11,9 +16,7 @@ import { z } from "zod";
|
|
|
11
16
|
* });
|
|
12
17
|
* ```
|
|
13
18
|
*
|
|
14
|
-
* z.input → string
|
|
15
|
-
* z.output → Date
|
|
16
|
-
*
|
|
17
|
-
* Requires `parsedApi.ts` so that schemas are parsed at runtime.
|
|
19
|
+
* z.input → string | Date
|
|
20
|
+
* z.output → Date
|
|
18
21
|
*/
|
|
19
|
-
export declare function dateTimeSchema(): z.ZodEffects<z.ZodString, Date, string>;
|
|
22
|
+
export declare function dateTimeSchema(): z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodDate]>, Date, string | Date>;
|
|
@@ -3,8 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.dateTimeSchema = dateTimeSchema;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
/**
|
|
6
|
-
* Validates
|
|
7
|
-
*
|
|
6
|
+
* Validates datetime inputs and normalizes them to Date objects.
|
|
7
|
+
*
|
|
8
|
+
* Accepts:
|
|
9
|
+
* - ISO-8601 datetime strings (validated strictly)
|
|
10
|
+
* - Date objects (passed through as-is)
|
|
11
|
+
*
|
|
12
|
+
* Rejects epoch numbers, date-only strings, and other loose inputs.
|
|
8
13
|
*
|
|
9
14
|
* Composable with `.optional()`, `.nullable()`, etc. at the call site:
|
|
10
15
|
* ```ts
|
|
@@ -14,15 +19,12 @@ const zod_1 = require("zod");
|
|
|
14
19
|
* });
|
|
15
20
|
* ```
|
|
16
21
|
*
|
|
17
|
-
* z.input → string
|
|
18
|
-
* z.output → Date
|
|
19
|
-
*
|
|
20
|
-
* Requires `parsedApi.ts` so that schemas are parsed at runtime.
|
|
22
|
+
* z.input → string | Date
|
|
23
|
+
* z.output → Date
|
|
21
24
|
*/
|
|
22
25
|
function dateTimeSchema() {
|
|
23
26
|
return zod_1.z
|
|
24
|
-
.string()
|
|
25
|
-
.
|
|
26
|
-
.transform((value) => new Date(value));
|
|
27
|
+
.union([zod_1.z.string().datetime(), zod_1.z.date()])
|
|
28
|
+
.transform((value) => (value instanceof Date ? value : new Date(value)));
|
|
27
29
|
}
|
|
28
30
|
//# sourceMappingURL=dateTime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateTime.js","sourceRoot":"","sources":["../../../../../../packages/contract-core/src/lib/schemas/dateTime.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"dateTime.js","sourceRoot":"","sources":["../../../../../../packages/contract-core/src/lib/schemas/dateTime.ts"],"names":[],"mappings":";;AAsBA,wCAIC;AA1BD,6BAAwB;AAExB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,cAAc;IAC5B,OAAO,OAAC;SACL,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,OAAC,CAAC,IAAI,EAAE,CAAC,CAAC;SACxC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|