@orpc/zod 0.0.0-next.4534675 → 0.0.0-next.460b50b

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
@@ -21,28 +21,24 @@
21
21
 
22
22
  <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
23
 
24
- **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
25
25
 
26
26
  ---
27
27
 
28
28
  ## Highlights
29
29
 
30
- - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
- - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
- - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
- - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
- - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
- - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
36
- - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
- - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
- - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
- - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
- - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
- - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
- - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
- - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
- - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
- - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
30
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
34
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
35
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
36
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
37
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
38
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
39
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
40
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
41
+ - **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
46
42
 
47
43
  ## Documentation
48
44
 
@@ -53,11 +49,15 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
49
  - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
50
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
51
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
- - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
- - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
- - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
52
  - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
53
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
54
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
55
+ - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
56
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
57
+ - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
60
58
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
59
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
60
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
61
61
 
62
62
  ## `@orpc/zod`
63
63
 
@@ -127,6 +127,14 @@ const InputSchema = oz.openapi(
127
127
  )
128
128
  ```
129
129
 
130
+ ## Sponsors
131
+
132
+ <p align="center">
133
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
134
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
135
+ </a>
136
+ </p>
137
+
130
138
  ## License
131
139
 
132
140
  Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
package/dist/index.d.mts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
2
2
  import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
3
3
  import { Context } from '@orpc/server';
4
- import { Plugin } from '@orpc/server/plugins';
5
- import { StandardHandlerOptions } from '@orpc/server/standard';
6
- import { Schema } from '@orpc/contract';
4
+ import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
5
+ import { AnySchema } from '@orpc/contract';
7
6
 
8
7
  declare function getCustomJsonSchema(def: ZodTypeDef, options: {
9
8
  strategy: 'input' | 'output' | 'both';
@@ -35,40 +34,49 @@ declare function regexp(params?: string | CustomParams | ((input: unknown) => Cu
35
34
 
36
35
  declare function url(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<URL, ZodTypeDef, URL>;
37
36
 
38
- declare class ZodSmartCoercionPlugin<TContext extends Context> implements Plugin<TContext> {
37
+ declare class ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
39
38
  init(options: StandardHandlerOptions<TContext>): void;
40
39
  }
41
40
 
42
41
  interface ZodToJsonSchemaOptions {
43
42
  /**
44
- * Max depth of lazy type, if it exceeds.
43
+ * Max depth of lazy type
45
44
  *
46
- * Used `{}` when reach max depth
45
+ * Used `{}` when exceed max depth
47
46
  *
48
47
  * @default 3
49
48
  */
50
49
  maxLazyDepth?: number;
51
50
  /**
52
- * The schema to be used when the Zod schema is unsupported.
51
+ * Max depth of nested types
53
52
  *
54
- * @default { not: {} }
53
+ * Used anyJsonSchema (`{}`) when exceed max depth
54
+ *
55
+ * @default 10
55
56
  */
56
- unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
57
+ maxStructureDepth?: number;
57
58
  /**
58
59
  * The schema to be used to represent the any | unknown type.
59
60
  *
60
61
  * @default { }
61
62
  */
62
63
  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>;
63
70
  }
64
71
  declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
65
72
  #private;
66
73
  private readonly maxLazyDepth;
74
+ private readonly maxStructureDepth;
67
75
  private readonly unsupportedJsonSchema;
68
76
  private readonly anyJsonSchema;
69
77
  constructor(options?: ZodToJsonSchemaOptions);
70
- condition(schema: Schema): boolean;
71
- convert(schema: Schema, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
78
+ 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>];
72
80
  }
73
81
 
74
82
  declare const oz: {
@@ -79,4 +87,5 @@ declare const oz: {
79
87
  openapi: typeof customJsonSchema;
80
88
  };
81
89
 
82
- export { type CustomParams, type CustomZodDef, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
90
+ export { ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
91
+ export type { CustomParams, CustomZodDef, ZodToJsonSchemaOptions };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
2
2
  import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
3
3
  import { Context } from '@orpc/server';
4
- import { Plugin } from '@orpc/server/plugins';
5
- import { StandardHandlerOptions } from '@orpc/server/standard';
6
- import { Schema } from '@orpc/contract';
4
+ import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
5
+ import { AnySchema } from '@orpc/contract';
7
6
 
8
7
  declare function getCustomJsonSchema(def: ZodTypeDef, options: {
9
8
  strategy: 'input' | 'output' | 'both';
@@ -35,40 +34,49 @@ declare function regexp(params?: string | CustomParams | ((input: unknown) => Cu
35
34
 
36
35
  declare function url(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<URL, ZodTypeDef, URL>;
37
36
 
38
- declare class ZodSmartCoercionPlugin<TContext extends Context> implements Plugin<TContext> {
37
+ declare class ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
39
38
  init(options: StandardHandlerOptions<TContext>): void;
40
39
  }
41
40
 
42
41
  interface ZodToJsonSchemaOptions {
43
42
  /**
44
- * Max depth of lazy type, if it exceeds.
43
+ * Max depth of lazy type
45
44
  *
46
- * Used `{}` when reach max depth
45
+ * Used `{}` when exceed max depth
47
46
  *
48
47
  * @default 3
49
48
  */
50
49
  maxLazyDepth?: number;
51
50
  /**
52
- * The schema to be used when the Zod schema is unsupported.
51
+ * Max depth of nested types
53
52
  *
54
- * @default { not: {} }
53
+ * Used anyJsonSchema (`{}`) when exceed max depth
54
+ *
55
+ * @default 10
55
56
  */
56
- unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
57
+ maxStructureDepth?: number;
57
58
  /**
58
59
  * The schema to be used to represent the any | unknown type.
59
60
  *
60
61
  * @default { }
61
62
  */
62
63
  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>;
63
70
  }
64
71
  declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
65
72
  #private;
66
73
  private readonly maxLazyDepth;
74
+ private readonly maxStructureDepth;
67
75
  private readonly unsupportedJsonSchema;
68
76
  private readonly anyJsonSchema;
69
77
  constructor(options?: ZodToJsonSchemaOptions);
70
- condition(schema: Schema): boolean;
71
- convert(schema: Schema, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
78
+ 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>];
72
80
  }
73
81
 
74
82
  declare const oz: {
@@ -79,4 +87,5 @@ declare const oz: {
79
87
  openapi: typeof customJsonSchema;
80
88
  };
81
89
 
82
- export { type CustomParams, type CustomZodDef, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
90
+ export { ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
91
+ export type { CustomParams, CustomZodDef, ZodToJsonSchemaOptions };
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 } from '@orpc/shared';
3
+ import { isObject, guard, toArray } from '@orpc/shared';
4
4
  import { JSONSchemaFormat } from '@orpc/openapi';
5
5
  import escapeStringRegexp from 'escape-string-regexp';
6
6
 
@@ -390,25 +390,39 @@ function safeToDate(value) {
390
390
 
391
391
  class ZodToJsonSchemaConverter {
392
392
  maxLazyDepth;
393
+ maxStructureDepth;
393
394
  unsupportedJsonSchema;
394
395
  anyJsonSchema;
395
396
  constructor(options = {}) {
396
397
  this.maxLazyDepth = options.maxLazyDepth ?? 3;
398
+ this.maxStructureDepth = options.maxStructureDepth ?? 10;
397
399
  this.unsupportedJsonSchema = options.unsupportedJsonSchema ?? { not: {} };
398
400
  this.anyJsonSchema = options.anyJsonSchema ?? {};
399
401
  }
400
402
  condition(schema) {
401
- return Boolean(schema && schema["~standard"].vendor === "zod");
403
+ return schema !== void 0 && schema["~standard"].vendor === "zod";
402
404
  }
403
- convert(schema, options, lazyDepth = 0, isHandledCustomJSONSchema = false, isHandledZodDescription = false) {
405
+ convert(schema, options, lazyDepth = 0, isHandledCustomJSONSchema = false, isHandledZodDescription = false, structureDepth = 0) {
404
406
  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
+ }
405
418
  if (!isHandledZodDescription && "description" in def && typeof def.description === "string") {
406
419
  const [required, json] = this.convert(
407
420
  schema,
408
421
  options,
409
422
  lazyDepth,
410
423
  isHandledCustomJSONSchema,
411
- true
424
+ true,
425
+ structureDepth
412
426
  );
413
427
  return [required, { ...json, description: def.description }];
414
428
  }
@@ -420,7 +434,8 @@ class ZodToJsonSchemaConverter {
420
434
  options,
421
435
  lazyDepth,
422
436
  true,
423
- isHandledZodDescription
437
+ isHandledZodDescription,
438
+ structureDepth
424
439
  );
425
440
  return [required, { ...json, ...customJSONSchema }];
426
441
  }
@@ -591,7 +606,7 @@ class ZodToJsonSchemaConverter {
591
606
  const schema_ = schema;
592
607
  const def2 = schema_._def;
593
608
  const json = { type: "array" };
594
- const [itemRequired, itemJson] = this.convert(def2.type, options, lazyDepth, false, false);
609
+ const [itemRequired, itemJson] = this.convert(def2.type, options, lazyDepth, false, false, structureDepth + 1);
595
610
  json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
596
611
  if (def2.exactLength) {
597
612
  json.maxItems = def2.exactLength.value;
@@ -610,7 +625,7 @@ class ZodToJsonSchemaConverter {
610
625
  const prefixItems = [];
611
626
  const json = { type: "array" };
612
627
  for (const item of schema_._def.items) {
613
- const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false);
628
+ const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth + 1);
614
629
  prefixItems.push(
615
630
  this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy)
616
631
  );
@@ -619,7 +634,7 @@ class ZodToJsonSchemaConverter {
619
634
  json.prefixItems = prefixItems;
620
635
  }
621
636
  if (schema_._def.rest) {
622
- const [itemRequired, itemJson] = this.convert(schema_._def.rest, options, lazyDepth, false, false);
637
+ const [itemRequired, itemJson] = this.convert(schema_._def.rest, options, lazyDepth, false, false, structureDepth + 1);
623
638
  json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
624
639
  }
625
640
  return [true, json];
@@ -630,7 +645,7 @@ class ZodToJsonSchemaConverter {
630
645
  const properties = {};
631
646
  const required = [];
632
647
  for (const [key, value] of Object.entries(schema_.shape)) {
633
- const [itemRequired, itemJson] = this.convert(value, options, lazyDepth, false, false);
648
+ const [itemRequired, itemJson] = this.convert(value, options, lazyDepth, false, false, structureDepth + 1);
634
649
  properties[key] = itemJson;
635
650
  if (itemRequired) {
636
651
  required.push(key);
@@ -648,7 +663,7 @@ class ZodToJsonSchemaConverter {
648
663
  json.additionalProperties = false;
649
664
  }
650
665
  } else {
651
- const [_, addJson] = this.convert(schema_._def.catchall, options, lazyDepth, false, false);
666
+ const [_, addJson] = this.convert(schema_._def.catchall, options, lazyDepth, false, false, structureDepth + 1);
652
667
  json.additionalProperties = addJson;
653
668
  }
654
669
  return [true, json];
@@ -656,21 +671,25 @@ class ZodToJsonSchemaConverter {
656
671
  case ZodFirstPartyTypeKind.ZodRecord: {
657
672
  const schema_ = schema;
658
673
  const json = { type: "object" };
659
- const [_, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false);
674
+ const [__, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false, structureDepth + 1);
675
+ if (Object.entries(keyJson).some(([k, v]) => k !== "type" || v !== "string")) {
676
+ json.propertyNames = keyJson;
677
+ }
678
+ const [_, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
660
679
  json.additionalProperties = itemJson;
661
680
  return [true, json];
662
681
  }
663
682
  case ZodFirstPartyTypeKind.ZodSet: {
664
683
  const schema_ = schema;
665
684
  const json = { type: "array", uniqueItems: true };
666
- const [itemRequired, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false);
685
+ const [itemRequired, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
667
686
  json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
668
687
  return [true, json];
669
688
  }
670
689
  case ZodFirstPartyTypeKind.ZodMap: {
671
690
  const schema_ = schema;
672
- const [keyRequired, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false);
673
- const [valueRequired, valueJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false);
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);
674
693
  return [true, {
675
694
  type: "array",
676
695
  items: {
@@ -690,7 +709,7 @@ class ZodToJsonSchemaConverter {
690
709
  const anyOf = [];
691
710
  let required = true;
692
711
  for (const item of schema_._def.options) {
693
- const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false);
712
+ const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth);
694
713
  if (!itemRequired) {
695
714
  required = false;
696
715
  if (itemJson !== this.unsupportedJsonSchema) {
@@ -710,7 +729,7 @@ class ZodToJsonSchemaConverter {
710
729
  const allOf = [];
711
730
  let required = false;
712
731
  for (const item of [schema_._def.left, schema_._def.right]) {
713
- const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false);
732
+ const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth);
714
733
  allOf.push(itemJson);
715
734
  if (itemRequired) {
716
735
  required = true;
@@ -719,24 +738,26 @@ class ZodToJsonSchemaConverter {
719
738
  return [required, { allOf }];
720
739
  }
721
740
  case ZodFirstPartyTypeKind.ZodLazy: {
722
- if (lazyDepth >= this.maxLazyDepth) {
741
+ const currentLazyDepth = lazyDepth + 1;
742
+ if (currentLazyDepth > this.maxLazyDepth) {
723
743
  return [false, this.anyJsonSchema];
724
744
  }
725
745
  const schema_ = schema;
726
- return this.convert(schema_._def.getter(), options, lazyDepth + 1, false, false);
746
+ return this.convert(schema_._def.getter(), options, currentLazyDepth, false, false, structureDepth);
727
747
  }
728
748
  case ZodFirstPartyTypeKind.ZodOptional: {
729
749
  const schema_ = schema;
730
- const [_, inner] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
750
+ const [_, inner] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
731
751
  return [false, inner];
732
752
  }
733
753
  case ZodFirstPartyTypeKind.ZodReadonly: {
734
754
  const schema_ = schema;
735
- return this.convert(schema_._def.innerType, options, lazyDepth, false, false);
755
+ const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
756
+ return [required, { ...json, readOnly: true }];
736
757
  }
737
758
  case ZodFirstPartyTypeKind.ZodDefault: {
738
759
  const schema_ = schema;
739
- const [_, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
760
+ const [_, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
740
761
  return [false, { default: schema_._def.defaultValue(), ...json }];
741
762
  }
742
763
  case ZodFirstPartyTypeKind.ZodEffects: {
@@ -744,15 +765,15 @@ class ZodToJsonSchemaConverter {
744
765
  if (schema_._def.effect.type === "transform" && options.strategy === "output") {
745
766
  return [false, this.anyJsonSchema];
746
767
  }
747
- return this.convert(schema_._def.schema, options, lazyDepth, false, false);
768
+ return this.convert(schema_._def.schema, options, lazyDepth, false, false, structureDepth);
748
769
  }
749
770
  case ZodFirstPartyTypeKind.ZodCatch: {
750
771
  const schema_ = schema;
751
- return this.convert(schema_._def.innerType, options, lazyDepth, false, false);
772
+ return this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
752
773
  }
753
774
  case ZodFirstPartyTypeKind.ZodBranded: {
754
775
  const schema_ = schema;
755
- return this.convert(schema_._def.type, options, lazyDepth, false, false);
776
+ return this.convert(schema_._def.type, options, lazyDepth, false, false, structureDepth);
756
777
  }
757
778
  case ZodFirstPartyTypeKind.ZodPipeline: {
758
779
  const schema_ = schema;
@@ -761,12 +782,13 @@ class ZodToJsonSchemaConverter {
761
782
  options,
762
783
  lazyDepth,
763
784
  false,
764
- false
785
+ false,
786
+ structureDepth
765
787
  );
766
788
  }
767
789
  case ZodFirstPartyTypeKind.ZodNullable: {
768
790
  const schema_ = schema;
769
- const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
791
+ const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
770
792
  return [required, { anyOf: [{ type: "null" }, json] }];
771
793
  }
772
794
  }