@orpc/zod 0.0.0-next.775667a → 0.0.0-next.77e421e

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.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { custom, ZodFirstPartyTypeKind } from 'zod';
1
+ import { custom, ZodFirstPartyTypeKind } from 'zod/v3';
2
2
  import wcmatch from 'wildcard-match';
3
- import { isObject, guard } from '@orpc/shared';
3
+ import { isObject, guard, toArray } from '@orpc/shared';
4
+ import { JsonSchemaXNativeType } from '@orpc/json-schema';
4
5
  import { JSONSchemaFormat } from '@orpc/openapi';
5
6
  import escapeStringRegexp from 'escape-string-regexp';
6
7
 
@@ -128,7 +129,7 @@ class ZodSmartCoercionPlugin {
128
129
  options.clientInterceptors ??= [];
129
130
  options.clientInterceptors.unshift((options2) => {
130
131
  const inputSchema = options2.procedure["~orpc"].inputSchema;
131
- if (!inputSchema || inputSchema["~standard"].vendor !== "zod") {
132
+ if (!inputSchema || inputSchema["~standard"].vendor !== "zod" || "_zod" in inputSchema) {
132
133
  return options2.next();
133
134
  }
134
135
  const coercedInput = zodCoerceInternal(inputSchema, options2.input);
@@ -390,25 +391,39 @@ function safeToDate(value) {
390
391
 
391
392
  class ZodToJsonSchemaConverter {
392
393
  maxLazyDepth;
394
+ maxStructureDepth;
393
395
  unsupportedJsonSchema;
394
396
  anyJsonSchema;
395
397
  constructor(options = {}) {
396
398
  this.maxLazyDepth = options.maxLazyDepth ?? 3;
399
+ this.maxStructureDepth = options.maxStructureDepth ?? 10;
397
400
  this.unsupportedJsonSchema = options.unsupportedJsonSchema ?? { not: {} };
398
401
  this.anyJsonSchema = options.anyJsonSchema ?? {};
399
402
  }
400
403
  condition(schema) {
401
- return schema !== void 0 && schema["~standard"].vendor === "zod";
404
+ return schema !== void 0 && schema["~standard"].vendor === "zod" && !("_zod" in schema);
402
405
  }
403
- convert(schema, options, lazyDepth = 0, isHandledCustomJSONSchema = false, isHandledZodDescription = false) {
406
+ convert(schema, options, lazyDepth = 0, isHandledCustomJSONSchema = false, isHandledZodDescription = false, structureDepth = 0) {
404
407
  const def = schema._def;
408
+ if (structureDepth > this.maxStructureDepth) {
409
+ return [false, this.anyJsonSchema];
410
+ }
411
+ if (!options.minStructureDepthForRef || options.minStructureDepthForRef <= structureDepth) {
412
+ const components = toArray(options.components);
413
+ for (const component of components) {
414
+ if (component.schema === schema && component.allowedStrategies.includes(options.strategy)) {
415
+ return [component.required, { $ref: component.ref }];
416
+ }
417
+ }
418
+ }
405
419
  if (!isHandledZodDescription && "description" in def && typeof def.description === "string") {
406
420
  const [required, json] = this.convert(
407
421
  schema,
408
422
  options,
409
423
  lazyDepth,
410
424
  isHandledCustomJSONSchema,
411
- true
425
+ true,
426
+ structureDepth
412
427
  );
413
428
  return [required, { ...json, description: def.description }];
414
429
  }
@@ -420,7 +435,8 @@ class ZodToJsonSchemaConverter {
420
435
  options,
421
436
  lazyDepth,
422
437
  true,
423
- isHandledZodDescription
438
+ isHandledZodDescription,
439
+ structureDepth
424
440
  );
425
441
  return [required, { ...json, ...customJSONSchema }];
426
442
  }
@@ -548,7 +564,11 @@ class ZodToJsonSchemaConverter {
548
564
  return [true, json];
549
565
  }
550
566
  case ZodFirstPartyTypeKind.ZodBigInt: {
551
- const json = { type: "string", pattern: "^-?[0-9]+$" };
567
+ const json = {
568
+ "type": "string",
569
+ "pattern": "^-?[0-9]+$",
570
+ "x-native-type": JsonSchemaXNativeType.BigInt
571
+ };
552
572
  return [true, json];
553
573
  }
554
574
  case ZodFirstPartyTypeKind.ZodNaN: {
@@ -558,7 +578,11 @@ class ZodToJsonSchemaConverter {
558
578
  return [true, { type: "boolean" }];
559
579
  }
560
580
  case ZodFirstPartyTypeKind.ZodDate: {
561
- const schema2 = { type: "string", format: JSONSchemaFormat.DateTime };
581
+ const schema2 = {
582
+ "type": "string",
583
+ "format": JSONSchemaFormat.DateTime,
584
+ "x-native-type": JsonSchemaXNativeType.Date
585
+ };
562
586
  return [true, schema2];
563
587
  }
564
588
  case ZodFirstPartyTypeKind.ZodNull: {
@@ -581,17 +605,26 @@ class ZodToJsonSchemaConverter {
581
605
  }
582
606
  case ZodFirstPartyTypeKind.ZodEnum: {
583
607
  const schema_ = schema;
584
- return [true, { enum: schema_._def.values }];
608
+ const values = schema_._def.values;
609
+ const json = { enum: values, type: "string" };
610
+ return [true, json];
585
611
  }
586
612
  case ZodFirstPartyTypeKind.ZodNativeEnum: {
587
613
  const schema_ = schema;
588
- return [true, { enum: Object.values(schema_._def.values) }];
614
+ const values = getEnumValues(schema_._def.values);
615
+ const json = { enum: values };
616
+ if (values.every((v) => typeof v === "string")) {
617
+ json.type = "string";
618
+ } else if (values.every((v) => Number.isFinite(v))) {
619
+ json.type = "number";
620
+ }
621
+ return [true, json];
589
622
  }
590
623
  case ZodFirstPartyTypeKind.ZodArray: {
591
624
  const schema_ = schema;
592
625
  const def2 = schema_._def;
593
626
  const json = { type: "array" };
594
- const [itemRequired, itemJson] = this.convert(def2.type, options, lazyDepth, false, false);
627
+ const [itemRequired, itemJson] = this.convert(def2.type, options, lazyDepth, false, false, structureDepth + 1);
595
628
  json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
596
629
  if (def2.exactLength) {
597
630
  json.maxItems = def2.exactLength.value;
@@ -610,7 +643,7 @@ class ZodToJsonSchemaConverter {
610
643
  const prefixItems = [];
611
644
  const json = { type: "array" };
612
645
  for (const item of schema_._def.items) {
613
- const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false);
646
+ const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth + 1);
614
647
  prefixItems.push(
615
648
  this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy)
616
649
  );
@@ -619,7 +652,7 @@ class ZodToJsonSchemaConverter {
619
652
  json.prefixItems = prefixItems;
620
653
  }
621
654
  if (schema_._def.rest) {
622
- const [itemRequired, itemJson] = this.convert(schema_._def.rest, options, lazyDepth, false, false);
655
+ const [itemRequired, itemJson] = this.convert(schema_._def.rest, options, lazyDepth, false, false, structureDepth + 1);
623
656
  json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
624
657
  }
625
658
  return [true, json];
@@ -630,7 +663,7 @@ class ZodToJsonSchemaConverter {
630
663
  const properties = {};
631
664
  const required = [];
632
665
  for (const [key, value] of Object.entries(schema_.shape)) {
633
- const [itemRequired, itemJson] = this.convert(value, options, lazyDepth, false, false);
666
+ const [itemRequired, itemJson] = this.convert(value, options, lazyDepth, false, false, structureDepth + 1);
634
667
  properties[key] = itemJson;
635
668
  if (itemRequired) {
636
669
  required.push(key);
@@ -648,7 +681,7 @@ class ZodToJsonSchemaConverter {
648
681
  json.additionalProperties = false;
649
682
  }
650
683
  } else {
651
- const [_, addJson] = this.convert(schema_._def.catchall, options, lazyDepth, false, false);
684
+ const [_, addJson] = this.convert(schema_._def.catchall, options, lazyDepth, false, false, structureDepth + 1);
652
685
  json.additionalProperties = addJson;
653
686
  }
654
687
  return [true, json];
@@ -656,28 +689,32 @@ class ZodToJsonSchemaConverter {
656
689
  case ZodFirstPartyTypeKind.ZodRecord: {
657
690
  const schema_ = schema;
658
691
  const json = { type: "object" };
659
- const [__, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false);
692
+ const [__, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false, structureDepth + 1);
660
693
  if (Object.entries(keyJson).some(([k, v]) => k !== "type" || v !== "string")) {
661
694
  json.propertyNames = keyJson;
662
695
  }
663
- const [_, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false);
696
+ const [_, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
664
697
  json.additionalProperties = itemJson;
665
698
  return [true, json];
666
699
  }
667
700
  case ZodFirstPartyTypeKind.ZodSet: {
668
701
  const schema_ = schema;
669
- const json = { type: "array", uniqueItems: true };
670
- const [itemRequired, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false);
702
+ const json = {
703
+ "type": "array",
704
+ "uniqueItems": true,
705
+ "x-native-type": JsonSchemaXNativeType.Set
706
+ };
707
+ const [itemRequired, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
671
708
  json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
672
709
  return [true, json];
673
710
  }
674
711
  case ZodFirstPartyTypeKind.ZodMap: {
675
712
  const schema_ = schema;
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);
678
- return [true, {
679
- type: "array",
680
- items: {
713
+ const [keyRequired, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false, structureDepth + 1);
714
+ const [valueRequired, valueJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
715
+ const json = {
716
+ "type": "array",
717
+ "items": {
681
718
  type: "array",
682
719
  prefixItems: [
683
720
  this.#toArrayItemJsonSchema(keyRequired, keyJson, options.strategy),
@@ -685,8 +722,10 @@ class ZodToJsonSchemaConverter {
685
722
  ],
686
723
  maxItems: 2,
687
724
  minItems: 2
688
- }
689
- }];
725
+ },
726
+ "x-native-type": JsonSchemaXNativeType.Map
727
+ };
728
+ return [true, json];
690
729
  }
691
730
  case ZodFirstPartyTypeKind.ZodUnion:
692
731
  case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
@@ -694,7 +733,7 @@ class ZodToJsonSchemaConverter {
694
733
  const anyOf = [];
695
734
  let required = true;
696
735
  for (const item of schema_._def.options) {
697
- const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false);
736
+ const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth + 1);
698
737
  if (!itemRequired) {
699
738
  required = false;
700
739
  if (itemJson !== this.unsupportedJsonSchema) {
@@ -704,9 +743,6 @@ class ZodToJsonSchemaConverter {
704
743
  anyOf.push(itemJson);
705
744
  }
706
745
  }
707
- if (anyOf.length === 1) {
708
- return [required, anyOf[0]];
709
- }
710
746
  return [required, { anyOf }];
711
747
  }
712
748
  case ZodFirstPartyTypeKind.ZodIntersection: {
@@ -714,7 +750,7 @@ class ZodToJsonSchemaConverter {
714
750
  const allOf = [];
715
751
  let required = false;
716
752
  for (const item of [schema_._def.left, schema_._def.right]) {
717
- const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false);
753
+ const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth + 1);
718
754
  allOf.push(itemJson);
719
755
  if (itemRequired) {
720
756
  required = true;
@@ -723,25 +759,26 @@ class ZodToJsonSchemaConverter {
723
759
  return [required, { allOf }];
724
760
  }
725
761
  case ZodFirstPartyTypeKind.ZodLazy: {
726
- if (lazyDepth >= this.maxLazyDepth) {
762
+ const currentLazyDepth = lazyDepth + 1;
763
+ if (currentLazyDepth > this.maxLazyDepth) {
727
764
  return [false, this.anyJsonSchema];
728
765
  }
729
766
  const schema_ = schema;
730
- return this.convert(schema_._def.getter(), options, lazyDepth + 1, false, false);
767
+ return this.convert(schema_._def.getter(), options, currentLazyDepth, false, false, structureDepth);
731
768
  }
732
769
  case ZodFirstPartyTypeKind.ZodOptional: {
733
770
  const schema_ = schema;
734
- const [_, inner] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
771
+ const [_, inner] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
735
772
  return [false, inner];
736
773
  }
737
774
  case ZodFirstPartyTypeKind.ZodReadonly: {
738
775
  const schema_ = schema;
739
- const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
776
+ const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
740
777
  return [required, { ...json, readOnly: true }];
741
778
  }
742
779
  case ZodFirstPartyTypeKind.ZodDefault: {
743
780
  const schema_ = schema;
744
- const [_, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
781
+ const [_, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
745
782
  return [false, { default: schema_._def.defaultValue(), ...json }];
746
783
  }
747
784
  case ZodFirstPartyTypeKind.ZodEffects: {
@@ -749,15 +786,15 @@ class ZodToJsonSchemaConverter {
749
786
  if (schema_._def.effect.type === "transform" && options.strategy === "output") {
750
787
  return [false, this.anyJsonSchema];
751
788
  }
752
- return this.convert(schema_._def.schema, options, lazyDepth, false, false);
789
+ return this.convert(schema_._def.schema, options, lazyDepth, false, false, structureDepth);
753
790
  }
754
791
  case ZodFirstPartyTypeKind.ZodCatch: {
755
792
  const schema_ = schema;
756
- return this.convert(schema_._def.innerType, options, lazyDepth, false, false);
793
+ return this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
757
794
  }
758
795
  case ZodFirstPartyTypeKind.ZodBranded: {
759
796
  const schema_ = schema;
760
- return this.convert(schema_._def.type, options, lazyDepth, false, false);
797
+ return this.convert(schema_._def.type, options, lazyDepth, false, false, structureDepth);
761
798
  }
762
799
  case ZodFirstPartyTypeKind.ZodPipeline: {
763
800
  const schema_ = schema;
@@ -766,13 +803,14 @@ class ZodToJsonSchemaConverter {
766
803
  options,
767
804
  lazyDepth,
768
805
  false,
769
- false
806
+ false,
807
+ structureDepth
770
808
  );
771
809
  }
772
810
  case ZodFirstPartyTypeKind.ZodNullable: {
773
811
  const schema_ = schema;
774
- const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false);
775
- return [required, { anyOf: [{ type: "null" }, json] }];
812
+ const [required, json] = this.convert(schema_._def.innerType, options, lazyDepth, false, false, structureDepth);
813
+ return [required, { anyOf: [json, { type: "null" }] }];
776
814
  }
777
815
  }
778
816
  return [true, this.unsupportedJsonSchema];
@@ -791,12 +829,17 @@ class ZodToJsonSchemaConverter {
791
829
  }
792
830
  case "regexp": {
793
831
  return {
794
- type: "string",
795
- pattern: "^\\/(.*)\\/([a-z]*)$"
832
+ "type": "string",
833
+ "pattern": "^\\/(.*)\\/([a-z]*)$",
834
+ "x-native-type": JsonSchemaXNativeType.RegExp
796
835
  };
797
836
  }
798
837
  case "url": {
799
- return { type: "string", format: JSONSchemaFormat.URI };
838
+ return {
839
+ "type": "string",
840
+ "format": JSONSchemaFormat.URI,
841
+ "x-native-type": JsonSchemaXNativeType.Url
842
+ };
800
843
  }
801
844
  }
802
845
  }
@@ -810,6 +853,11 @@ class ZodToJsonSchemaConverter {
810
853
  return strategy === "input" ? { anyOf: [schema, this.unsupportedJsonSchema] } : { anyOf: [schema, { type: "null" }] };
811
854
  }
812
855
  }
856
+ function getEnumValues(entries) {
857
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
858
+ const values = Object.entries(entries).filter(([k, _]) => !numericValues.includes(+k)).map(([_, v]) => v);
859
+ return values;
860
+ }
813
861
 
814
862
  const oz = {
815
863
  file,
@@ -2,24 +2,35 @@ import { Context } from '@orpc/server';
2
2
  import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
3
3
  import { AnySchema } from '@orpc/contract';
4
4
  import { JSONSchema, SchemaConvertOptions, ConditionalSchemaConverter } from '@orpc/openapi';
5
- import { Interceptor, ThrowableError, Promisable } from '@orpc/shared';
6
- import * as _zod_core from '@zod/core';
7
- import { $ZodType, $input, $output } from '@zod/core';
5
+ import { Interceptor } from '@orpc/shared';
6
+ import * as zod_v4_core from 'zod/v4/core';
7
+ import { $ZodType, $input, $output } from 'zod/v4/core';
8
8
 
9
+ /**
10
+ * @deprecated Use [Smart Coercion Plugin](https://orpc.dev/docs/openapi/plugins/smart-coercion) instead.
11
+ */
9
12
  declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
10
13
  #private;
11
14
  init(options: StandardHandlerOptions<TContext>): void;
12
15
  }
13
16
 
14
- interface experimental_ZodToJsonSchemaOptions {
17
+ interface ZodToJsonSchemaConverterOptions {
15
18
  /**
16
- * Max depth of lazy type, if it exceeds.
19
+ * Max depth of lazy type.
17
20
  *
18
- * Used anyJsonSchema (`{}`) when reach max depth
21
+ * Used anyJsonSchema (`{}`) when exceed max depth
19
22
  *
20
23
  * @default 2
21
24
  */
22
25
  maxLazyDepth?: number;
26
+ /**
27
+ * Max depth of nested types.
28
+ *
29
+ * Used anyJsonSchema (`{}`) when exceed max depth
30
+ *
31
+ * @default 10
32
+ */
33
+ maxStructureDepth?: number;
23
34
  /**
24
35
  * The schema to be used to represent the any | unknown type.
25
36
  *
@@ -46,18 +57,19 @@ interface experimental_ZodToJsonSchemaOptions {
46
57
  }, [
47
58
  required: boolean,
48
59
  jsonSchema: Exclude<JSONSchema, boolean>
49
- ], ThrowableError>[];
60
+ ]>[];
50
61
  }
51
- declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
62
+ declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
52
63
  #private;
53
64
  private readonly maxLazyDepth;
65
+ private readonly maxStructureDepth;
54
66
  private readonly anyJsonSchema;
55
67
  private readonly unsupportedJsonSchema;
56
68
  private readonly undefinedJsonSchema;
57
69
  private readonly interceptors;
58
- constructor(options?: experimental_ZodToJsonSchemaOptions);
70
+ constructor(options?: ZodToJsonSchemaConverterOptions);
59
71
  condition(schema: AnySchema | undefined): boolean;
60
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: Exclude<JSONSchema, boolean>]>;
72
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
61
73
  }
62
74
 
63
75
  /**
@@ -77,7 +89,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
77
89
  * })
78
90
  * ```
79
91
  */
80
- declare const experimental_JSON_SCHEMA_REGISTRY: _zod_core.$ZodRegistry<{
92
+ declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
81
93
  $anchor?: string;
82
94
  $comment?: string;
83
95
  $defs?: Record<string, JSONSchema>;
@@ -138,7 +150,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: _zod_core.$ZodRegistry<{
138
150
  unevaluatedProperties?: JSONSchema;
139
151
  uniqueItems?: boolean;
140
152
  writeOnly?: boolean;
141
- }, _zod_core.$ZodType<unknown, unknown>>;
153
+ }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
142
154
  /**
143
155
  * Zod registry for customizing generated JSON schema, only useful for .input
144
156
  *
@@ -156,7 +168,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: _zod_core.$ZodRegistry<{
156
168
  * })
157
169
  * ```
158
170
  */
159
- declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: _zod_core.$ZodRegistry<{
171
+ declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
160
172
  $anchor?: string;
161
173
  $comment?: string;
162
174
  $defs?: Record<string, JSONSchema>;
@@ -217,7 +229,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: _zod_core.$ZodRegistry<{
217
229
  unevaluatedProperties?: JSONSchema;
218
230
  uniqueItems?: boolean;
219
231
  writeOnly?: boolean;
220
- }, _zod_core.$ZodType<unknown, unknown>>;
232
+ }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
221
233
  /**
222
234
  * Zod registry for customizing generated JSON schema, only useful for .input
223
235
  *
@@ -235,7 +247,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: _zod_core.$ZodRegistry<{
235
247
  * })
236
248
  * ```
237
249
  */
238
- declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: _zod_core.$ZodRegistry<{
250
+ declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
239
251
  $anchor?: string;
240
252
  $comment?: string;
241
253
  $defs?: Record<string, JSONSchema>;
@@ -296,7 +308,7 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: _zod_core.$ZodRegistry<{
296
308
  unevaluatedProperties?: JSONSchema;
297
309
  uniqueItems?: boolean;
298
310
  writeOnly?: boolean;
299
- }, _zod_core.$ZodType<unknown, unknown>>;
311
+ }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
300
312
 
301
- export { experimental_JSON_SCHEMA_INPUT_REGISTRY, experimental_JSON_SCHEMA_OUTPUT_REGISTRY, experimental_JSON_SCHEMA_REGISTRY, experimental_ZodSmartCoercionPlugin, experimental_ZodToJsonSchemaConverter };
302
- export type { experimental_ZodToJsonSchemaOptions };
313
+ export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter, experimental_ZodSmartCoercionPlugin };
314
+ export type { ZodToJsonSchemaConverterOptions };
@@ -2,24 +2,35 @@ import { Context } from '@orpc/server';
2
2
  import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
3
3
  import { AnySchema } from '@orpc/contract';
4
4
  import { JSONSchema, SchemaConvertOptions, ConditionalSchemaConverter } from '@orpc/openapi';
5
- import { Interceptor, ThrowableError, Promisable } from '@orpc/shared';
6
- import * as _zod_core from '@zod/core';
7
- import { $ZodType, $input, $output } from '@zod/core';
5
+ import { Interceptor } from '@orpc/shared';
6
+ import * as zod_v4_core from 'zod/v4/core';
7
+ import { $ZodType, $input, $output } from 'zod/v4/core';
8
8
 
9
+ /**
10
+ * @deprecated Use [Smart Coercion Plugin](https://orpc.dev/docs/openapi/plugins/smart-coercion) instead.
11
+ */
9
12
  declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
10
13
  #private;
11
14
  init(options: StandardHandlerOptions<TContext>): void;
12
15
  }
13
16
 
14
- interface experimental_ZodToJsonSchemaOptions {
17
+ interface ZodToJsonSchemaConverterOptions {
15
18
  /**
16
- * Max depth of lazy type, if it exceeds.
19
+ * Max depth of lazy type.
17
20
  *
18
- * Used anyJsonSchema (`{}`) when reach max depth
21
+ * Used anyJsonSchema (`{}`) when exceed max depth
19
22
  *
20
23
  * @default 2
21
24
  */
22
25
  maxLazyDepth?: number;
26
+ /**
27
+ * Max depth of nested types.
28
+ *
29
+ * Used anyJsonSchema (`{}`) when exceed max depth
30
+ *
31
+ * @default 10
32
+ */
33
+ maxStructureDepth?: number;
23
34
  /**
24
35
  * The schema to be used to represent the any | unknown type.
25
36
  *
@@ -46,18 +57,19 @@ interface experimental_ZodToJsonSchemaOptions {
46
57
  }, [
47
58
  required: boolean,
48
59
  jsonSchema: Exclude<JSONSchema, boolean>
49
- ], ThrowableError>[];
60
+ ]>[];
50
61
  }
51
- declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
62
+ declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
52
63
  #private;
53
64
  private readonly maxLazyDepth;
65
+ private readonly maxStructureDepth;
54
66
  private readonly anyJsonSchema;
55
67
  private readonly unsupportedJsonSchema;
56
68
  private readonly undefinedJsonSchema;
57
69
  private readonly interceptors;
58
- constructor(options?: experimental_ZodToJsonSchemaOptions);
70
+ constructor(options?: ZodToJsonSchemaConverterOptions);
59
71
  condition(schema: AnySchema | undefined): boolean;
60
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: Exclude<JSONSchema, boolean>]>;
72
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
61
73
  }
62
74
 
63
75
  /**
@@ -77,7 +89,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
77
89
  * })
78
90
  * ```
79
91
  */
80
- declare const experimental_JSON_SCHEMA_REGISTRY: _zod_core.$ZodRegistry<{
92
+ declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
81
93
  $anchor?: string;
82
94
  $comment?: string;
83
95
  $defs?: Record<string, JSONSchema>;
@@ -138,7 +150,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: _zod_core.$ZodRegistry<{
138
150
  unevaluatedProperties?: JSONSchema;
139
151
  uniqueItems?: boolean;
140
152
  writeOnly?: boolean;
141
- }, _zod_core.$ZodType<unknown, unknown>>;
153
+ }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
142
154
  /**
143
155
  * Zod registry for customizing generated JSON schema, only useful for .input
144
156
  *
@@ -156,7 +168,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: _zod_core.$ZodRegistry<{
156
168
  * })
157
169
  * ```
158
170
  */
159
- declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: _zod_core.$ZodRegistry<{
171
+ declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
160
172
  $anchor?: string;
161
173
  $comment?: string;
162
174
  $defs?: Record<string, JSONSchema>;
@@ -217,7 +229,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: _zod_core.$ZodRegistry<{
217
229
  unevaluatedProperties?: JSONSchema;
218
230
  uniqueItems?: boolean;
219
231
  writeOnly?: boolean;
220
- }, _zod_core.$ZodType<unknown, unknown>>;
232
+ }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
221
233
  /**
222
234
  * Zod registry for customizing generated JSON schema, only useful for .input
223
235
  *
@@ -235,7 +247,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: _zod_core.$ZodRegistry<{
235
247
  * })
236
248
  * ```
237
249
  */
238
- declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: _zod_core.$ZodRegistry<{
250
+ declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
239
251
  $anchor?: string;
240
252
  $comment?: string;
241
253
  $defs?: Record<string, JSONSchema>;
@@ -296,7 +308,7 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: _zod_core.$ZodRegistry<{
296
308
  unevaluatedProperties?: JSONSchema;
297
309
  uniqueItems?: boolean;
298
310
  writeOnly?: boolean;
299
- }, _zod_core.$ZodType<unknown, unknown>>;
311
+ }, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
300
312
 
301
- export { experimental_JSON_SCHEMA_INPUT_REGISTRY, experimental_JSON_SCHEMA_OUTPUT_REGISTRY, experimental_JSON_SCHEMA_REGISTRY, experimental_ZodSmartCoercionPlugin, experimental_ZodToJsonSchemaConverter };
302
- export type { experimental_ZodToJsonSchemaOptions };
313
+ export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter, experimental_ZodSmartCoercionPlugin };
314
+ export type { ZodToJsonSchemaConverterOptions };