zod 3.17.2 → 3.17.3
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/external.js +1 -5
- package/lib/helpers/errorUtil.d.ts +6 -2
- package/lib/helpers/parseUtil.d.ts +2 -2
- package/lib/helpers/parseUtil.js +2 -2
- package/lib/index.js +1 -5
- package/lib/index.mjs +2 -2
- package/lib/index.umd.js +2 -2
- package/lib/types.d.ts +17 -7
- package/lib/types.js +80 -80
- package/package.json +2 -2
package/lib/external.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -2,8 +2,12 @@ export declare namespace errorUtil {
|
|
|
2
2
|
type ErrMessage = string | {
|
|
3
3
|
message?: string;
|
|
4
4
|
};
|
|
5
|
-
const errToObj: (message?:
|
|
5
|
+
const errToObj: (message?: string | {
|
|
6
|
+
message?: string | undefined;
|
|
7
|
+
} | undefined) => {
|
|
6
8
|
message?: string | undefined;
|
|
7
9
|
};
|
|
8
|
-
const toString: (message?:
|
|
10
|
+
const toString: (message?: string | {
|
|
11
|
+
message?: string | undefined;
|
|
12
|
+
} | undefined) => string | undefined;
|
|
9
13
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError";
|
|
2
|
+
import type { ZodParsedType } from "./util";
|
|
3
3
|
export declare const makeIssue: (params: {
|
|
4
4
|
data: any;
|
|
5
5
|
path: (string | number)[];
|
package/lib/helpers/parseUtil.js
CHANGED
|
@@ -26,7 +26,7 @@ const makeIssue = (params) => {
|
|
|
26
26
|
exports.makeIssue = makeIssue;
|
|
27
27
|
exports.EMPTY_PATH = [];
|
|
28
28
|
function addIssueToContext(ctx, issueData) {
|
|
29
|
-
const issue =
|
|
29
|
+
const issue = exports.makeIssue({
|
|
30
30
|
issueData: issueData,
|
|
31
31
|
data: ctx.data,
|
|
32
32
|
path: ctx.path,
|
|
@@ -34,7 +34,7 @@ function addIssueToContext(ctx, issueData) {
|
|
|
34
34
|
ctx.common.contextualErrorMap,
|
|
35
35
|
ctx.schemaErrorMap,
|
|
36
36
|
ZodError_1.overrideErrorMap,
|
|
37
|
-
ZodError_1.defaultErrorMap,
|
|
37
|
+
ZodError_1.defaultErrorMap,
|
|
38
38
|
].filter((x) => !!x),
|
|
39
39
|
});
|
|
40
40
|
ctx.common.issues.push(issue);
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/index.mjs
CHANGED
|
@@ -354,7 +354,7 @@ function addIssueToContext(ctx, issueData) {
|
|
|
354
354
|
ctx.common.contextualErrorMap,
|
|
355
355
|
ctx.schemaErrorMap,
|
|
356
356
|
overrideErrorMap,
|
|
357
|
-
defaultErrorMap,
|
|
357
|
+
defaultErrorMap,
|
|
358
358
|
].filter((x) => !!x),
|
|
359
359
|
});
|
|
360
360
|
ctx.common.issues.push(issue);
|
|
@@ -1388,7 +1388,7 @@ var objectUtil;
|
|
|
1388
1388
|
objectUtil.mergeShapes = (first, second) => {
|
|
1389
1389
|
return {
|
|
1390
1390
|
...first,
|
|
1391
|
-
...second,
|
|
1391
|
+
...second,
|
|
1392
1392
|
};
|
|
1393
1393
|
};
|
|
1394
1394
|
})(objectUtil || (objectUtil = {}));
|
package/lib/index.umd.js
CHANGED
|
@@ -360,7 +360,7 @@
|
|
|
360
360
|
ctx.common.contextualErrorMap,
|
|
361
361
|
ctx.schemaErrorMap,
|
|
362
362
|
exports.overrideErrorMap,
|
|
363
|
-
defaultErrorMap,
|
|
363
|
+
defaultErrorMap,
|
|
364
364
|
].filter((x) => !!x),
|
|
365
365
|
});
|
|
366
366
|
ctx.common.issues.push(issue);
|
|
@@ -1394,7 +1394,7 @@
|
|
|
1394
1394
|
objectUtil.mergeShapes = (first, second) => {
|
|
1395
1395
|
return {
|
|
1396
1396
|
...first,
|
|
1397
|
-
...second,
|
|
1397
|
+
...second,
|
|
1398
1398
|
};
|
|
1399
1399
|
};
|
|
1400
1400
|
})(exports.objectUtil || (exports.objectUtil = {}));
|
package/lib/types.d.ts
CHANGED
|
@@ -112,7 +112,9 @@ export interface ZodStringDef extends ZodTypeDef {
|
|
|
112
112
|
}
|
|
113
113
|
export declare class ZodString extends ZodType<string, ZodStringDef> {
|
|
114
114
|
_parse(input: ParseInput): ParseReturnType<string>;
|
|
115
|
-
protected _regex: (regex: RegExp, validation: StringValidation, message?:
|
|
115
|
+
protected _regex: (regex: RegExp, validation: StringValidation, message?: string | {
|
|
116
|
+
message?: string | undefined;
|
|
117
|
+
} | undefined) => ZodEffects<this, string, string>;
|
|
116
118
|
_addCheck(check: ZodStringCheck): ZodString;
|
|
117
119
|
email(message?: errorUtil.ErrMessage): ZodString;
|
|
118
120
|
url(message?: errorUtil.ErrMessage): ZodString;
|
|
@@ -126,7 +128,9 @@ export declare class ZodString extends ZodType<string, ZodStringDef> {
|
|
|
126
128
|
* @deprecated Use z.string().min(1) instead.
|
|
127
129
|
* @see {@link ZodString.min}
|
|
128
130
|
*/
|
|
129
|
-
nonempty: (message?:
|
|
131
|
+
nonempty: (message?: string | {
|
|
132
|
+
message?: string | undefined;
|
|
133
|
+
} | undefined) => ZodString;
|
|
130
134
|
trim: () => ZodString;
|
|
131
135
|
get isEmail(): boolean;
|
|
132
136
|
get isURL(): boolean;
|
|
@@ -162,10 +166,14 @@ export declare class ZodNumber extends ZodType<number, ZodNumberDef> {
|
|
|
162
166
|
_parse(input: ParseInput): ParseReturnType<number>;
|
|
163
167
|
static create: (params?: RawCreateParams) => ZodNumber;
|
|
164
168
|
gte(value: number, message?: errorUtil.ErrMessage): ZodNumber;
|
|
165
|
-
min: (value: number, message?:
|
|
169
|
+
min: (value: number, message?: string | {
|
|
170
|
+
message?: string | undefined;
|
|
171
|
+
} | undefined) => ZodNumber;
|
|
166
172
|
gt(value: number, message?: errorUtil.ErrMessage): ZodNumber;
|
|
167
173
|
lte(value: number, message?: errorUtil.ErrMessage): ZodNumber;
|
|
168
|
-
max: (value: number, message?:
|
|
174
|
+
max: (value: number, message?: string | {
|
|
175
|
+
message?: string | undefined;
|
|
176
|
+
} | undefined) => ZodNumber;
|
|
169
177
|
lt(value: number, message?: errorUtil.ErrMessage): ZodNumber;
|
|
170
178
|
protected setLimit(kind: "min" | "max", value: number, inclusive: boolean, message?: string): ZodNumber;
|
|
171
179
|
_addCheck(check: ZodNumberCheck): ZodNumber;
|
|
@@ -175,7 +183,9 @@ export declare class ZodNumber extends ZodType<number, ZodNumberDef> {
|
|
|
175
183
|
nonpositive(message?: errorUtil.ErrMessage): ZodNumber;
|
|
176
184
|
nonnegative(message?: errorUtil.ErrMessage): ZodNumber;
|
|
177
185
|
multipleOf(value: number, message?: errorUtil.ErrMessage): ZodNumber;
|
|
178
|
-
step: (value: number, message?:
|
|
186
|
+
step: (value: number, message?: string | {
|
|
187
|
+
message?: string | undefined;
|
|
188
|
+
} | undefined) => ZodNumber;
|
|
179
189
|
get minValue(): number | null;
|
|
180
190
|
get maxValue(): number | null;
|
|
181
191
|
get isInt(): boolean;
|
|
@@ -519,7 +529,7 @@ export interface ZodLiteralDef<T = any> extends ZodTypeDef {
|
|
|
519
529
|
export declare class ZodLiteral<T> extends ZodType<T, ZodLiteralDef<T>> {
|
|
520
530
|
_parse(input: ParseInput): ParseReturnType<this["_output"]>;
|
|
521
531
|
get value(): T;
|
|
522
|
-
static create: <T_1 extends
|
|
532
|
+
static create: <T_1 extends string | number | bigint | boolean | null | undefined>(value: T_1, params?: RawCreateParams) => ZodLiteral<T_1>;
|
|
523
533
|
}
|
|
524
534
|
export declare type ArrayKeys = keyof any[];
|
|
525
535
|
export declare type Indices<T> = Exclude<keyof T, ArrayKeys>;
|
|
@@ -693,7 +703,7 @@ declare const mapType: <Key extends ZodTypeAny = ZodTypeAny, Value extends ZodTy
|
|
|
693
703
|
declare const setType: <Value extends ZodTypeAny = ZodTypeAny>(valueType: Value, params?: RawCreateParams) => ZodSet<Value>;
|
|
694
704
|
declare const functionType: <T extends ZodTuple<any, any> = ZodTuple<[], ZodUnknown>, U extends ZodTypeAny = ZodUnknown>(args?: T | undefined, returns?: U | undefined, params?: RawCreateParams) => ZodFunction<T, U>;
|
|
695
705
|
declare const lazyType: <T extends ZodTypeAny>(getter: () => T, params?: RawCreateParams) => ZodLazy<T>;
|
|
696
|
-
declare const literalType: <T extends
|
|
706
|
+
declare const literalType: <T extends string | number | bigint | boolean | null | undefined>(value: T, params?: RawCreateParams) => ZodLiteral<T>;
|
|
697
707
|
declare const enumType: typeof createZodEnum;
|
|
698
708
|
declare const nativeEnumType: <T extends EnumLike>(values: T, params?: RawCreateParams) => ZodNativeEnum<T>;
|
|
699
709
|
declare const promiseType: <T extends ZodTypeAny>(schema: T, params?: RawCreateParams) => ZodPromise<T>;
|
package/lib/types.js
CHANGED
|
@@ -18,7 +18,7 @@ class ParseInputLazyPath {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
const handleResult = (ctx, result) => {
|
|
21
|
-
if (
|
|
21
|
+
if (parseUtil_1.isValid(result)) {
|
|
22
22
|
return { success: true, data: result.value };
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
@@ -80,13 +80,13 @@ class ZodType {
|
|
|
80
80
|
return this._def.description;
|
|
81
81
|
}
|
|
82
82
|
_getType(input) {
|
|
83
|
-
return
|
|
83
|
+
return util_1.getParsedType(input.data);
|
|
84
84
|
}
|
|
85
85
|
_getOrReturnCtx(input, ctx) {
|
|
86
86
|
return (ctx || {
|
|
87
87
|
common: input.parent.common,
|
|
88
88
|
data: input.data,
|
|
89
|
-
parsedType:
|
|
89
|
+
parsedType: util_1.getParsedType(input.data),
|
|
90
90
|
schemaErrorMap: this._def.errorMap,
|
|
91
91
|
path: input.path,
|
|
92
92
|
parent: input.parent,
|
|
@@ -98,7 +98,7 @@ class ZodType {
|
|
|
98
98
|
ctx: {
|
|
99
99
|
common: input.parent.common,
|
|
100
100
|
data: input.data,
|
|
101
|
-
parsedType:
|
|
101
|
+
parsedType: util_1.getParsedType(input.data),
|
|
102
102
|
schemaErrorMap: this._def.errorMap,
|
|
103
103
|
path: input.path,
|
|
104
104
|
parent: input.parent,
|
|
@@ -107,7 +107,7 @@ class ZodType {
|
|
|
107
107
|
}
|
|
108
108
|
_parseSync(input) {
|
|
109
109
|
const result = this._parse(input);
|
|
110
|
-
if (
|
|
110
|
+
if (parseUtil_1.isAsync(result)) {
|
|
111
111
|
throw new Error("Synchronous parse encountered promise.");
|
|
112
112
|
}
|
|
113
113
|
return result;
|
|
@@ -134,7 +134,7 @@ class ZodType {
|
|
|
134
134
|
schemaErrorMap: this._def.errorMap,
|
|
135
135
|
parent: null,
|
|
136
136
|
data,
|
|
137
|
-
parsedType:
|
|
137
|
+
parsedType: util_1.getParsedType(data),
|
|
138
138
|
};
|
|
139
139
|
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
140
140
|
return handleResult(ctx, result);
|
|
@@ -156,10 +156,10 @@ class ZodType {
|
|
|
156
156
|
schemaErrorMap: this._def.errorMap,
|
|
157
157
|
parent: null,
|
|
158
158
|
data,
|
|
159
|
-
parsedType:
|
|
159
|
+
parsedType: util_1.getParsedType(data),
|
|
160
160
|
};
|
|
161
161
|
const maybeAsyncResult = this._parse({ data, path: [], parent: ctx });
|
|
162
|
-
const result = await (
|
|
162
|
+
const result = await (parseUtil_1.isAsync(maybeAsyncResult)
|
|
163
163
|
? maybeAsyncResult
|
|
164
164
|
: Promise.resolve(maybeAsyncResult));
|
|
165
165
|
return handleResult(ctx, result);
|
|
@@ -304,7 +304,7 @@ class ZodString extends ZodType {
|
|
|
304
304
|
const parsedType = this._getType(input);
|
|
305
305
|
if (parsedType !== util_1.ZodParsedType.string) {
|
|
306
306
|
const ctx = this._getOrReturnCtx(input);
|
|
307
|
-
|
|
307
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
308
308
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
309
309
|
expected: util_1.ZodParsedType.string,
|
|
310
310
|
received: ctx.parsedType,
|
|
@@ -319,7 +319,7 @@ class ZodString extends ZodType {
|
|
|
319
319
|
if (check.kind === "min") {
|
|
320
320
|
if (input.data.length < check.value) {
|
|
321
321
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
322
|
-
|
|
322
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
323
323
|
code: ZodError_1.ZodIssueCode.too_small,
|
|
324
324
|
minimum: check.value,
|
|
325
325
|
type: "string",
|
|
@@ -332,7 +332,7 @@ class ZodString extends ZodType {
|
|
|
332
332
|
else if (check.kind === "max") {
|
|
333
333
|
if (input.data.length > check.value) {
|
|
334
334
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
335
|
-
|
|
335
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
336
336
|
code: ZodError_1.ZodIssueCode.too_big,
|
|
337
337
|
maximum: check.value,
|
|
338
338
|
type: "string",
|
|
@@ -345,7 +345,7 @@ class ZodString extends ZodType {
|
|
|
345
345
|
else if (check.kind === "email") {
|
|
346
346
|
if (!emailRegex.test(input.data)) {
|
|
347
347
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
348
|
-
|
|
348
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
349
349
|
validation: "email",
|
|
350
350
|
code: ZodError_1.ZodIssueCode.invalid_string,
|
|
351
351
|
message: check.message,
|
|
@@ -356,7 +356,7 @@ class ZodString extends ZodType {
|
|
|
356
356
|
else if (check.kind === "uuid") {
|
|
357
357
|
if (!uuidRegex.test(input.data)) {
|
|
358
358
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
359
|
-
|
|
359
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
360
360
|
validation: "uuid",
|
|
361
361
|
code: ZodError_1.ZodIssueCode.invalid_string,
|
|
362
362
|
message: check.message,
|
|
@@ -367,7 +367,7 @@ class ZodString extends ZodType {
|
|
|
367
367
|
else if (check.kind === "cuid") {
|
|
368
368
|
if (!cuidRegex.test(input.data)) {
|
|
369
369
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
370
|
-
|
|
370
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
371
371
|
validation: "cuid",
|
|
372
372
|
code: ZodError_1.ZodIssueCode.invalid_string,
|
|
373
373
|
message: check.message,
|
|
@@ -381,7 +381,7 @@ class ZodString extends ZodType {
|
|
|
381
381
|
}
|
|
382
382
|
catch (_a) {
|
|
383
383
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
384
|
-
|
|
384
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
385
385
|
validation: "url",
|
|
386
386
|
code: ZodError_1.ZodIssueCode.invalid_string,
|
|
387
387
|
message: check.message,
|
|
@@ -394,7 +394,7 @@ class ZodString extends ZodType {
|
|
|
394
394
|
const testResult = check.regex.test(input.data);
|
|
395
395
|
if (!testResult) {
|
|
396
396
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
397
|
-
|
|
397
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
398
398
|
validation: "regex",
|
|
399
399
|
code: ZodError_1.ZodIssueCode.invalid_string,
|
|
400
400
|
message: check.message,
|
|
@@ -516,7 +516,7 @@ class ZodNumber extends ZodType {
|
|
|
516
516
|
const parsedType = this._getType(input);
|
|
517
517
|
if (parsedType !== util_1.ZodParsedType.number) {
|
|
518
518
|
const ctx = this._getOrReturnCtx(input);
|
|
519
|
-
|
|
519
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
520
520
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
521
521
|
expected: util_1.ZodParsedType.number,
|
|
522
522
|
received: ctx.parsedType,
|
|
@@ -529,7 +529,7 @@ class ZodNumber extends ZodType {
|
|
|
529
529
|
if (check.kind === "int") {
|
|
530
530
|
if (!util_1.util.isInteger(input.data)) {
|
|
531
531
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
532
|
-
|
|
532
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
533
533
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
534
534
|
expected: "integer",
|
|
535
535
|
received: "float",
|
|
@@ -544,7 +544,7 @@ class ZodNumber extends ZodType {
|
|
|
544
544
|
: input.data <= check.value;
|
|
545
545
|
if (tooSmall) {
|
|
546
546
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
547
|
-
|
|
547
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
548
548
|
code: ZodError_1.ZodIssueCode.too_small,
|
|
549
549
|
minimum: check.value,
|
|
550
550
|
type: "number",
|
|
@@ -560,7 +560,7 @@ class ZodNumber extends ZodType {
|
|
|
560
560
|
: input.data >= check.value;
|
|
561
561
|
if (tooBig) {
|
|
562
562
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
563
|
-
|
|
563
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
564
564
|
code: ZodError_1.ZodIssueCode.too_big,
|
|
565
565
|
maximum: check.value,
|
|
566
566
|
type: "number",
|
|
@@ -573,7 +573,7 @@ class ZodNumber extends ZodType {
|
|
|
573
573
|
else if (check.kind === "multipleOf") {
|
|
574
574
|
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
575
575
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
576
|
-
|
|
576
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
577
577
|
code: ZodError_1.ZodIssueCode.not_multiple_of,
|
|
578
578
|
multipleOf: check.value,
|
|
579
579
|
message: check.message,
|
|
@@ -701,14 +701,14 @@ class ZodBigInt extends ZodType {
|
|
|
701
701
|
const parsedType = this._getType(input);
|
|
702
702
|
if (parsedType !== util_1.ZodParsedType.bigint) {
|
|
703
703
|
const ctx = this._getOrReturnCtx(input);
|
|
704
|
-
|
|
704
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
705
705
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
706
706
|
expected: util_1.ZodParsedType.bigint,
|
|
707
707
|
received: ctx.parsedType,
|
|
708
708
|
});
|
|
709
709
|
return parseUtil_1.INVALID;
|
|
710
710
|
}
|
|
711
|
-
return
|
|
711
|
+
return parseUtil_1.OK(input.data);
|
|
712
712
|
}
|
|
713
713
|
}
|
|
714
714
|
exports.ZodBigInt = ZodBigInt;
|
|
@@ -723,14 +723,14 @@ class ZodBoolean extends ZodType {
|
|
|
723
723
|
const parsedType = this._getType(input);
|
|
724
724
|
if (parsedType !== util_1.ZodParsedType.boolean) {
|
|
725
725
|
const ctx = this._getOrReturnCtx(input);
|
|
726
|
-
|
|
726
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
727
727
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
728
728
|
expected: util_1.ZodParsedType.boolean,
|
|
729
729
|
received: ctx.parsedType,
|
|
730
730
|
});
|
|
731
731
|
return parseUtil_1.INVALID;
|
|
732
732
|
}
|
|
733
|
-
return
|
|
733
|
+
return parseUtil_1.OK(input.data);
|
|
734
734
|
}
|
|
735
735
|
}
|
|
736
736
|
exports.ZodBoolean = ZodBoolean;
|
|
@@ -745,7 +745,7 @@ class ZodDate extends ZodType {
|
|
|
745
745
|
const parsedType = this._getType(input);
|
|
746
746
|
if (parsedType !== util_1.ZodParsedType.date) {
|
|
747
747
|
const ctx = this._getOrReturnCtx(input);
|
|
748
|
-
|
|
748
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
749
749
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
750
750
|
expected: util_1.ZodParsedType.date,
|
|
751
751
|
received: ctx.parsedType,
|
|
@@ -754,7 +754,7 @@ class ZodDate extends ZodType {
|
|
|
754
754
|
}
|
|
755
755
|
if (isNaN(input.data.getTime())) {
|
|
756
756
|
const ctx = this._getOrReturnCtx(input);
|
|
757
|
-
|
|
757
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
758
758
|
code: ZodError_1.ZodIssueCode.invalid_date,
|
|
759
759
|
});
|
|
760
760
|
return parseUtil_1.INVALID;
|
|
@@ -777,14 +777,14 @@ class ZodUndefined extends ZodType {
|
|
|
777
777
|
const parsedType = this._getType(input);
|
|
778
778
|
if (parsedType !== util_1.ZodParsedType.undefined) {
|
|
779
779
|
const ctx = this._getOrReturnCtx(input);
|
|
780
|
-
|
|
780
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
781
781
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
782
782
|
expected: util_1.ZodParsedType.undefined,
|
|
783
783
|
received: ctx.parsedType,
|
|
784
784
|
});
|
|
785
785
|
return parseUtil_1.INVALID;
|
|
786
786
|
}
|
|
787
|
-
return
|
|
787
|
+
return parseUtil_1.OK(input.data);
|
|
788
788
|
}
|
|
789
789
|
}
|
|
790
790
|
exports.ZodUndefined = ZodUndefined;
|
|
@@ -799,14 +799,14 @@ class ZodNull extends ZodType {
|
|
|
799
799
|
const parsedType = this._getType(input);
|
|
800
800
|
if (parsedType !== util_1.ZodParsedType.null) {
|
|
801
801
|
const ctx = this._getOrReturnCtx(input);
|
|
802
|
-
|
|
802
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
803
803
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
804
804
|
expected: util_1.ZodParsedType.null,
|
|
805
805
|
received: ctx.parsedType,
|
|
806
806
|
});
|
|
807
807
|
return parseUtil_1.INVALID;
|
|
808
808
|
}
|
|
809
|
-
return
|
|
809
|
+
return parseUtil_1.OK(input.data);
|
|
810
810
|
}
|
|
811
811
|
}
|
|
812
812
|
exports.ZodNull = ZodNull;
|
|
@@ -823,7 +823,7 @@ class ZodAny extends ZodType {
|
|
|
823
823
|
this._any = true;
|
|
824
824
|
}
|
|
825
825
|
_parse(input) {
|
|
826
|
-
return
|
|
826
|
+
return parseUtil_1.OK(input.data);
|
|
827
827
|
}
|
|
828
828
|
}
|
|
829
829
|
exports.ZodAny = ZodAny;
|
|
@@ -840,7 +840,7 @@ class ZodUnknown extends ZodType {
|
|
|
840
840
|
this._unknown = true;
|
|
841
841
|
}
|
|
842
842
|
_parse(input) {
|
|
843
|
-
return
|
|
843
|
+
return parseUtil_1.OK(input.data);
|
|
844
844
|
}
|
|
845
845
|
}
|
|
846
846
|
exports.ZodUnknown = ZodUnknown;
|
|
@@ -853,7 +853,7 @@ ZodUnknown.create = (params) => {
|
|
|
853
853
|
class ZodNever extends ZodType {
|
|
854
854
|
_parse(input) {
|
|
855
855
|
const ctx = this._getOrReturnCtx(input);
|
|
856
|
-
|
|
856
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
857
857
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
858
858
|
expected: util_1.ZodParsedType.never,
|
|
859
859
|
received: ctx.parsedType,
|
|
@@ -873,14 +873,14 @@ class ZodVoid extends ZodType {
|
|
|
873
873
|
const parsedType = this._getType(input);
|
|
874
874
|
if (parsedType !== util_1.ZodParsedType.undefined) {
|
|
875
875
|
const ctx = this._getOrReturnCtx(input);
|
|
876
|
-
|
|
876
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
877
877
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
878
878
|
expected: util_1.ZodParsedType.void,
|
|
879
879
|
received: ctx.parsedType,
|
|
880
880
|
});
|
|
881
881
|
return parseUtil_1.INVALID;
|
|
882
882
|
}
|
|
883
|
-
return
|
|
883
|
+
return parseUtil_1.OK(input.data);
|
|
884
884
|
}
|
|
885
885
|
}
|
|
886
886
|
exports.ZodVoid = ZodVoid;
|
|
@@ -895,7 +895,7 @@ class ZodArray extends ZodType {
|
|
|
895
895
|
const { ctx, status } = this._processInputParams(input);
|
|
896
896
|
const def = this._def;
|
|
897
897
|
if (ctx.parsedType !== util_1.ZodParsedType.array) {
|
|
898
|
-
|
|
898
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
899
899
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
900
900
|
expected: util_1.ZodParsedType.array,
|
|
901
901
|
received: ctx.parsedType,
|
|
@@ -904,7 +904,7 @@ class ZodArray extends ZodType {
|
|
|
904
904
|
}
|
|
905
905
|
if (def.minLength !== null) {
|
|
906
906
|
if (ctx.data.length < def.minLength.value) {
|
|
907
|
-
|
|
907
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
908
908
|
code: ZodError_1.ZodIssueCode.too_small,
|
|
909
909
|
minimum: def.minLength.value,
|
|
910
910
|
type: "array",
|
|
@@ -916,7 +916,7 @@ class ZodArray extends ZodType {
|
|
|
916
916
|
}
|
|
917
917
|
if (def.maxLength !== null) {
|
|
918
918
|
if (ctx.data.length > def.maxLength.value) {
|
|
919
|
-
|
|
919
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
920
920
|
code: ZodError_1.ZodIssueCode.too_big,
|
|
921
921
|
maximum: def.maxLength.value,
|
|
922
922
|
type: "array",
|
|
@@ -982,7 +982,7 @@ var objectUtil;
|
|
|
982
982
|
objectUtil.mergeShapes = (first, second) => {
|
|
983
983
|
return {
|
|
984
984
|
...first,
|
|
985
|
-
...second,
|
|
985
|
+
...second,
|
|
986
986
|
};
|
|
987
987
|
};
|
|
988
988
|
})(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
|
|
@@ -1046,7 +1046,7 @@ class ZodObject extends ZodType {
|
|
|
1046
1046
|
const parsedType = this._getType(input);
|
|
1047
1047
|
if (parsedType !== util_1.ZodParsedType.object) {
|
|
1048
1048
|
const ctx = this._getOrReturnCtx(input);
|
|
1049
|
-
|
|
1049
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1050
1050
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1051
1051
|
expected: util_1.ZodParsedType.object,
|
|
1052
1052
|
received: ctx.parsedType,
|
|
@@ -1083,7 +1083,7 @@ class ZodObject extends ZodType {
|
|
|
1083
1083
|
}
|
|
1084
1084
|
else if (unknownKeys === "strict") {
|
|
1085
1085
|
if (extraKeys.length > 0) {
|
|
1086
|
-
|
|
1086
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1087
1087
|
code: ZodError_1.ZodIssueCode.unrecognized_keys,
|
|
1088
1088
|
keys: extraKeys,
|
|
1089
1089
|
});
|
|
@@ -1313,7 +1313,7 @@ class ZodUnion extends ZodType {
|
|
|
1313
1313
|
}
|
|
1314
1314
|
// return invalid
|
|
1315
1315
|
const unionErrors = results.map((result) => new ZodError_1.ZodError(result.ctx.common.issues));
|
|
1316
|
-
|
|
1316
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1317
1317
|
code: ZodError_1.ZodIssueCode.invalid_union,
|
|
1318
1318
|
unionErrors,
|
|
1319
1319
|
});
|
|
@@ -1371,7 +1371,7 @@ class ZodUnion extends ZodType {
|
|
|
1371
1371
|
return dirty.result;
|
|
1372
1372
|
}
|
|
1373
1373
|
const unionErrors = issues.map((issues) => new ZodError_1.ZodError(issues));
|
|
1374
|
-
|
|
1374
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1375
1375
|
code: ZodError_1.ZodIssueCode.invalid_union,
|
|
1376
1376
|
unionErrors,
|
|
1377
1377
|
});
|
|
@@ -1394,7 +1394,7 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
1394
1394
|
_parse(input) {
|
|
1395
1395
|
const { ctx } = this._processInputParams(input);
|
|
1396
1396
|
if (ctx.parsedType !== util_1.ZodParsedType.object) {
|
|
1397
|
-
|
|
1397
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1398
1398
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1399
1399
|
expected: util_1.ZodParsedType.object,
|
|
1400
1400
|
received: ctx.parsedType,
|
|
@@ -1405,7 +1405,7 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
1405
1405
|
const discriminatorValue = ctx.data[discriminator];
|
|
1406
1406
|
const option = this.options.get(discriminatorValue);
|
|
1407
1407
|
if (!option) {
|
|
1408
|
-
|
|
1408
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1409
1409
|
code: ZodError_1.ZodIssueCode.invalid_union_discriminator,
|
|
1410
1410
|
options: this.validDiscriminatorValues,
|
|
1411
1411
|
path: [discriminator],
|
|
@@ -1470,8 +1470,8 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
1470
1470
|
}
|
|
1471
1471
|
exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
|
|
1472
1472
|
function mergeValues(a, b) {
|
|
1473
|
-
const aType =
|
|
1474
|
-
const bType =
|
|
1473
|
+
const aType = util_1.getParsedType(a);
|
|
1474
|
+
const bType = util_1.getParsedType(b);
|
|
1475
1475
|
if (a === b) {
|
|
1476
1476
|
return { valid: true, data: a };
|
|
1477
1477
|
}
|
|
@@ -1519,17 +1519,17 @@ class ZodIntersection extends ZodType {
|
|
|
1519
1519
|
_parse(input) {
|
|
1520
1520
|
const { status, ctx } = this._processInputParams(input);
|
|
1521
1521
|
const handleParsed = (parsedLeft, parsedRight) => {
|
|
1522
|
-
if (
|
|
1522
|
+
if (parseUtil_1.isAborted(parsedLeft) || parseUtil_1.isAborted(parsedRight)) {
|
|
1523
1523
|
return parseUtil_1.INVALID;
|
|
1524
1524
|
}
|
|
1525
1525
|
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
1526
1526
|
if (!merged.valid) {
|
|
1527
|
-
|
|
1527
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1528
1528
|
code: ZodError_1.ZodIssueCode.invalid_intersection_types,
|
|
1529
1529
|
});
|
|
1530
1530
|
return parseUtil_1.INVALID;
|
|
1531
1531
|
}
|
|
1532
|
-
if (
|
|
1532
|
+
if (parseUtil_1.isDirty(parsedLeft) || parseUtil_1.isDirty(parsedRight)) {
|
|
1533
1533
|
status.dirty();
|
|
1534
1534
|
}
|
|
1535
1535
|
return { status: status.value, value: merged.data };
|
|
@@ -1574,7 +1574,7 @@ class ZodTuple extends ZodType {
|
|
|
1574
1574
|
_parse(input) {
|
|
1575
1575
|
const { status, ctx } = this._processInputParams(input);
|
|
1576
1576
|
if (ctx.parsedType !== util_1.ZodParsedType.array) {
|
|
1577
|
-
|
|
1577
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1578
1578
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1579
1579
|
expected: util_1.ZodParsedType.array,
|
|
1580
1580
|
received: ctx.parsedType,
|
|
@@ -1582,7 +1582,7 @@ class ZodTuple extends ZodType {
|
|
|
1582
1582
|
return parseUtil_1.INVALID;
|
|
1583
1583
|
}
|
|
1584
1584
|
if (ctx.data.length < this._def.items.length) {
|
|
1585
|
-
|
|
1585
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1586
1586
|
code: ZodError_1.ZodIssueCode.too_small,
|
|
1587
1587
|
minimum: this._def.items.length,
|
|
1588
1588
|
inclusive: true,
|
|
@@ -1592,7 +1592,7 @@ class ZodTuple extends ZodType {
|
|
|
1592
1592
|
}
|
|
1593
1593
|
const rest = this._def.rest;
|
|
1594
1594
|
if (!rest && ctx.data.length > this._def.items.length) {
|
|
1595
|
-
|
|
1595
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1596
1596
|
code: ZodError_1.ZodIssueCode.too_big,
|
|
1597
1597
|
maximum: this._def.items.length,
|
|
1598
1598
|
inclusive: true,
|
|
@@ -1646,7 +1646,7 @@ class ZodRecord extends ZodType {
|
|
|
1646
1646
|
_parse(input) {
|
|
1647
1647
|
const { status, ctx } = this._processInputParams(input);
|
|
1648
1648
|
if (ctx.parsedType !== util_1.ZodParsedType.object) {
|
|
1649
|
-
|
|
1649
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1650
1650
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1651
1651
|
expected: util_1.ZodParsedType.object,
|
|
1652
1652
|
received: ctx.parsedType,
|
|
@@ -1694,7 +1694,7 @@ class ZodMap extends ZodType {
|
|
|
1694
1694
|
_parse(input) {
|
|
1695
1695
|
const { status, ctx } = this._processInputParams(input);
|
|
1696
1696
|
if (ctx.parsedType !== util_1.ZodParsedType.map) {
|
|
1697
|
-
|
|
1697
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1698
1698
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1699
1699
|
expected: util_1.ZodParsedType.map,
|
|
1700
1700
|
received: ctx.parsedType,
|
|
@@ -1756,7 +1756,7 @@ class ZodSet extends ZodType {
|
|
|
1756
1756
|
_parse(input) {
|
|
1757
1757
|
const { status, ctx } = this._processInputParams(input);
|
|
1758
1758
|
if (ctx.parsedType !== util_1.ZodParsedType.set) {
|
|
1759
|
-
|
|
1759
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1760
1760
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1761
1761
|
expected: util_1.ZodParsedType.set,
|
|
1762
1762
|
received: ctx.parsedType,
|
|
@@ -1766,7 +1766,7 @@ class ZodSet extends ZodType {
|
|
|
1766
1766
|
const def = this._def;
|
|
1767
1767
|
if (def.minSize !== null) {
|
|
1768
1768
|
if (ctx.data.size < def.minSize.value) {
|
|
1769
|
-
|
|
1769
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1770
1770
|
code: ZodError_1.ZodIssueCode.too_small,
|
|
1771
1771
|
minimum: def.minSize.value,
|
|
1772
1772
|
type: "set",
|
|
@@ -1778,7 +1778,7 @@ class ZodSet extends ZodType {
|
|
|
1778
1778
|
}
|
|
1779
1779
|
if (def.maxSize !== null) {
|
|
1780
1780
|
if (ctx.data.size > def.maxSize.value) {
|
|
1781
|
-
|
|
1781
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1782
1782
|
code: ZodError_1.ZodIssueCode.too_big,
|
|
1783
1783
|
maximum: def.maxSize.value,
|
|
1784
1784
|
type: "set",
|
|
@@ -1845,7 +1845,7 @@ class ZodFunction extends ZodType {
|
|
|
1845
1845
|
_parse(input) {
|
|
1846
1846
|
const { ctx } = this._processInputParams(input);
|
|
1847
1847
|
if (ctx.parsedType !== util_1.ZodParsedType.function) {
|
|
1848
|
-
|
|
1848
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1849
1849
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1850
1850
|
expected: util_1.ZodParsedType.function,
|
|
1851
1851
|
received: ctx.parsedType,
|
|
@@ -1853,7 +1853,7 @@ class ZodFunction extends ZodType {
|
|
|
1853
1853
|
return parseUtil_1.INVALID;
|
|
1854
1854
|
}
|
|
1855
1855
|
function makeArgsIssue(args, error) {
|
|
1856
|
-
return
|
|
1856
|
+
return parseUtil_1.makeIssue({
|
|
1857
1857
|
data: args,
|
|
1858
1858
|
path: ctx.path,
|
|
1859
1859
|
errorMaps: [
|
|
@@ -1869,7 +1869,7 @@ class ZodFunction extends ZodType {
|
|
|
1869
1869
|
});
|
|
1870
1870
|
}
|
|
1871
1871
|
function makeReturnsIssue(returns, error) {
|
|
1872
|
-
return
|
|
1872
|
+
return parseUtil_1.makeIssue({
|
|
1873
1873
|
data: returns,
|
|
1874
1874
|
path: ctx.path,
|
|
1875
1875
|
errorMaps: [
|
|
@@ -1887,7 +1887,7 @@ class ZodFunction extends ZodType {
|
|
|
1887
1887
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
1888
1888
|
const fn = ctx.data;
|
|
1889
1889
|
if (this._def.returns instanceof ZodPromise) {
|
|
1890
|
-
return
|
|
1890
|
+
return parseUtil_1.OK(async (...args) => {
|
|
1891
1891
|
const error = new ZodError_1.ZodError([]);
|
|
1892
1892
|
const parsedArgs = await this._def.args
|
|
1893
1893
|
.parseAsync(args, params)
|
|
@@ -1906,7 +1906,7 @@ class ZodFunction extends ZodType {
|
|
|
1906
1906
|
});
|
|
1907
1907
|
}
|
|
1908
1908
|
else {
|
|
1909
|
-
return
|
|
1909
|
+
return parseUtil_1.OK((...args) => {
|
|
1910
1910
|
const parsedArgs = this._def.args.safeParse(args, params);
|
|
1911
1911
|
if (!parsedArgs.success) {
|
|
1912
1912
|
throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
@@ -1980,7 +1980,7 @@ class ZodLiteral extends ZodType {
|
|
|
1980
1980
|
_parse(input) {
|
|
1981
1981
|
if (input.data !== this._def.value) {
|
|
1982
1982
|
const ctx = this._getOrReturnCtx(input);
|
|
1983
|
-
|
|
1983
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
1984
1984
|
code: ZodError_1.ZodIssueCode.invalid_literal,
|
|
1985
1985
|
expected: this._def.value,
|
|
1986
1986
|
});
|
|
@@ -2012,7 +2012,7 @@ class ZodEnum extends ZodType {
|
|
|
2012
2012
|
if (typeof input.data !== "string") {
|
|
2013
2013
|
const ctx = this._getOrReturnCtx(input);
|
|
2014
2014
|
const expectedValues = this._def.values;
|
|
2015
|
-
|
|
2015
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
2016
2016
|
expected: util_1.util.joinValues(expectedValues),
|
|
2017
2017
|
received: ctx.parsedType,
|
|
2018
2018
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2022,14 +2022,14 @@ class ZodEnum extends ZodType {
|
|
|
2022
2022
|
if (this._def.values.indexOf(input.data) === -1) {
|
|
2023
2023
|
const ctx = this._getOrReturnCtx(input);
|
|
2024
2024
|
const expectedValues = this._def.values;
|
|
2025
|
-
|
|
2025
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
2026
2026
|
received: ctx.data,
|
|
2027
2027
|
code: ZodError_1.ZodIssueCode.invalid_enum_value,
|
|
2028
2028
|
options: expectedValues,
|
|
2029
2029
|
});
|
|
2030
2030
|
return parseUtil_1.INVALID;
|
|
2031
2031
|
}
|
|
2032
|
-
return
|
|
2032
|
+
return parseUtil_1.OK(input.data);
|
|
2033
2033
|
}
|
|
2034
2034
|
get options() {
|
|
2035
2035
|
return this._def.values;
|
|
@@ -2065,7 +2065,7 @@ class ZodNativeEnum extends ZodType {
|
|
|
2065
2065
|
if (ctx.parsedType !== util_1.ZodParsedType.string &&
|
|
2066
2066
|
ctx.parsedType !== util_1.ZodParsedType.number) {
|
|
2067
2067
|
const expectedValues = util_1.util.objectValues(nativeEnumValues);
|
|
2068
|
-
|
|
2068
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
2069
2069
|
expected: util_1.util.joinValues(expectedValues),
|
|
2070
2070
|
received: ctx.parsedType,
|
|
2071
2071
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2074,14 +2074,14 @@ class ZodNativeEnum extends ZodType {
|
|
|
2074
2074
|
}
|
|
2075
2075
|
if (nativeEnumValues.indexOf(input.data) === -1) {
|
|
2076
2076
|
const expectedValues = util_1.util.objectValues(nativeEnumValues);
|
|
2077
|
-
|
|
2077
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
2078
2078
|
received: ctx.data,
|
|
2079
2079
|
code: ZodError_1.ZodIssueCode.invalid_enum_value,
|
|
2080
2080
|
options: expectedValues,
|
|
2081
2081
|
});
|
|
2082
2082
|
return parseUtil_1.INVALID;
|
|
2083
2083
|
}
|
|
2084
|
-
return
|
|
2084
|
+
return parseUtil_1.OK(input.data);
|
|
2085
2085
|
}
|
|
2086
2086
|
get enum() {
|
|
2087
2087
|
return this._def.values;
|
|
@@ -2100,7 +2100,7 @@ class ZodPromise extends ZodType {
|
|
|
2100
2100
|
const { ctx } = this._processInputParams(input);
|
|
2101
2101
|
if (ctx.parsedType !== util_1.ZodParsedType.promise &&
|
|
2102
2102
|
ctx.common.async === false) {
|
|
2103
|
-
|
|
2103
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
2104
2104
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
2105
2105
|
expected: util_1.ZodParsedType.promise,
|
|
2106
2106
|
received: ctx.parsedType,
|
|
@@ -2110,7 +2110,7 @@ class ZodPromise extends ZodType {
|
|
|
2110
2110
|
const promisified = ctx.parsedType === util_1.ZodParsedType.promise
|
|
2111
2111
|
? ctx.data
|
|
2112
2112
|
: Promise.resolve(ctx.data);
|
|
2113
|
-
return
|
|
2113
|
+
return parseUtil_1.OK(promisified.then((data) => {
|
|
2114
2114
|
return this._def.type.parseAsync(data, {
|
|
2115
2115
|
path: ctx.path,
|
|
2116
2116
|
errorMap: ctx.common.contextualErrorMap,
|
|
@@ -2154,7 +2154,7 @@ class ZodEffects extends ZodType {
|
|
|
2154
2154
|
}
|
|
2155
2155
|
const checkCtx = {
|
|
2156
2156
|
addIssue: (arg) => {
|
|
2157
|
-
|
|
2157
|
+
parseUtil_1.addIssueToContext(ctx, arg);
|
|
2158
2158
|
if (arg.fatal) {
|
|
2159
2159
|
status.abort();
|
|
2160
2160
|
}
|
|
@@ -2219,7 +2219,7 @@ class ZodEffects extends ZodType {
|
|
|
2219
2219
|
// if (base.status === "dirty") {
|
|
2220
2220
|
// return { status: "dirty", value: base.value };
|
|
2221
2221
|
// }
|
|
2222
|
-
if (!
|
|
2222
|
+
if (!parseUtil_1.isValid(base))
|
|
2223
2223
|
return base;
|
|
2224
2224
|
const result = effect.transform(base.value, checkCtx);
|
|
2225
2225
|
if (result instanceof Promise) {
|
|
@@ -2231,7 +2231,7 @@ class ZodEffects extends ZodType {
|
|
|
2231
2231
|
return this._def.schema
|
|
2232
2232
|
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
2233
2233
|
.then((base) => {
|
|
2234
|
-
if (!
|
|
2234
|
+
if (!parseUtil_1.isValid(base))
|
|
2235
2235
|
return base;
|
|
2236
2236
|
// if (base.status === "aborted") return INVALID;
|
|
2237
2237
|
// if (base.status === "dirty") {
|
|
@@ -2266,7 +2266,7 @@ class ZodOptional extends ZodType {
|
|
|
2266
2266
|
_parse(input) {
|
|
2267
2267
|
const parsedType = this._getType(input);
|
|
2268
2268
|
if (parsedType === util_1.ZodParsedType.undefined) {
|
|
2269
|
-
return
|
|
2269
|
+
return parseUtil_1.OK(undefined);
|
|
2270
2270
|
}
|
|
2271
2271
|
return this._def.innerType._parse(input);
|
|
2272
2272
|
}
|
|
@@ -2286,7 +2286,7 @@ class ZodNullable extends ZodType {
|
|
|
2286
2286
|
_parse(input) {
|
|
2287
2287
|
const parsedType = this._getType(input);
|
|
2288
2288
|
if (parsedType === util_1.ZodParsedType.null) {
|
|
2289
|
-
return
|
|
2289
|
+
return parseUtil_1.OK(null);
|
|
2290
2290
|
}
|
|
2291
2291
|
return this._def.innerType._parse(input);
|
|
2292
2292
|
}
|
|
@@ -2332,7 +2332,7 @@ class ZodNaN extends ZodType {
|
|
|
2332
2332
|
const parsedType = this._getType(input);
|
|
2333
2333
|
if (parsedType !== util_1.ZodParsedType.nan) {
|
|
2334
2334
|
const ctx = this._getOrReturnCtx(input);
|
|
2335
|
-
|
|
2335
|
+
parseUtil_1.addIssueToContext(ctx, {
|
|
2336
2336
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
2337
2337
|
expected: util_1.ZodParsedType.nan,
|
|
2338
2338
|
received: ctx.parsedType,
|
|
@@ -2400,7 +2400,7 @@ var ZodFirstPartyTypeKind;
|
|
|
2400
2400
|
})(ZodFirstPartyTypeKind = exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
|
|
2401
2401
|
const instanceOfType = (cls, params = {
|
|
2402
2402
|
message: `Input not instance of ${cls.name}`,
|
|
2403
|
-
}) =>
|
|
2403
|
+
}) => exports.custom((data) => data instanceof cls, params, true);
|
|
2404
2404
|
exports.instanceof = instanceOfType;
|
|
2405
2405
|
const stringType = ZodString.create;
|
|
2406
2406
|
exports.string = stringType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.3",
|
|
4
4
|
"description": "TypeScript-first schema declaration and validation library with static type inference",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"ts-morph": "^14.0.0",
|
|
91
91
|
"ts-node": "^10.7.0",
|
|
92
92
|
"tslib": "^2.3.1",
|
|
93
|
-
"typescript": "
|
|
93
|
+
"typescript": "4.1"
|
|
94
94
|
},
|
|
95
95
|
"lint-staged": {
|
|
96
96
|
"src/*.ts": [
|