@orpc/zod 0.0.0-next.8b6cb3a → 0.0.0-next.8be6412

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/dist/index.d.mts CHANGED
@@ -40,43 +40,34 @@ declare class ZodSmartCoercionPlugin<TContext extends Context> implements Standa
40
40
 
41
41
  interface ZodToJsonSchemaOptions {
42
42
  /**
43
- * Max depth of lazy type
43
+ * Max depth of lazy type, if it exceeds.
44
44
  *
45
- * Used `{}` when exceed max depth
45
+ * Used `{}` when reach max depth
46
46
  *
47
47
  * @default 3
48
48
  */
49
49
  maxLazyDepth?: number;
50
50
  /**
51
- * Max depth of nested types
52
- *
53
- * Used anyJsonSchema (`{}`) when exceed max depth
51
+ * The schema to be used when the Zod schema is unsupported.
54
52
  *
55
- * @default 10
53
+ * @default { not: {} }
56
54
  */
57
- maxStructureDepth?: number;
55
+ unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
58
56
  /**
59
57
  * The schema to be used to represent the any | unknown type.
60
58
  *
61
59
  * @default { }
62
60
  */
63
61
  anyJsonSchema?: Exclude<JSONSchema, boolean>;
64
- /**
65
- * The schema to be used when the Zod schema is unsupported.
66
- *
67
- * @default { not: {} }
68
- */
69
- unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
70
62
  }
71
63
  declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
72
64
  #private;
73
65
  private readonly maxLazyDepth;
74
- private readonly maxStructureDepth;
75
66
  private readonly unsupportedJsonSchema;
76
67
  private readonly anyJsonSchema;
77
68
  constructor(options?: ZodToJsonSchemaOptions);
78
69
  condition(schema: AnySchema | undefined): boolean;
79
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean, structureDepth?: number): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
70
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
80
71
  }
81
72
 
82
73
  declare const oz: {
package/dist/index.d.ts CHANGED
@@ -40,43 +40,34 @@ declare class ZodSmartCoercionPlugin<TContext extends Context> implements Standa
40
40
 
41
41
  interface ZodToJsonSchemaOptions {
42
42
  /**
43
- * Max depth of lazy type
43
+ * Max depth of lazy type, if it exceeds.
44
44
  *
45
- * Used `{}` when exceed max depth
45
+ * Used `{}` when reach max depth
46
46
  *
47
47
  * @default 3
48
48
  */
49
49
  maxLazyDepth?: number;
50
50
  /**
51
- * Max depth of nested types
52
- *
53
- * Used anyJsonSchema (`{}`) when exceed max depth
51
+ * The schema to be used when the Zod schema is unsupported.
54
52
  *
55
- * @default 10
53
+ * @default { not: {} }
56
54
  */
57
- maxStructureDepth?: number;
55
+ unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
58
56
  /**
59
57
  * The schema to be used to represent the any | unknown type.
60
58
  *
61
59
  * @default { }
62
60
  */
63
61
  anyJsonSchema?: Exclude<JSONSchema, boolean>;
64
- /**
65
- * The schema to be used when the Zod schema is unsupported.
66
- *
67
- * @default { not: {} }
68
- */
69
- unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
70
62
  }
71
63
  declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
72
64
  #private;
73
65
  private readonly maxLazyDepth;
74
- private readonly maxStructureDepth;
75
66
  private readonly unsupportedJsonSchema;
76
67
  private readonly anyJsonSchema;
77
68
  constructor(options?: ZodToJsonSchemaOptions);
78
69
  condition(schema: AnySchema | undefined): boolean;
79
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean, structureDepth?: number): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
70
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
80
71
  }
81
72
 
