zod 3.14.3 → 3.14.4
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/lib/ZodError.d.ts +6 -1
- package/lib/ZodError.js +4 -0
- package/lib/helpers/parseUtil.d.ts +0 -1
- package/lib/index.mjs +12 -7
- package/lib/types.js +8 -7
- package/package.json +1 -1
package/lib/ZodError.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Primitive } from "./helpers/typeAliases";
|
|
|
3
3
|
import { util } from "./helpers/util";
|
|
4
4
|
export declare const ZodIssueCode: {
|
|
5
5
|
invalid_type: "invalid_type";
|
|
6
|
+
invalid_literal: "invalid_literal";
|
|
6
7
|
custom: "custom";
|
|
7
8
|
invalid_union: "invalid_union";
|
|
8
9
|
invalid_union_discriminator: "invalid_union_discriminator";
|
|
@@ -27,6 +28,10 @@ export interface ZodInvalidTypeIssue extends ZodIssueBase {
|
|
|
27
28
|
expected: ZodParsedType;
|
|
28
29
|
received: ZodParsedType;
|
|
29
30
|
}
|
|
31
|
+
export interface ZodInvalidLiteralIssue extends ZodIssueBase {
|
|
32
|
+
code: typeof ZodIssueCode.invalid_literal;
|
|
33
|
+
expected: unknown;
|
|
34
|
+
}
|
|
30
35
|
export interface ZodUnrecognizedKeysIssue extends ZodIssueBase {
|
|
31
36
|
code: typeof ZodIssueCode.unrecognized_keys;
|
|
32
37
|
keys: string[];
|
|
@@ -87,7 +92,7 @@ export interface ZodCustomIssue extends ZodIssueBase {
|
|
|
87
92
|
export declare type DenormalizedError = {
|
|
88
93
|
[k: string]: DenormalizedError | string[];
|
|
89
94
|
};
|
|
90
|
-
export declare type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidUnionDiscriminatorIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodNotMultipleOfIssue | ZodCustomIssue;
|
|
95
|
+
export declare type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodInvalidLiteralIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidUnionDiscriminatorIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodNotMultipleOfIssue | ZodCustomIssue;
|
|
91
96
|
export declare type ZodIssue = ZodIssueOptionalMessage & {
|
|
92
97
|
message: string;
|
|
93
98
|
};
|
package/lib/ZodError.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.setErrorMap = exports.overrideErrorMap = exports.defaultErrorMap = expor
|
|
|
4
4
|
const util_1 = require("./helpers/util");
|
|
5
5
|
exports.ZodIssueCode = util_1.util.arrayToEnum([
|
|
6
6
|
"invalid_type",
|
|
7
|
+
"invalid_literal",
|
|
7
8
|
"custom",
|
|
8
9
|
"invalid_union",
|
|
9
10
|
"invalid_union_discriminator",
|
|
@@ -135,6 +136,9 @@ const defaultErrorMap = (issue, _ctx) => {
|
|
|
135
136
|
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
136
137
|
}
|
|
137
138
|
break;
|
|
139
|
+
case exports.ZodIssueCode.invalid_literal:
|
|
140
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected)}`;
|
|
141
|
+
break;
|
|
138
142
|
case exports.ZodIssueCode.unrecognized_keys:
|
|
139
143
|
message = `Unrecognized key(s) in object: ${issue.keys
|
|
140
144
|
.map((k) => `'${k}'`)
|
|
@@ -42,7 +42,6 @@ export interface ParseContext {
|
|
|
42
42
|
readonly issues: ZodIssue[];
|
|
43
43
|
readonly contextualErrorMap?: ZodErrorMap;
|
|
44
44
|
readonly async: boolean;
|
|
45
|
-
readonly typeCache: Map<any, ZodParsedType> | undefined;
|
|
46
45
|
};
|
|
47
46
|
readonly path: ParsePath;
|
|
48
47
|
readonly schemaErrorMap?: ZodErrorMap;
|
package/lib/index.mjs
CHANGED
|
@@ -49,6 +49,7 @@ var util;
|
|
|
49
49
|
|
|
50
50
|
const ZodIssueCode = util.arrayToEnum([
|
|
51
51
|
"invalid_type",
|
|
52
|
+
"invalid_literal",
|
|
52
53
|
"custom",
|
|
53
54
|
"invalid_union",
|
|
54
55
|
"invalid_union_discriminator",
|
|
@@ -178,6 +179,9 @@ const defaultErrorMap = (issue, _ctx) => {
|
|
|
178
179
|
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
179
180
|
}
|
|
180
181
|
break;
|
|
182
|
+
case ZodIssueCode.invalid_literal:
|
|
183
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected)}`;
|
|
184
|
+
break;
|
|
181
185
|
case ZodIssueCode.unrecognized_keys:
|
|
182
186
|
message = `Unrecognized key(s) in object: ${issue.keys
|
|
183
187
|
.map((k) => `'${k}'`)
|
|
@@ -541,7 +545,6 @@ class ZodType {
|
|
|
541
545
|
common: {
|
|
542
546
|
issues: [],
|
|
543
547
|
async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
|
|
544
|
-
typeCache: typeof Map !== "undefined" ? new Map() : undefined,
|
|
545
548
|
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
546
549
|
},
|
|
547
550
|
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
@@ -565,7 +568,6 @@ class ZodType {
|
|
|
565
568
|
issues: [],
|
|
566
569
|
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
567
570
|
async: true,
|
|
568
|
-
typeCache: typeof Map !== "undefined" ? new Map() : undefined,
|
|
569
571
|
},
|
|
570
572
|
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
571
573
|
schemaErrorMap: this._def.errorMap,
|
|
@@ -1445,8 +1447,12 @@ class ZodObject extends ZodType {
|
|
|
1445
1447
|
}
|
|
1446
1448
|
const { status, ctx } = this._processInputParams(input);
|
|
1447
1449
|
const { shape, keys: shapeKeys } = this._getCached();
|
|
1448
|
-
const
|
|
1449
|
-
const
|
|
1450
|
+
const extraKeys = [];
|
|
1451
|
+
for (const key in ctx.data) {
|
|
1452
|
+
if (!shapeKeys.includes(key)) {
|
|
1453
|
+
extraKeys.push(key);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1450
1456
|
const pairs = [];
|
|
1451
1457
|
for (const key of shapeKeys) {
|
|
1452
1458
|
const keyValidator = shape[key];
|
|
@@ -2354,9 +2360,8 @@ class ZodLiteral extends ZodType {
|
|
|
2354
2360
|
if (input.data !== this._def.value) {
|
|
2355
2361
|
const ctx = this._getOrReturnCtx(input);
|
|
2356
2362
|
addIssueToContext(ctx, {
|
|
2357
|
-
code: ZodIssueCode.
|
|
2358
|
-
expected:
|
|
2359
|
-
received: ctx.parsedType,
|
|
2363
|
+
code: ZodIssueCode.invalid_literal,
|
|
2364
|
+
expected: this._def.value,
|
|
2360
2365
|
});
|
|
2361
2366
|
return INVALID;
|
|
2362
2367
|
}
|
package/lib/types.js
CHANGED
|
@@ -128,7 +128,6 @@ class ZodType {
|
|
|
128
128
|
common: {
|
|
129
129
|
issues: [],
|
|
130
130
|
async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
|
|
131
|
-
typeCache: typeof Map !== "undefined" ? new Map() : undefined,
|
|
132
131
|
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
133
132
|
},
|
|
134
133
|
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
@@ -152,7 +151,6 @@ class ZodType {
|
|
|
152
151
|
issues: [],
|
|
153
152
|
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
154
153
|
async: true,
|
|
155
|
-
typeCache: typeof Map !== "undefined" ? new Map() : undefined,
|
|
156
154
|
},
|
|
157
155
|
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
158
156
|
schemaErrorMap: this._def.errorMap,
|
|
@@ -1049,8 +1047,12 @@ class ZodObject extends ZodType {
|
|
|
1049
1047
|
}
|
|
1050
1048
|
const { status, ctx } = this._processInputParams(input);
|
|
1051
1049
|
const { shape, keys: shapeKeys } = this._getCached();
|
|
1052
|
-
const
|
|
1053
|
-
const
|
|
1050
|
+
const extraKeys = [];
|
|
1051
|
+
for (const key in ctx.data) {
|
|
1052
|
+
if (!shapeKeys.includes(key)) {
|
|
1053
|
+
extraKeys.push(key);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1054
1056
|
const pairs = [];
|
|
1055
1057
|
for (const key of shapeKeys) {
|
|
1056
1058
|
const keyValidator = shape[key];
|
|
@@ -1969,9 +1971,8 @@ class ZodLiteral extends ZodType {
|
|
|
1969
1971
|
if (input.data !== this._def.value) {
|
|
1970
1972
|
const ctx = this._getOrReturnCtx(input);
|
|
1971
1973
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1972
|
-
code: ZodError_1.ZodIssueCode.
|
|
1973
|
-
expected:
|
|
1974
|
-
received: ctx.parsedType,
|
|
1974
|
+
code: ZodError_1.ZodIssueCode.invalid_literal,
|
|
1975
|
+
expected: this._def.value,
|
|
1975
1976
|
});
|
|
1976
1977
|
return parseUtil_1.INVALID;
|
|
1977
1978
|
}
|