zod 3.14.2 → 3.14.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/README.md +72 -10
- package/lib/index.mjs +22 -43
- package/lib/types.d.ts +1 -5
- package/lib/types.js +24 -43
- package/package.json +22 -30
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<h1 align="center">Zod</h1>
|
|
4
4
|
</p>
|
|
5
5
|
<p align="center">
|
|
6
|
-
<a href="https://github.com/edgedb/edgedb-js/actions"><img src="https://github.com/colinhacks/zod/workflows/test.yml/badge.svg?event=push&branch=master" alt="Zod CI status" /></a>
|
|
6
|
+
<a href="https://github.com/edgedb/edgedb-js/actions"><img src="https://github.com/colinhacks/zod/actions/workflows/test.yml/badge.svg?event=push&branch=master" alt="Zod CI status" /></a>
|
|
7
7
|
<a href="https://twitter.com/colinhacks" rel="nofollow"><img src="https://img.shields.io/badge/created%20by-@colinhacks-4BBAAB.svg" alt="Created by Colin McDonnell"></a>
|
|
8
8
|
<a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/colinhacks/zod" alt="License"></a>
|
|
9
9
|
<a href="https://www.npmjs.com/package/zod" rel="nofollow"><img src="https://img.shields.io/npm/dw/zod.svg" alt="npm"></a>
|
|
@@ -94,8 +94,10 @@ These docs have been translated into [Chinese](./README_ZH.md).
|
|
|
94
94
|
- [.promise](#promise)
|
|
95
95
|
- [.or](#or)
|
|
96
96
|
- [.and](#and)
|
|
97
|
-
- [
|
|
98
|
-
- [
|
|
97
|
+
- [Guides and concepts](#guides-and-concepts)
|
|
98
|
+
- [Type inference](#type-inference)
|
|
99
|
+
- [Writing generic functions](#writing-generic-functions)
|
|
100
|
+
- [Error handling](#error-handling)
|
|
99
101
|
- [Comparison](#comparison)
|
|
100
102
|
- [Joi](#joi)
|
|
101
103
|
- [Yup](#yup)
|
|
@@ -241,6 +243,8 @@ There are a growing number of tools that are built atop or support Zod natively!
|
|
|
241
243
|
- [`soly`](https://github.com/mdbetancourt/soly): Create CLI applications with zod.
|
|
242
244
|
- [`graphql-codegen-typescript-validation-schema`](https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema): GraphQL Code Generator plugin to generate form validation schema from your GraphQL schema
|
|
243
245
|
- [`zod-prisma`](https://github.com/CarterGrimmeisen/zod-prisma): Generate Zod schemas from your Prisma schema.
|
|
246
|
+
- [`fastify-type-provider-zod`](https://github.com/turkerdev/fastify-type-provider-zod): Create Fastify type providers from Zod schemas
|
|
247
|
+
- [`Supervillain`](https://github.com/Southclaws/supervillain): Generate Zod schemas from your Go structs
|
|
244
248
|
|
|
245
249
|
### Form integrations
|
|
246
250
|
|
|
@@ -1687,7 +1691,9 @@ z.object({ name: z.string() }).and(z.object({ age: z.number() })); // { name: st
|
|
|
1687
1691
|
z.intersection(z.object({ name: z.string() }), z.object({ age: z.number() }));
|
|
1688
1692
|
```
|
|
1689
1693
|
|
|
1690
|
-
#
|
|
1694
|
+
# Guides and concepts
|
|
1695
|
+
|
|
1696
|
+
## Type inference
|
|
1691
1697
|
|
|
1692
1698
|
You can extract the TypeScript type of any schema with `z.infer<typeof mySchema>` .
|
|
1693
1699
|
|
|
@@ -1716,16 +1722,72 @@ type output = z.output<typeof stringToNumber>; // number
|
|
|
1716
1722
|
type inferred = z.infer<typeof stringToNumber>; // number
|
|
1717
1723
|
```
|
|
1718
1724
|
|
|
1719
|
-
|
|
1725
|
+
## Writing generic functions
|
|
1726
|
+
|
|
1727
|
+
When attempting to write a functions that accepts a Zod schemas as an input, it's common to try something like this:
|
|
1728
|
+
|
|
1729
|
+
```ts
|
|
1730
|
+
function makeSchemaOptional<T>(schema: z.ZodType<T>) {
|
|
1731
|
+
return schema.optional();
|
|
1732
|
+
}
|
|
1733
|
+
```
|
|
1734
|
+
|
|
1735
|
+
This approach has some issues. The `schema` variable in this function is typed as an instance of `ZodType`, which is an abstract class that all Zod schemas inherit from. This approach loses type information, namely _which subclass_ the input actually is.
|
|
1736
|
+
|
|
1737
|
+
```ts
|
|
1738
|
+
const arg = makeSchemaOptional(z.string());
|
|
1739
|
+
arg.unwrap();
|
|
1740
|
+
```
|
|
1741
|
+
|
|
1742
|
+
A better approach is for the generate parameter to refer to _the schema as a whole_.
|
|
1743
|
+
|
|
1744
|
+
```ts
|
|
1745
|
+
function makeSchemaOptional<T extends z.ZodTypeAny>(schema: T) {
|
|
1746
|
+
return schema.optional();
|
|
1747
|
+
}
|
|
1748
|
+
```
|
|
1749
|
+
|
|
1750
|
+
> `ZodTypeAny` is just a shorthand for `ZodType<any, any, any>`, a type that is broad enough to match any Zod schema.
|
|
1751
|
+
|
|
1752
|
+
As you can see, `schema` is now fully and properly typed.
|
|
1753
|
+
|
|
1754
|
+
```ts
|
|
1755
|
+
const arg = makeSchemaOptional(z.string());
|
|
1756
|
+
arg.unwrap(); // ZodString
|
|
1757
|
+
```
|
|
1758
|
+
|
|
1759
|
+
### Restricting valid schemas
|
|
1760
|
+
|
|
1761
|
+
The `ZodType` class has three generic parameters.
|
|
1762
|
+
|
|
1763
|
+
```ts
|
|
1764
|
+
class ZodType<
|
|
1765
|
+
Output,
|
|
1766
|
+
Def extends ZodTypeDef = ZodTypeDef,
|
|
1767
|
+
Input = Output
|
|
1768
|
+
> { ... }
|
|
1769
|
+
```
|
|
1770
|
+
|
|
1771
|
+
By contraining these in your generic input, you can limit what schemas are allowable as inputs to your function:
|
|
1772
|
+
|
|
1773
|
+
```ts
|
|
1774
|
+
function makeSchemaOptional<T extends z.ZodType<string>>(schema: T) {
|
|
1775
|
+
return schema.optional();
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
makeSchemaOptional(z.string());
|
|
1779
|
+
// works fine
|
|
1780
|
+
|
|
1781
|
+
makeSchemaOptional(z.number());
|
|
1782
|
+
// Error: 'ZodNumber' is not assignable to parameter of type 'ZodType<string, ZodTypeDef, string>'
|
|
1783
|
+
```
|
|
1784
|
+
|
|
1785
|
+
## Error handling
|
|
1720
1786
|
|
|
1721
1787
|
Zod provides a subclass of Error called `ZodError`. ZodErrors contain an `issues` array containing detailed information about the validation problems.
|
|
1722
1788
|
|
|
1723
1789
|
```ts
|
|
1724
|
-
const data = z
|
|
1725
|
-
.object({
|
|
1726
|
-
name: z.string(),
|
|
1727
|
-
})
|
|
1728
|
-
.safeParse({ name: 12 });
|
|
1790
|
+
const data = z.object({ name: z.string() }).safeParse({ name: 12 });
|
|
1729
1791
|
|
|
1730
1792
|
if (!data.success) {
|
|
1731
1793
|
data.error.issues;
|
package/lib/index.mjs
CHANGED
|
@@ -419,6 +419,17 @@ var errorUtil;
|
|
|
419
419
|
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
420
420
|
})(errorUtil || (errorUtil = {}));
|
|
421
421
|
|
|
422
|
+
class ParseInputLazyPath {
|
|
423
|
+
constructor(parent, value, path, key) {
|
|
424
|
+
this.parent = parent;
|
|
425
|
+
this.data = value;
|
|
426
|
+
this._path = path;
|
|
427
|
+
this._key = key;
|
|
428
|
+
}
|
|
429
|
+
get path() {
|
|
430
|
+
return this._path.concat(this._key);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
422
433
|
const handleResult = (ctx, result) => {
|
|
423
434
|
if (isValid(result)) {
|
|
424
435
|
return { success: true, data: result.value };
|
|
@@ -475,8 +486,8 @@ class ZodType {
|
|
|
475
486
|
this.transform = this.transform.bind(this);
|
|
476
487
|
this.default = this.default.bind(this);
|
|
477
488
|
this.describe = this.describe.bind(this);
|
|
478
|
-
this.isOptional = this.isOptional.bind(this);
|
|
479
489
|
this.isNullable = this.isNullable.bind(this);
|
|
490
|
+
this.isOptional = this.isOptional.bind(this);
|
|
480
491
|
}
|
|
481
492
|
get description() {
|
|
482
493
|
return this._def.description;
|
|
@@ -1308,21 +1319,13 @@ class ZodArray extends ZodType {
|
|
|
1308
1319
|
}
|
|
1309
1320
|
if (ctx.common.async) {
|
|
1310
1321
|
return Promise.all(ctx.data.map((item, i) => {
|
|
1311
|
-
return def.type._parseAsync(
|
|
1312
|
-
parent: ctx,
|
|
1313
|
-
path: [...ctx.path, i],
|
|
1314
|
-
data: item,
|
|
1315
|
-
});
|
|
1322
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
1316
1323
|
})).then((result) => {
|
|
1317
1324
|
return ParseStatus.mergeArray(status, result);
|
|
1318
1325
|
});
|
|
1319
1326
|
}
|
|
1320
1327
|
const result = ctx.data.map((item, i) => {
|
|
1321
|
-
return def.type._parseSync(
|
|
1322
|
-
parent: ctx,
|
|
1323
|
-
path: [...ctx.path, i],
|
|
1324
|
-
data: item,
|
|
1325
|
-
});
|
|
1328
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
1326
1329
|
});
|
|
1327
1330
|
return ParseStatus.mergeArray(status, result);
|
|
1328
1331
|
}
|
|
@@ -1450,11 +1453,7 @@ class ZodObject extends ZodType {
|
|
|
1450
1453
|
const value = ctx.data[key];
|
|
1451
1454
|
pairs.push({
|
|
1452
1455
|
key: { status: "valid", value: key },
|
|
1453
|
-
value: keyValidator._parse(
|
|
1454
|
-
parent: ctx,
|
|
1455
|
-
data: value,
|
|
1456
|
-
path: [...ctx.path, key],
|
|
1457
|
-
}),
|
|
1456
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
1458
1457
|
alwaysSet: key in ctx.data,
|
|
1459
1458
|
});
|
|
1460
1459
|
}
|
|
@@ -1489,7 +1488,7 @@ class ZodObject extends ZodType {
|
|
|
1489
1488
|
const value = ctx.data[key];
|
|
1490
1489
|
pairs.push({
|
|
1491
1490
|
key: { status: "valid", value: key },
|
|
1492
|
-
value: catchall._parse(
|
|
1491
|
+
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
|
|
1493
1492
|
),
|
|
1494
1493
|
alwaysSet: key in ctx.data,
|
|
1495
1494
|
});
|
|
@@ -1985,11 +1984,7 @@ class ZodTuple extends ZodType {
|
|
|
1985
1984
|
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
1986
1985
|
if (!schema)
|
|
1987
1986
|
return null;
|
|
1988
|
-
return schema._parse(
|
|
1989
|
-
data: item,
|
|
1990
|
-
path: [...ctx.path, itemIndex],
|
|
1991
|
-
parent: ctx,
|
|
1992
|
-
});
|
|
1987
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
1993
1988
|
})
|
|
1994
1989
|
.filter((x) => !!x); // filter nulls
|
|
1995
1990
|
if (ctx.common.async) {
|
|
@@ -2041,16 +2036,8 @@ class ZodRecord extends ZodType {
|
|
|
2041
2036
|
const valueType = this._def.valueType;
|
|
2042
2037
|
for (const key in ctx.data) {
|
|
2043
2038
|
pairs.push({
|
|
2044
|
-
key: keyType._parse(
|
|
2045
|
-
|
|
2046
|
-
path: [...ctx.path, key],
|
|
2047
|
-
parent: ctx,
|
|
2048
|
-
}),
|
|
2049
|
-
value: valueType._parse({
|
|
2050
|
-
data: ctx.data[key],
|
|
2051
|
-
path: [...ctx.path, key],
|
|
2052
|
-
parent: ctx,
|
|
2053
|
-
}),
|
|
2039
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
2040
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
2054
2041
|
});
|
|
2055
2042
|
}
|
|
2056
2043
|
if (ctx.common.async) {
|
|
@@ -2095,16 +2082,8 @@ class ZodMap extends ZodType {
|
|
|
2095
2082
|
const valueType = this._def.valueType;
|
|
2096
2083
|
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
2097
2084
|
return {
|
|
2098
|
-
key: keyType._parse(
|
|
2099
|
-
|
|
2100
|
-
path: [...ctx.path, index, "key"],
|
|
2101
|
-
parent: ctx,
|
|
2102
|
-
}),
|
|
2103
|
-
value: valueType._parse({
|
|
2104
|
-
data: value,
|
|
2105
|
-
path: [...ctx.path, index, "value"],
|
|
2106
|
-
parent: ctx,
|
|
2107
|
-
}),
|
|
2085
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
2086
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
|
|
2108
2087
|
};
|
|
2109
2088
|
});
|
|
2110
2089
|
if (ctx.common.async) {
|
|
@@ -2197,7 +2176,7 @@ class ZodSet extends ZodType {
|
|
|
2197
2176
|
}
|
|
2198
2177
|
return { status: status.value, value: parsedSet };
|
|
2199
2178
|
}
|
|
2200
|
-
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(
|
|
2179
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
2201
2180
|
if (ctx.common.async) {
|
|
2202
2181
|
return Promise.all(elements).then((elements) => finalizeSet(elements));
|
|
2203
2182
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export declare type SafeParseError<Input> = {
|
|
|
44
44
|
error: ZodError<Input>;
|
|
45
45
|
};
|
|
46
46
|
export declare type SafeParseReturnType<Input, Output> = SafeParseSuccess<Output> | SafeParseError<Input>;
|
|
47
|
-
export declare abstract class ZodType<Output, Def extends ZodTypeDef = ZodTypeDef, Input = Output> {
|
|
47
|
+
export declare abstract class ZodType<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> {
|
|
48
48
|
readonly _type: Output;
|
|
49
49
|
readonly _output: Output;
|
|
50
50
|
readonly _input: Input;
|
|
@@ -65,10 +65,6 @@ export declare abstract class ZodType<Output, Def extends ZodTypeDef = ZodTypeDe
|
|
|
65
65
|
safeParseAsync(data: unknown, params?: Partial<ParseParams>): Promise<SafeParseReturnType<Input, Output>>;
|
|
66
66
|
/** Alias of safeParseAsync */
|
|
67
67
|
spa: (data: unknown, params?: Partial<ParseParams> | undefined) => Promise<SafeParseReturnType<Input, Output>>;
|
|
68
|
-
/** The .is method has been removed in Zod 3. For details see https://github.com/colinhacks/zod/tree/v3. */
|
|
69
|
-
is: never;
|
|
70
|
-
/** The .check method has been removed in Zod 3. For details see https://github.com/colinhacks/zod/tree/v3. */
|
|
71
|
-
check: never;
|
|
72
68
|
refine<RefinedOutput extends Output>(check: (arg: Output) => arg is RefinedOutput, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)): ZodEffects<this, RefinedOutput, RefinedOutput>;
|
|
73
69
|
refine(check: (arg: Output) => unknown | Promise<unknown>, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)): ZodEffects<this, Output, Input>;
|
|
74
70
|
refinement<RefinedOutput extends Output>(check: (arg: Output) => arg is RefinedOutput, refinementData: IssueData | ((arg: Output, ctx: RefinementCtx) => IssueData)): ZodEffects<this, RefinedOutput, RefinedOutput>;
|
package/lib/types.js
CHANGED
|
@@ -6,6 +6,17 @@ const errorUtil_1 = require("./helpers/errorUtil");
|
|
|
6
6
|
const parseUtil_1 = require("./helpers/parseUtil");
|
|
7
7
|
const util_1 = require("./helpers/util");
|
|
8
8
|
const ZodError_1 = require("./ZodError");
|
|
9
|
+
class ParseInputLazyPath {
|
|
10
|
+
constructor(parent, value, path, key) {
|
|
11
|
+
this.parent = parent;
|
|
12
|
+
this.data = value;
|
|
13
|
+
this._path = path;
|
|
14
|
+
this._key = key;
|
|
15
|
+
}
|
|
16
|
+
get path() {
|
|
17
|
+
return this._path.concat(this._key);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
9
20
|
const handleResult = (ctx, result) => {
|
|
10
21
|
if ((0, parseUtil_1.isValid)(result)) {
|
|
11
22
|
return { success: true, data: result.value };
|
|
@@ -62,8 +73,8 @@ class ZodType {
|
|
|
62
73
|
this.transform = this.transform.bind(this);
|
|
63
74
|
this.default = this.default.bind(this);
|
|
64
75
|
this.describe = this.describe.bind(this);
|
|
65
|
-
this.isOptional = this.isOptional.bind(this);
|
|
66
76
|
this.isNullable = this.isNullable.bind(this);
|
|
77
|
+
this.isOptional = this.isOptional.bind(this);
|
|
67
78
|
}
|
|
68
79
|
get description() {
|
|
69
80
|
return this._def.description;
|
|
@@ -214,6 +225,8 @@ class ZodType {
|
|
|
214
225
|
});
|
|
215
226
|
}
|
|
216
227
|
optional() {
|
|
228
|
+
("");
|
|
229
|
+
("asdf");
|
|
217
230
|
return ZodOptional.create(this);
|
|
218
231
|
}
|
|
219
232
|
nullable() {
|
|
@@ -909,21 +922,13 @@ class ZodArray extends ZodType {
|
|
|
909
922
|
}
|
|
910
923
|
if (ctx.common.async) {
|
|
911
924
|
return Promise.all(ctx.data.map((item, i) => {
|
|
912
|
-
return def.type._parseAsync(
|
|
913
|
-
parent: ctx,
|
|
914
|
-
path: [...ctx.path, i],
|
|
915
|
-
data: item,
|
|
916
|
-
});
|
|
925
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
917
926
|
})).then((result) => {
|
|
918
927
|
return parseUtil_1.ParseStatus.mergeArray(status, result);
|
|
919
928
|
});
|
|
920
929
|
}
|
|
921
930
|
const result = ctx.data.map((item, i) => {
|
|
922
|
-
return def.type._parseSync(
|
|
923
|
-
parent: ctx,
|
|
924
|
-
path: [...ctx.path, i],
|
|
925
|
-
data: item,
|
|
926
|
-
});
|
|
931
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
927
932
|
});
|
|
928
933
|
return parseUtil_1.ParseStatus.mergeArray(status, result);
|
|
929
934
|
}
|
|
@@ -1052,11 +1057,7 @@ class ZodObject extends ZodType {
|
|
|
1052
1057
|
const value = ctx.data[key];
|
|
1053
1058
|
pairs.push({
|
|
1054
1059
|
key: { status: "valid", value: key },
|
|
1055
|
-
value: keyValidator._parse(
|
|
1056
|
-
parent: ctx,
|
|
1057
|
-
data: value,
|
|
1058
|
-
path: [...ctx.path, key],
|
|
1059
|
-
}),
|
|
1060
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
1060
1061
|
alwaysSet: key in ctx.data,
|
|
1061
1062
|
});
|
|
1062
1063
|
}
|
|
@@ -1092,7 +1093,7 @@ class ZodObject extends ZodType {
|
|
|
1092
1093
|
const value = ctx.data[key];
|
|
1093
1094
|
pairs.push({
|
|
1094
1095
|
key: { status: "valid", value: key },
|
|
1095
|
-
value: catchall._parse(
|
|
1096
|
+
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
|
|
1096
1097
|
),
|
|
1097
1098
|
alwaysSet: key in ctx.data,
|
|
1098
1099
|
});
|
|
@@ -1592,11 +1593,7 @@ class ZodTuple extends ZodType {
|
|
|
1592
1593
|
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
1593
1594
|
if (!schema)
|
|
1594
1595
|
return null;
|
|
1595
|
-
return schema._parse(
|
|
1596
|
-
data: item,
|
|
1597
|
-
path: [...ctx.path, itemIndex],
|
|
1598
|
-
parent: ctx,
|
|
1599
|
-
});
|
|
1596
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
1600
1597
|
})
|
|
1601
1598
|
.filter((x) => !!x); // filter nulls
|
|
1602
1599
|
if (ctx.common.async) {
|
|
@@ -1649,16 +1646,8 @@ class ZodRecord extends ZodType {
|
|
|
1649
1646
|
const valueType = this._def.valueType;
|
|
1650
1647
|
for (const key in ctx.data) {
|
|
1651
1648
|
pairs.push({
|
|
1652
|
-
key: keyType._parse(
|
|
1653
|
-
|
|
1654
|
-
path: [...ctx.path, key],
|
|
1655
|
-
parent: ctx,
|
|
1656
|
-
}),
|
|
1657
|
-
value: valueType._parse({
|
|
1658
|
-
data: ctx.data[key],
|
|
1659
|
-
path: [...ctx.path, key],
|
|
1660
|
-
parent: ctx,
|
|
1661
|
-
}),
|
|
1649
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
1650
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
1662
1651
|
});
|
|
1663
1652
|
}
|
|
1664
1653
|
if (ctx.common.async) {
|
|
@@ -1704,16 +1693,8 @@ class ZodMap extends ZodType {
|
|
|
1704
1693
|
const valueType = this._def.valueType;
|
|
1705
1694
|
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
1706
1695
|
return {
|
|
1707
|
-
key: keyType._parse(
|
|
1708
|
-
|
|
1709
|
-
path: [...ctx.path, index, "key"],
|
|
1710
|
-
parent: ctx,
|
|
1711
|
-
}),
|
|
1712
|
-
value: valueType._parse({
|
|
1713
|
-
data: value,
|
|
1714
|
-
path: [...ctx.path, index, "value"],
|
|
1715
|
-
parent: ctx,
|
|
1716
|
-
}),
|
|
1696
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
1697
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
|
|
1717
1698
|
};
|
|
1718
1699
|
});
|
|
1719
1700
|
if (ctx.common.async) {
|
|
@@ -1807,7 +1788,7 @@ class ZodSet extends ZodType {
|
|
|
1807
1788
|
}
|
|
1808
1789
|
return { status: status.value, value: parsedSet };
|
|
1809
1790
|
}
|
|
1810
|
-
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(
|
|
1791
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
1811
1792
|
if (ctx.common.async) {
|
|
1812
1793
|
return Promise.all(elements).then((elements) => finalizeSet(elements));
|
|
1813
1794
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.3",
|
|
4
4
|
"description": "TypeScript-first schema declaration and validation library with static type inference",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"scripts": {
|
|
45
45
|
"prettier:check": "prettier --check src/**/*.ts deno/lib/**/*.ts --no-error-on-unmatched-pattern",
|
|
46
|
-
"prettier:fix": "prettier --write src/**/*.ts deno/lib/**/*.ts --no-error-on-unmatched-pattern",
|
|
46
|
+
"prettier:fix": "prettier --write src/**/*.ts deno/lib/**/*.ts --ignore-unknown --no-error-on-unmatched-pattern",
|
|
47
47
|
"lint:check": "eslint --ext .ts ./src",
|
|
48
48
|
"lint:fix": "eslint --fix --ext .ts ./src",
|
|
49
49
|
"check": "yarn lint:check && yarn prettier:check",
|
|
@@ -57,51 +57,43 @@
|
|
|
57
57
|
"rollup": "rollup --config rollup.config.js",
|
|
58
58
|
"test": "jest --coverage",
|
|
59
59
|
"test:deno": "cd deno && deno test",
|
|
60
|
-
"badge": "make-coverage-badge --output-path ./coverage.svg",
|
|
61
60
|
"prepublishOnly": "npm run test && npm run build && npm run build:deno",
|
|
62
61
|
"play": "nodemon -e ts -w . -x ts-node src/playground.ts --project tsconfig.json --trace-warnings",
|
|
63
62
|
"depcruise": "depcruise -c .dependency-cruiser.js src",
|
|
64
|
-
"benchmark": "ts-node src/benchmarks/index.ts"
|
|
63
|
+
"benchmark": "ts-node src/benchmarks/index.ts",
|
|
64
|
+
"prepare": "husky install"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@rollup/plugin-typescript": "^8.2.0",
|
|
68
68
|
"@types/benchmark": "^2.1.0",
|
|
69
69
|
"@types/jest": "^26.0.17",
|
|
70
|
-
"@types/node": "
|
|
70
|
+
"@types/node": "14",
|
|
71
71
|
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
|
72
72
|
"@typescript-eslint/parser": "^5.15.0",
|
|
73
73
|
"benchmark": "^2.1.4",
|
|
74
74
|
"dependency-cruiser": "^9.19.0",
|
|
75
|
-
"eslint": "^
|
|
76
|
-
"eslint-config-prettier": "^
|
|
77
|
-
"eslint-plugin-ban": "^1.
|
|
78
|
-
"eslint-plugin-import": "^2.
|
|
75
|
+
"eslint": "^8.11.0",
|
|
76
|
+
"eslint-config-prettier": "^8.5.0",
|
|
77
|
+
"eslint-plugin-ban": "^1.6.0",
|
|
78
|
+
"eslint-plugin-import": "^2.25.4",
|
|
79
79
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
80
|
-
"eslint-plugin-unused-imports": "^
|
|
81
|
-
"husky": "^
|
|
82
|
-
"jest": "^
|
|
83
|
-
"lint-staged": "^
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"rollup": "^2.
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"ts-jest": "^26.4.4",
|
|
91
|
-
"ts-node": "^9.1.0",
|
|
80
|
+
"eslint-plugin-unused-imports": "^2.0.0",
|
|
81
|
+
"husky": "^7.0.4",
|
|
82
|
+
"jest": "^27.5.1",
|
|
83
|
+
"lint-staged": "^12.3.7",
|
|
84
|
+
"nodemon": "^2.0.15",
|
|
85
|
+
"prettier": "^2.6.0",
|
|
86
|
+
"pretty-quick": "^3.1.3",
|
|
87
|
+
"rollup": "^2.70.1",
|
|
88
|
+
"ts-jest": "^27.1.3",
|
|
89
|
+
"ts-node": "^10.7.0",
|
|
92
90
|
"tslib": "^2.3.1",
|
|
93
91
|
"typescript": "^4.6.2"
|
|
94
92
|
},
|
|
95
|
-
"husky": {
|
|
96
|
-
"hooks": {
|
|
97
|
-
"pre-commit": "lint-staged",
|
|
98
|
-
"pre-push": "lint-staged"
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
93
|
"lint-staged": {
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
94
|
+
"src/*.ts": [
|
|
95
|
+
"eslint --cache --fix",
|
|
96
|
+
"prettier --ignore-unknown --write"
|
|
105
97
|
]
|
|
106
98
|
}
|
|
107
99
|
}
|