@orpc/zod 0.0.0-next.9588d75 → 0.0.0-next.9723092
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.js +496 -10
- package/dist/src/coercer.d.ts +5 -4
- package/dist/src/converter.d.ts +50 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/schemas.d.ts +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
@@ -31,14 +31,17 @@ var guard = (func, shouldGuard) => {
|
|
31
31
|
import {
|
32
32
|
ZodFirstPartyTypeKind
|
33
33
|
} from "zod";
|
34
|
-
var
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
var ZodAutoCoercePlugin = class {
|
35
|
+
beforeCreateProcedureClient(clientOptions) {
|
36
|
+
clientOptions.interceptors ??= [];
|
37
|
+
clientOptions.interceptors.unshift((options) => {
|
38
|
+
const inputSchema = options.procedure["~orpc"].inputSchema;
|
39
|
+
if (!inputSchema || inputSchema["~standard"].vendor !== "zod") {
|
40
|
+
return options.next();
|
41
|
+
}
|
42
|
+
const coercedInput = zodCoerceInternal(inputSchema, options.input, { bracketNotation: true });
|
43
|
+
return options.next({ ...options, input: coercedInput });
|
44
|
+
});
|
42
45
|
}
|
43
46
|
};
|
44
47
|
function zodCoerceInternal(schema, value, options) {
|
@@ -340,6 +343,22 @@ function zodCoerceInternal(schema, value, options) {
|
|
340
343
|
return value;
|
341
344
|
}
|
342
345
|
|
346
|
+
// src/converter.ts
|
347
|
+
import { JSONSchemaFormat } from "@orpc/openapi";
|
348
|
+
|
349
|
+
// ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
|
350
|
+
function escapeStringRegexp(string) {
|
351
|
+
if (typeof string !== "string") {
|
352
|
+
throw new TypeError("Expected a string");
|
353
|
+
}
|
354
|
+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
355
|
+
}
|
356
|
+
|
357
|
+
// src/converter.ts
|
358
|
+
import {
|
359
|
+
ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
|
360
|
+
} from "zod";
|
361
|
+
|
343
362
|
// src/schemas.ts
|
344
363
|
import wcmatch from "wildcard-match";
|
345
364
|
import {
|
@@ -475,8 +494,474 @@ var oz = {
|
|
475
494
|
regexp,
|
476
495
|
url
|
477
496
|
};
|
497
|
+
|
498
|
+
// src/converter.ts
|
499
|
+
var NON_LOGIC_KEYWORDS = [
|
500
|
+
// Core Documentation Keywords
|
501
|
+
"$anchor",
|
502
|
+
"$comment",
|
503
|
+
"$defs",
|
504
|
+
"$id",
|
505
|
+
"title",
|
506
|
+
"description",
|
507
|
+
// Value Keywords
|
508
|
+
"default",
|
509
|
+
"deprecated",
|
510
|
+
"examples",
|
511
|
+
// Metadata Keywords
|
512
|
+
"$schema",
|
513
|
+
"definitions",
|
514
|
+
// Legacy, but still used
|
515
|
+
"readOnly",
|
516
|
+
"writeOnly",
|
517
|
+
// Display and UI Hints
|
518
|
+
"contentMediaType",
|
519
|
+
"contentEncoding",
|
520
|
+
"format",
|
521
|
+
// Custom Extensions
|
522
|
+
"$vocabulary",
|
523
|
+
"$dynamicAnchor",
|
524
|
+
"$dynamicRef"
|
525
|
+
];
|
526
|
+
var UNSUPPORTED_JSON_SCHEMA = { not: {} };
|
527
|
+
var UNDEFINED_JSON_SCHEMA = { const: "undefined" };
|
528
|
+
function zodToJsonSchema(schema, options) {
|
529
|
+
if (schema["~standard"].vendor !== "zod") {
|
530
|
+
console.warn(`Generate JSON schema not support ${schema["~standard"].vendor} yet`);
|
531
|
+
return {};
|
532
|
+
}
|
533
|
+
const schema__ = schema;
|
534
|
+
if (!options?.isHandledZodDescription && "description" in schema__._def) {
|
535
|
+
const json = zodToJsonSchema(schema__, {
|
536
|
+
...options,
|
537
|
+
isHandledZodDescription: true
|
538
|
+
});
|
539
|
+
return {
|
540
|
+
description: schema__._def.description,
|
541
|
+
...json
|
542
|
+
};
|
543
|
+
}
|
544
|
+
if (!options?.isHandledCustomJSONSchema) {
|
545
|
+
const customJSONSchema = getCustomJSONSchema(schema__._def, options);
|
546
|
+
if (customJSONSchema) {
|
547
|
+
const json = zodToJsonSchema(schema__, {
|
548
|
+
...options,
|
549
|
+
isHandledCustomJSONSchema: true
|
550
|
+
});
|
551
|
+
return {
|
552
|
+
...json,
|
553
|
+
...customJSONSchema
|
554
|
+
};
|
555
|
+
}
|
556
|
+
}
|
557
|
+
const childOptions = { ...options, isHandledCustomJSONSchema: false, isHandledZodDescription: false };
|
558
|
+
const customType = getCustomZodType(schema__._def);
|
559
|
+
switch (customType) {
|
560
|
+
case "Blob": {
|
561
|
+
return { type: "string", contentMediaType: "*/*" };
|
562
|
+
}
|
563
|
+
case "File": {
|
564
|
+
const mimeType = getCustomZodFileMimeType(schema__._def) ?? "*/*";
|
565
|
+
return { type: "string", contentMediaType: mimeType };
|
566
|
+
}
|
567
|
+
case "Invalid Date": {
|
568
|
+
return { const: "Invalid Date" };
|
569
|
+
}
|
570
|
+
case "RegExp": {
|
571
|
+
return {
|
572
|
+
type: "string",
|
573
|
+
pattern: "^\\/(.*)\\/([a-z]*)$"
|
574
|
+
};
|
575
|
+
}
|
576
|
+
case "URL": {
|
577
|
+
return { type: "string", format: JSONSchemaFormat.URI };
|
578
|
+
}
|
579
|
+
}
|
580
|
+
const _expectedCustomType = customType;
|
581
|
+
const typeName = schema__._def.typeName;
|
582
|
+
switch (typeName) {
|
583
|
+
case ZodFirstPartyTypeKind2.ZodString: {
|
584
|
+
const schema_ = schema__;
|
585
|
+
const json = { type: "string" };
|
586
|
+
for (const check of schema_._def.checks) {
|
587
|
+
switch (check.kind) {
|
588
|
+
case "base64":
|
589
|
+
json.contentEncoding = "base64";
|
590
|
+
break;
|
591
|
+
case "cuid":
|
592
|
+
json.pattern = "^[0-9A-HJKMNP-TV-Z]{26}$";
|
593
|
+
break;
|
594
|
+
case "email":
|
595
|
+
json.format = JSONSchemaFormat.Email;
|
596
|
+
break;
|
597
|
+
case "url":
|
598
|
+
json.format = JSONSchemaFormat.URI;
|
599
|
+
break;
|
600
|
+
case "uuid":
|
601
|
+
json.format = JSONSchemaFormat.UUID;
|
602
|
+
break;
|
603
|
+
case "regex":
|
604
|
+
json.pattern = check.regex.source;
|
605
|
+
break;
|
606
|
+
case "min":
|
607
|
+
json.minLength = check.value;
|
608
|
+
break;
|
609
|
+
case "max":
|
610
|
+
json.maxLength = check.value;
|
611
|
+
break;
|
612
|
+
case "length":
|
613
|
+
json.minLength = check.value;
|
614
|
+
json.maxLength = check.value;
|
615
|
+
break;
|
616
|
+
case "includes":
|
617
|
+
json.pattern = escapeStringRegexp(check.value);
|
618
|
+
break;
|
619
|
+
case "startsWith":
|
620
|
+
json.pattern = `^${escapeStringRegexp(check.value)}`;
|
621
|
+
break;
|
622
|
+
case "endsWith":
|
623
|
+
json.pattern = `${escapeStringRegexp(check.value)}$`;
|
624
|
+
break;
|
625
|
+
case "emoji":
|
626
|
+
json.pattern = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
|
627
|
+
break;
|
628
|
+
case "nanoid":
|
629
|
+
json.pattern = "^[a-zA-Z0-9_-]{21}$";
|
630
|
+
break;
|
631
|
+
case "cuid2":
|
632
|
+
json.pattern = "^[0-9a-z]+$";
|
633
|
+
break;
|
634
|
+
case "ulid":
|
635
|
+
json.pattern = "^[0-9A-HJKMNP-TV-Z]{26}$";
|
636
|
+
break;
|
637
|
+
case "datetime":
|
638
|
+
json.format = JSONSchemaFormat.DateTime;
|
639
|
+
break;
|
640
|
+
case "date":
|
641
|
+
json.format = JSONSchemaFormat.Date;
|
642
|
+
break;
|
643
|
+
case "time":
|
644
|
+
json.format = JSONSchemaFormat.Time;
|
645
|
+
break;
|
646
|
+
case "duration":
|
647
|
+
json.format = JSONSchemaFormat.Duration;
|
648
|
+
break;
|
649
|
+
case "ip":
|
650
|
+
json.format = JSONSchemaFormat.IPv4;
|
651
|
+
break;
|
652
|
+
case "jwt":
|
653
|
+
json.pattern = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$";
|
654
|
+
break;
|
655
|
+
case "base64url":
|
656
|
+
json.pattern = "^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$";
|
657
|
+
break;
|
658
|
+
default: {
|
659
|
+
const _expect = check.kind;
|
660
|
+
}
|
661
|
+
}
|
662
|
+
}
|
663
|
+
return json;
|
664
|
+
}
|
665
|
+
case ZodFirstPartyTypeKind2.ZodNumber: {
|
666
|
+
const schema_ = schema__;
|
667
|
+
const json = { type: "number" };
|
668
|
+
for (const check of schema_._def.checks) {
|
669
|
+
switch (check.kind) {
|
670
|
+
case "int":
|
671
|
+
json.type = "integer";
|
672
|
+
break;
|
673
|
+
case "min":
|
674
|
+
json.minimum = check.value;
|
675
|
+
break;
|
676
|
+
case "max":
|
677
|
+
json.maximum = check.value;
|
678
|
+
break;
|
679
|
+
case "multipleOf":
|
680
|
+
json.multipleOf = check.value;
|
681
|
+
break;
|
682
|
+
default: {
|
683
|
+
const _expect = check.kind;
|
684
|
+
}
|
685
|
+
}
|
686
|
+
}
|
687
|
+
return json;
|
688
|
+
}
|
689
|
+
case ZodFirstPartyTypeKind2.ZodNaN: {
|
690
|
+
return { const: "NaN" };
|
691
|
+
}
|
692
|
+
case ZodFirstPartyTypeKind2.ZodBigInt: {
|
693
|
+
const json = { type: "string", pattern: "^-?[0-9]+$" };
|
694
|
+
return json;
|
695
|
+
}
|
696
|
+
case ZodFirstPartyTypeKind2.ZodBoolean: {
|
697
|
+
return { type: "boolean" };
|
698
|
+
}
|
699
|
+
case ZodFirstPartyTypeKind2.ZodDate: {
|
700
|
+
const schema2 = { type: "string", format: JSONSchemaFormat.Date };
|
701
|
+
return schema2;
|
702
|
+
}
|
703
|
+
case ZodFirstPartyTypeKind2.ZodNull: {
|
704
|
+
return { type: "null" };
|
705
|
+
}
|
706
|
+
case ZodFirstPartyTypeKind2.ZodVoid:
|
707
|
+
case ZodFirstPartyTypeKind2.ZodUndefined: {
|
708
|
+
return UNDEFINED_JSON_SCHEMA;
|
709
|
+
}
|
710
|
+
case ZodFirstPartyTypeKind2.ZodLiteral: {
|
711
|
+
const schema_ = schema__;
|
712
|
+
return { const: schema_._def.value };
|
713
|
+
}
|
714
|
+
case ZodFirstPartyTypeKind2.ZodEnum: {
|
715
|
+
const schema_ = schema__;
|
716
|
+
return {
|
717
|
+
enum: schema_._def.values
|
718
|
+
};
|
719
|
+
}
|
720
|
+
case ZodFirstPartyTypeKind2.ZodNativeEnum: {
|
721
|
+
const schema_ = schema__;
|
722
|
+
return {
|
723
|
+
enum: Object.values(schema_._def.values)
|
724
|
+
};
|
725
|
+
}
|
726
|
+
case ZodFirstPartyTypeKind2.ZodArray: {
|
727
|
+
const schema_ = schema__;
|
728
|
+
const def = schema_._def;
|
729
|
+
const json = { type: "array" };
|
730
|
+
json.items = zodToJsonSchema(def.type, childOptions);
|
731
|
+
if (def.exactLength) {
|
732
|
+
json.maxItems = def.exactLength.value;
|
733
|
+
json.minItems = def.exactLength.value;
|
734
|
+
}
|
735
|
+
if (def.minLength) {
|
736
|
+
json.minItems = def.minLength.value;
|
737
|
+
}
|
738
|
+
if (def.maxLength) {
|
739
|
+
json.maxItems = def.maxLength.value;
|
740
|
+
}
|
741
|
+
return json;
|
742
|
+
}
|
743
|
+
case ZodFirstPartyTypeKind2.ZodTuple: {
|
744
|
+
const schema_ = schema__;
|
745
|
+
const prefixItems = [];
|
746
|
+
const json = { type: "array" };
|
747
|
+
for (const item of schema_._def.items) {
|
748
|
+
prefixItems.push(zodToJsonSchema(item, childOptions));
|
749
|
+
}
|
750
|
+
if (prefixItems?.length) {
|
751
|
+
json.prefixItems = prefixItems;
|
752
|
+
}
|
753
|
+
if (schema_._def.rest) {
|
754
|
+
const items = zodToJsonSchema(schema_._def.rest, childOptions);
|
755
|
+
if (items) {
|
756
|
+
json.items = items;
|
757
|
+
}
|
758
|
+
}
|
759
|
+
return json;
|
760
|
+
}
|
761
|
+
case ZodFirstPartyTypeKind2.ZodObject: {
|
762
|
+
const schema_ = schema__;
|
763
|
+
const json = { type: "object" };
|
764
|
+
const properties = {};
|
765
|
+
const required = [];
|
766
|
+
for (const [key, value] of Object.entries(schema_.shape)) {
|
767
|
+
const { schema: schema2, matches } = extractJSONSchema(
|
768
|
+
zodToJsonSchema(value, childOptions),
|
769
|
+
(schema3) => schema3 === UNDEFINED_JSON_SCHEMA
|
770
|
+
);
|
771
|
+
if (schema2) {
|
772
|
+
properties[key] = schema2;
|
773
|
+
}
|
774
|
+
if (matches.length === 0) {
|
775
|
+
required.push(key);
|
776
|
+
}
|
777
|
+
}
|
778
|
+
if (Object.keys(properties).length) {
|
779
|
+
json.properties = properties;
|
780
|
+
}
|
781
|
+
if (required.length) {
|
782
|
+
json.required = required;
|
783
|
+
}
|
784
|
+
const additionalProperties = zodToJsonSchema(
|
785
|
+
schema_._def.catchall,
|
786
|
+
childOptions
|
787
|
+
);
|
788
|
+
if (schema_._def.unknownKeys === "strict") {
|
789
|
+
json.additionalProperties = additionalProperties === UNSUPPORTED_JSON_SCHEMA ? false : additionalProperties;
|
790
|
+
} else {
|
791
|
+
if (additionalProperties && additionalProperties !== UNSUPPORTED_JSON_SCHEMA) {
|
792
|
+
json.additionalProperties = additionalProperties;
|
793
|
+
}
|
794
|
+
}
|
795
|
+
return json;
|
796
|
+
}
|
797
|
+
case ZodFirstPartyTypeKind2.ZodRecord: {
|
798
|
+
const schema_ = schema__;
|
799
|
+
const json = { type: "object" };
|
800
|
+
json.additionalProperties = zodToJsonSchema(
|
801
|
+
schema_._def.valueType,
|
802
|
+
childOptions
|
803
|
+
);
|
804
|
+
return json;
|
805
|
+
}
|
806
|
+
case ZodFirstPartyTypeKind2.ZodSet: {
|
807
|
+
const schema_ = schema__;
|
808
|
+
return {
|
809
|
+
type: "array",
|
810
|
+
items: zodToJsonSchema(schema_._def.valueType, childOptions)
|
811
|
+
};
|
812
|
+
}
|
813
|
+
case ZodFirstPartyTypeKind2.ZodMap: {
|
814
|
+
const schema_ = schema__;
|
815
|
+
return {
|
816
|
+
type: "array",
|
817
|
+
items: {
|
818
|
+
type: "array",
|
819
|
+
prefixItems: [
|
820
|
+
zodToJsonSchema(schema_._def.keyType, childOptions),
|
821
|
+
zodToJsonSchema(schema_._def.valueType, childOptions)
|
822
|
+
],
|
823
|
+
maxItems: 2,
|
824
|
+
minItems: 2
|
825
|
+
}
|
826
|
+
};
|
827
|
+
}
|
828
|
+
case ZodFirstPartyTypeKind2.ZodUnion:
|
829
|
+
case ZodFirstPartyTypeKind2.ZodDiscriminatedUnion: {
|
830
|
+
const schema_ = schema__;
|
831
|
+
const anyOf = [];
|
832
|
+
for (const s of schema_._def.options) {
|
833
|
+
anyOf.push(zodToJsonSchema(s, childOptions));
|
834
|
+
}
|
835
|
+
return { anyOf };
|
836
|
+
}
|
837
|
+
case ZodFirstPartyTypeKind2.ZodIntersection: {
|
838
|
+
const schema_ = schema__;
|
839
|
+
const allOf = [];
|
840
|
+
for (const s of [schema_._def.left, schema_._def.right]) {
|
841
|
+
allOf.push(zodToJsonSchema(s, childOptions));
|
842
|
+
}
|
843
|
+
return { allOf };
|
844
|
+
}
|
845
|
+
case ZodFirstPartyTypeKind2.ZodLazy: {
|
846
|
+
const schema_ = schema__;
|
847
|
+
const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
|
848
|
+
const lazyDepth = childOptions?.lazyDepth ?? 0;
|
849
|
+
if (lazyDepth > maxLazyDepth) {
|
850
|
+
return {};
|
851
|
+
}
|
852
|
+
return zodToJsonSchema(schema_._def.getter(), {
|
853
|
+
...childOptions,
|
854
|
+
lazyDepth: lazyDepth + 1
|
855
|
+
});
|
856
|
+
}
|
857
|
+
case ZodFirstPartyTypeKind2.ZodUnknown:
|
858
|
+
case ZodFirstPartyTypeKind2.ZodAny:
|
859
|
+
case void 0: {
|
860
|
+
return {};
|
861
|
+
}
|
862
|
+
case ZodFirstPartyTypeKind2.ZodOptional: {
|
863
|
+
const schema_ = schema__;
|
864
|
+
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
865
|
+
return {
|
866
|
+
anyOf: [UNDEFINED_JSON_SCHEMA, inner]
|
867
|
+
};
|
868
|
+
}
|
869
|
+
case ZodFirstPartyTypeKind2.ZodReadonly: {
|
870
|
+
const schema_ = schema__;
|
871
|
+
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
872
|
+
}
|
873
|
+
case ZodFirstPartyTypeKind2.ZodDefault: {
|
874
|
+
const schema_ = schema__;
|
875
|
+
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
876
|
+
}
|
877
|
+
case ZodFirstPartyTypeKind2.ZodEffects: {
|
878
|
+
const schema_ = schema__;
|
879
|
+
if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
|
880
|
+
return {};
|
881
|
+
}
|
882
|
+
return zodToJsonSchema(schema_._def.schema, childOptions);
|
883
|
+
}
|
884
|
+
case ZodFirstPartyTypeKind2.ZodCatch: {
|
885
|
+
const schema_ = schema__;
|
886
|
+
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
887
|
+
}
|
888
|
+
case ZodFirstPartyTypeKind2.ZodBranded: {
|
889
|
+
const schema_ = schema__;
|
890
|
+
return zodToJsonSchema(schema_._def.type, childOptions);
|
891
|
+
}
|
892
|
+
case ZodFirstPartyTypeKind2.ZodPipeline: {
|
893
|
+
const schema_ = schema__;
|
894
|
+
return zodToJsonSchema(
|
895
|
+
childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
|
896
|
+
childOptions
|
897
|
+
);
|
898
|
+
}
|
899
|
+
case ZodFirstPartyTypeKind2.ZodNullable: {
|
900
|
+
const schema_ = schema__;
|
901
|
+
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
902
|
+
return {
|
903
|
+
anyOf: [{ type: "null" }, inner]
|
904
|
+
};
|
905
|
+
}
|
906
|
+
}
|
907
|
+
const _expected = typeName;
|
908
|
+
return UNSUPPORTED_JSON_SCHEMA;
|
909
|
+
}
|
910
|
+
function extractJSONSchema(schema, check, matches = []) {
|
911
|
+
if (check(schema)) {
|
912
|
+
matches.push(schema);
|
913
|
+
return { schema: void 0, matches };
|
914
|
+
}
|
915
|
+
if (typeof schema === "boolean") {
|
916
|
+
return { schema, matches };
|
917
|
+
}
|
918
|
+
if (schema.anyOf && Object.keys(schema).every(
|
919
|
+
(k) => k === "anyOf" || NON_LOGIC_KEYWORDS.includes(k)
|
920
|
+
)) {
|
921
|
+
const anyOf = schema.anyOf.map((s) => extractJSONSchema(s, check, matches).schema).filter((v) => !!v);
|
922
|
+
if (anyOf.length === 1 && typeof anyOf[0] === "object") {
|
923
|
+
return { schema: { ...schema, anyOf: void 0, ...anyOf[0] }, matches };
|
924
|
+
}
|
925
|
+
return {
|
926
|
+
schema: {
|
927
|
+
...schema,
|
928
|
+
anyOf
|
929
|
+
},
|
930
|
+
matches
|
931
|
+
};
|
932
|
+
}
|
933
|
+
if (schema.oneOf && Object.keys(schema).every(
|
934
|
+
(k) => k === "oneOf" || NON_LOGIC_KEYWORDS.includes(k)
|
935
|
+
)) {
|
936
|
+
const oneOf = schema.oneOf.map((s) => extractJSONSchema(s, check, matches).schema).filter((v) => !!v);
|
937
|
+
if (oneOf.length === 1 && typeof oneOf[0] === "object") {
|
938
|
+
return { schema: { ...schema, oneOf: void 0, ...oneOf[0] }, matches };
|
939
|
+
}
|
940
|
+
return {
|
941
|
+
schema: {
|
942
|
+
...schema,
|
943
|
+
oneOf
|
944
|
+
},
|
945
|
+
matches
|
946
|
+
};
|
947
|
+
}
|
948
|
+
return { schema, matches };
|
949
|
+
}
|
950
|
+
var ZodToJsonSchemaConverter = class {
|
951
|
+
condition(schema) {
|
952
|
+
return Boolean(schema && schema["~standard"].vendor === "zod");
|
953
|
+
}
|
954
|
+
convert(schema, options) {
|
955
|
+
const jsonSchema = schema;
|
956
|
+
return zodToJsonSchema(jsonSchema, { mode: options.strategy });
|
957
|
+
}
|
958
|
+
};
|
478
959
|
export {
|
479
|
-
|
960
|
+
NON_LOGIC_KEYWORDS,
|
961
|
+
UNDEFINED_JSON_SCHEMA,
|
962
|
+
UNSUPPORTED_JSON_SCHEMA,
|
963
|
+
ZodAutoCoercePlugin,
|
964
|
+
ZodToJsonSchemaConverter,
|
480
965
|
blob,
|
481
966
|
file,
|
482
967
|
getCustomJSONSchema,
|
@@ -486,6 +971,7 @@ export {
|
|
486
971
|
openapi,
|
487
972
|
oz,
|
488
973
|
regexp,
|
489
|
-
url
|
974
|
+
url,
|
975
|
+
zodToJsonSchema
|
490
976
|
};
|
491
977
|
//# sourceMappingURL=index.js.map
|
package/dist/src/coercer.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
|
4
|
-
|
1
|
+
import type { Context } from '@orpc/server';
|
2
|
+
import type { Plugin } from '@orpc/server/plugins';
|
3
|
+
import type { WellCreateProcedureClientOptions } from '@orpc/server/standard';
|
4
|
+
export declare class ZodAutoCoercePlugin<TContext extends Context> implements Plugin<TContext> {
|
5
|
+
beforeCreateProcedureClient(clientOptions: WellCreateProcedureClientOptions<TContext>): void;
|
5
6
|
}
|
6
7
|
//# sourceMappingURL=coercer.d.ts.map
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import type { Schema } from '@orpc/contract';
|
2
|
+
import type { JSONSchema, SchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
3
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
4
|
+
export declare const NON_LOGIC_KEYWORDS: ("$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "contentEncoding" | "contentMediaType" | "default" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly")[];
|
5
|
+
export declare const UNSUPPORTED_JSON_SCHEMA: {
|
6
|
+
not: {};
|
7
|
+
};
|
8
|
+
export declare const UNDEFINED_JSON_SCHEMA: {
|
9
|
+
const: string;
|
10
|
+
};
|
11
|
+
export interface ZodToJsonSchemaOptions {
|
12
|
+
/**
|
13
|
+
* Max depth of lazy type, if it exceeds.
|
14
|
+
*
|
15
|
+
* Used `{}` when reach max depth
|
16
|
+
*
|
17
|
+
* @default 5
|
18
|
+
*/
|
19
|
+
maxLazyDepth?: number;
|
20
|
+
/**
|
21
|
+
* The length used to track the depth of lazy type
|
22
|
+
*
|
23
|
+
* @internal
|
24
|
+
*/
|
25
|
+
lazyDepth?: number;
|
26
|
+
/**
|
27
|
+
* The expected json schema for input or output zod schema
|
28
|
+
*
|
29
|
+
* @default input
|
30
|
+
*/
|
31
|
+
mode?: 'input' | 'output';
|
32
|
+
/**
|
33
|
+
* Track if current level schema is handled custom json schema to prevent recursive
|
34
|
+
*
|
35
|
+
* @internal
|
36
|
+
*/
|
37
|
+
isHandledCustomJSONSchema?: boolean;
|
38
|
+
/**
|
39
|
+
* Track if current level schema is handled zod description to prevent recursive
|
40
|
+
*
|
41
|
+
* @internal
|
42
|
+
*/
|
43
|
+
isHandledZodDescription?: boolean;
|
44
|
+
}
|
45
|
+
export declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema.JSONSchema, boolean>;
|
46
|
+
export declare class ZodToJsonSchemaConverter implements SchemaConverter {
|
47
|
+
condition(schema: Schema): boolean;
|
48
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
49
|
+
}
|
50
|
+
//# sourceMappingURL=converter.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/schemas.d.ts
CHANGED
@@ -10,7 +10,7 @@ export declare function getCustomJSONSchema(def: ZodTypeDef, options?: {
|
|
10
10
|
mode?: 'input' | 'output';
|
11
11
|
}): Exclude<JSONSchema, boolean> | undefined;
|
12
12
|
export declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
|
13
|
-
type
|
13
|
+
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>;
|
14
14
|
};
|
15
15
|
export declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>;
|
16
16
|
export declare function invalidDate(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Date, ZodTypeDef, Date>;
|
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.
|
4
|
+
"version": "0.0.0-next.9723092",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -29,7 +29,8 @@
|
|
29
29
|
"dist"
|
30
30
|
],
|
31
31
|
"peerDependencies": {
|
32
|
-
"@orpc/
|
32
|
+
"@orpc/server": "0.0.0-next.9723092",
|
33
|
+
"@orpc/openapi": "0.0.0-next.9723092"
|
33
34
|
},
|
34
35
|
"dependencies": {
|
35
36
|
"json-schema-typed": "^8.0.1",
|