zod 3.25.4 → 3.25.6
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/commonjs/v3/types.d.ts +1 -1
- package/dist/commonjs/v4/classic/errors.d.ts +1 -1
- package/dist/commonjs/v4/classic/errors.js +1 -0
- package/dist/commonjs/v4/classic/parse.d.ts +1 -1
- package/dist/commonjs/v4/classic/parse.js +2 -2
- package/dist/commonjs/v4/core/errors.d.ts +1 -1
- package/dist/commonjs/v4/core/errors.js +44 -0
- package/dist/commonjs/v4/core/parse.js +2 -2
- package/dist/esm/v3/types.d.ts +1 -1
- package/dist/esm/v4/classic/errors.d.ts +1 -1
- package/dist/esm/v4/classic/errors.js +1 -0
- package/dist/esm/v4/classic/parse.d.ts +1 -1
- package/dist/esm/v4/classic/parse.js +3 -3
- package/dist/esm/v4/core/errors.d.ts +1 -1
- package/dist/esm/v4/core/errors.js +11 -0
- package/dist/esm/v4/core/parse.js +2 -2
- package/package.json +1 -1
- package/src/v3/types.ts +1 -1
- package/src/v4/classic/errors.ts +2 -1
- package/src/v4/classic/parse.ts +3 -3
- package/src/v4/classic/tests/array.test.ts +42 -46
- package/src/v4/classic/tests/async-refinements.test.ts +14 -18
- package/src/v4/classic/tests/catch.test.ts +10 -12
- package/src/v4/classic/tests/discriminated-unions.test.ts +77 -87
- package/src/v4/classic/tests/enum.test.ts +33 -39
- package/src/v4/classic/tests/error-utils.test.ts +25 -27
- package/src/v4/classic/tests/error.test.ts +115 -128
- package/src/v4/classic/tests/literal.test.ts +10 -12
- package/src/v4/classic/tests/map.test.ts +60 -68
- package/src/v4/classic/tests/nested-refine.test.ts +68 -72
- package/src/v4/classic/tests/nonoptional.test.ts +36 -44
- package/src/v4/classic/tests/number.test.ts +36 -44
- package/src/v4/classic/tests/pipe.test.ts +18 -22
- package/src/v4/classic/tests/preprocess.test.ts +91 -107
- package/src/v4/classic/tests/primitive.test.ts +9 -11
- package/src/v4/classic/tests/record.test.ts +101 -121
- package/src/v4/classic/tests/set.test.ts +30 -36
- package/src/v4/classic/tests/string.test.ts +50 -60
- package/src/v4/classic/tests/template-literal.test.ts +45 -55
- package/src/v4/classic/tests/transform.test.ts +36 -46
- package/src/v4/classic/tests/tuple.test.ts +54 -66
- package/src/v4/core/errors.ts +12 -1
- package/src/v4/core/parse.ts +2 -2
- package/src/v4/core/tests/index.test.ts +42 -1
- package/src/v4/mini/tests/error.test.ts +1 -1
|
@@ -654,7 +654,7 @@ export type AnyZodTuple = ZodTuple<[ZodTypeAny, ...ZodTypeAny[]] | [], ZodTypeAn
|
|
|
654
654
|
export declare class ZodTuple<T extends ZodTupleItems | [] = ZodTupleItems, Rest extends ZodTypeAny | null = null> extends ZodType<OutputTypeOfTupleWithRest<T, Rest>, ZodTupleDef<T, Rest>, InputTypeOfTupleWithRest<T, Rest>> {
|
|
655
655
|
_parse(input: ParseInput): ParseReturnType<this["_output"]>;
|
|
656
656
|
get items(): T;
|
|
657
|
-
rest<
|
|
657
|
+
rest<RestSchema extends ZodTypeAny>(rest: RestSchema): ZodTuple<T, RestSchema>;
|
|
658
658
|
static create: <Items extends [ZodTypeAny, ...ZodTypeAny[]] | []>(schemas: Items, params?: RawCreateParams) => ZodTuple<Items, null>;
|
|
659
659
|
}
|
|
660
660
|
export interface ZodRecordDef<Key extends KeySchema = ZodString, Value extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
|
|
@@ -2,7 +2,7 @@ import * as core from "zod/v4/core";
|
|
|
2
2
|
import { $ZodError } from "zod/v4/core";
|
|
3
3
|
/** @deprecated Use `z.core.$ZodIssue` from `@zod/core` instead, especially if you are building a library on top of Zod. */
|
|
4
4
|
export type ZodIssue = core.$ZodIssue;
|
|
5
|
-
/** An Error-like class
|
|
5
|
+
/** An Error-like class used to store Zod validation issues. */
|
|
6
6
|
export interface ZodError<T = unknown> extends $ZodError<T> {
|
|
7
7
|
/** @deprecated Use the `z.treeifyError(err)` function instead. */
|
|
8
8
|
format(): core.$ZodFormattedError<T>;
|
|
@@ -38,6 +38,7 @@ const core = __importStar(require("zod/v4/core"));
|
|
|
38
38
|
const core_1 = require("zod/v4/core");
|
|
39
39
|
const initializer = (inst, issues) => {
|
|
40
40
|
core_1.$ZodError.init(inst, issues);
|
|
41
|
+
inst.name = "ZodError";
|
|
41
42
|
Object.defineProperties(inst, {
|
|
42
43
|
format: {
|
|
43
44
|
value: (mapper) => core.formatError(inst, mapper),
|
|
@@ -38,5 +38,5 @@ const core = __importStar(require("zod/v4/core"));
|
|
|
38
38
|
const errors_js_1 = require("./errors.js");
|
|
39
39
|
exports.parse = core._parse(errors_js_1.ZodRealError);
|
|
40
40
|
exports.parseAsync = core._parseAsync(errors_js_1.ZodRealError);
|
|
41
|
-
exports.safeParse = core._safeParse(errors_js_1.
|
|
42
|
-
exports.safeParseAsync = core._safeParseAsync(errors_js_1.
|
|
41
|
+
exports.safeParse = core._safeParse(errors_js_1.ZodRealError);
|
|
42
|
+
exports.safeParseAsync = core._safeParseAsync(errors_js_1.ZodRealError);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { $ZodCheck, $ZodStringFormats } from "./checks.js";
|
|
2
2
|
import { $constructor } from "./core.js";
|
|
3
3
|
import type { $ZodType } from "./schemas.js";
|
|
4
|
-
import
|
|
4
|
+
import * as util from "./util.js";
|
|
5
5
|
export interface $ZodIssueBase {
|
|
6
6
|
readonly code?: string;
|
|
7
7
|
readonly input?: unknown;
|
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.$ZodRealError = exports.$ZodError = void 0;
|
|
4
37
|
exports.flattenError = flattenError;
|
|
@@ -7,15 +40,26 @@ exports.treeifyError = treeifyError;
|
|
|
7
40
|
exports.toDotPath = toDotPath;
|
|
8
41
|
exports.prettifyError = prettifyError;
|
|
9
42
|
const core_js_1 = require("./core.js");
|
|
43
|
+
const util = __importStar(require("./util.js"));
|
|
10
44
|
const initializer = (inst, def) => {
|
|
45
|
+
inst.name = "$ZodError";
|
|
11
46
|
Object.defineProperty(inst, "_zod", {
|
|
12
47
|
value: inst._zod,
|
|
13
48
|
enumerable: false,
|
|
14
49
|
});
|
|
15
50
|
Object.defineProperty(inst, "issues", {
|
|
16
51
|
value: def,
|
|
52
|
+
enumerable: false,
|
|
53
|
+
});
|
|
54
|
+
// inst.message = JSON.stringify(def, util.jsonStringifyReplacer, 2);
|
|
55
|
+
Object.defineProperty(inst, "message", {
|
|
56
|
+
get() {
|
|
57
|
+
return JSON.stringify(def, util.jsonStringifyReplacer, 2);
|
|
58
|
+
},
|
|
17
59
|
enumerable: true,
|
|
60
|
+
// configurable: false,
|
|
18
61
|
});
|
|
62
|
+
// inst.toString = () => inst.message;
|
|
19
63
|
// inst.message = `Invalid input`;
|
|
20
64
|
// Object.defineProperty(inst, "message", {
|
|
21
65
|
// get() {
|
|
@@ -80,7 +80,7 @@ const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
|
80
80
|
: { success: true, data: result.value };
|
|
81
81
|
};
|
|
82
82
|
exports._safeParse = _safeParse;
|
|
83
|
-
exports.safeParse = (0, exports._safeParse)(errors.$
|
|
83
|
+
exports.safeParse = (0, exports._safeParse)(errors.$ZodRealError);
|
|
84
84
|
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
85
85
|
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
86
86
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
@@ -94,4 +94,4 @@ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
|
94
94
|
: { success: true, data: result.value };
|
|
95
95
|
};
|
|
96
96
|
exports._safeParseAsync = _safeParseAsync;
|
|
97
|
-
exports.safeParseAsync = (0, exports._safeParseAsync)(errors.$
|
|
97
|
+
exports.safeParseAsync = (0, exports._safeParseAsync)(errors.$ZodRealError);
|
package/dist/esm/v3/types.d.ts
CHANGED
|
@@ -654,7 +654,7 @@ export type AnyZodTuple = ZodTuple<[ZodTypeAny, ...ZodTypeAny[]] | [], ZodTypeAn
|
|
|
654
654
|
export declare class ZodTuple<T extends ZodTupleItems | [] = ZodTupleItems, Rest extends ZodTypeAny | null = null> extends ZodType<OutputTypeOfTupleWithRest<T, Rest>, ZodTupleDef<T, Rest>, InputTypeOfTupleWithRest<T, Rest>> {
|
|
655
655
|
_parse(input: ParseInput): ParseReturnType<this["_output"]>;
|
|
656
656
|
get items(): T;
|
|
657
|
-
rest<
|
|
657
|
+
rest<RestSchema extends ZodTypeAny>(rest: RestSchema): ZodTuple<T, RestSchema>;
|
|
658
658
|
static create: <Items extends [ZodTypeAny, ...ZodTypeAny[]] | []>(schemas: Items, params?: RawCreateParams) => ZodTuple<Items, null>;
|
|
659
659
|
}
|
|
660
660
|
export interface ZodRecordDef<Key extends KeySchema = ZodString, Value extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
|
|
@@ -2,7 +2,7 @@ import * as core from "zod/v4/core";
|
|
|
2
2
|
import { $ZodError } from "zod/v4/core";
|
|
3
3
|
/** @deprecated Use `z.core.$ZodIssue` from `@zod/core` instead, especially if you are building a library on top of Zod. */
|
|
4
4
|
export type ZodIssue = core.$ZodIssue;
|
|
5
|
-
/** An Error-like class
|
|
5
|
+
/** An Error-like class used to store Zod validation issues. */
|
|
6
6
|
export interface ZodError<T = unknown> extends $ZodError<T> {
|
|
7
7
|
/** @deprecated Use the `z.treeifyError(err)` function instead. */
|
|
8
8
|
format(): core.$ZodFormattedError<T>;
|
|
@@ -2,6 +2,7 @@ import * as core from "zod/v4/core";
|
|
|
2
2
|
import { $ZodError } from "zod/v4/core";
|
|
3
3
|
const initializer = (inst, issues) => {
|
|
4
4
|
$ZodError.init(inst, issues);
|
|
5
|
+
inst.name = "ZodError";
|
|
5
6
|
Object.defineProperties(inst, {
|
|
6
7
|
format: {
|
|
7
8
|
value: (mapper) => core.formatError(inst, mapper),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as core from "zod/v4/core";
|
|
2
|
-
import {
|
|
2
|
+
import { ZodRealError } from "./errors.js";
|
|
3
3
|
export const parse = /* @__PURE__ */ core._parse(ZodRealError);
|
|
4
4
|
export const parseAsync = /* @__PURE__ */ core._parseAsync(ZodRealError);
|
|
5
|
-
export const safeParse = /* @__PURE__ */ core._safeParse(
|
|
6
|
-
export const safeParseAsync = /* @__PURE__ */ core._safeParseAsync(
|
|
5
|
+
export const safeParse = /* @__PURE__ */ core._safeParse(ZodRealError);
|
|
6
|
+
export const safeParseAsync = /* @__PURE__ */ core._safeParseAsync(ZodRealError);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { $ZodCheck, $ZodStringFormats } from "./checks.js";
|
|
2
2
|
import { $constructor } from "./core.js";
|
|
3
3
|
import type { $ZodType } from "./schemas.js";
|
|
4
|
-
import
|
|
4
|
+
import * as util from "./util.js";
|
|
5
5
|
export interface $ZodIssueBase {
|
|
6
6
|
readonly code?: string;
|
|
7
7
|
readonly input?: unknown;
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { $constructor } from "./core.js";
|
|
2
|
+
import * as util from "./util.js";
|
|
2
3
|
const initializer = (inst, def) => {
|
|
4
|
+
inst.name = "$ZodError";
|
|
3
5
|
Object.defineProperty(inst, "_zod", {
|
|
4
6
|
value: inst._zod,
|
|
5
7
|
enumerable: false,
|
|
6
8
|
});
|
|
7
9
|
Object.defineProperty(inst, "issues", {
|
|
8
10
|
value: def,
|
|
11
|
+
enumerable: false,
|
|
12
|
+
});
|
|
13
|
+
// inst.message = JSON.stringify(def, util.jsonStringifyReplacer, 2);
|
|
14
|
+
Object.defineProperty(inst, "message", {
|
|
15
|
+
get() {
|
|
16
|
+
return JSON.stringify(def, util.jsonStringifyReplacer, 2);
|
|
17
|
+
},
|
|
9
18
|
enumerable: true,
|
|
19
|
+
// configurable: false,
|
|
10
20
|
});
|
|
21
|
+
// inst.toString = () => inst.message;
|
|
11
22
|
// inst.message = `Invalid input`;
|
|
12
23
|
// Object.defineProperty(inst, "message", {
|
|
13
24
|
// get() {
|
|
@@ -41,7 +41,7 @@ export const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
|
41
41
|
}
|
|
42
42
|
: { success: true, data: result.value };
|
|
43
43
|
};
|
|
44
|
-
export const safeParse = /* @__PURE__*/ _safeParse(errors.$
|
|
44
|
+
export const safeParse = /* @__PURE__*/ _safeParse(errors.$ZodRealError);
|
|
45
45
|
export const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
46
46
|
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
47
47
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
@@ -54,4 +54,4 @@ export const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
|
54
54
|
}
|
|
55
55
|
: { success: true, data: result.value };
|
|
56
56
|
};
|
|
57
|
-
export const safeParseAsync = /* @__PURE__*/ _safeParseAsync(errors.$
|
|
57
|
+
export const safeParseAsync = /* @__PURE__*/ _safeParseAsync(errors.$ZodRealError);
|
package/package.json
CHANGED
package/src/v3/types.ts
CHANGED
|
@@ -3450,7 +3450,7 @@ export class ZodTuple<
|
|
|
3450
3450
|
return this._def.items;
|
|
3451
3451
|
}
|
|
3452
3452
|
|
|
3453
|
-
rest<
|
|
3453
|
+
rest<RestSchema extends ZodTypeAny>(rest: RestSchema): ZodTuple<T, RestSchema> {
|
|
3454
3454
|
return new ZodTuple({
|
|
3455
3455
|
...this._def,
|
|
3456
3456
|
rest,
|
package/src/v4/classic/errors.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { $ZodError } from "zod/v4/core";
|
|
|
4
4
|
/** @deprecated Use `z.core.$ZodIssue` from `@zod/core` instead, especially if you are building a library on top of Zod. */
|
|
5
5
|
export type ZodIssue = core.$ZodIssue;
|
|
6
6
|
|
|
7
|
-
/** An Error-like class
|
|
7
|
+
/** An Error-like class used to store Zod validation issues. */
|
|
8
8
|
export interface ZodError<T = unknown> extends $ZodError<T> {
|
|
9
9
|
/** @deprecated Use the `z.treeifyError(err)` function instead. */
|
|
10
10
|
format(): core.$ZodFormattedError<T>;
|
|
@@ -23,6 +23,7 @@ export interface ZodError<T = unknown> extends $ZodError<T> {
|
|
|
23
23
|
|
|
24
24
|
const initializer = (inst: ZodError, issues: core.$ZodIssue[]) => {
|
|
25
25
|
$ZodError.init(inst, issues);
|
|
26
|
+
inst.name = "ZodError";
|
|
26
27
|
Object.defineProperties(inst, {
|
|
27
28
|
format: {
|
|
28
29
|
value: (mapper: any) => core.formatError(inst, mapper),
|
package/src/v4/classic/parse.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from "zod/v4/core";
|
|
2
|
-
import { ZodError, ZodRealError } from "./errors.js";
|
|
2
|
+
import { type ZodError, ZodRealError } from "./errors.js";
|
|
3
3
|
|
|
4
4
|
export type ZodSafeParseResult<T> = ZodSafeParseSuccess<T> | ZodSafeParseError<T>;
|
|
5
5
|
export type ZodSafeParseSuccess<T> = { success: true; data: T; error?: never };
|
|
@@ -24,10 +24,10 @@ export const safeParse: <T extends core.$ZodType>(
|
|
|
24
24
|
value: unknown,
|
|
25
25
|
_ctx?: core.ParseContext<core.$ZodIssue>
|
|
26
26
|
// _params?: { callee?: core.util.AnyFunc; Err?: core.$ZodErrorClass }
|
|
27
|
-
) => ZodSafeParseResult<core.output<T>> = /* @__PURE__ */ core._safeParse(
|
|
27
|
+
) => ZodSafeParseResult<core.output<T>> = /* @__PURE__ */ core._safeParse(ZodRealError) as any;
|
|
28
28
|
|
|
29
29
|
export const safeParseAsync: <T extends core.$ZodType>(
|
|
30
30
|
schema: T,
|
|
31
31
|
value: unknown,
|
|
32
32
|
_ctx?: core.ParseContext<core.$ZodIssue>
|
|
33
|
-
) => Promise<ZodSafeParseResult<core.output<T>>> = /* @__PURE__ */ core._safeParseAsync(
|
|
33
|
+
) => Promise<ZodSafeParseResult<core.output<T>>> = /* @__PURE__ */ core._safeParseAsync(ZodRealError) as any;
|
|
@@ -108,28 +108,26 @@ test("continue parsing despite array size error", () => {
|
|
|
108
108
|
});
|
|
109
109
|
expect(result).toMatchInlineSnapshot(`
|
|
110
110
|
{
|
|
111
|
-
"error": ZodError
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
"people",
|
|
119
|
-
0,
|
|
120
|
-
],
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
"code": "too_small",
|
|
124
|
-
"message": "Too small: expected array to have >2 items",
|
|
125
|
-
"minimum": 2,
|
|
126
|
-
"origin": "array",
|
|
127
|
-
"path": [
|
|
128
|
-
"people",
|
|
129
|
-
],
|
|
130
|
-
},
|
|
111
|
+
"error": [ZodError: [
|
|
112
|
+
{
|
|
113
|
+
"expected": "string",
|
|
114
|
+
"code": "invalid_type",
|
|
115
|
+
"path": [
|
|
116
|
+
"people",
|
|
117
|
+
0
|
|
131
118
|
],
|
|
119
|
+
"message": "Invalid input: expected string, received number"
|
|
132
120
|
},
|
|
121
|
+
{
|
|
122
|
+
"origin": "array",
|
|
123
|
+
"code": "too_small",
|
|
124
|
+
"minimum": 2,
|
|
125
|
+
"path": [
|
|
126
|
+
"people"
|
|
127
|
+
],
|
|
128
|
+
"message": "Too small: expected array to have >2 items"
|
|
129
|
+
}
|
|
130
|
+
]],
|
|
133
131
|
"success": false,
|
|
134
132
|
}
|
|
135
133
|
`);
|
|
@@ -141,34 +139,32 @@ test("parse should fail given sparse array", () => {
|
|
|
141
139
|
expect(result.success).toEqual(false);
|
|
142
140
|
expect(result).toMatchInlineSnapshot(`
|
|
143
141
|
{
|
|
144
|
-
"error": ZodError
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
"path": [
|
|
159
|
-
1,
|
|
160
|
-
],
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
"code": "invalid_type",
|
|
164
|
-
"expected": "string",
|
|
165
|
-
"message": "Invalid input: expected string, received undefined",
|
|
166
|
-
"path": [
|
|
167
|
-
2,
|
|
168
|
-
],
|
|
169
|
-
},
|
|
142
|
+
"error": [ZodError: [
|
|
143
|
+
{
|
|
144
|
+
"expected": "string",
|
|
145
|
+
"code": "invalid_type",
|
|
146
|
+
"path": [
|
|
147
|
+
0
|
|
148
|
+
],
|
|
149
|
+
"message": "Invalid input: expected string, received undefined"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"expected": "string",
|
|
153
|
+
"code": "invalid_type",
|
|
154
|
+
"path": [
|
|
155
|
+
1
|
|
170
156
|
],
|
|
157
|
+
"message": "Invalid input: expected string, received undefined"
|
|
171
158
|
},
|
|
159
|
+
{
|
|
160
|
+
"expected": "string",
|
|
161
|
+
"code": "invalid_type",
|
|
162
|
+
"path": [
|
|
163
|
+
2
|
|
164
|
+
],
|
|
165
|
+
"message": "Invalid input: expected string, received undefined"
|
|
166
|
+
}
|
|
167
|
+
]],
|
|
172
168
|
"success": false,
|
|
173
169
|
}
|
|
174
170
|
`);
|
|
@@ -18,15 +18,13 @@ test("async refine", async () => {
|
|
|
18
18
|
expect(r2.success).toBe(false);
|
|
19
19
|
expect(r2).toMatchInlineSnapshot(`
|
|
20
20
|
{
|
|
21
|
-
"error": ZodError
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
],
|
|
29
|
-
},
|
|
21
|
+
"error": [ZodError: [
|
|
22
|
+
{
|
|
23
|
+
"code": "custom",
|
|
24
|
+
"path": [],
|
|
25
|
+
"message": "Invalid input"
|
|
26
|
+
}
|
|
27
|
+
]],
|
|
30
28
|
"success": false,
|
|
31
29
|
}
|
|
32
30
|
`);
|
|
@@ -55,15 +53,13 @@ test("async refine that uses value", async () => {
|
|
|
55
53
|
const r1 = await schema1.safeParseAsync("asdf");
|
|
56
54
|
expect(r1.success).toBe(false);
|
|
57
55
|
expect(r1.error).toMatchInlineSnapshot(`
|
|
58
|
-
ZodError
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
],
|
|
66
|
-
}
|
|
56
|
+
[ZodError: [
|
|
57
|
+
{
|
|
58
|
+
"code": "custom",
|
|
59
|
+
"path": [],
|
|
60
|
+
"message": "Invalid input"
|
|
61
|
+
}
|
|
62
|
+
]]
|
|
67
63
|
`);
|
|
68
64
|
|
|
69
65
|
const r2 = await schema1.safeParseAsync("asdf123");
|
|
@@ -230,18 +230,16 @@ test("catch error", () => {
|
|
|
230
230
|
|
|
231
231
|
expect(result.success).toEqual(false);
|
|
232
232
|
expect(result.error!).toMatchInlineSnapshot(`
|
|
233
|
-
ZodError
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
"
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
],
|
|
244
|
-
}
|
|
233
|
+
[ZodError: [
|
|
234
|
+
{
|
|
235
|
+
"expected": "number",
|
|
236
|
+
"code": "invalid_type",
|
|
237
|
+
"path": [
|
|
238
|
+
"age"
|
|
239
|
+
],
|
|
240
|
+
"message": "Invalid input: expected number, received null"
|
|
241
|
+
}
|
|
242
|
+
]]
|
|
245
243
|
`);
|
|
246
244
|
});
|
|
247
245
|
|