zod 3.20.0 → 3.20.1

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
@@ -89,9 +89,9 @@
89
89
  - [Cyclical data](#cyclical-objects)
90
90
  - [Promises](#promises)
91
91
  - [Instanceof](#instanceof)
92
- - [Functions](#function-schemas)
92
+ - [Functions](#functions)
93
93
  - [Preprocess](#preprocess)
94
- - [Custom](#custom)
94
+ - [Custom](#custom-schemas)
95
95
  - [Schema methods](#schema-methods)
96
96
  - [.parse](#parse)
97
97
  - [.parseAsync](#parseasync)
@@ -1534,7 +1534,7 @@ TestSchema.parse(new Test()); // passes
1534
1534
  TestSchema.parse("blob"); // throws
1535
1535
  ```
1536
1536
 
1537
- ## Function schemas
1537
+ ## Functions
1538
1538
 
1539
1539
  Zod also lets you define "function schemas". This makes it easy to validate the inputs and outputs of a function without intermixing your validation code and "business logic".
1540
1540
 
@@ -1980,7 +1980,8 @@ const Strings = z.string().transform((val, ctx) => {
1980
1980
  Transforms and refinements can be interleaved. These will be executed in the order they are declared.
1981
1981
 
1982
1982
  ```ts
1983
- const nameToGreeting = z.string()
1983
+ const nameToGreeting = z
1984
+ .string()
1984
1985
  .transform((val) => val.toUpperCase())
1985
1986
  .refine((val) => val.length > 15)
1986
1987
  .transform((val) => `Hello ${val}`)
@@ -2124,7 +2125,9 @@ z.union([z.string(), z.number()]);
2124
2125
  A convenience method for creating intersection types.
2125
2126
 
2126
2127
  ```ts
2127
- const nameAndAge = z.object({ name: z.string() }).and(z.object({ age: z.number() })); // { name: string } & { age: number }
2128
+ const nameAndAge = z
2129
+ .object({ name: z.string() })
2130
+ .and(z.object({ age: z.number() })); // { name: string } & { age: number }
2128
2131
 
2129
2132
  // equivalent to
2130
2133
  z.intersection(z.object({ name: z.string() }), z.object({ age: z.number() }));
package/lib/index.mjs CHANGED
@@ -1081,7 +1081,7 @@ class ZodString extends ZodType {
1081
1081
  ...errorUtil.errToObj(message),
1082
1082
  });
1083
1083
  }
1084
- isDatetime() {
1084
+ get isDatetime() {
1085
1085
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
1086
1086
  }
1087
1087
  get isEmail() {
@@ -3166,18 +3166,16 @@ class ZodCatch extends ZodType {
3166
3166
  });
3167
3167
  if (isAsync(result)) {
3168
3168
  return result.then((result) => {
3169
- const defaultValue = this._def.defaultValue();
3170
3169
  return {
3171
3170
  status: "valid",
3172
- value: result.status === "valid" ? result.value : defaultValue,
3171
+ value: result.status === "valid" ? result.value : this._def.defaultValue(),
3173
3172
  };
3174
3173
  });
3175
3174
  }
3176
3175
  else {
3177
- const defaultValue = this._def.defaultValue();
3178
3176
  return {
3179
3177
  status: "valid",
3180
- value: result.status === "valid" ? result.value : defaultValue,
3178
+ value: result.status === "valid" ? result.value : this._def.defaultValue(),
3181
3179
  };
3182
3180
  }
3183
3181
  }
package/lib/index.umd.js CHANGED
@@ -1087,7 +1087,7 @@
1087
1087
  ...errorUtil.errToObj(message),
1088
1088
  });
1089
1089
  }
1090
- isDatetime() {
1090
+ get isDatetime() {
1091
1091
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
1092
1092
  }
1093
1093
  get isEmail() {
@@ -3172,18 +3172,16 @@
3172
3172
  });
3173
3173
  if (isAsync(result)) {
3174
3174
  return result.then((result) => {
3175
- const defaultValue = this._def.defaultValue();
3176
3175
  return {
3177
3176
  status: "valid",
3178
- value: result.status === "valid" ? result.value : defaultValue,
3177
+ value: result.status === "valid" ? result.value : this._def.defaultValue(),
3179
3178
  };
3180
3179
  });
3181
3180
  }
3182
3181
  else {
3183
- const defaultValue = this._def.defaultValue();
3184
3182
  return {
3185
3183
  status: "valid",
3186
- value: result.status === "valid" ? result.value : defaultValue,
3184
+ value: result.status === "valid" ? result.value : this._def.defaultValue(),
3187
3185
  };
3188
3186
  }
3189
3187
  }
package/lib/types.d.ts CHANGED
@@ -163,7 +163,7 @@ export declare class ZodString extends ZodType<string, ZodStringDef> {
163
163
  */
164
164
  nonempty: (message?: errorUtil.ErrMessage | undefined) => ZodString;
165
165
  trim: () => ZodString;
166
- isDatetime(): boolean;
166
+ get isDatetime(): boolean;
167
167
  get isEmail(): boolean;
168
168
  get isURL(): boolean;
169
169
  get isUUID(): boolean;
@@ -495,7 +495,7 @@ export declare class ZodUnion<T extends ZodUnionOptions> extends ZodType<T[numbe
495
495
  export declare type ZodDiscriminatedUnionOption<Discriminator extends string> = ZodObject<{
496
496
  [key in Discriminator]: ZodTypeAny;
497
497
  } & ZodRawShape, any, any>;
498
- export interface ZodDiscriminatedUnionDef<Discriminator extends string, Options extends ZodDiscriminatedUnionOption<any>[]> extends ZodTypeDef {
498
+ export interface ZodDiscriminatedUnionDef<Discriminator extends string, Options extends ZodDiscriminatedUnionOption<any>[] = ZodDiscriminatedUnionOption<any>[]> extends ZodTypeDef {
499
499
  discriminator: Discriminator;
500
500
  options: Options;
501
501
  optionsMap: Map<Primitive, ZodDiscriminatedUnionOption<any>>;
package/lib/types.js CHANGED
@@ -611,7 +611,7 @@ class ZodString extends ZodType {
611
611
  ...errorUtil_1.errorUtil.errToObj(message),
612
612
  });
613
613
  }
614
- isDatetime() {
614
+ get isDatetime() {
615
615
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
616
616
  }
617
617
  get isEmail() {
@@ -2729,18 +2729,16 @@ class ZodCatch extends ZodType {
2729
2729
  });
2730
2730
  if ((0, parseUtil_1.isAsync)(result)) {
2731
2731
  return result.then((result) => {
2732
- const defaultValue = this._def.defaultValue();
2733
2732
  return {
2734
2733
  status: "valid",
2735
- value: result.status === "valid" ? result.value : defaultValue,
2734
+ value: result.status === "valid" ? result.value : this._def.defaultValue(),
2736
2735
  };
2737
2736
  });
2738
2737
  }
2739
2738
  else {
2740
- const defaultValue = this._def.defaultValue();
2741
2739
  return {
2742
2740
  status: "valid",
2743
- value: result.status === "valid" ? result.value : defaultValue,
2741
+ value: result.status === "valid" ? result.value : this._def.defaultValue(),
2744
2742
  };
2745
2743
  }
2746
2744
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.20.0",
3
+ "version": "3.20.1",
4
4
  "description": "TypeScript-first schema declaration and validation library with static type inference",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./index.d.ts",