zod 3.24.1 → 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/index.mjs +33 -10
- package/lib/index.umd.js +33 -10
- package/lib/types.d.ts +1 -1
- package/lib/types.js +33 -10
- package/package.json +1 -1
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/index.mjs
CHANGED
|
@@ -4144,7 +4144,23 @@ ZodReadonly.create = (type, params) => {
|
|
|
4144
4144
|
...processCreateParams(params),
|
|
4145
4145
|
});
|
|
4146
4146
|
};
|
|
4147
|
-
|
|
4147
|
+
////////////////////////////////////////
|
|
4148
|
+
////////////////////////////////////////
|
|
4149
|
+
////////// //////////
|
|
4150
|
+
////////// z.custom //////////
|
|
4151
|
+
////////// //////////
|
|
4152
|
+
////////////////////////////////////////
|
|
4153
|
+
////////////////////////////////////////
|
|
4154
|
+
function cleanParams(params, data) {
|
|
4155
|
+
const p = typeof params === "function"
|
|
4156
|
+
? params(data)
|
|
4157
|
+
: typeof params === "string"
|
|
4158
|
+
? { message: params }
|
|
4159
|
+
: params;
|
|
4160
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
4161
|
+
return p2;
|
|
4162
|
+
}
|
|
4163
|
+
function custom(check, _params = {},
|
|
4148
4164
|
/**
|
|
4149
4165
|
* @deprecated
|
|
4150
4166
|
*
|
|
@@ -4159,16 +4175,23 @@ fatal) {
|
|
|
4159
4175
|
if (check)
|
|
4160
4176
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
4161
4177
|
var _a, _b;
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4178
|
+
const r = check(data);
|
|
4179
|
+
if (r instanceof Promise) {
|
|
4180
|
+
return r.then((r) => {
|
|
4181
|
+
var _a, _b;
|
|
4182
|
+
if (!r) {
|
|
4183
|
+
const params = cleanParams(_params, data);
|
|
4184
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
4185
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4186
|
+
}
|
|
4187
|
+
});
|
|
4188
|
+
}
|
|
4189
|
+
if (!r) {
|
|
4190
|
+
const params = cleanParams(_params, data);
|
|
4191
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
4192
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4171
4193
|
}
|
|
4194
|
+
return;
|
|
4172
4195
|
});
|
|
4173
4196
|
return ZodAny.create();
|
|
4174
4197
|
}
|
package/lib/index.umd.js
CHANGED
|
@@ -4150,7 +4150,23 @@
|
|
|
4150
4150
|
...processCreateParams(params),
|
|
4151
4151
|
});
|
|
4152
4152
|
};
|
|
4153
|
-
|
|
4153
|
+
////////////////////////////////////////
|
|
4154
|
+
////////////////////////////////////////
|
|
4155
|
+
////////// //////////
|
|
4156
|
+
////////// z.custom //////////
|
|
4157
|
+
////////// //////////
|
|
4158
|
+
////////////////////////////////////////
|
|
4159
|
+
////////////////////////////////////////
|
|
4160
|
+
function cleanParams(params, data) {
|
|
4161
|
+
const p = typeof params === "function"
|
|
4162
|
+
? params(data)
|
|
4163
|
+
: typeof params === "string"
|
|
4164
|
+
? { message: params }
|
|
4165
|
+
: params;
|
|
4166
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
4167
|
+
return p2;
|
|
4168
|
+
}
|
|
4169
|
+
function custom(check, _params = {},
|
|
4154
4170
|
/**
|
|
4155
4171
|
* @deprecated
|
|
4156
4172
|
*
|
|
@@ -4165,16 +4181,23 @@
|
|
|
4165
4181
|
if (check)
|
|
4166
4182
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
4167
4183
|
var _a, _b;
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4184
|
+
const r = check(data);
|
|
4185
|
+
if (r instanceof Promise) {
|
|
4186
|
+
return r.then((r) => {
|
|
4187
|
+
var _a, _b;
|
|
4188
|
+
if (!r) {
|
|
4189
|
+
const params = cleanParams(_params, data);
|
|
4190
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
4191
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4192
|
+
}
|
|
4193
|
+
});
|
|
4194
|
+
}
|
|
4195
|
+
if (!r) {
|
|
4196
|
+
const params = cleanParams(_params, data);
|
|
4197
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
4198
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4177
4199
|
}
|
|
4200
|
+
return;
|
|
4178
4201
|
});
|
|
4179
4202
|
return ZodAny.create();
|
|
4180
4203
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -935,7 +935,7 @@ export declare class ZodReadonly<T extends ZodTypeAny> extends ZodType<MakeReado
|
|
|
935
935
|
type CustomParams = CustomErrorParams & {
|
|
936
936
|
fatal?: boolean;
|
|
937
937
|
};
|
|
938
|
-
export declare function custom<T>(check?: (data: any) => any,
|
|
938
|
+
export declare function custom<T>(check?: (data: any) => any, _params?: string | CustomParams | ((input: any) => CustomParams),
|
|
939
939
|
/**
|
|
940
940
|
* @deprecated
|
|
941
941
|
*
|
package/lib/types.js
CHANGED
|
@@ -3654,7 +3654,23 @@ ZodReadonly.create = (type, params) => {
|
|
|
3654
3654
|
...processCreateParams(params),
|
|
3655
3655
|
});
|
|
3656
3656
|
};
|
|
3657
|
-
|
|
3657
|
+
////////////////////////////////////////
|
|
3658
|
+
////////////////////////////////////////
|
|
3659
|
+
////////// //////////
|
|
3660
|
+
////////// z.custom //////////
|
|
3661
|
+
////////// //////////
|
|
3662
|
+
////////////////////////////////////////
|
|
3663
|
+
////////////////////////////////////////
|
|
3664
|
+
function cleanParams(params, data) {
|
|
3665
|
+
const p = typeof params === "function"
|
|
3666
|
+
? params(data)
|
|
3667
|
+
: typeof params === "string"
|
|
3668
|
+
? { message: params }
|
|
3669
|
+
: params;
|
|
3670
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
3671
|
+
return p2;
|
|
3672
|
+
}
|
|
3673
|
+
function custom(check, _params = {},
|
|
3658
3674
|
/**
|
|
3659
3675
|
* @deprecated
|
|
3660
3676
|
*
|
|
@@ -3669,16 +3685,23 @@ fatal) {
|
|
|
3669
3685
|
if (check)
|
|
3670
3686
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
3671
3687
|
var _a, _b;
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3688
|
+
const r = check(data);
|
|
3689
|
+
if (r instanceof Promise) {
|
|
3690
|
+
return r.then((r) => {
|
|
3691
|
+
var _a, _b;
|
|
3692
|
+
if (!r) {
|
|
3693
|
+
const params = cleanParams(_params, data);
|
|
3694
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
3695
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3696
|
+
}
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
if (!r) {
|
|
3700
|
+
const params = cleanParams(_params, data);
|
|
3701
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
3702
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3681
3703
|
}
|
|
3704
|
+
return;
|
|
3682
3705
|
});
|
|
3683
3706
|
return ZodAny.create();
|
|
3684
3707
|
}
|