@orpc/zod 0.0.0-next.6b26cdc → 0.0.0-next.6bc474e
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 +146 -36
- package/dist/index.d.mts +18 -8
- package/dist/index.d.ts +18 -8
- package/dist/index.mjs +94 -46
- package/dist/zod4/index.d.mts +314 -0
- package/dist/zod4/index.d.ts +314 -0
- package/dist/zod4/index.mjs +698 -0
- package/package.json +16 -11
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 = {
|
|
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 = {
|
|
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
|
-
|
|
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
|
-
|
|
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 = {
|
|
670
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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" }
|
|
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 {
|
|
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,
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { Context } from '@orpc/server';
|
|
2
|
+
import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
3
|
+
import { AnySchema } from '@orpc/contract';
|
|
4
|
+
import { JSONSchema, SchemaConvertOptions, ConditionalSchemaConverter } from '@orpc/openapi';
|
|
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
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use [Smart Coercion Plugin](https://orpc.dev/docs/openapi/plugins/smart-coercion) instead.
|
|
11
|
+
*/
|
|
12
|
+
declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
|
|
13
|
+
#private;
|
|
14
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface ZodToJsonSchemaConverterOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Max depth of lazy type.
|
|
20
|
+
*
|
|
21
|
+
* Used anyJsonSchema (`{}`) when exceed max depth
|
|
22
|
+
*
|
|
23
|
+
* @default 2
|
|
24
|
+
*/
|
|
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;
|
|
34
|
+
/**
|
|
35
|
+
* The schema to be used to represent the any | unknown type.
|
|
36
|
+
*
|
|
37
|
+
* @default { }
|
|
38
|
+
*/
|
|
39
|
+
anyJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* The schema to be used when the Zod schema is unsupported.
|
|
42
|
+
*
|
|
43
|
+
* @default { not: {} }
|
|
44
|
+
*/
|
|
45
|
+
unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* The schema to be used to represent the undefined type.
|
|
48
|
+
*
|
|
49
|
+
* @default { not: {} }
|
|
50
|
+
*/
|
|
51
|
+
undefinedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
52
|
+
interceptors?: Interceptor<{
|
|
53
|
+
schema: $ZodType;
|
|
54
|
+
options: SchemaConvertOptions;
|
|
55
|
+
lazyDepth: number;
|
|
56
|
+
isHandledCustomJSONSchema: boolean;
|
|
57
|
+
}, [
|
|
58
|
+
required: boolean,
|
|
59
|
+
jsonSchema: Exclude<JSONSchema, boolean>
|
|
60
|
+
]>[];
|
|
61
|
+
}
|
|
62
|
+
declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
|
63
|
+
#private;
|
|
64
|
+
private readonly maxLazyDepth;
|
|
65
|
+
private readonly maxStructureDepth;
|
|
66
|
+
private readonly anyJsonSchema;
|
|
67
|
+
private readonly unsupportedJsonSchema;
|
|
68
|
+
private readonly undefinedJsonSchema;
|
|
69
|
+
private readonly interceptors;
|
|
70
|
+
constructor(options?: ZodToJsonSchemaConverterOptions);
|
|
71
|
+
condition(schema: AnySchema | undefined): boolean;
|
|
72
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Zod registry for customizing generated JSON schema, can use both for .input and .output
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { JSON_SCHEMA_REGISTRY } from '@orpc/zod/zod4'
|
|
81
|
+
*
|
|
82
|
+
* const user = z.object({
|
|
83
|
+
* name: z.string(),
|
|
84
|
+
* age: z.number(),
|
|
85
|
+
* })
|
|
86
|
+
*
|
|
87
|
+
* JSON_SCHEMA_REGISTRY.add(user, {
|
|
88
|
+
* examples: [{ name: 'John', age: 20 }],
|
|
89
|
+
* })
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
93
|
+
$anchor?: string;
|
|
94
|
+
$comment?: string;
|
|
95
|
+
$defs?: Record<string, JSONSchema>;
|
|
96
|
+
$dynamicAnchor?: string;
|
|
97
|
+
$dynamicRef?: string;
|
|
98
|
+
$id?: string;
|
|
99
|
+
$ref?: string;
|
|
100
|
+
$schema?: string;
|
|
101
|
+
$vocabulary?: Record<string, string>;
|
|
102
|
+
additionalItems?: JSONSchema;
|
|
103
|
+
additionalProperties?: JSONSchema;
|
|
104
|
+
allOf?: (JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue>[] | readonly JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue>[]) | undefined;
|
|
105
|
+
anyOf?: (JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue>[] | readonly JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue>[]) | undefined;
|
|
106
|
+
const?: typeof $input | typeof $output | undefined;
|
|
107
|
+
contains?: JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue> | undefined;
|
|
108
|
+
contentEncoding?: "7bit" | "8bit" | "base64" | "binary" | "ietf-token" | "quoted-printable" | "x-token";
|
|
109
|
+
contentMediaType?: string;
|
|
110
|
+
contentSchema?: JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue> | undefined;
|
|
111
|
+
default?: typeof $input | typeof $output | undefined;
|
|
112
|
+
definitions?: Record<string, JSONSchema>;
|
|
113
|
+
dependencies?: Record<string, (string[] | readonly string[]) | JSONSchema>;
|
|
114
|
+
dependentRequired?: Record<string, string[] | readonly string[]>;
|
|
115
|
+
dependentSchemas?: Record<string, JSONSchema>;
|
|
116
|
+
deprecated?: boolean;
|
|
117
|
+
description?: string;
|
|
118
|
+
else?: JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue> | undefined;
|
|
119
|
+
enum?: ((typeof $input | typeof $output)[] | readonly (typeof $input | typeof $output)[]) | undefined;
|
|
120
|
+
examples?: ((typeof $input | typeof $output)[] | readonly (typeof $input | typeof $output)[]) | undefined;
|
|
121
|
+
exclusiveMaximum?: number;
|
|
122
|
+
exclusiveMinimum?: number;
|
|
123
|
+
format?: string;
|
|
124
|
+
if?: JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue> | undefined;
|
|
125
|
+
items?: JSONSchema;
|
|
126
|
+
maxContains?: number;
|
|
127
|
+
maximum?: number;
|
|
128
|
+
maxItems?: number;
|
|
129
|
+
maxLength?: number;
|
|
130
|
+
maxProperties?: number;
|
|
131
|
+
minContains?: number;
|
|
132
|
+
minimum?: number;
|
|
133
|
+
minItems?: number;
|
|
134
|
+
minLength?: number;
|
|
135
|
+
minProperties?: number;
|
|
136
|
+
multipleOf?: number;
|
|
137
|
+
not?: JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue> | undefined;
|
|
138
|
+
oneOf?: (JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue>[] | readonly JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue>[]) | undefined;
|
|
139
|
+
pattern?: string;
|
|
140
|
+
patternProperties?: Record<string, JSONSchema>;
|
|
141
|
+
prefixItems?: (JSONSchema<any, JSONSchema.TypeValue>[] | readonly JSONSchema<any, JSONSchema.TypeValue>[]) | JSONSchema;
|
|
142
|
+
properties?: Record<string, JSONSchema>;
|
|
143
|
+
propertyNames?: JSONSchema;
|
|
144
|
+
readOnly?: boolean;
|
|
145
|
+
required?: string[] | readonly string[];
|
|
146
|
+
then?: JSONSchema<typeof $input | typeof $output, JSONSchema.TypeValue> | undefined;
|
|
147
|
+
title?: string;
|
|
148
|
+
type?: JSONSchema.TypeValue | undefined;
|
|
149
|
+
unevaluatedItems?: JSONSchema;
|
|
150
|
+
unevaluatedProperties?: JSONSchema;
|
|
151
|
+
uniqueItems?: boolean;
|
|
152
|
+
writeOnly?: boolean;
|
|
153
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
|
154
|
+
/**
|
|
155
|
+
* Zod registry for customizing generated JSON schema, only useful for .input
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { JSON_SCHEMA_INPUT_REGISTRY } from '@orpc/zod/zod4'
|
|
160
|
+
*
|
|
161
|
+
* const user = z.object({
|
|
162
|
+
* name: z.string(),
|
|
163
|
+
* age: z.string().transform(v => Number(v)),
|
|
164
|
+
* })
|
|
165
|
+
*
|
|
166
|
+
* JSON_SCHEMA_REGISTRY.add(user, {
|
|
167
|
+
* examples: [{ name: 'John', age: "20" }],
|
|
168
|
+
* })
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
172
|
+
$anchor?: string;
|
|
173
|
+
$comment?: string;
|
|
174
|
+
$defs?: Record<string, JSONSchema>;
|
|
175
|
+
$dynamicAnchor?: string;
|
|
176
|
+
$dynamicRef?: string;
|
|
177
|
+
$id?: string;
|
|
178
|
+
$ref?: string;
|
|
179
|
+
$schema?: string;
|
|
180
|
+
$vocabulary?: Record<string, string>;
|
|
181
|
+
additionalItems?: JSONSchema;
|
|
182
|
+
additionalProperties?: JSONSchema;
|
|
183
|
+
allOf?: (JSONSchema<typeof $input, JSONSchema.TypeValue>[] | readonly JSONSchema<typeof $input, JSONSchema.TypeValue>[]) | undefined;
|
|
184
|
+
anyOf?: (JSONSchema<typeof $input, JSONSchema.TypeValue>[] | readonly JSONSchema<typeof $input, JSONSchema.TypeValue>[]) | undefined;
|
|
185
|
+
const?: typeof $input | undefined;
|
|
186
|
+
contains?: JSONSchema<typeof $input, JSONSchema.TypeValue> | undefined;
|
|
187
|
+
contentEncoding?: "7bit" | "8bit" | "base64" | "binary" | "ietf-token" | "quoted-printable" | "x-token";
|
|
188
|
+
contentMediaType?: string;
|
|
189
|
+
contentSchema?: JSONSchema<typeof $input, JSONSchema.TypeValue> | undefined;
|
|
190
|
+
default?: typeof $input | undefined;
|
|
191
|
+
definitions?: Record<string, JSONSchema>;
|
|
192
|
+
dependencies?: Record<string, (string[] | readonly string[]) | JSONSchema>;
|
|
193
|
+
dependentRequired?: Record<string, string[] | readonly string[]>;
|
|
194
|
+
dependentSchemas?: Record<string, JSONSchema>;
|
|
195
|
+
deprecated?: boolean;
|
|
196
|
+
description?: string;
|
|
197
|
+
else?: JSONSchema<typeof $input, JSONSchema.TypeValue> | undefined;
|
|
198
|
+
enum?: ((typeof $input)[] | readonly (typeof $input)[]) | undefined;
|
|
199
|
+
examples?: ((typeof $input)[] | readonly (typeof $input)[]) | undefined;
|
|
200
|
+
exclusiveMaximum?: number;
|
|
201
|
+
exclusiveMinimum?: number;
|
|
202
|
+
format?: string;
|
|
203
|
+
if?: JSONSchema<typeof $input, JSONSchema.TypeValue> | undefined;
|
|
204
|
+
items?: JSONSchema;
|
|
205
|
+
maxContains?: number;
|
|
206
|
+
maximum?: number;
|
|
207
|
+
maxItems?: number;
|
|
208
|
+
maxLength?: number;
|
|
209
|
+
maxProperties?: number;
|
|
210
|
+
minContains?: number;
|
|
211
|
+
minimum?: number;
|
|
212
|
+
minItems?: number;
|
|
213
|
+
minLength?: number;
|
|
214
|
+
minProperties?: number;
|
|
215
|
+
multipleOf?: number;
|
|
216
|
+
not?: JSONSchema<typeof $input, JSONSchema.TypeValue> | undefined;
|
|
217
|
+
oneOf?: (JSONSchema<typeof $input, JSONSchema.TypeValue>[] | readonly JSONSchema<typeof $input, JSONSchema.TypeValue>[]) | undefined;
|
|
218
|
+
pattern?: string;
|
|
219
|
+
patternProperties?: Record<string, JSONSchema>;
|
|
220
|
+
prefixItems?: (JSONSchema<any, JSONSchema.TypeValue>[] | readonly JSONSchema<any, JSONSchema.TypeValue>[]) | JSONSchema;
|
|
221
|
+
properties?: Record<string, JSONSchema>;
|
|
222
|
+
propertyNames?: JSONSchema;
|
|
223
|
+
readOnly?: boolean;
|
|
224
|
+
required?: string[] | readonly string[];
|
|
225
|
+
then?: JSONSchema<typeof $input, JSONSchema.TypeValue> | undefined;
|
|
226
|
+
title?: string;
|
|
227
|
+
type?: JSONSchema.TypeValue | undefined;
|
|
228
|
+
unevaluatedItems?: JSONSchema;
|
|
229
|
+
unevaluatedProperties?: JSONSchema;
|
|
230
|
+
uniqueItems?: boolean;
|
|
231
|
+
writeOnly?: boolean;
|
|
232
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
|
233
|
+
/**
|
|
234
|
+
* Zod registry for customizing generated JSON schema, only useful for .input
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* import { JSON_SCHEMA_OUTPUT_REGISTRY } from '@orpc/zod/zod4'
|
|
239
|
+
*
|
|
240
|
+
* const user = z.object({
|
|
241
|
+
* name: z.string(),
|
|
242
|
+
* age: z.string().transform(v => Number(v)),
|
|
243
|
+
* })
|
|
244
|
+
*
|
|
245
|
+
* JSON_SCHEMA_OUTPUT_REGISTRY.add(user, {
|
|
246
|
+
* examples: [{ name: 'John', age: 20 }],
|
|
247
|
+
* })
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
251
|
+
$anchor?: string;
|
|
252
|
+
$comment?: string;
|
|
253
|
+
$defs?: Record<string, JSONSchema>;
|
|
254
|
+
$dynamicAnchor?: string;
|
|
255
|
+
$dynamicRef?: string;
|
|
256
|
+
$id?: string;
|
|
257
|
+
$ref?: string;
|
|
258
|
+
$schema?: string;
|
|
259
|
+
$vocabulary?: Record<string, string>;
|
|
260
|
+
additionalItems?: JSONSchema;
|
|
261
|
+
additionalProperties?: JSONSchema;
|
|
262
|
+
allOf?: (JSONSchema<typeof $output, JSONSchema.TypeValue>[] | readonly JSONSchema<typeof $output, JSONSchema.TypeValue>[]) | undefined;
|
|
263
|
+
anyOf?: (JSONSchema<typeof $output, JSONSchema.TypeValue>[] | readonly JSONSchema<typeof $output, JSONSchema.TypeValue>[]) | undefined;
|
|
264
|
+
const?: typeof $output | undefined;
|
|
265
|
+
contains?: JSONSchema<typeof $output, JSONSchema.TypeValue> | undefined;
|
|
266
|
+
contentEncoding?: "7bit" | "8bit" | "base64" | "binary" | "ietf-token" | "quoted-printable" | "x-token";
|
|
267
|
+
contentMediaType?: string;
|
|
268
|
+
contentSchema?: JSONSchema<typeof $output, JSONSchema.TypeValue> | undefined;
|
|
269
|
+
default?: typeof $output | undefined;
|
|
270
|
+
definitions?: Record<string, JSONSchema>;
|
|
271
|
+
dependencies?: Record<string, (string[] | readonly string[]) | JSONSchema>;
|
|
272
|
+
dependentRequired?: Record<string, string[] | readonly string[]>;
|
|
273
|
+
dependentSchemas?: Record<string, JSONSchema>;
|
|
274
|
+
deprecated?: boolean;
|
|
275
|
+
description?: string;
|
|
276
|
+
else?: JSONSchema<typeof $output, JSONSchema.TypeValue> | undefined;
|
|
277
|
+
enum?: ((typeof $output)[] | readonly (typeof $output)[]) | undefined;
|
|
278
|
+
examples?: ((typeof $output)[] | readonly (typeof $output)[]) | undefined;
|
|
279
|
+
exclusiveMaximum?: number;
|
|
280
|
+
exclusiveMinimum?: number;
|
|
281
|
+
format?: string;
|
|
282
|
+
if?: JSONSchema<typeof $output, JSONSchema.TypeValue> | undefined;
|
|
283
|
+
items?: JSONSchema;
|
|
284
|
+
maxContains?: number;
|
|
285
|
+
maximum?: number;
|
|
286
|
+
maxItems?: number;
|
|
287
|
+
maxLength?: number;
|
|
288
|
+
maxProperties?: number;
|
|
289
|
+
minContains?: number;
|
|
290
|
+
minimum?: number;
|
|
291
|
+
minItems?: number;
|
|
292
|
+
minLength?: number;
|
|
293
|
+
minProperties?: number;
|
|
294
|
+
multipleOf?: number;
|
|
295
|
+
not?: JSONSchema<typeof $output, JSONSchema.TypeValue> | undefined;
|
|
296
|
+
oneOf?: (JSONSchema<typeof $output, JSONSchema.TypeValue>[] | readonly JSONSchema<typeof $output, JSONSchema.TypeValue>[]) | undefined;
|
|
297
|
+
pattern?: string;
|
|
298
|
+
patternProperties?: Record<string, JSONSchema>;
|
|
299
|
+
prefixItems?: (JSONSchema<any, JSONSchema.TypeValue>[] | readonly JSONSchema<any, JSONSchema.TypeValue>[]) | JSONSchema;
|
|
300
|
+
properties?: Record<string, JSONSchema>;
|
|
301
|
+
propertyNames?: JSONSchema;
|
|
302
|
+
readOnly?: boolean;
|
|
303
|
+
required?: string[] | readonly string[];
|
|
304
|
+
then?: JSONSchema<typeof $output, JSONSchema.TypeValue> | undefined;
|
|
305
|
+
title?: string;
|
|
306
|
+
type?: JSONSchema.TypeValue | undefined;
|
|
307
|
+
unevaluatedItems?: JSONSchema;
|
|
308
|
+
unevaluatedProperties?: JSONSchema;
|
|
309
|
+
uniqueItems?: boolean;
|
|
310
|
+
writeOnly?: boolean;
|
|
311
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
|
312
|
+
|
|
313
|
+
export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter, experimental_ZodSmartCoercionPlugin };
|
|
314
|
+
export type { ZodToJsonSchemaConverterOptions };
|