zod 3.24.0 → 3.24.2
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 +62 -16
- package/lib/ZodError.d.ts +16 -16
- package/lib/ZodError.js +3 -3
- package/lib/external.js +5 -1
- package/lib/helpers/errorUtil.d.ts +2 -2
- package/lib/helpers/errorUtil.js +1 -1
- package/lib/helpers/parseUtil.d.ts +11 -11
- package/lib/helpers/parseUtil.js +3 -3
- package/lib/helpers/typeAliases.d.ts +2 -2
- package/lib/helpers/util.d.ts +9 -9
- package/lib/helpers/util.js +2 -2
- package/lib/index.js +5 -1
- package/lib/index.mjs +80 -55
- package/lib/index.umd.js +80 -55
- package/lib/standard-schema.d.ts +1 -1
- package/lib/types.d.ts +130 -221
- package/lib/types.js +75 -50
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
|
|
45
45
|
## Table of contents
|
|
46
46
|
|
|
47
|
-
> These docs have been translated into [Chinese](./README_ZH.md).
|
|
47
|
+
> These docs have been translated into [Chinese](./README_ZH.md) and [Korean](./README_KO.md).
|
|
48
48
|
|
|
49
49
|
- [Table of contents](#table-of-contents)
|
|
50
50
|
- [Introduction](#introduction)
|
|
@@ -213,6 +213,47 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod
|
|
|
213
213
|
|
|
214
214
|
<table align="center" style="justify-content: center;align-items: center;display: flex;">
|
|
215
215
|
<tr>
|
|
216
|
+
<td align="center">
|
|
217
|
+
<p></p>
|
|
218
|
+
<p>
|
|
219
|
+
<a href="https://www.coderabbit.ai/">
|
|
220
|
+
<picture height="80px">
|
|
221
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/user-attachments/assets/eea24edb-ff20-4532-b57c-e8719f455d6d">
|
|
222
|
+
<img alt="CodeRabbit logo" height="80px" src="https://github.com/user-attachments/assets/d791bc7d-dc60-4d55-9c31-97779839cb74">
|
|
223
|
+
</picture>
|
|
224
|
+
</a>
|
|
225
|
+
<br />
|
|
226
|
+
Cut code review time & bugs in half
|
|
227
|
+
<br/>
|
|
228
|
+
<a href="https://www.coderabbit.ai/" style="text-decoration:none;">coderabbit.ai</a>
|
|
229
|
+
</p>
|
|
230
|
+
<p></p>
|
|
231
|
+
</td>
|
|
232
|
+
</tr>
|
|
233
|
+
</table>
|
|
234
|
+
|
|
235
|
+
<br/>
|
|
236
|
+
|
|
237
|
+
<h3 align="center">Gold</h3>
|
|
238
|
+
|
|
239
|
+
<table align="center" style="justify-content: center;align-items: center;display: flex;">
|
|
240
|
+
<tr>
|
|
241
|
+
<td align="center">
|
|
242
|
+
<p></p>
|
|
243
|
+
<p>
|
|
244
|
+
<a href="https://www.courier.com/?utm_source=zod&utm_campaign=osssponsors">
|
|
245
|
+
<picture height="62px">
|
|
246
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/user-attachments/assets/6b09506a-78de-47e8-a8c1-792efe31910a">
|
|
247
|
+
<img alt="Courier logo" height="62px" src="https://github.com/user-attachments/assets/6b09506a-78de-47e8-a8c1-792efe31910a">
|
|
248
|
+
</picture>
|
|
249
|
+
</a>
|
|
250
|
+
<br />
|
|
251
|
+
The API platform for sending notifications
|
|
252
|
+
<br/>
|
|
253
|
+
<a href="https://www.courier.com/?utm_source=zod&utm_campaign=osssponsors" style="text-decoration:none;">courier.com</a>
|
|
254
|
+
</p>
|
|
255
|
+
<p></p>
|
|
256
|
+
</td>
|
|
216
257
|
<td align="center">
|
|
217
258
|
<p></p>
|
|
218
259
|
<p>
|
|
@@ -247,8 +288,6 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod
|
|
|
247
288
|
</p>
|
|
248
289
|
<p></p>
|
|
249
290
|
</td>
|
|
250
|
-
</tr>
|
|
251
|
-
<tr>
|
|
252
291
|
<td align="center">
|
|
253
292
|
<p></p>
|
|
254
293
|
<p>
|
|
@@ -283,8 +322,6 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod
|
|
|
283
322
|
</p>
|
|
284
323
|
<p></p>
|
|
285
324
|
</td>
|
|
286
|
-
</tr>
|
|
287
|
-
<tr>
|
|
288
325
|
<td align="center">
|
|
289
326
|
<p></p>
|
|
290
327
|
<p>
|
|
@@ -306,10 +343,15 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod
|
|
|
306
343
|
|
|
307
344
|
<br/>
|
|
308
345
|
|
|
309
|
-
<h3 align="center">
|
|
346
|
+
<h3 align="center">Silver</h3>
|
|
310
347
|
|
|
311
348
|
<table align="center" style="justify-content: center;align-items: center;display: flex;">
|
|
312
349
|
<tr>
|
|
350
|
+
<td align="center">
|
|
351
|
+
<img src="https://avatars.githubusercontent.com/u/72055470?s=200&v=4" height="50px;" alt="Nitric" />
|
|
352
|
+
<br />
|
|
353
|
+
<a style="text-decoration:none;" href="https://nitric.io/" target="_blank">Nitric</a>
|
|
354
|
+
</td>
|
|
313
355
|
<td align="center">
|
|
314
356
|
<img src="https://avatars.githubusercontent.com/u/89474619?s=200&v=4" height="50px;" alt="PropelAuth" />
|
|
315
357
|
<br />
|
|
@@ -325,12 +367,12 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod
|
|
|
325
367
|
<br />
|
|
326
368
|
<a style="text-decoration:none;" href="https://scalar.com/" target="_blank">Scalar</a>
|
|
327
369
|
</td>
|
|
370
|
+
</tr><tr>
|
|
328
371
|
<td align="center">
|
|
329
372
|
<img src="https://avatars.githubusercontent.com/u/95297378?s=200&v=4" height="50px;" alt="Trigger.dev logo" />
|
|
330
373
|
<br />
|
|
331
374
|
<a style="text-decoration:none;" href="https://trigger.dev" target="_blank">Trigger.dev</a>
|
|
332
375
|
</td>
|
|
333
|
-
</tr><tr>
|
|
334
376
|
<td align="center">
|
|
335
377
|
<img src="https://avatars.githubusercontent.com/u/125754?s=200&v=4" height="50px;" alt="Transloadit logo" />
|
|
336
378
|
<br />
|
|
@@ -347,12 +389,12 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod
|
|
|
347
389
|
<br />
|
|
348
390
|
<a style="text-decoration:none;" href="https://whop.com/" target="_blank">Whop</a>
|
|
349
391
|
</td>
|
|
392
|
+
</tr><tr>
|
|
350
393
|
<td align="center">
|
|
351
394
|
<img src="https://avatars.githubusercontent.com/u/36402888?s=200&v=4" height="50px;" alt="CryptoJobsList logo" />
|
|
352
395
|
<br />
|
|
353
396
|
<a style="text-decoration:none;" href="https://cryptojobslist.com/" target="_blank">CryptoJobsList</a>
|
|
354
397
|
</td>
|
|
355
|
-
</tr><tr>
|
|
356
398
|
<td align="center">
|
|
357
399
|
<img src="https://avatars.githubusercontent.com/u/70170949?s=200&v=4" height="50px;" alt="Plain logo" />
|
|
358
400
|
<br />
|
|
@@ -368,6 +410,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod
|
|
|
368
410
|
<br />
|
|
369
411
|
<a style="text-decoration:none;" href="https://storyblok.com/" target="_blank">Storyblok</a>
|
|
370
412
|
</td>
|
|
413
|
+
</tr><tr>
|
|
371
414
|
<td align="center">
|
|
372
415
|
<img src="https://avatars.githubusercontent.com/u/16199997?s=200&v=4" height="50px;" alt="Mux logo" />
|
|
373
416
|
<br />
|
|
@@ -378,7 +421,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod
|
|
|
378
421
|
|
|
379
422
|
<br/>
|
|
380
423
|
|
|
381
|
-
<h3 align="center">
|
|
424
|
+
<h3 align="center">Bronze</h3>
|
|
382
425
|
|
|
383
426
|
<table align="center" style="justify-content: center;align-items: center;display: flex;">
|
|
384
427
|
<tr>
|
|
@@ -442,7 +485,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod
|
|
|
442
485
|
</tr>
|
|
443
486
|
</table>
|
|
444
487
|
|
|
445
|
-
<h3 align="center">Bronze</h3>
|
|
488
|
+
<!-- <h3 align="center">Bronze</h3>
|
|
446
489
|
|
|
447
490
|
<table align="center" style="justify-content: center;align-items: center;display: flex;">
|
|
448
491
|
<tr>
|
|
@@ -469,7 +512,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod
|
|
|
469
512
|
<td>Mohammad-Ali A'râbi</td>
|
|
470
513
|
<td>Supatool</td>
|
|
471
514
|
</tr>
|
|
472
|
-
</table>
|
|
515
|
+
</table> -->
|
|
473
516
|
|
|
474
517
|
### Ecosystem
|
|
475
518
|
|
|
@@ -520,7 +563,7 @@ There are a growing number of tools that are built atop or support Zod natively!
|
|
|
520
563
|
- [`zod-to-json-schema`](https://github.com/StefanTerdell/zod-to-json-schema): Convert your Zod schemas into [JSON Schemas](https://json-schema.org/).
|
|
521
564
|
- [`@anatine/zod-openapi`](https://github.com/anatine/zod-plugins/tree/main/packages/zod-openapi): Converts a Zod schema to an OpenAPI v3.x `SchemaObject`.
|
|
522
565
|
- [`zod-fast-check`](https://github.com/DavidTimms/zod-fast-check): Generate `fast-check` arbitraries from Zod schemas.
|
|
523
|
-
- [`zod-dto`](https://github.com/kbkk/abitia/tree/
|
|
566
|
+
- [`zod-dto`](https://github.com/kbkk/abitia/tree/master/packages/zod-dto): Generate Nest.js DTOs from a Zod schema.
|
|
524
567
|
- [`fastify-type-provider-zod`](https://github.com/turkerdev/fastify-type-provider-zod): Create Fastify type providers from Zod schemas.
|
|
525
568
|
- [`zod-to-openapi`](https://github.com/asteasolutions/zod-to-openapi): Generate full OpenAPI (Swagger) docs from Zod, including schemas, endpoints & parameters.
|
|
526
569
|
- [`nestjs-graphql-zod`](https://github.com/incetarik/nestjs-graphql-zod): Generates NestJS GraphQL model classes from Zod schemas. Provides GraphQL method decorators working with Zod schemas.
|
|
@@ -532,7 +575,7 @@ There are a growing number of tools that are built atop or support Zod natively!
|
|
|
532
575
|
#### X to Zod
|
|
533
576
|
|
|
534
577
|
- [`ts-to-zod`](https://github.com/fabien0102/ts-to-zod): Convert TypeScript definitions into Zod schemas.
|
|
535
|
-
- [`@runtyping/zod`](https://github.com/johngeorgewright/runtyping
|
|
578
|
+
- [`@runtyping/zod`](https://github.com/johngeorgewright/runtyping): Generate Zod from static types & JSON schema.
|
|
536
579
|
- [`json-schema-to-zod`](https://github.com/StefanTerdell/json-schema-to-zod): Convert your [JSON Schemas](https://json-schema.org/) into Zod schemas. [Live demo](https://StefanTerdell.github.io/json-schema-to-zod-react/).
|
|
537
580
|
- [`json-to-zod`](https://github.com/rsinohara/json-to-zod): Convert JSON objects into Zod schemas. [Live demo](https://rsinohara.github.io/json-to-zod-react/).
|
|
538
581
|
- [`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.
|
|
@@ -568,6 +611,7 @@ There are a growing number of tools that are built atop or support Zod natively!
|
|
|
568
611
|
- [`znv`](https://github.com/lostfictions/znv): Type-safe environment parsing and validation for Node.js with Zod schemas.
|
|
569
612
|
- [`zod-config`](https://github.com/alexmarqs/zod-config): Load configurations across multiple sources with flexible adapters, ensuring type safety with Zod.
|
|
570
613
|
- [`unplugin-environment`](https://github.com/r17x/js/tree/main/packages/unplugin-environment#readme): A plugin for loading enviroment variables safely with schema validation, simple with virtual module, type-safe with intellisense, and better DX 🔥 🚀 👷. Powered by Zod.
|
|
614
|
+
- [`zod-struct`](https://codeberg.org/reesericci/zod-struct): Create runtime-checked structs with Zod.
|
|
571
615
|
|
|
572
616
|
#### Utilities for Zod
|
|
573
617
|
|
|
@@ -3005,13 +3049,15 @@ This more declarative API makes schema definitions vastly more concise.
|
|
|
3005
3049
|
|
|
3006
3050
|
### Runtypes
|
|
3007
3051
|
|
|
3008
|
-
[https://github.com/
|
|
3052
|
+
[https://github.com/runtypes/runtypes](https://github.com/runtypes/runtypes)
|
|
3009
3053
|
|
|
3010
|
-
|
|
3054
|
+
Runtypes is focused on ergonomics, with good type inference support.
|
|
3011
3055
|
|
|
3012
3056
|
- Supports "pattern matching": computed properties that distribute over unions
|
|
3057
|
+
- Supports branded types
|
|
3058
|
+
- Supports template literals
|
|
3059
|
+
- Supports conformance to predefined static types
|
|
3013
3060
|
- Missing object methods: (deepPartial, merge)
|
|
3014
|
-
- Missing nonempty arrays with proper typing (`[T, ...T[]]`)
|
|
3015
3061
|
- Missing promise schemas
|
|
3016
3062
|
- Missing error customization
|
|
3017
3063
|
|
package/lib/ZodError.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TypeOf, ZodType } from ".";
|
|
2
2
|
import { Primitive } from "./helpers/typeAliases";
|
|
3
3
|
import { util, ZodParsedType } from "./helpers/util";
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export
|
|
4
|
+
type allKeys<T> = T extends any ? keyof T : never;
|
|
5
|
+
export type inferFlattenedErrors<T extends ZodType<any, any, any>, U = string> = typeToFlattenedError<TypeOf<T>, U>;
|
|
6
|
+
export type typeToFlattenedError<T, U = string> = {
|
|
7
7
|
formErrors: U[];
|
|
8
8
|
fieldErrors: {
|
|
9
9
|
[P in allKeys<T>]?: U[];
|
|
@@ -27,8 +27,8 @@ export declare const ZodIssueCode: {
|
|
|
27
27
|
not_multiple_of: "not_multiple_of";
|
|
28
28
|
not_finite: "not_finite";
|
|
29
29
|
};
|
|
30
|
-
export
|
|
31
|
-
export
|
|
30
|
+
export type ZodIssueCode = keyof typeof ZodIssueCode;
|
|
31
|
+
export type ZodIssueBase = {
|
|
32
32
|
path: (string | number)[];
|
|
33
33
|
message?: string;
|
|
34
34
|
};
|
|
@@ -70,7 +70,7 @@ export interface ZodInvalidReturnTypeIssue extends ZodIssueBase {
|
|
|
70
70
|
export interface ZodInvalidDateIssue extends ZodIssueBase {
|
|
71
71
|
code: typeof ZodIssueCode.invalid_date;
|
|
72
72
|
}
|
|
73
|
-
export
|
|
73
|
+
export type StringValidation = "email" | "url" | "emoji" | "uuid" | "nanoid" | "regex" | "cuid" | "cuid2" | "ulid" | "datetime" | "date" | "time" | "duration" | "ip" | "cidr" | "base64" | "jwt" | "base64url" | {
|
|
74
74
|
includes: string;
|
|
75
75
|
position?: number;
|
|
76
76
|
} | {
|
|
@@ -112,26 +112,26 @@ export interface ZodCustomIssue extends ZodIssueBase {
|
|
|
112
112
|
[k: string]: any;
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
-
export
|
|
115
|
+
export type DenormalizedError = {
|
|
116
116
|
[k: string]: DenormalizedError | string[];
|
|
117
117
|
};
|
|
118
|
-
export
|
|
119
|
-
export
|
|
118
|
+
export type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodInvalidLiteralIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidUnionDiscriminatorIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodNotMultipleOfIssue | ZodNotFiniteIssue | ZodCustomIssue;
|
|
119
|
+
export type ZodIssue = ZodIssueOptionalMessage & {
|
|
120
120
|
fatal?: boolean;
|
|
121
121
|
message: string;
|
|
122
122
|
};
|
|
123
123
|
export declare const quotelessJson: (obj: any) => string;
|
|
124
|
-
|
|
124
|
+
type recursiveZodFormattedError<T> = T extends [any, ...any[]] ? {
|
|
125
125
|
[K in keyof T]?: ZodFormattedError<T[K]>;
|
|
126
126
|
} : T extends any[] ? {
|
|
127
127
|
[k: number]: ZodFormattedError<T[number]>;
|
|
128
128
|
} : T extends object ? {
|
|
129
129
|
[K in keyof T]?: ZodFormattedError<T[K]>;
|
|
130
130
|
} : unknown;
|
|
131
|
-
export
|
|
131
|
+
export type ZodFormattedError<T, U = string> = {
|
|
132
132
|
_errors: U[];
|
|
133
133
|
} & recursiveZodFormattedError<NonNullable<T>>;
|
|
134
|
-
export
|
|
134
|
+
export type inferFormattedError<T extends ZodType<any, any, any>, U = string> = ZodFormattedError<TypeOf<T>, U>;
|
|
135
135
|
export declare class ZodError<T = any> extends Error {
|
|
136
136
|
issues: ZodIssue[];
|
|
137
137
|
get errors(): ZodIssue[];
|
|
@@ -149,16 +149,16 @@ export declare class ZodError<T = any> extends Error {
|
|
|
149
149
|
flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
|
|
150
150
|
get formErrors(): typeToFlattenedError<T, string>;
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
export
|
|
152
|
+
type stripPath<T extends object> = T extends any ? util.OmitKeys<T, "path"> : never;
|
|
153
|
+
export type IssueData = stripPath<ZodIssueOptionalMessage> & {
|
|
154
154
|
path?: (string | number)[];
|
|
155
155
|
fatal?: boolean;
|
|
156
156
|
};
|
|
157
|
-
export
|
|
157
|
+
export type ErrorMapCtx = {
|
|
158
158
|
defaultError: string;
|
|
159
159
|
data: any;
|
|
160
160
|
};
|
|
161
|
-
export
|
|
161
|
+
export type ZodErrorMap = (issue: ZodIssueOptionalMessage, _ctx: ErrorMapCtx) => {
|
|
162
162
|
message: string;
|
|
163
163
|
};
|
|
164
164
|
export {};
|
package/lib/ZodError.js
CHANGED
|
@@ -26,6 +26,9 @@ const quotelessJson = (obj) => {
|
|
|
26
26
|
};
|
|
27
27
|
exports.quotelessJson = quotelessJson;
|
|
28
28
|
class ZodError extends Error {
|
|
29
|
+
get errors() {
|
|
30
|
+
return this.issues;
|
|
31
|
+
}
|
|
29
32
|
constructor(issues) {
|
|
30
33
|
super();
|
|
31
34
|
this.issues = [];
|
|
@@ -46,9 +49,6 @@ class ZodError extends Error {
|
|
|
46
49
|
this.name = "ZodError";
|
|
47
50
|
this.issues = issues;
|
|
48
51
|
}
|
|
49
|
-
get errors() {
|
|
50
|
-
return this.issues;
|
|
51
|
-
}
|
|
52
52
|
format(_mapper) {
|
|
53
53
|
const mapper = _mapper ||
|
|
54
54
|
function (issue) {
|
package/lib/external.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
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
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -2,8 +2,8 @@ export declare namespace errorUtil {
|
|
|
2
2
|
type ErrMessage = string | {
|
|
3
3
|
message?: string;
|
|
4
4
|
};
|
|
5
|
-
const errToObj: (message?: ErrMessage
|
|
5
|
+
const errToObj: (message?: ErrMessage) => {
|
|
6
6
|
message?: string | undefined;
|
|
7
7
|
};
|
|
8
|
-
const toString: (message?: ErrMessage
|
|
8
|
+
const toString: (message?: ErrMessage) => string | undefined;
|
|
9
9
|
}
|
package/lib/helpers/errorUtil.js
CHANGED
|
@@ -5,4 +5,4 @@ var errorUtil;
|
|
|
5
5
|
(function (errorUtil) {
|
|
6
6
|
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
7
7
|
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
8
|
-
})(errorUtil
|
|
8
|
+
})(errorUtil || (exports.errorUtil = errorUtil = {}));
|
|
@@ -6,13 +6,13 @@ export declare const makeIssue: (params: {
|
|
|
6
6
|
errorMaps: ZodErrorMap[];
|
|
7
7
|
issueData: IssueData;
|
|
8
8
|
}) => ZodIssue;
|
|
9
|
-
export
|
|
9
|
+
export type ParseParams = {
|
|
10
10
|
path: (string | number)[];
|
|
11
11
|
errorMap: ZodErrorMap;
|
|
12
12
|
async: boolean;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
15
|
-
export
|
|
14
|
+
export type ParsePathComponent = string | number;
|
|
15
|
+
export type ParsePath = ParsePathComponent[];
|
|
16
16
|
export declare const EMPTY_PATH: ParsePath;
|
|
17
17
|
export interface ParseContext {
|
|
18
18
|
readonly common: {
|
|
@@ -26,13 +26,13 @@ export interface ParseContext {
|
|
|
26
26
|
readonly data: any;
|
|
27
27
|
readonly parsedType: ZodParsedType;
|
|
28
28
|
}
|
|
29
|
-
export
|
|
29
|
+
export type ParseInput = {
|
|
30
30
|
data: any;
|
|
31
31
|
path: (string | number)[];
|
|
32
32
|
parent: ParseContext;
|
|
33
33
|
};
|
|
34
34
|
export declare function addIssueToContext(ctx: ParseContext, issueData: IssueData): void;
|
|
35
|
-
export
|
|
35
|
+
export type ObjectPair = {
|
|
36
36
|
key: SyncParseReturnType<any>;
|
|
37
37
|
value: SyncParseReturnType<any>;
|
|
38
38
|
};
|
|
@@ -55,23 +55,23 @@ export interface ParseResult {
|
|
|
55
55
|
status: "aborted" | "dirty" | "valid";
|
|
56
56
|
data: any;
|
|
57
57
|
}
|
|
58
|
-
export
|
|
58
|
+
export type INVALID = {
|
|
59
59
|
status: "aborted";
|
|
60
60
|
};
|
|
61
61
|
export declare const INVALID: INVALID;
|
|
62
|
-
export
|
|
62
|
+
export type DIRTY<T> = {
|
|
63
63
|
status: "dirty";
|
|
64
64
|
value: T;
|
|
65
65
|
};
|
|
66
66
|
export declare const DIRTY: <T>(value: T) => DIRTY<T>;
|
|
67
|
-
export
|
|
67
|
+
export type OK<T> = {
|
|
68
68
|
status: "valid";
|
|
69
69
|
value: T;
|
|
70
70
|
};
|
|
71
71
|
export declare const OK: <T>(value: T) => OK<T>;
|
|
72
|
-
export
|
|
73
|
-
export
|
|
74
|
-
export
|
|
72
|
+
export type SyncParseReturnType<T = any> = OK<T> | DIRTY<T> | INVALID;
|
|
73
|
+
export type AsyncParseReturnType<T> = Promise<SyncParseReturnType<T>>;
|
|
74
|
+
export type ParseReturnType<T> = SyncParseReturnType<T> | AsyncParseReturnType<T>;
|
|
75
75
|
export declare const isAborted: (x: ParseReturnType<any>) => x is INVALID;
|
|
76
76
|
export declare const isDirty: <T>(x: ParseReturnType<T>) => x is OK<T> | DIRTY<T>;
|
|
77
77
|
export declare const isValid: <T>(x: ParseReturnType<T>) => x is OK<T>;
|
package/lib/helpers/parseUtil.js
CHANGED
|
@@ -43,9 +43,9 @@ function addIssueToContext(ctx, issueData) {
|
|
|
43
43
|
data: ctx.data,
|
|
44
44
|
path: ctx.path,
|
|
45
45
|
errorMaps: [
|
|
46
|
-
ctx.common.contextualErrorMap,
|
|
47
|
-
ctx.schemaErrorMap,
|
|
48
|
-
overrideMap,
|
|
46
|
+
ctx.common.contextualErrorMap, // contextual error map is first priority
|
|
47
|
+
ctx.schemaErrorMap, // then schema-bound map if available
|
|
48
|
+
overrideMap, // then global override map
|
|
49
49
|
overrideMap === en_1.default ? undefined : en_1.default, // then global default map
|
|
50
50
|
].filter((x) => !!x),
|
|
51
51
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export type Primitive = string | number | symbol | bigint | boolean | null | undefined;
|
|
2
|
+
export type Scalars = Primitive | Primitive[];
|
package/lib/helpers/util.d.ts
CHANGED
|
@@ -57,26 +57,26 @@ export declare namespace objectUtil {
|
|
|
57
57
|
export {};
|
|
58
58
|
}
|
|
59
59
|
export declare const ZodParsedType: {
|
|
60
|
-
function: "function";
|
|
61
|
-
number: "number";
|
|
62
60
|
string: "string";
|
|
61
|
+
number: "number";
|
|
62
|
+
bigint: "bigint";
|
|
63
|
+
boolean: "boolean";
|
|
64
|
+
symbol: "symbol";
|
|
65
|
+
undefined: "undefined";
|
|
66
|
+
object: "object";
|
|
67
|
+
function: "function";
|
|
68
|
+
map: "map";
|
|
63
69
|
nan: "nan";
|
|
64
70
|
integer: "integer";
|
|
65
71
|
float: "float";
|
|
66
|
-
boolean: "boolean";
|
|
67
72
|
date: "date";
|
|
68
|
-
bigint: "bigint";
|
|
69
|
-
symbol: "symbol";
|
|
70
|
-
undefined: "undefined";
|
|
71
73
|
null: "null";
|
|
72
74
|
array: "array";
|
|
73
|
-
object: "object";
|
|
74
75
|
unknown: "unknown";
|
|
75
76
|
promise: "promise";
|
|
76
77
|
void: "void";
|
|
77
78
|
never: "never";
|
|
78
|
-
map: "map";
|
|
79
79
|
set: "set";
|
|
80
80
|
};
|
|
81
|
-
export
|
|
81
|
+
export type ZodParsedType = keyof typeof ZodParsedType;
|
|
82
82
|
export declare const getParsedType: (data: any) => ZodParsedType;
|
package/lib/helpers/util.js
CHANGED
|
@@ -63,7 +63,7 @@ var util;
|
|
|
63
63
|
}
|
|
64
64
|
return value;
|
|
65
65
|
};
|
|
66
|
-
})(util
|
|
66
|
+
})(util || (exports.util = util = {}));
|
|
67
67
|
var objectUtil;
|
|
68
68
|
(function (objectUtil) {
|
|
69
69
|
objectUtil.mergeShapes = (first, second) => {
|
|
@@ -72,7 +72,7 @@ var objectUtil;
|
|
|
72
72
|
...second, // second overwrites first
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
|
-
})(objectUtil
|
|
75
|
+
})(objectUtil || (exports.objectUtil = objectUtil = {}));
|
|
76
76
|
exports.ZodParsedType = util.arrayToEnum([
|
|
77
77
|
"string",
|
|
78
78
|
"nan",
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
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
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|