zod 3.25.74 → 3.25.75

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.25.74",
3
+ "version": "3.25.75",
4
4
  "type": "module",
5
5
  "author": "Colin McDonnell <zod@colinhacks.com>",
6
6
  "description": "TypeScript-first schema declaration and validation library with static type inference",
@@ -28,10 +28,9 @@ describe("toJSONSchema", () => {
28
28
  "type": "null",
29
29
  }
30
30
  `);
31
- expect(z.toJSONSchema(z.undefined())).toMatchInlineSnapshot(`
31
+ expect(z.toJSONSchema(z.undefined(), { unrepresentable: "any" })).toMatchInlineSnapshot(`
32
32
  {
33
33
  "$schema": "https://json-schema.org/draft/2020-12/schema",
34
- "not": {},
35
34
  }
36
35
  `);
37
36
  expect(z.toJSONSchema(z.any())).toMatchInlineSnapshot(`
@@ -232,6 +231,7 @@ describe("toJSONSchema", () => {
232
231
  expect(() => z.toJSONSchema(z.int64())).toThrow("BigInt cannot be represented in JSON Schema");
233
232
  expect(() => z.toJSONSchema(z.symbol())).toThrow("Symbols cannot be represented in JSON Schema");
234
233
  expect(() => z.toJSONSchema(z.void())).toThrow("Void cannot be represented in JSON Schema");
234
+ expect(() => z.toJSONSchema(z.undefined())).toThrow("Undefined cannot be represented in JSON Schema");
235
235
  expect(() => z.toJSONSchema(z.date())).toThrow("Date cannot be represented in JSON Schema");
236
236
  expect(() => z.toJSONSchema(z.map(z.string(), z.number()))).toThrow("Map cannot be represented in JSON Schema");
237
237
  expect(() => z.toJSONSchema(z.set(z.string()))).toThrow("Set cannot be represented in JSON Schema");
@@ -1887,9 +1887,8 @@ test("input type", () => {
1887
1887
  e: z.string().prefault("hello"),
1888
1888
  f: z.string().catch("hello"),
1889
1889
  g: z.never(),
1890
- h: z.undefined(),
1891
- i: z.union([z.string(), z.number().default(2)]),
1892
- j: z.union([z.string(), z.string().optional()]),
1890
+ h: z.union([z.string(), z.number().default(2)]),
1891
+ i: z.union([z.string(), z.string().optional()]),
1893
1892
  });
1894
1893
  expect(z.toJSONSchema(schema, { io: "input" })).toMatchInlineSnapshot(`
1895
1894
  {
@@ -1927,9 +1926,6 @@ test("input type", () => {
1927
1926
  "not": {},
1928
1927
  },
1929
1928
  "h": {
1930
- "not": {},
1931
- },
1932
- "i": {
1933
1929
  "anyOf": [
1934
1930
  {
1935
1931
  "type": "string",
@@ -1940,7 +1936,7 @@ test("input type", () => {
1940
1936
  },
1941
1937
  ],
1942
1938
  },
1943
- "j": {
1939
+ "i": {
1944
1940
  "anyOf": [
1945
1941
  {
1946
1942
  "type": "string",
@@ -1995,9 +1991,6 @@ test("input type", () => {
1995
1991
  "not": {},
1996
1992
  },
1997
1993
  "h": {
1998
- "not": {},
1999
- },
2000
- "i": {
2001
1994
  "anyOf": [
2002
1995
  {
2003
1996
  "type": "string",
@@ -2008,7 +2001,7 @@ test("input type", () => {
2008
2001
  },
2009
2002
  ],
2010
2003
  },
2011
- "j": {
2004
+ "i": {
2012
2005
  "anyOf": [
2013
2006
  {
2014
2007
  "type": "string",
@@ -2026,7 +2019,7 @@ test("input type", () => {
2026
2019
  "e",
2027
2020
  "f",
2028
2021
  "g",
2029
- "i",
2022
+ "h",
2030
2023
  ],
2031
2024
  "type": "object",
2032
2025
  }
@@ -2106,6 +2106,8 @@ export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B exte
2106
2106
  extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
2107
2107
  def: $ZodIntersectionDef<A, B>;
2108
2108
  isst: never;
2109
+ optin: A["_zod"]["optin"] | B["_zod"]["optin"];
2110
+ optout: A["_zod"]["optout"] | B["_zod"]["optout"];
2109
2111
  }
2110
2112
 
2111
2113
  export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
@@ -2418,6 +2420,8 @@ export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey,
2418
2420
  extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
2419
2421
  def: $ZodRecordDef<Key, Value>;
2420
2422
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
2423
+ optin?: "optional" | undefined;
2424
+ optout?: "optional" | undefined;
2421
2425
  }
2422
2426
 
2423
2427
  export type $partial = { "~~partial": true };
@@ -2551,6 +2555,8 @@ export interface $ZodMapInternals<Key extends SomeType = $ZodType, Value extends
2551
2555
  extends $ZodTypeInternals<Map<core.output<Key>, core.output<Value>>, Map<core.input<Key>, core.input<Value>>> {
2552
2556
  def: $ZodMapDef<Key, Value>;
2553
2557
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey | errors.$ZodIssueInvalidElement<unknown>;
2558
+ optin?: "optional" | undefined;
2559
+ optout?: "optional" | undefined;
2554
2560
  }
2555
2561
 
2556
2562
  export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodType {
@@ -2650,6 +2656,8 @@ export interface $ZodSetInternals<T extends SomeType = $ZodType>
2650
2656
  extends $ZodTypeInternals<Set<core.output<T>>, Set<core.input<T>>> {
2651
2657
  def: $ZodSetDef<T>;
2652
2658
  isst: errors.$ZodIssueInvalidType;
2659
+ optin?: "optional" | undefined;
2660
+ optout?: "optional" | undefined;
2653
2661
  }
2654
2662
 
2655
2663
  export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
@@ -3060,6 +3068,7 @@ export interface $ZodDefaultInternals<T extends SomeType = $ZodType>
3060
3068
  extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
3061
3069
  def: $ZodDefaultDef<T>;
3062
3070
  optin: "optional";
3071
+ optout?: "optional" | undefined; // required
3063
3072
  isst: never;
3064
3073
  values: T["_zod"]["values"];
3065
3074
  }
@@ -3120,6 +3129,7 @@ export interface $ZodPrefaultInternals<T extends SomeType = $ZodType>
3120
3129
  extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
3121
3130
  def: $ZodPrefaultDef<T>;
3122
3131
  optin: "optional";
3132
+ optout?: "optional" | undefined;
3123
3133
  isst: never;
3124
3134
  values: T["_zod"]["values"];
3125
3135
  }
@@ -3162,6 +3172,8 @@ export interface $ZodNonOptionalInternals<T extends SomeType = $ZodType>
3162
3172
  def: $ZodNonOptionalDef<T>;
3163
3173
  isst: errors.$ZodIssueInvalidType;
3164
3174
  values: T["_zod"]["values"];
3175
+ optin: "optional" | undefined;
3176
+ optout: "optional" | undefined;
3165
3177
  }
3166
3178
 
3167
3179
  export interface $ZodNonOptional<T extends SomeType = $ZodType> extends $ZodType {
@@ -3255,6 +3267,8 @@ export interface $ZodSuccessDef<T extends SomeType = $ZodType> extends $ZodTypeD
3255
3267
  export interface $ZodSuccessInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<boolean, core.input<T>> {
3256
3268
  def: $ZodSuccessDef<T>;
3257
3269
  isst: never;
3270
+ optin: T["_zod"]["optin"];
3271
+ optout: "optional" | undefined;
3258
3272
  }
3259
3273
 
3260
3274
  export interface $ZodSuccess<T extends SomeType = $ZodType> extends $ZodType {
@@ -227,9 +227,10 @@ export class JSONSchemaGenerator {
227
227
  case "unknown": {
228
228
  break;
229
229
  }
230
- case "undefined":
231
- case "never": {
232
- _json.not = {};
230
+ case "undefined": {
231
+ if (this.unrepresentable === "throw") {
232
+ throw new Error("Undefined cannot be represented in JSON Schema");
233
+ }
233
234
  break;
234
235
  }
235
236
  case "void": {
@@ -238,6 +239,10 @@ export class JSONSchemaGenerator {
238
239
  }
239
240
  break;
240
241
  }
242
+ case "never": {
243
+ _json.not = {};
244
+ break;
245
+ }
241
246
  case "date": {
242
247
  if (this.unrepresentable === "throw") {
243
248
  throw new Error("Date cannot be represented in JSON Schema");
@@ -635,6 +635,8 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
635
635
  export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
636
636
  def: $ZodIntersectionDef<A, B>;
637
637
  isst: never;
638
+ optin: A["_zod"]["optin"] | B["_zod"]["optin"];
639
+ optout: A["_zod"]["optout"] | B["_zod"]["optout"];
638
640
  }
639
641
  export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
640
642
  _zod: $ZodIntersectionInternals<A, B>;
@@ -686,6 +688,8 @@ export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Valu
686
688
  export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
687
689
  def: $ZodRecordDef<Key, Value>;
688
690
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
691
+ optin?: "optional" | undefined;
692
+ optout?: "optional" | undefined;
689
693
  }
690
694
  export type $partial = {
691
695
  "~~partial": true;
@@ -702,6 +706,8 @@ export interface $ZodMapDef<Key extends SomeType = $ZodType, Value extends SomeT
702
706
  export interface $ZodMapInternals<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodTypeInternals<Map<core.output<Key>, core.output<Value>>, Map<core.input<Key>, core.input<Value>>> {
703
707
  def: $ZodMapDef<Key, Value>;
704
708
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey | errors.$ZodIssueInvalidElement<unknown>;
709
+ optin?: "optional" | undefined;
710
+ optout?: "optional" | undefined;
705
711
  }
706
712
  export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodType {
707
713
  _zod: $ZodMapInternals<Key, Value>;
@@ -714,6 +720,8 @@ export interface $ZodSetDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
714
720
  export interface $ZodSetInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<Set<core.output<T>>, Set<core.input<T>>> {
715
721
  def: $ZodSetDef<T>;
716
722
  isst: errors.$ZodIssueInvalidType;
723
+ optin?: "optional" | undefined;
724
+ optout?: "optional" | undefined;
717
725
  }
718
726
  export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
719
727
  _zod: $ZodSetInternals<T>;
@@ -826,6 +834,7 @@ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeD
826
834
  export interface $ZodDefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
827
835
  def: $ZodDefaultDef<T>;
828
836
  optin: "optional";
837
+ optout?: "optional" | undefined;
829
838
  isst: never;
830
839
  values: T["_zod"]["values"];
831
840
  }
@@ -842,6 +851,7 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
842
851
  export interface $ZodPrefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
843
852
  def: $ZodPrefaultDef<T>;
844
853
  optin: "optional";
854
+ optout?: "optional" | undefined;
845
855
  isst: never;
846
856
  values: T["_zod"]["values"];
847
857
  }
@@ -857,6 +867,8 @@ export interface $ZodNonOptionalInternals<T extends SomeType = $ZodType> extends
857
867
  def: $ZodNonOptionalDef<T>;
858
868
  isst: errors.$ZodIssueInvalidType;
859
869
  values: T["_zod"]["values"];
870
+ optin: "optional" | undefined;
871
+ optout: "optional" | undefined;
860
872
  }
861
873
  export interface $ZodNonOptional<T extends SomeType = $ZodType> extends $ZodType {
862
874
  _zod: $ZodNonOptionalInternals<T>;
@@ -869,6 +881,8 @@ export interface $ZodSuccessDef<T extends SomeType = $ZodType> extends $ZodTypeD
869
881
  export interface $ZodSuccessInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<boolean, core.input<T>> {
870
882
  def: $ZodSuccessDef<T>;
871
883
  isst: never;
884
+ optin: T["_zod"]["optin"];
885
+ optout: "optional" | undefined;
872
886
  }
873
887
  export interface $ZodSuccess<T extends SomeType = $ZodType> extends $ZodType {
874
888
  _zod: $ZodSuccessInternals<T>;
@@ -635,6 +635,8 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
635
635
  export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
636
636
  def: $ZodIntersectionDef<A, B>;
637
637
  isst: never;
638
+ optin: A["_zod"]["optin"] | B["_zod"]["optin"];
639
+ optout: A["_zod"]["optout"] | B["_zod"]["optout"];
638
640
  }
639
641
  export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
640
642
  _zod: $ZodIntersectionInternals<A, B>;
@@ -686,6 +688,8 @@ export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Valu
686
688
  export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
687
689
  def: $ZodRecordDef<Key, Value>;
688
690
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
691
+ optin?: "optional" | undefined;
692
+ optout?: "optional" | undefined;
689
693
  }
690
694
  export type $partial = {
691
695
  "~~partial": true;
@@ -702,6 +706,8 @@ export interface $ZodMapDef<Key extends SomeType = $ZodType, Value extends SomeT
702
706
  export interface $ZodMapInternals<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodTypeInternals<Map<core.output<Key>, core.output<Value>>, Map<core.input<Key>, core.input<Value>>> {
703
707
  def: $ZodMapDef<Key, Value>;
704
708
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey | errors.$ZodIssueInvalidElement<unknown>;
709
+ optin?: "optional" | undefined;
710
+ optout?: "optional" | undefined;
705
711
  }
706
712
  export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodType {
707
713
  _zod: $ZodMapInternals<Key, Value>;
@@ -714,6 +720,8 @@ export interface $ZodSetDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
714
720
  export interface $ZodSetInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<Set<core.output<T>>, Set<core.input<T>>> {
715
721
  def: $ZodSetDef<T>;
716
722
  isst: errors.$ZodIssueInvalidType;
723
+ optin?: "optional" | undefined;
724
+ optout?: "optional" | undefined;
717
725
  }
718
726
  export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
719
727
  _zod: $ZodSetInternals<T>;
@@ -826,6 +834,7 @@ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeD
826
834
  export interface $ZodDefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
827
835
  def: $ZodDefaultDef<T>;
828
836
  optin: "optional";
837
+ optout?: "optional" | undefined;
829
838
  isst: never;
830
839
  values: T["_zod"]["values"];
831
840
  }
@@ -842,6 +851,7 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
842
851
  export interface $ZodPrefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
843
852
  def: $ZodPrefaultDef<T>;
844
853
  optin: "optional";
854
+ optout?: "optional" | undefined;
845
855
  isst: never;
846
856
  values: T["_zod"]["values"];
847
857
  }
@@ -857,6 +867,8 @@ export interface $ZodNonOptionalInternals<T extends SomeType = $ZodType> extends
857
867
  def: $ZodNonOptionalDef<T>;
858
868
  isst: errors.$ZodIssueInvalidType;
859
869
  values: T["_zod"]["values"];
870
+ optin: "optional" | undefined;
871
+ optout: "optional" | undefined;
860
872
  }
861
873
  export interface $ZodNonOptional<T extends SomeType = $ZodType> extends $ZodType {
862
874
  _zod: $ZodNonOptionalInternals<T>;
@@ -869,6 +881,8 @@ export interface $ZodSuccessDef<T extends SomeType = $ZodType> extends $ZodTypeD
869
881
  export interface $ZodSuccessInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<boolean, core.input<T>> {
870
882
  def: $ZodSuccessDef<T>;
871
883
  isst: never;
884
+ optin: T["_zod"]["optin"];
885
+ optout: "optional" | undefined;
872
886
  }
873
887
  export interface $ZodSuccess<T extends SomeType = $ZodType> extends $ZodType {
874
888
  _zod: $ZodSuccessInternals<T>;
@@ -151,9 +151,10 @@ class JSONSchemaGenerator {
151
151
  case "unknown": {
152
152
  break;
153
153
  }
154
- case "undefined":
155
- case "never": {
156
- _json.not = {};
154
+ case "undefined": {
155
+ if (this.unrepresentable === "throw") {
156
+ throw new Error("Undefined cannot be represented in JSON Schema");
157
+ }
157
158
  break;
158
159
  }
159
160
  case "void": {
@@ -162,6 +163,10 @@ class JSONSchemaGenerator {
162
163
  }
163
164
  break;
164
165
  }
166
+ case "never": {
167
+ _json.not = {};
168
+ break;
169
+ }
165
170
  case "date": {
166
171
  if (this.unrepresentable === "throw") {
167
172
  throw new Error("Date cannot be represented in JSON Schema");
@@ -147,9 +147,10 @@ export class JSONSchemaGenerator {
147
147
  case "unknown": {
148
148
  break;
149
149
  }
150
- case "undefined":
151
- case "never": {
152
- _json.not = {};
150
+ case "undefined": {
151
+ if (this.unrepresentable === "throw") {
152
+ throw new Error("Undefined cannot be represented in JSON Schema");
153
+ }
153
154
  break;
154
155
  }
155
156
  case "void": {
@@ -158,6 +159,10 @@ export class JSONSchemaGenerator {
158
159
  }
159
160
  break;
160
161
  }
162
+ case "never": {
163
+ _json.not = {};
164
+ break;
165
+ }
161
166
  case "date": {
162
167
  if (this.unrepresentable === "throw") {
163
168
  throw new Error("Date cannot be represented in JSON Schema");