zod 3.25.18 → 3.25.21
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/cjs/v4/classic/tests/index.test.js +5 -4
- package/dist/types/v4/classic/schemas.d.ts +1 -1
- package/dist/types/v4/core/errors.d.ts +2 -1
- package/dist/types/v4/core/schemas.d.ts +3 -1
- package/package.json +1 -1
- package/src/v4/classic/schemas.ts +3 -3
- package/src/v4/classic/tests/error-utils.test.ts +2 -0
- package/src/v4/classic/tests/index.test.ts +5 -5
- package/src/v4/core/errors.ts +3 -1
- package/src/v4/core/schemas.ts +4 -1
|
@@ -594,15 +594,16 @@ const z = __importStar(require("zod/v4"));
|
|
|
594
594
|
(0, vitest_1.expect)(() => z.parse(e, 123)).toThrow();
|
|
595
595
|
});
|
|
596
596
|
// this returns both a schema and a check
|
|
597
|
-
(0, vitest_1.test)("z.custom", () => {
|
|
597
|
+
(0, vitest_1.test)("z.custom schema", () => {
|
|
598
598
|
const a = z.custom((val) => {
|
|
599
599
|
return typeof val === "string";
|
|
600
600
|
});
|
|
601
601
|
(0, vitest_1.expect)(z.parse(a, "hello")).toEqual("hello");
|
|
602
602
|
(0, vitest_1.expect)(() => z.parse(a, 123)).toThrow();
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
603
|
+
});
|
|
604
|
+
(0, vitest_1.test)("z.custom check", () => {
|
|
605
|
+
// @ts-expect-error Inference not possible, use z.refine()
|
|
606
|
+
z.date().check(z.custom((val) => val.getTime() > 0));
|
|
606
607
|
});
|
|
607
608
|
(0, vitest_1.test)("z.check", () => {
|
|
608
609
|
// this is a more flexible version of z.custom that accepts an arbitrary _parse logic
|
|
@@ -631,7 +631,7 @@ export interface ZodCustom<O = unknown, I = unknown> extends ZodType {
|
|
|
631
631
|
}
|
|
632
632
|
export declare const ZodCustom: core.$constructor<ZodCustom>;
|
|
633
633
|
export declare function check<O = unknown>(fn: core.CheckFn<O>, params?: string | core.$ZodCustomParams): core.$ZodCheck<O>;
|
|
634
|
-
export declare function custom<O
|
|
634
|
+
export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
|
|
635
635
|
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
|
|
636
636
|
export declare function superRefine<T>(fn: (arg: T, payload: RefinementCtx<T>) => void | Promise<void>, params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
|
|
637
637
|
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
|
|
@@ -67,7 +67,7 @@ export interface $ZodIssueInvalidValue<Input = unknown> extends $ZodIssueBase {
|
|
|
67
67
|
readonly input: Input;
|
|
68
68
|
}
|
|
69
69
|
export interface $ZodIssueCustom extends $ZodIssueBase {
|
|
70
|
-
readonly code
|
|
70
|
+
readonly code: "custom";
|
|
71
71
|
readonly params?: Record<string, any> | undefined;
|
|
72
72
|
readonly input: unknown;
|
|
73
73
|
}
|
|
@@ -96,6 +96,7 @@ export interface $ZodIssueStringIncludes extends $ZodIssueInvalidStringFormat {
|
|
|
96
96
|
}
|
|
97
97
|
export type $ZodStringFormatIssues = $ZodIssueStringCommonFormats | $ZodIssueStringInvalidRegex | $ZodIssueStringInvalidJWT | $ZodIssueStringStartsWith | $ZodIssueStringEndsWith | $ZodIssueStringIncludes;
|
|
98
98
|
export type $ZodIssue = $ZodIssueInvalidType | $ZodIssueTooBig | $ZodIssueTooSmall | $ZodIssueInvalidStringFormat | $ZodIssueNotMultipleOf | $ZodIssueUnrecognizedKeys | $ZodIssueInvalidUnion | $ZodIssueInvalidKey | $ZodIssueInvalidElement | $ZodIssueInvalidValue | $ZodIssueCustom;
|
|
99
|
+
export type $ZodIssueCode = $ZodIssue["code"];
|
|
99
100
|
export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
|
|
100
101
|
type RawIssue<T extends $ZodIssueBase> = util.Flatten<util.MakePartial<T, "message" | "path"> & {
|
|
101
102
|
/** The input data */
|
|
@@ -723,7 +723,9 @@ export interface $ZodLiteral<T extends util.Primitive = util.Primitive> extends
|
|
|
723
723
|
_zod: $ZodLiteralInternals<T>;
|
|
724
724
|
}
|
|
725
725
|
export declare const $ZodLiteral: core.$constructor<$ZodLiteral>;
|
|
726
|
-
|
|
726
|
+
declare global {
|
|
727
|
+
interface File {
|
|
728
|
+
}
|
|
727
729
|
}
|
|
728
730
|
export interface $ZodFileDef extends $ZodTypeDef {
|
|
729
731
|
type: "file";
|
package/package.json
CHANGED
|
@@ -1962,10 +1962,10 @@ export function check<O = unknown>(fn: core.CheckFn<O>, params?: string | core.$
|
|
|
1962
1962
|
return ch;
|
|
1963
1963
|
}
|
|
1964
1964
|
|
|
1965
|
-
export function custom<O
|
|
1966
|
-
fn?: (data:
|
|
1965
|
+
export function custom<O>(
|
|
1966
|
+
fn?: (data: unknown) => unknown,
|
|
1967
1967
|
_params?: string | core.$ZodCustomParams | undefined
|
|
1968
|
-
): ZodCustom<O,
|
|
1968
|
+
): ZodCustom<O, O> {
|
|
1969
1969
|
return core._custom(ZodCustom, fn ?? (() => true), _params) as any;
|
|
1970
1970
|
}
|
|
1971
1971
|
|
|
@@ -706,17 +706,17 @@ test("z.templateLiteral", () => {
|
|
|
706
706
|
});
|
|
707
707
|
|
|
708
708
|
// this returns both a schema and a check
|
|
709
|
-
test("z.custom", () => {
|
|
709
|
+
test("z.custom schema", () => {
|
|
710
710
|
const a = z.custom((val) => {
|
|
711
711
|
return typeof val === "string";
|
|
712
712
|
});
|
|
713
713
|
expect(z.parse(a, "hello")).toEqual("hello");
|
|
714
714
|
expect(() => z.parse(a, 123)).toThrow();
|
|
715
|
+
});
|
|
715
716
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
expect(() => z.parse(b, "hi")).toThrow();
|
|
717
|
+
test("z.custom check", () => {
|
|
718
|
+
// @ts-expect-error Inference not possible, use z.refine()
|
|
719
|
+
z.date().check(z.custom((val) => val.getTime() > 0));
|
|
720
720
|
});
|
|
721
721
|
|
|
722
722
|
test("z.check", () => {
|
package/src/v4/core/errors.ts
CHANGED
|
@@ -86,7 +86,7 @@ export interface $ZodIssueInvalidValue<Input = unknown> extends $ZodIssueBase {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
export interface $ZodIssueCustom extends $ZodIssueBase {
|
|
89
|
-
readonly code
|
|
89
|
+
readonly code: "custom";
|
|
90
90
|
readonly params?: Record<string, any> | undefined;
|
|
91
91
|
readonly input: unknown;
|
|
92
92
|
}
|
|
@@ -149,6 +149,8 @@ export type $ZodIssue =
|
|
|
149
149
|
| $ZodIssueInvalidValue
|
|
150
150
|
| $ZodIssueCustom;
|
|
151
151
|
|
|
152
|
+
export type $ZodIssueCode = $ZodIssue["code"];
|
|
153
|
+
|
|
152
154
|
export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
|
|
153
155
|
type RawIssue<T extends $ZodIssueBase> = util.Flatten<
|
|
154
156
|
util.MakePartial<T, "message" | "path"> & {
|
package/src/v4/core/schemas.ts
CHANGED
|
@@ -2865,7 +2865,10 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
|
|
|
2865
2865
|
//////////////////////////////////////////
|
|
2866
2866
|
|
|
2867
2867
|
// provide a fallback in case the File interface isn't provided in the environment
|
|
2868
|
-
|
|
2868
|
+
declare global {
|
|
2869
|
+
interface File {}
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2869
2872
|
export interface $ZodFileDef extends $ZodTypeDef {
|
|
2870
2873
|
type: "file";
|
|
2871
2874
|
}
|