82
73
  declare const oz: {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { custom, ZodFirstPartyTypeKind } from 'zod';
2
2
  import wcmatch from 'wildcard-match';
3
- import { isObject, guard, toArray } from '@orpc/shared';
3
+ import { isObject, guard } from '@orpc/shared';
4
4
  import { JSONSchemaFormat } from '@orpc/openapi';
5
5
  import escapeStringRegexp from 'escape-string-regexp';
6
6
 
@@ -390,39 +390,25 @@ function safeToDate(value) {
390
390
 
391
391
  class ZodToJsonSchemaConverter {
392
392
  maxLazyDepth;
393
- maxStructureDepth;
394
393
  unsupportedJsonSchema;
395
394
  anyJsonSchema;
396
395
  constructor(options = {}) {
397
396
  this.maxLazyDepth = options.maxLazyDepth ?? 3;
398
- this.maxStructureDepth = options.maxStructureDepth ?? 10;
399
397
  this.unsupportedJsonSchema = options.unsupportedJsonSchema ?? { not: {} };
400
398
  this.anyJsonSchema = options.anyJsonSchema ?? {};
401
399
  }
402
400
  condition(schema) {
403
401
  return schema !== void 0 && schema["~standard"].vendor === "zod";
404
402
  }
405
- convert(schema, options, lazyDepth = 0, isHandledCustomJSONSchema = false, isHandledZodDescription = false, structureDepth = 0) {
403
+ convert(schema, options, lazyDepth = 0, isHandledCustomJSONSchema = false, isHandledZodDescription = false) {
406
404
  const def = schema._def;
407
- if (structureDepth > this.maxStructureDepth) {
408
- return [false, this.anyJsonSchema];
409
- }
410
- if (!options.minStructureDepthForRef || options.minStructureDepthForRef <= structureDepth) {
411
- const components = toArray(options.components);
412
- for (const component of components) {
413
- if (component.schema === schema && component.allowedStrategies.includes(options.strategy)) {
414
- return [component.required, { $ref: component.ref }];
415
- }
416
- }
417
- }
418
405
  if (!isHandledZodDescription && "description" in def && typeof def.description === "string") {
419
406
  const [required, json] = this.convert(
420
407
  schema,
421
408
  options,
422
409
  lazyDepth,
423
410
  isHandledCustomJSONSchema,
424
- true,
425
- structureDepth
411
+ true
426
412
  );
427
413
  return [required, { ...json, description: def.description }];
428
414
  }
@@ -434,8 +420,7 @@ class ZodToJsonSchemaConverter {
434
420
  options,
435
421
  lazyDepth,
436
422
  true,
437
- isHandledZodDescription,
438
- structureDepth
423
+ isHandledZodDescription
439
424
  );
440
425
  return [required, { ...json, ...customJSONSchema }];
441
426
  }
@@ -606,7 +591,7 @@ class ZodToJsonSchemaConverter {
606
591
  const schema_ = schema;
607
592
  const def2 = schema_._def;
608
593
  const json = { type: "array" };
609
- const [itemRequired, itemJson] = this.convert(def2.type, options, lazyDepth, false, false, structureDepth + 1);
594
+ const [itemRequired, itemJson] = this.convert(def2.type, options, lazyDepth, false, false);
610
595
  json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
611
596
  if (def2.exactLength) {
612
597
  json.maxItems = def2.exactLength.value;
@@ -625,7 +610,7 @@ class ZodToJsonSchemaConverter {
625
610
  const prefixItems = [];
626
611
  const json = { type: "array" };
627
612
  for (const item of schema_._def.items) {
628
- const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth + 1);
613
+ const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false);
629
614
  prefixItems.push(
630
615
  this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy)
631
616
  );
@@ -634,7 +619,7 @@ class ZodToJsonSchemaConverter {
634
619
  json.prefixItems = prefixItems;
635
620
  }
636
621
  if (schema_._def.rest) {
637
- const [itemRequired, itemJson] = this.convert(schema_._def.rest, options, lazyDepth, false, false, structureDepth + 1);
622
+ const [itemRequired, itemJson] = this.convert(schema_._def.rest, options, lazyDepth, false, false);
638
623
  json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
639
624
  }
640
625
  return [true, json];
@@ -645,7 +630,7 @@ class ZodToJsonSchemaConverter {
645
630
  const properties = {};
646
631
  const required = [];
647
632
  for (const [key, value] of Object.entries(schema_.shape)) {
648
- const [itemRequired, itemJson] = this.convert(value, options, lazyDepth, false, false, structureDepth + 1);
633
+ const [itemRequired, itemJson] = this.convert(value, options, lazyDepth, false, false);
649
634
  properties[key] = itemJson;
650
635
  if (itemRequired) {
651
636
  required.push(key);
@@ -663,7 +648,7 @@ class ZodToJsonSchemaConverter {
663
648
  json.additionalProperties = false;
664
649
  }
665
650
  } else {
666
- const [_, addJson] = this.convert(schema_._def.catchall, options, lazyDepth, false, false, structureDepth + 1);
651
+ const [_, addJson] = this.convert(schema_._def.catchall, options, lazyDepth, false, false);
667
652
  json.additionalProperties = addJson;
668
653
  }
669
654
  return [true, json];
@@ -671,25 +656,25 @@ class ZodToJsonSchemaConverter {
671
656
  case ZodFirstPartyTypeKind.ZodRecord: {
672
657
  const schema_ = schema;
673
658
  const json = { type: "object" };
674
- const [__, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false, structureDepth + 1);
659
+ const [__, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false);
675
660
  if (Object.entries(keyJson).some(([k, v]) => k !== "type" || v !== "string")) {
676
661
  json.propertyNames = keyJson;
677
662
  }
678
- const [_, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
663
+ const [_, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false);
679
664
  json.additionalProperties = itemJson;
680
665
  return [true, json];
681
666
  }
682
667
  case ZodFirstPartyTypeKind.ZodSet: {
683
668
  const schema_ = schema;
684
669
  const json = { type: "array", uniqueItems: true };
685
- const [itemRequired, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
670
+ const [itemRequired, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false);
686
671
  json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
687
672
  return [true, json];
688
673
  }
689
674
  case ZodFirstPartyTypeKind.ZodMap: {
690
675
  const schema_ = schema;
691
- const [keyRequired, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false, structureDepth + 1);
692
- const [valueRequired, valueJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
676
+ const [keyRequired, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false);
677
+ const [valueRequired, valueJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false);
693
678
  return [true, {
694
679
  type: "array",
695
680
  items: {
@@ -709,7 +694,7 @@ class ZodToJsonSchemaConverter {
709
694
  const anyOf = [];
710
695
  let required = true;
711
696
  for (const item of schema_._def.options) {
712
- const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth);
697
+ const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false);
713
698
  if (!itemRequired) {
714
699
  required = false;
715
700
  if (itemJson !== this.unsupportedJsonSchema) {
@@ -729,7 +714,7 @@ class ZodToJsonSchemaConverter {
729
714
  const allOf = [];
730
715
  let required = false;
731
716
  for (const item of [schema_._def.left, schema_._def.right]) {
732
- const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth);
717
+ const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false);
733
718
  allOf.push(itemJson);
734
719
  if (itemRequired) {
735
720
  required = true;
@@ -738,26 +723,25 @@ class ZodToJsonSchemaConverter {
738
723
  return [required, { allOf }];
739
724
  }
740
725
  case ZodFirstPartyTypeKind.ZodLazy: {
741
- const currentLazyDepth = lazyDepth + 1;
742
- if (currentLazyDepth > this.maxLazyDepth) {
726
+ if (lazyDepth >= this.maxLazyDepth) {
743
727
  return [false, this.anyJsonSchema];
744
728
  }
745
729
  const schema_ = schema;
746
- return this.convert(schema_._def.getter(), options, currentLazyDepth, false, false, structureDepth);
730
+ return this.convert(schema_._def.getter(), options, lazyDepth + 1, false, false);
747
731
  }
748
732
  case ZodFirstPartyTypeKind.ZodOptional: {
749
733
  const schema_ = schema;
750
- const [_, inner] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
734
+ const [_, inner] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
751
735
  return [false, inner];
752
736
  }
753
737
  case ZodFirstPartyTypeKind.ZodReadonly: {
754
738
  const schema_ = schema;
755
- const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
739
+ const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
756
740
  return [required, { ...json, readOnly: true }];
757
741
  }
758
742
  case ZodFirstPartyTypeKind.ZodDefault: {
759
743
  const schema_ = schema;
760
- const [_, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
744
+ const [_, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
761
745
  return [false, { default: schema_._def.defaultValue(), ...json }];
762
746
  }
763
747
  case ZodFirstPartyTypeKind.ZodEffects: {
@@ -765,15 +749,15 @@ class ZodToJsonSchemaConverter {
765
749
  if (schema_._def.effect.type === "transform" && options.strategy === "output") {
766
750
  return [false, this.anyJsonSchema];
767
751
  }
768
- return this.convert(schema_._def.schema, options, lazyDepth, false, false, structureDepth);
752
+ return this.convert(schema_._def.schema, options, lazyDepth, false, false);
769
753
  }
770
754
  case ZodFirstPartyTypeKind.ZodCatch: {
771
755
  const schema_ = schema;
772
- return this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
756
+ return this.convert(schema_._def.innerType, options, lazyDepth, false, false);
773
757
  }
774
758
  case ZodFirstPartyTypeKind.ZodBranded: {
775
759
  const schema_ = schema;
776
- return this.convert(schema_._def.type, options, lazyDepth, false, false, structureDepth);
760
+ return this.convert(schema_._def.type, options, lazyDepth, false, false);
777
761
  }
778
762
  case ZodFirstPartyTypeKind.ZodPipeline: {
779
763
  const schema_ = schema;
@@ -782,13 +766,12 @@ class ZodToJsonSchemaConverter {
782
766
  options,
783
767
  lazyDepth,
784
768
  false,
785
- false,
786
- structureDepth
769
+ false
787
770
  );
788
771
  }
789
772
  case ZodFirstPartyTypeKind.ZodNullable: {
790
773
  const schema_ = schema;
791
- const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
774
+ const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
792
775
  return [required, { anyOf: [{ type: "null" }, json] }];
793
776
  }
794
777
  }
@@ -13,21 +13,13 @@ declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> impl
13
13
 
14
14
  interface experimental_ZodToJsonSchemaOptions {
15
15
  /**
16
- * Max depth of lazy type.
16
+ * Max depth of lazy type, if it exceeds.
17
17
  *
18
- * Used anyJsonSchema (`{}`) when exceed max depth
18
+ * Used anyJsonSchema (`{}`) when reach max depth
19
19
  *
20
20
  * @default 2
21
21
  */
22
22
  maxLazyDepth?: number;
23
- /**
24
- * Max depth of nested types.
25
- *
26
- * Used anyJsonSchema (`{}`) when exceed max depth
27
- *
28
- * @default 10
29
- */
30
- maxStructureDepth?: number;
31
23
  /**
32
24
  * The schema to be used to represent the any | unknown type.
33
25
  *
@@ -59,7 +51,6 @@ interface experimental_ZodToJsonSchemaOptions {
59
51
  declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
60
52
  #private;
61
53
  private readonly maxLazyDepth;
62
- private readonly maxStructureDepth;
63
54
  private readonly anyJsonSchema;
64
55
  private readonly unsupportedJsonSchema;
65
56
  private readonly undefinedJsonSchema;
@@ -13,21 +13,13 @@ declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> impl
13
13
 
14
14
  interface experimental_ZodToJsonSchemaOptions {
15
15
  /**
16
- * Max depth of lazy type.
16
+ * Max depth of lazy type, if it exceeds.
17
17
  *
18
- * Used anyJsonSchema (`{}`) when exceed max depth
18
+ * Used anyJsonSchema (`{}`) when reach max depth
19
19
  *
20
20
  * @default 2
21
21
  */
22
22
  maxLazyDepth?: number;
23
- /**
24
- * Max depth of nested types.
25
- *
26
- * Used anyJsonSchema (`{}`) when exceed max depth
27
- *
28
- * @default 10
29
- */
30
- maxStructureDepth?: number;
31
23
  /**
32
24
  * The schema to be used to represent the any | unknown type.
33
25
  *
@@ -59,7 +51,6 @@ interface experimental_ZodToJsonSchemaOptions {
59
51
  declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
60
52
  #private;
61
53
  private readonly maxLazyDepth;
62
- private readonly maxStructureDepth;
63
54
  private readonly anyJsonSchema;
64
55
  private readonly unsupportedJsonSchema;
65
56
  private readonly undefinedJsonSchema;
@@ -1,4 +1,4 @@
1
- import { isObject, guard, intercept, toArray } from '@orpc/shared';
1
+ import { isObject, guard, intercept } from '@orpc/shared';
2
2
  import { JSONSchemaFormat, JSONSchemaContentEncoding } from '@orpc/openapi';
3
3
  import { registry, globalRegistry } from 'zod/v4/core';
4
4
 
@@ -274,14 +274,12 @@ const experimental_JSON_SCHEMA_OUTPUT_REGISTRY = registry();
274
274
 
275
275
  class experimental_ZodToJsonSchemaConverter {
276
276
  maxLazyDepth;
277
- maxStructureDepth;
278
277
  anyJsonSchema;
279
278
  unsupportedJsonSchema;
280
279
  undefinedJsonSchema;
281
280
  interceptors;
282
281
  constructor(options = {}) {
283
282
  this.maxLazyDepth = options.maxLazyDepth ?? 2;
284
- this.maxStructureDepth = options.maxStructureDepth ?? 10;
285
283
  this.anyJsonSchema = options.anyJsonSchema ?? {};
286
284
  this.unsupportedJsonSchema = options.unsupportedJsonSchema ?? { not: {} };
287
285
  this.undefinedJsonSchema = options.undefinedJsonSchema ?? { not: {} };
@@ -291,28 +289,17 @@ class experimental_ZodToJsonSchemaConverter {
291
289
  return schema !== void 0 && schema["~standard"].vendor === "zod";
292
290
  }
293
291
  convert(schema, options) {
294
- return this.#convert(schema, options, 0, 0);
292
+ return this.#convert(schema, options, 0);
295
293
  }
296
- #convert(schema, options, lazyDepth, structureDepth, isHandledCustomJSONSchema = false) {
294
+ #convert(schema, options, lazyDepth, isHandledCustomJSONSchema = false) {
297
295
  return intercept(
298
296
  this.interceptors,
299
297
  { schema, options, lazyDepth, isHandledCustomJSONSchema },
300
298
  ({ schema: schema2, options: options2, lazyDepth: lazyDepth2, isHandledCustomJSONSchema: isHandledCustomJSONSchema2 }) => {
301
- if (structureDepth > this.maxStructureDepth) {
302
- return [false, this.anyJsonSchema];
303
- }
304
- if (!options2.minStructureDepthForRef || options2.minStructureDepthForRef <= structureDepth) {
305
- const components = toArray(options2.components);
306
- for (const component of components) {
307
- if (component.schema === schema2 && component.allowedStrategies.includes(options2.strategy)) {
308
- return [component.required, { $ref: component.ref }];
309
- }
310
- }
311
- }
312
299
  if (!isHandledCustomJSONSchema2) {
313
300
  const customJSONSchema = this.#getCustomJsonSchema(schema2, options2);
314
301
  if (customJSONSchema) {
315
- const [required, json] = this.#convert(schema2, options2, lazyDepth2, structureDepth, true);
302
+ const [required, json] = this.#convert(schema2, options2, lazyDepth2, true);
316
303
  return [required, { ...json, ...customJSONSchema }];
317
304
  }
318
305
  }
@@ -407,14 +394,14 @@ class experimental_ZodToJsonSchemaConverter {
407
394
  if (typeof maximum === "number") {
408
395
  json.maxItems = maximum;
409
396
  }
410
- json.items = this.#handleArrayItemJsonSchema(this.#convert(array._zod.def.element, options2, lazyDepth2, structureDepth + 1), options2);
397
+ json.items = this.#handleArrayItemJsonSchema(this.#convert(array._zod.def.element, options2, lazyDepth2), options2);
411
398
  return [true, json];
412
399
  }
413
400
  case "object": {
414
401
  const object = schema2;
415
402
  const json = { type: "object" };
416
403
  for (const [key, value] of Object.entries(object._zod.def.shape)) {
417
- const [itemRequired, itemJson] = this.#convert(value, options2, lazyDepth2, structureDepth + 1);
404
+ const [itemRequired, itemJson] = this.#convert(value, options2, lazyDepth2);
418
405
  json.properties ??= {};
419
406
  json.properties[key] = itemJson;
420
407
  if (itemRequired) {
@@ -426,7 +413,7 @@ class experimental_ZodToJsonSchemaConverter {
426
413
  if (object._zod.def.catchall._zod.def.type === "never") {
427
414
  json.additionalProperties = false;
428
415
  } else {
429
- const [_, addJson] = this.#convert(object._zod.def.catchall, options2, lazyDepth2, structureDepth + 1);
416
+ const [_, addJson] = this.#convert(object._zod.def.catchall, options2, lazyDepth2);
430
417
  json.additionalProperties = addJson;
431
418
  }
432
419
  }
@@ -437,7 +424,7 @@ class experimental_ZodToJsonSchemaConverter {
437
424
  const anyOf = [];
438
425
  let required = true;
439
426
  for (const item of union._zod.def.options) {
440
- const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2, structureDepth);
427
+ const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2);
441
428
  if (!itemRequired) {
442
429
  required = false;
443
430
  }
@@ -458,7 +445,7 @@ class experimental_ZodToJsonSchemaConverter {
458
445
  const json = { allOf: [] };
459
446
  let required = false;
460
447
  for (const item of [intersection._zod.def.left, intersection._zod.def.right]) {
461
- const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2, structureDepth);
448
+ const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2);
462
449
  json.allOf.push(itemJson);
463
450
  if (itemRequired) {
464
451
  required = true;
@@ -470,10 +457,10 @@ class experimental_ZodToJsonSchemaConverter {
470
457
  const tuple = schema2;
471
458
  const json = { type: "array", prefixItems: [] };
472
459
  for (const item of tuple._zod.def.items) {
473
- json.prefixItems.push(this.#handleArrayItemJsonSchema(this.#convert(item, options2, lazyDepth2, structureDepth + 1), options2));
460
+ json.prefixItems.push(this.#handleArrayItemJsonSchema(this.#convert(item, options2, lazyDepth2), options2));
474
461
  }
475
462
  if (tuple._zod.def.rest) {
476
- json.items = this.#handleArrayItemJsonSchema(this.#convert(tuple._zod.def.rest, options2, lazyDepth2, structureDepth + 1), options2);
463
+ json.items = this.#handleArrayItemJsonSchema(this.#convert(tuple._zod.def.rest, options2, lazyDepth2), options2);
477
464
  }
478
465
  const { minimum, maximum } = tuple._zod.bag;
479
466
  if (typeof minimum === "number") {
@@ -487,8 +474,8 @@ class experimental_ZodToJsonSchemaConverter {
487
474
  case "record": {
488
475
  const record = schema2;
489
476
  const json = { type: "object" };
490
- json.propertyNames = this.#convert(record._zod.def.keyType, options2, lazyDepth2, structureDepth + 1)[1];
491
- json.additionalProperties = this.#convert(record._zod.def.valueType, options2, lazyDepth2, structureDepth + 1)[1];
477
+ json.propertyNames = this.#convert(record._zod.def.keyType, options2, lazyDepth2)[1];
478
+ json.additionalProperties = this.#convert(record._zod.def.valueType, options2, lazyDepth2)[1];
492
479
  return [true, json];
493
480
  }
494
481
  case "map": {
@@ -498,8 +485,8 @@ class experimental_ZodToJsonSchemaConverter {
498
485
  items: {
499
486
  type: "array",
500
487
  prefixItems: [
501
- this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.keyType, options2, lazyDepth2, structureDepth + 1), options2),
502
- this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.valueType, options2, lazyDepth2, structureDepth + 1), options2)
488
+ this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.keyType, options2, lazyDepth2), options2),
489
+ this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.valueType, options2, lazyDepth2), options2)
503
490
  ],
504
491
  maxItems: 2,
505
492
  minItems: 2
@@ -511,7 +498,7 @@ class experimental_ZodToJsonSchemaConverter {
511
498
  return [true, {
512
499
  type: "array",
513
500
  uniqueItems: true,
514
- items: this.#handleArrayItemJsonSchema(this.#convert(set._zod.def.valueType, options2, lazyDepth2, structureDepth + 1), options2)
501
+ items: this.#handleArrayItemJsonSchema(this.#convert(set._zod.def.valueType, options2, lazyDepth2), options2)
515
502
  }];
516
503
  }
517
504
  case "enum": {
@@ -551,12 +538,12 @@ class experimental_ZodToJsonSchemaConverter {
551
538
  }
552
539
  case "nullable": {
553
540
  const nullable = schema2;
554
- const [required, json] = this.#convert(nullable._zod.def.innerType, options2, lazyDepth2, structureDepth);
541
+ const [required, json] = this.#convert(nullable._zod.def.innerType, options2, lazyDepth2);
555
542
  return [required, { anyOf: [json, { type: "null" }] }];
556
543
  }
557
544
  case "nonoptional": {
558
545
  const nonoptional = schema2;
559
- const [, json] = this.#convert(nonoptional._zod.def.innerType, options2, lazyDepth2, structureDepth);
546
+ const [, json] = this.#convert(nonoptional._zod.def.innerType, options2, lazyDepth2);
560
547
  return [true, json];
561
548
  }
562
549
  case "success": {
@@ -565,7 +552,7 @@ class experimental_ZodToJsonSchemaConverter {
565
552
  case "default":
566
553
  case "prefault": {
567
554
  const default_ = schema2;
568
- const [, json] = this.#convert(default_._zod.def.innerType, options2, lazyDepth2, structureDepth);
555
+ const [, json] = this.#convert(default_._zod.def.innerType, options2, lazyDepth2);
569
556
  return [false, {
570
557
  ...json,
571
558
  default: default_._zod.def.defaultValue
@@ -573,18 +560,18 @@ class experimental_ZodToJsonSchemaConverter {
573
560
  }
574
561
  case "catch": {
575
562
  const catch_ = schema2;
576
- return this.#convert(catch_._zod.def.innerType, options2, lazyDepth2, structureDepth);
563
+ return this.#convert(catch_._zod.def.innerType, options2, lazyDepth2);
577
564
  }
578
565
  case "nan": {
579
566
  return [true, options2.strategy === "input" ? this.unsupportedJsonSchema : { type: "null" }];
580
567
  }
581
568
  case "pipe": {
582
569
  const pipe = schema2;
583
- return this.#convert(options2.strategy === "input" ? pipe._zod.def.in : pipe._zod.def.out, options2, lazyDepth2, structureDepth);
570
+ return this.#convert(options2.strategy === "input" ? pipe._zod.def.in : pipe._zod.def.out, options2, lazyDepth2);
584
571
  }
585
572
  case "readonly": {
586
573
  const readonly_ = schema2;
587
- const [required, json] = this.#convert(readonly_._zod.def.innerType, options2, lazyDepth2, structureDepth);
574
+ const [required, json] = this.#convert(readonly_._zod.def.innerType, options2, lazyDepth2);
588
575
  return [required, { ...json, readOnly: true }];
589
576
  }
590
577
  case "template_literal": {
@@ -596,16 +583,15 @@ class experimental_ZodToJsonSchemaConverter {
596
583
  }
597
584
  case "optional": {
598
585
  const optional = schema2;
599
- const [, json] = this.#convert(optional._zod.def.innerType, options2, lazyDepth2, structureDepth);
586
+ const [, json] = this.#convert(optional._zod.def.innerType, options2, lazyDepth2);
600
587
  return [false, json];
601
588
  }
602
589
  case "lazy": {
603
590
  const lazy = schema2;
604
- const currentLazyDepth = lazyDepth2 + 1;
605
- if (currentLazyDepth > this.maxLazyDepth) {
591
+ if (lazyDepth2 >= this.maxLazyDepth) {
606
592
  return [false, this.anyJsonSchema];
607
593
  }
608
- return this.#convert(lazy._zod.def.getter(), options2, currentLazyDepth, structureDepth);
594
+ return this.#convert(lazy._zod.def.getter(), options2, lazyDepth2 + 1);
609
595
  }
610
596
  default: {
611
597
  schema2._zod.def.type;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/zod",
3
3
  "type": "module",
4
- "version": "0.0.0-next.8b6cb3a",
4
+ "version": "0.0.0-next.8be6412",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -30,17 +30,17 @@
30
30
  ],
31
31
  "peerDependencies": {
32
32
  "zod": ">=3.24.2",
33
- "@orpc/contract": "0.0.0-next.8b6cb3a",
34
- "@orpc/server": "0.0.0-next.8b6cb3a"
33
+ "@orpc/server": "0.0.0-next.8be6412",
34
+ "@orpc/contract": "0.0.0-next.8be6412"
35
35
  },
36
36
  "dependencies": {
37
37
  "escape-string-regexp": "^5.0.0",
38
38
  "wildcard-match": "^5.1.3",
39
- "@orpc/openapi": "0.0.0-next.8b6cb3a",
40
- "@orpc/shared": "0.0.0-next.8b6cb3a"
39
+ "@orpc/openapi": "0.0.0-next.8be6412",
40
+ "@orpc/shared": "0.0.0-next.8be6412"
41
41
  },
42
42
  "devDependencies": {
43
- "zod": "^3.25.63",
43
+ "zod": "^3.25.57",
44
44
  "zod-to-json-schema": "^3.24.5"
45
45
  },
46
46
  "scripts": {