zod 3.22.1 → 3.22.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 +32 -45
- package/lib/index.mjs +1 -1
- package/lib/index.umd.js +1 -1
- package/lib/types.d.ts +2 -1
- package/lib/types.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -185,23 +185,19 @@ Sponsorship at any level is appreciated and encouraged. For individual developer
|
|
|
185
185
|
<table>
|
|
186
186
|
<tr>
|
|
187
187
|
<td align="center">
|
|
188
|
-
<a href="https://
|
|
189
|
-
<img src="https://avatars.githubusercontent.com/u/
|
|
188
|
+
<a href="https://speakeasyapi.dev/">
|
|
189
|
+
<img src="https://avatars.githubusercontent.com/u/91446104?s=200&v=4" width="200px;" alt="Speakeasy API" />
|
|
190
190
|
</a>
|
|
191
191
|
<br />
|
|
192
|
-
<b>
|
|
192
|
+
<b>Speakeasy</b>
|
|
193
193
|
<br />
|
|
194
|
-
<a href="https://
|
|
194
|
+
<a href="https://speakeasyapi.dev/">speakeasyapi.dev</a>
|
|
195
195
|
<br />
|
|
196
|
-
<p width="200px">
|
|
197
|
-
Astro is a new kind of static <br/>
|
|
198
|
-
site builder for the modern web. <br/>
|
|
199
|
-
Powerful developer experience meets <br/>
|
|
200
|
-
lightweight output.</p>
|
|
196
|
+
<p width="200px">SDKs, Terraform, Docs.<br/>Your API made enterprise-ready.</p>
|
|
201
197
|
</td>
|
|
202
198
|
<td align="center">
|
|
203
199
|
<a href="https://glow.app/">
|
|
204
|
-
<img src="https://i.imgur.com/R0R43S2.jpg" width="200px;" alt="" />
|
|
200
|
+
<img src="https://i.imgur.com/R0R43S2.jpg" width="200px;" alt="Glow Wallet" />
|
|
205
201
|
</a>
|
|
206
202
|
<br />
|
|
207
203
|
<b>Glow Wallet</b>
|
|
@@ -223,17 +219,6 @@ Sponsorship at any level is appreciated and encouraged. For individual developer
|
|
|
223
219
|
<br />
|
|
224
220
|
<a href="https://deletype.com">deletype.com</a>
|
|
225
221
|
</td>
|
|
226
|
-
<td align="center">
|
|
227
|
-
<a href="https://proxy.com/">
|
|
228
|
-
<img src="https://avatars.githubusercontent.com/u/14321439?s=200&v=4" width="200px;" alt="Proxy logo" />
|
|
229
|
-
</a>
|
|
230
|
-
<br />
|
|
231
|
-
<b>Proxy</b>
|
|
232
|
-
<br />
|
|
233
|
-
<a href="https://proxy.com">proxy.com</a>
|
|
234
|
-
</td>
|
|
235
|
-
</tr>
|
|
236
|
-
<tr>
|
|
237
222
|
<td align="center">
|
|
238
223
|
<a href="https://trigger.dev/">
|
|
239
224
|
<img src="https://avatars.githubusercontent.com/u/95297378?s=200&v=4" width="200px;" alt="Trigger.dev logo" />
|
|
@@ -245,19 +230,19 @@ Sponsorship at any level is appreciated and encouraged. For individual developer
|
|
|
245
230
|
<br/>
|
|
246
231
|
<p>Effortless automation for developers.</p>
|
|
247
232
|
</td>
|
|
233
|
+
</tr>
|
|
234
|
+
<tr>
|
|
248
235
|
<td align="center">
|
|
249
|
-
<a href="https://transloadit.com
|
|
236
|
+
<a href="https://transloadit.com/?utm_source=zod&utm_medium=referral&utm_campaign=sponsorship&utm_content=github">
|
|
250
237
|
<img src="https://avatars.githubusercontent.com/u/125754?s=200&v=4" width="200px;" alt="Transloadit logo" />
|
|
251
238
|
</a>
|
|
252
239
|
<br />
|
|
253
240
|
<b>Transloadit</b>
|
|
254
241
|
<br />
|
|
255
|
-
<a href="https://transloadit.com">transloadit.com</a>
|
|
242
|
+
<a href="https://transloadit.com/?utm_source=zod&utm_medium=referral&utm_campaign=sponsorship&utm_content=github">transloadit.com</a>
|
|
256
243
|
<br/>
|
|
257
244
|
<p>Simple file processing for developers.</p>
|
|
258
245
|
</td>
|
|
259
|
-
</tr>
|
|
260
|
-
<tr>
|
|
261
246
|
<td align="center">
|
|
262
247
|
<a href="https://infisical.com">
|
|
263
248
|
<img src="https://avatars.githubusercontent.com/u/107880645?s=200&v=4" width="200px;" alt="Infisical logo" />
|
|
@@ -270,13 +255,25 @@ Sponsorship at any level is appreciated and encouraged. For individual developer
|
|
|
270
255
|
<p>Open-source platform for secret<br/>management: sync secrets across your<br/>team/infrastructure and prevent secret leaks.</p>
|
|
271
256
|
</td>
|
|
272
257
|
</tr>
|
|
258
|
+
<tr>
|
|
259
|
+
<td align="center">
|
|
260
|
+
<a href="https://whop.com/">
|
|
261
|
+
<img src="https://avatars.githubusercontent.com/u/91036480?s=200&v=4" width="200px;" alt="Whop logo" />
|
|
262
|
+
</a>
|
|
263
|
+
<br />
|
|
264
|
+
<b>Whop</b>
|
|
265
|
+
<br />
|
|
266
|
+
<a href="https://whop.com/">whop.com</a>
|
|
267
|
+
<br />
|
|
268
|
+
<p width="200px">A marketplace for really cool internet products.</p>
|
|
269
|
+
</td>
|
|
273
270
|
</table>
|
|
274
271
|
|
|
275
272
|
#### Silver
|
|
276
273
|
|
|
277
274
|
<table>
|
|
278
275
|
<tr>
|
|
279
|
-
|
|
276
|
+
<td align="center" colspan="2">
|
|
280
277
|
<a href="https://www.numeric.io">
|
|
281
278
|
<img src="https://i.imgur.com/kTiLtZt.png" width="250px;" alt="Numeric logo" />
|
|
282
279
|
</a>
|
|
@@ -286,17 +283,6 @@ Sponsorship at any level is appreciated and encouraged. For individual developer
|
|
|
286
283
|
<a href="https://www.numeric.io">numeric.io</a>
|
|
287
284
|
</td>
|
|
288
285
|
<td align="center">
|
|
289
|
-
<a href="https://snaplet.dev">
|
|
290
|
-
<img src="https://avatars.githubusercontent.com/u/69029941?s=200&v=4" width="150px;" alt="Snaplet logo" />
|
|
291
|
-
</a>
|
|
292
|
-
<br />
|
|
293
|
-
<b>Snaplet</b>
|
|
294
|
-
<br />
|
|
295
|
-
<a href="https://snaplet.dev">snaplet.dev</a>
|
|
296
|
-
</td>
|
|
297
|
-
</tr>
|
|
298
|
-
<tr>
|
|
299
|
-
<td align="center">
|
|
300
286
|
<a href="https://marcatopartners.com/">
|
|
301
287
|
<img src="https://avatars.githubusercontent.com/u/84106192?s=200&v=4" width="150px;" alt="Marcato Partners" />
|
|
302
288
|
</a>
|
|
@@ -305,7 +291,9 @@ Sponsorship at any level is appreciated and encouraged. For individual developer
|
|
|
305
291
|
<br />
|
|
306
292
|
<a href="https://marcatopartners.com/">marcatopartners.com</a>
|
|
307
293
|
</td>
|
|
308
|
-
|
|
294
|
+
</tr>
|
|
295
|
+
<tr>
|
|
296
|
+
<td align="center">
|
|
309
297
|
<a href="https://interval.com">
|
|
310
298
|
<img src="https://avatars.githubusercontent.com/u/67802063?s=200&v=4" width="150px;" alt="" />
|
|
311
299
|
</a>
|
|
@@ -323,8 +311,6 @@ Sponsorship at any level is appreciated and encouraged. For individual developer
|
|
|
323
311
|
<br />
|
|
324
312
|
<a href="https://seasoned.cc">seasoned.cc</a>
|
|
325
313
|
</td>
|
|
326
|
-
</tr>
|
|
327
|
-
<tr>
|
|
328
314
|
<td align="center">
|
|
329
315
|
<a href="https://www.bamboocreative.nz/">
|
|
330
316
|
<img src="https://avatars.githubusercontent.com/u/41406870?v=4" width="150px;" alt="Bamboo Creative logo" />
|
|
@@ -488,6 +474,7 @@ There are a growing number of tools that are built atop or support Zod natively!
|
|
|
488
474
|
- [`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.
|
|
489
475
|
- [`zod-openapi`](https://github.com/samchungy/zod-openapi): Create full OpenAPI v3.x documentation from Zod schemas.
|
|
490
476
|
- [`fastify-zod-openapi`](https://github.com/samchungy/fastify-zod-openapi): Fastify type provider, validation, serialization and @fastify/swagger support for Zod schemas.
|
|
477
|
+
- [`typeschema`](https://typeschema.com/): Universal adapter for schema validation.
|
|
491
478
|
|
|
492
479
|
#### X to Zod
|
|
493
480
|
|
|
@@ -501,6 +488,7 @@ There are a growing number of tools that are built atop or support Zod natively!
|
|
|
501
488
|
- [`prisma-zod-generator`](https://github.com/omar-dulaimi/prisma-zod-generator): Emit Zod schemas from your Prisma schema.
|
|
502
489
|
- [`prisma-trpc-generator`](https://github.com/omar-dulaimi/prisma-trpc-generator): Emit fully implemented tRPC routers and their validation schemas using Zod.
|
|
503
490
|
- [`zod-prisma-types`](https://github.com/chrishoermann/zod-prisma-types) Create Zod types from your Prisma models.
|
|
491
|
+
- [`quicktype`](https://app.quicktype.io/): Convert JSON objects and JSON schemas into Zod schemas.
|
|
504
492
|
|
|
505
493
|
#### Mocking
|
|
506
494
|
|
|
@@ -719,7 +707,7 @@ z.string().regex(regex);
|
|
|
719
707
|
z.string().includes(string);
|
|
720
708
|
z.string().startsWith(string);
|
|
721
709
|
z.string().endsWith(string);
|
|
722
|
-
z.string().datetime(); //
|
|
710
|
+
z.string().datetime(); // ISO 8601; default is without UTC offset, see below for options
|
|
723
711
|
z.string().ip(); // defaults to IPv4 and IPv6, see below for options
|
|
724
712
|
|
|
725
713
|
// transformations
|
|
@@ -758,7 +746,7 @@ z.string().ip({ message: "Invalid IP address" });
|
|
|
758
746
|
|
|
759
747
|
### ISO datetimes
|
|
760
748
|
|
|
761
|
-
The `z.string().datetime()` method
|
|
749
|
+
The `z.string().datetime()` method enforces ISO 8601; default is no timezone offsets and arbitrary sub-second decimal precision.
|
|
762
750
|
|
|
763
751
|
```ts
|
|
764
752
|
const datetime = z.string().datetime();
|
|
@@ -1891,7 +1879,7 @@ You can create a Zod schema for any TypeScript type by using `z.custom()`. This
|
|
|
1891
1879
|
|
|
1892
1880
|
```ts
|
|
1893
1881
|
const px = z.custom<`${number}px`>((val) => {
|
|
1894
|
-
return /^\d+px$/.test(val
|
|
1882
|
+
return typeof val === "string" ? /^\d+px$/.test(val) : false;
|
|
1895
1883
|
});
|
|
1896
1884
|
|
|
1897
1885
|
type px = z.infer<typeof px>; // `${number}px`
|
|
@@ -2823,10 +2811,9 @@ This more declarative API makes schema definitions vastly more concise.
|
|
|
2823
2811
|
|
|
2824
2812
|
[https://github.com/pelotom/runtypes](https://github.com/pelotom/runtypes)
|
|
2825
2813
|
|
|
2826
|
-
Good type inference support.
|
|
2814
|
+
Good type inference support.
|
|
2827
2815
|
|
|
2828
2816
|
- Supports "pattern matching": computed properties that distribute over unions
|
|
2829
|
-
- Supports readonly types
|
|
2830
2817
|
- Missing object methods: (deepPartial, merge)
|
|
2831
2818
|
- Missing nonempty arrays with proper typing (`[T, ...T[]]`)
|
|
2832
2819
|
- Missing promise schemas
|
package/lib/index.mjs
CHANGED
|
@@ -832,7 +832,7 @@ const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-
|
|
|
832
832
|
// /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
833
833
|
// const emailRegex =
|
|
834
834
|
// /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
|
|
835
|
-
const emailRegex = /^([A-Z0-9_
|
|
835
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
836
836
|
// const emailRegex =
|
|
837
837
|
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
|
|
838
838
|
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
package/lib/index.umd.js
CHANGED
|
@@ -838,7 +838,7 @@
|
|
|
838
838
|
// /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
839
839
|
// const emailRegex =
|
|
840
840
|
// /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
|
|
841
|
-
const emailRegex = /^([A-Z0-9_
|
|
841
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
842
842
|
// const emailRegex =
|
|
843
843
|
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
|
|
844
844
|
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
package/lib/types.d.ts
CHANGED
|
@@ -67,7 +67,8 @@ export declare abstract class ZodType<Output = any, Def extends ZodTypeDef = Zod
|
|
|
67
67
|
refinement(check: (arg: Output) => boolean, refinementData: IssueData | ((arg: Output, ctx: RefinementCtx) => IssueData)): ZodEffects<this, Output, Input>;
|
|
68
68
|
_refinement(refinement: RefinementEffect<Output>["refinement"]): ZodEffects<this, Output, Input>;
|
|
69
69
|
superRefine<RefinedOutput extends Output>(refinement: (arg: Output, ctx: RefinementCtx) => arg is RefinedOutput): ZodEffects<this, RefinedOutput, Input>;
|
|
70
|
-
superRefine(refinement: (arg: Output, ctx: RefinementCtx) => void
|
|
70
|
+
superRefine(refinement: (arg: Output, ctx: RefinementCtx) => void): ZodEffects<this, Output, Input>;
|
|
71
|
+
superRefine(refinement: (arg: Output, ctx: RefinementCtx) => Promise<void>): ZodEffects<this, Output, Input>;
|
|
71
72
|
constructor(def: Def);
|
|
72
73
|
optional(): ZodOptional<this>;
|
|
73
74
|
nullable(): ZodNullable<this>;
|
package/lib/types.js
CHANGED
|
@@ -325,7 +325,7 @@ const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
|
325
325
|
const cuid2Regex = /^[a-z][a-z0-9]*$/;
|
|
326
326
|
const ulidRegex = /[0-9A-HJKMNP-TV-Z]{26}/;
|
|
327
327
|
const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
328
|
-
const emailRegex = /^([A-Z0-9_
|
|
328
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
329
329
|
const emojiRegex = /^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u;
|
|
330
330
|
const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
|
|
331
331
|
const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
|