zod 3.22.0 → 3.22.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 CHANGED
@@ -488,6 +488,7 @@ There are a growing number of tools that are built atop or support Zod natively!
488
488
  - [`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
489
  - [`zod-openapi`](https://github.com/samchungy/zod-openapi): Create full OpenAPI v3.x documentation from Zod schemas.
490
490
  - [`fastify-zod-openapi`](https://github.com/samchungy/fastify-zod-openapi): Fastify type provider, validation, serialization and @fastify/swagger support for Zod schemas.
491
+ - [`typeschema`](https://typeschema.com/): Universal adapter for schema validation.
491
492
 
492
493
  #### X to Zod
493
494
 
@@ -501,6 +502,7 @@ There are a growing number of tools that are built atop or support Zod natively!
501
502
  - [`prisma-zod-generator`](https://github.com/omar-dulaimi/prisma-zod-generator): Emit Zod schemas from your Prisma schema.
502
503
  - [`prisma-trpc-generator`](https://github.com/omar-dulaimi/prisma-trpc-generator): Emit fully implemented tRPC routers and their validation schemas using Zod.
503
504
  - [`zod-prisma-types`](https://github.com/chrishoermann/zod-prisma-types) Create Zod types from your Prisma models.
505
+ - [`quicktype`](https://app.quicktype.io/): Convert JSON objects and JSON schemas into Zod schemas.
504
506
 
505
507
  #### Mocking
506
508
 
package/lib/index.mjs CHANGED
@@ -3147,16 +3147,20 @@ class ZodFunction extends ZodType {
3147
3147
  const params = { errorMap: ctx.common.contextualErrorMap };
3148
3148
  const fn = ctx.data;
3149
3149
  if (this._def.returns instanceof ZodPromise) {
3150
- return OK(async (...args) => {
3150
+ // Would love a way to avoid disabling this rule, but we need
3151
+ // an alias (using an arrow function was what caused 2651).
3152
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3153
+ const me = this;
3154
+ return OK(async function (...args) {
3151
3155
  const error = new ZodError([]);
3152
- const parsedArgs = await this._def.args
3156
+ const parsedArgs = await me._def.args
3153
3157
  .parseAsync(args, params)
3154
3158
  .catch((e) => {
3155
3159
  error.addIssue(makeArgsIssue(args, e));
3156
3160
  throw error;
3157
3161
  });
3158
- const result = await fn(...parsedArgs);
3159
- const parsedReturns = await this._def.returns._def.type
3162
+ const result = await Reflect.apply(fn, this, parsedArgs);
3163
+ const parsedReturns = await me._def.returns._def.type
3160
3164
  .parseAsync(result, params)
3161
3165
  .catch((e) => {
3162
3166
  error.addIssue(makeReturnsIssue(result, e));
@@ -3166,13 +3170,17 @@ class ZodFunction extends ZodType {
3166
3170
  });
3167
3171
  }
3168
3172
  else {
3169
- return OK((...args) => {
3170
- const parsedArgs = this._def.args.safeParse(args, params);
3173
+ // Would love a way to avoid disabling this rule, but we need
3174
+ // an alias (using an arrow function was what caused 2651).
3175
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3176
+ const me = this;
3177
+ return OK(function (...args) {
3178
+ const parsedArgs = me._def.args.safeParse(args, params);
3171
3179
  if (!parsedArgs.success) {
3172
3180
  throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3173
3181
  }
3174
- const result = fn(...parsedArgs.data);
3175
- const parsedReturns = this._def.returns.safeParse(result, params);
3182
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3183
+ const parsedReturns = me._def.returns.safeParse(result, params);
3176
3184
  if (!parsedReturns.success) {
3177
3185
  throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3178
3186
  }
package/lib/index.umd.js CHANGED
@@ -3153,16 +3153,20 @@
3153
3153
  const params = { errorMap: ctx.common.contextualErrorMap };
3154
3154
  const fn = ctx.data;
3155
3155
  if (this._def.returns instanceof ZodPromise) {
3156
- return OK(async (...args) => {
3156
+ // Would love a way to avoid disabling this rule, but we need
3157
+ // an alias (using an arrow function was what caused 2651).
3158
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3159
+ const me = this;
3160
+ return OK(async function (...args) {
3157
3161
  const error = new ZodError([]);
3158
- const parsedArgs = await this._def.args
3162
+ const parsedArgs = await me._def.args
3159
3163
  .parseAsync(args, params)
3160
3164
  .catch((e) => {
3161
3165
  error.addIssue(makeArgsIssue(args, e));
3162
3166
  throw error;
3163
3167
  });
3164
- const result = await fn(...parsedArgs);
3165
- const parsedReturns = await this._def.returns._def.type
3168
+ const result = await Reflect.apply(fn, this, parsedArgs);
3169
+ const parsedReturns = await me._def.returns._def.type
3166
3170
  .parseAsync(result, params)
3167
3171
  .catch((e) => {
3168
3172
  error.addIssue(makeReturnsIssue(result, e));
@@ -3172,13 +3176,17 @@
3172
3176
  });
3173
3177
  }
3174
3178
  else {
3175
- return OK((...args) => {
3176
- const parsedArgs = this._def.args.safeParse(args, params);
3179
+ // Would love a way to avoid disabling this rule, but we need
3180
+ // an alias (using an arrow function was what caused 2651).
3181
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3182
+ const me = this;
3183
+ return OK(function (...args) {
3184
+ const parsedArgs = me._def.args.safeParse(args, params);
3177
3185
  if (!parsedArgs.success) {
3178
3186
  throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3179
3187
  }
3180
- const result = fn(...parsedArgs.data);
3181
- const parsedReturns = this._def.returns.safeParse(result, params);
3188
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3189
+ const parsedReturns = me._def.returns.safeParse(result, params);
3182
3190
  if (!parsedReturns.success) {
3183
3191
  throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3184
3192
  }
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 | Promise<void>): ZodEffects<this, Output, Input>;
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
@@ -2505,16 +2505,17 @@ class ZodFunction extends ZodType {
2505
2505
  const params = { errorMap: ctx.common.contextualErrorMap };
2506
2506
  const fn = ctx.data;
2507
2507
  if (this._def.returns instanceof ZodPromise) {
2508
- return (0, parseUtil_1.OK)(async (...args) => {
2508
+ const me = this;
2509
+ return (0, parseUtil_1.OK)(async function (...args) {
2509
2510
  const error = new ZodError_1.ZodError([]);
2510
- const parsedArgs = await this._def.args
2511
+ const parsedArgs = await me._def.args
2511
2512
  .parseAsync(args, params)
2512
2513
  .catch((e) => {
2513
2514
  error.addIssue(makeArgsIssue(args, e));
2514
2515
  throw error;
2515
2516
  });
2516
- const result = await fn(...parsedArgs);
2517
- const parsedReturns = await this._def.returns._def.type
2517
+ const result = await Reflect.apply(fn, this, parsedArgs);
2518
+ const parsedReturns = await me._def.returns._def.type
2518
2519
  .parseAsync(result, params)
2519
2520
  .catch((e) => {
2520
2521
  error.addIssue(makeReturnsIssue(result, e));
@@ -2524,13 +2525,14 @@ class ZodFunction extends ZodType {
2524
2525
  });
2525
2526
  }
2526
2527
  else {
2527
- return (0, parseUtil_1.OK)((...args) => {
2528
- const parsedArgs = this._def.args.safeParse(args, params);
2528
+ const me = this;
2529
+ return (0, parseUtil_1.OK)(function (...args) {
2530
+ const parsedArgs = me._def.args.safeParse(args, params);
2529
2531
  if (!parsedArgs.success) {
2530
2532
  throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
2531
2533
  }
2532
- const result = fn(...parsedArgs.data);
2533
- const parsedReturns = this._def.returns.safeParse(result, params);
2534
+ const result = Reflect.apply(fn, this, parsedArgs.data);
2535
+ const parsedReturns = me._def.returns.safeParse(result, params);
2534
2536
  if (!parsedReturns.success) {
2535
2537
  throw new ZodError_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
2536
2538
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.22.0",
3
+ "version": "3.22.2",
4
4
  "author": "Colin McDonnell <colin@colinhacks.com>",
5
5
  "repository": {
6
6
  "type": "git",