zod 3.25.4 → 3.25.5
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/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/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/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
|
@@ -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);
|
|
@@ -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/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
|
|
|
@@ -149,19 +149,17 @@ test("invalid discriminator value", () => {
|
|
|
149
149
|
|
|
150
150
|
expect(result).toMatchInlineSnapshot(`
|
|
151
151
|
{
|
|
152
|
-
"error": ZodError
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
"path": [
|
|
160
|
-
"type",
|
|
161
|
-
],
|
|
162
|
-
},
|
|
152
|
+
"error": [ZodError: [
|
|
153
|
+
{
|
|
154
|
+
"code": "invalid_union",
|
|
155
|
+
"errors": [],
|
|
156
|
+
"note": "No matching discriminator",
|
|
157
|
+
"path": [
|
|
158
|
+
"type"
|
|
163
159
|
],
|
|
164
|
-
|
|
160
|
+
"message": "Invalid input"
|
|
161
|
+
}
|
|
162
|
+
]],
|
|
165
163
|
"success": false,
|
|
166
164
|
}
|
|
167
165
|
`);
|
|
@@ -177,49 +175,47 @@ test("invalid discriminator value - unionFallback", () => {
|
|
|
177
175
|
.safeParse({ type: "x", a: "abc" });
|
|
178
176
|
expect(result).toMatchInlineSnapshot(`
|
|
179
177
|
{
|
|
180
|
-
"error": ZodError
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
"path": [
|
|
190
|
-
"type",
|
|
191
|
-
],
|
|
192
|
-
"values": [
|
|
193
|
-
"a",
|
|
194
|
-
],
|
|
195
|
-
},
|
|
178
|
+
"error": [ZodError: [
|
|
179
|
+
{
|
|
180
|
+
"code": "invalid_union",
|
|
181
|
+
"errors": [
|
|
182
|
+
[
|
|
183
|
+
{
|
|
184
|
+
"code": "invalid_value",
|
|
185
|
+
"values": [
|
|
186
|
+
"a"
|
|
196
187
|
],
|
|
197
|
-
[
|
|
198
|
-
|
|
199
|
-
"code": "invalid_value",
|
|
200
|
-
"message": "Invalid input: expected "b"",
|
|
201
|
-
"path": [
|
|
202
|
-
"type",
|
|
203
|
-
],
|
|
204
|
-
"values": [
|
|
205
|
-
"b",
|
|
206
|
-
],
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
"code": "invalid_type",
|
|
210
|
-
"expected": "string",
|
|
211
|
-
"message": "Invalid input: expected string, received undefined",
|
|
212
|
-
"path": [
|
|
213
|
-
"b",
|
|
214
|
-
],
|
|
215
|
-
},
|
|
188
|
+
"path": [
|
|
189
|
+
"type"
|
|
216
190
|
],
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
191
|
+
"message": "Invalid input: expected \\"a\\""
|
|
192
|
+
}
|
|
193
|
+
],
|
|
194
|
+
[
|
|
195
|
+
{
|
|
196
|
+
"code": "invalid_value",
|
|
197
|
+
"values": [
|
|
198
|
+
"b"
|
|
199
|
+
],
|
|
200
|
+
"path": [
|
|
201
|
+
"type"
|
|
202
|
+
],
|
|
203
|
+
"message": "Invalid input: expected \\"b\\""
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"expected": "string",
|
|
207
|
+
"code": "invalid_type",
|
|
208
|
+
"path": [
|
|
209
|
+
"b"
|
|
210
|
+
],
|
|
211
|
+
"message": "Invalid input: expected string, received undefined"
|
|
212
|
+
}
|
|
213
|
+
]
|
|
221
214
|
],
|
|
222
|
-
|
|
215
|
+
"path": [],
|
|
216
|
+
"message": "Invalid input"
|
|
217
|
+
}
|
|
218
|
+
]],
|
|
223
219
|
"success": false,
|
|
224
220
|
}
|
|
225
221
|
`);
|
|
@@ -244,18 +240,16 @@ test("valid discriminator value, invalid data", () => {
|
|
|
244
240
|
// ];
|
|
245
241
|
expect(result).toMatchInlineSnapshot(`
|
|
246
242
|
{
|
|
247
|
-
"error": ZodError
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
"path": [
|
|
254
|
-
"a",
|
|
255
|
-
],
|
|
256
|
-
},
|
|
243
|
+
"error": [ZodError: [
|
|
244
|
+
{
|
|
245
|
+
"expected": "string",
|
|
246
|
+
"code": "invalid_type",
|
|
247
|
+
"path": [
|
|
248
|
+
"a"
|
|
257
249
|
],
|
|
258
|
-
|
|
250
|
+
"message": "Invalid input: expected string, received undefined"
|
|
251
|
+
}
|
|
252
|
+
]],
|
|
259
253
|
"success": false,
|
|
260
254
|
}
|
|
261
255
|
`);
|
|
@@ -333,18 +327,16 @@ test("async - invalid", async () => {
|
|
|
333
327
|
// },
|
|
334
328
|
// ]);
|
|
335
329
|
expect(result.error).toMatchInlineSnapshot(`
|
|
336
|
-
ZodError
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
"
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
],
|
|
347
|
-
}
|
|
330
|
+
[ZodError: [
|
|
331
|
+
{
|
|
332
|
+
"expected": "string",
|
|
333
|
+
"code": "invalid_type",
|
|
334
|
+
"path": [
|
|
335
|
+
"a"
|
|
336
|
+
],
|
|
337
|
+
"message": "Invalid input: expected string, received number"
|
|
338
|
+
}
|
|
339
|
+
]]
|
|
348
340
|
`);
|
|
349
341
|
});
|
|
350
342
|
|
|
@@ -509,19 +501,17 @@ test("single element union", () => {
|
|
|
509
501
|
expect(result).toMatchObject({ success: false });
|
|
510
502
|
expect(result).toMatchInlineSnapshot(`
|
|
511
503
|
{
|
|
512
|
-
"error": ZodError
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
"c",
|
|
520
|
-
"id",
|
|
521
|
-
],
|
|
522
|
-
},
|
|
504
|
+
"error": [ZodError: [
|
|
505
|
+
{
|
|
506
|
+
"expected": "string",
|
|
507
|
+
"code": "invalid_type",
|
|
508
|
+
"path": [
|
|
509
|
+
"c",
|
|
510
|
+
"id"
|
|
523
511
|
],
|
|
524
|
-
|
|
512
|
+
"message": "Invalid input: expected string, received undefined"
|
|
513
|
+
}
|
|
514
|
+
]],
|
|
525
515
|
"success": false,
|
|
526
516
|
}
|
|
527
517
|
`);
|