zod 3.25.39 → 3.25.40

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.
@@ -830,7 +830,7 @@ exports.ZodFile = core.$constructor("ZodFile", (inst, def) => {
830
830
  exports.ZodType.init(inst, def);
831
831
  inst.min = (size, params) => inst.check(core._minSize(size, params));
832
832
  inst.max = (size, params) => inst.check(core._maxSize(size, params));
833
- inst.mime = (types, params) => inst.check(core._mime(types, params));
833
+ inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params));
834
834
  });
835
835
  function file(params) {
836
836
  return core._file(exports.ZodFile, params);
@@ -32,8 +32,6 @@ class JSONSchemaGenerator {
32
32
  if (isCycle) {
33
33
  seen.cycle = _params.path;
34
34
  }
35
- seen.count++;
36
- // break cycle
37
35
  return seen.schema;
38
36
  }
39
37
  // initialize
@@ -247,16 +245,20 @@ class JSONSchemaGenerator {
247
245
  }
248
246
  case "intersection": {
249
247
  const json = _json;
250
- json.allOf = [
251
- this.process(def.left, {
252
- ...params,
253
- path: [...params.path, "allOf", 0],
254
- }),
255
- this.process(def.right, {
256
- ...params,
257
- path: [...params.path, "allOf", 1],
258
- }),
248
+ const a = this.process(def.left, {
249
+ ...params,
250
+ path: [...params.path, "allOf", 0],
251
+ });
252
+ const b = this.process(def.right, {
253
+ ...params,
254
+ path: [...params.path, "allOf", 1],
255
+ });
256
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
257
+ const allOf = [
258
+ ...(isSimpleIntersection(a) ? a.allOf : [a]),
259
+ ...(isSimpleIntersection(b) ? b.allOf : [b]),
259
260
  ];
261
+ json.allOf = allOf;
260
262
  break;
261
263
  }
262
264
  case "tuple": {
@@ -360,9 +362,35 @@ class JSONSchemaGenerator {
360
362
  break;
361
363
  }
362
364
  case "file": {
363
- if (this.unrepresentable === "throw") {
364
- throw new Error("File cannot be represented in JSON Schema");
365
+ const json = _json;
366
+ const file = {
367
+ type: "string",
368
+ format: "binary",
369
+ contentEncoding: "binary",
370
+ };
371
+ const { minimum, maximum, mime } = schema._zod.bag;
372
+ if (minimum !== undefined)
373
+ file.minLength = minimum;
374
+ if (maximum !== undefined)
375
+ file.maxLength = maximum;
376
+ if (mime) {
377
+ if (mime.length === 1) {
378
+ file.contentMediaType = mime[0];
379
+ Object.assign(json, file);
380
+ }
381
+ else {
382
+ json.anyOf = mime.map((m) => {
383
+ const mFile = { ...file, contentMediaType: m };
384
+ return mFile;
385
+ });
386
+ }
387
+ }
388
+ else {
389
+ Object.assign(json, file);
365
390
  }
391
+ // if (this.unrepresentable === "throw") {
392
+ // throw new Error("File cannot be represented in JSON Schema");
393
+ // }
366
394
  break;
367
395
  }
368
396
  case "transform": {
@@ -727,7 +727,7 @@ export const ZodFile = /*@__PURE__*/ core.$constructor("ZodFile", (inst, def) =>
727
727
  ZodType.init(inst, def);
728
728
  inst.min = (size, params) => inst.check(core._minSize(size, params));
729
729
  inst.max = (size, params) => inst.check(core._maxSize(size, params));
730
- inst.mime = (types, params) => inst.check(core._mime(types, params));
730
+ inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params));
731
731
  });
732
732
  export function file(params) {
733
733
  return core._file(ZodFile, params);
@@ -28,8 +28,6 @@ export class JSONSchemaGenerator {
28
28
  if (isCycle) {
29
29
  seen.cycle = _params.path;
30
30
  }
31
- seen.count++;
32
- // break cycle
33
31
  return seen.schema;
34
32
  }
35
33
  // initialize
@@ -243,16 +241,20 @@ export class JSONSchemaGenerator {
243
241
  }
244
242
  case "intersection": {
245
243
  const json = _json;
246
- json.allOf = [
247
- this.process(def.left, {
248
- ...params,
249
- path: [...params.path, "allOf", 0],
250
- }),
251
- this.process(def.right, {
252
- ...params,
253
- path: [...params.path, "allOf", 1],
254
- }),
244
+ const a = this.process(def.left, {
245
+ ...params,
246
+ path: [...params.path, "allOf", 0],
247
+ });
248
+ const b = this.process(def.right, {
249
+ ...params,
250
+ path: [...params.path, "allOf", 1],
251
+ });
252
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
253
+ const allOf = [
254
+ ...(isSimpleIntersection(a) ? a.allOf : [a]),
255
+ ...(isSimpleIntersection(b) ? b.allOf : [b]),
255
256
  ];
257
+ json.allOf = allOf;
256
258
  break;
257
259
  }
258
260
  case "tuple": {
@@ -356,9 +358,35 @@ export class JSONSchemaGenerator {
356
358
  break;
357
359
  }
358
360
  case "file": {
359
- if (this.unrepresentable === "throw") {
360
- throw new Error("File cannot be represented in JSON Schema");
361
+ const json = _json;
362
+ const file = {
363
+ type: "string",
364
+ format: "binary",
365
+ contentEncoding: "binary",
366
+ };
367
+ const { minimum, maximum, mime } = schema._zod.bag;
368
+ if (minimum !== undefined)
369
+ file.minLength = minimum;
370
+ if (maximum !== undefined)
371
+ file.maxLength = maximum;
372
+ if (mime) {
373
+ if (mime.length === 1) {
374
+ file.contentMediaType = mime[0];
375
+ Object.assign(json, file);
376
+ }
377
+ else {
378
+ json.anyOf = mime.map((m) => {
379
+ const mFile = { ...file, contentMediaType: m };
380
+ return mFile;
381
+ });
382
+ }
383
+ }
384
+ else {
385
+ Object.assign(json, file);
361
386
  }
387
+ // if (this.unrepresentable === "throw") {
388
+ // throw new Error("File cannot be represented in JSON Schema");
389
+ // }
362
390
  break;
363
391
  }
364
392
  case "transform": {
@@ -535,7 +535,7 @@ export interface ZodFile extends ZodType {
535
535
  _zod: core.$ZodFileInternals;
536
536
  min(size: number, params?: string | core.$ZodCheckMinSizeParams): this;
537
537
  max(size: number, params?: string | core.$ZodCheckMaxSizeParams): this;
538
- mime(types: Array<util.MimeTypes>, params?: string | core.$ZodCheckMimeTypeParams): this;
538
+ mime(types: util.MimeTypes | Array<util.MimeTypes>, params?: string | core.$ZodCheckMimeTypeParams): this;
539
539
  }
540
540
  export declare const ZodFile: core.$constructor<ZodFile>;
541
541
  export declare function file(params?: string | core.$ZodFileParams): ZodFile;
@@ -734,6 +734,11 @@ export interface $ZodFileDef extends $ZodTypeDef {
734
734
  export interface $ZodFileInternals extends $ZodTypeInternals<File, File> {
735
735
  def: $ZodFileDef;
736
736
  isst: errors.$ZodIssueInvalidType;
737
+ bag: util.LoosePartial<{
738
+ minimum: number;
739
+ maximum: number;
740
+ mime: util.MimeTypes[];
741
+ }>;
737
742
  }
738
743
  export interface $ZodFile extends $ZodType {
739
744
  _zod: $ZodFileInternals;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.25.39",
3
+ "version": "3.25.40",
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",