Skip to content

Commit 198c83e

Browse files
committed
feat: zod v4 migration
1 parent 2235d4c commit 198c83e

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

packages/temporal-zod/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"temporal-polyfill": "^0.3.0",
3131
"typescript": "^5.8.2",
3232
"vitest": "^3.1.1",
33-
"zod": "^3.24.2"
33+
"zod": "^4"
3434
},
3535
"main": "dist/index.js",
3636
"types": "dist/index.d.ts",
@@ -56,6 +56,6 @@
5656
},
5757
"peerDependencies": {
5858
"temporal-polyfill": "^0.2 || ^0.3",
59-
"zod": "^3.24.1"
59+
"zod": "^4"
6060
}
6161
}

packages/temporal-zod/src/base/instant.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ const validators = temporalValidators(Instant);
1010
/**
1111
* Validates or coerces a string or Date to a {@link Temporal.Instant}.
1212
*/
13-
export const zInstant: z.ZodType<
14-
Temporal.Instant,
15-
z.ZodTypeDef,
16-
Temporal.Instant | string | Date
17-
> = z.union([
13+
export const zInstant = z.union([
1814
validators.coerce,
1915
z
2016
.date()
2117
.transform((value) =>
2218
Temporal.Instant.fromEpochMilliseconds(value.getTime()),
2319
),
24-
]);
20+
]) as z.ZodType<Temporal.Instant>;
2521

2622
/**
2723
* Validates that the value is an instance of {@link Temporal.Instant}.

packages/temporal-zod/src/base/temporalValidator.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ export type ZodTemporal<
1212
TClass extends typeof Class & {
1313
from: (arg: string) => InstanceType<TClass>;
1414
},
15-
> = z.ZodType<
16-
InstanceType<TClass>,
17-
z.ZodTypeDef,
18-
InstanceType<TClass> | string
19-
>;
15+
> = z.ZodType<InstanceType<TClass>>;
2016

2117
/**
2218
* Creates Zod validators for a Temporal class.
@@ -40,9 +36,10 @@ export function temporalValidators<
4036
try {
4137
return cls.from(value);
4238
} catch (error: unknown) {
43-
ctx.addIssue({
44-
code: z.ZodIssueCode.invalid_date,
39+
ctx.issues.push({
40+
code: "custom",
4541
message: `Invalid ${cls.name}: ${(error as { message?: string }).message ?? "unknown error"}`,
42+
input: value,
4643
});
4744
return z.NEVER;
4845
}

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)