zod 3.26.0-canary.20250703T214020 → 3.26.0-canary.20250707T201657
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/index.cjs +2 -2
- package/index.d.cts +2 -2
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/v4/classic/schemas.ts +4 -2
- package/src/v4/classic/tests/brand.test.ts +1 -3
- package/src/v4/classic/tests/discriminated-unions.test.ts +27 -0
- package/src/v4/classic/tests/index.test.ts +1 -1
- package/src/v4/classic/tests/object.test.ts +11 -1
- package/src/v4/classic/tests/optional.test.ts +20 -0
- package/src/v4/classic/tests/record.test.ts +11 -1
- package/src/v4/classic/tests/recursive-types.test.ts +3 -2
- package/src/v4/classic/tests/to-json-schema.test.ts +95 -2
- package/src/v4/core/registries.ts +4 -0
- package/src/v4/core/schemas.ts +93 -32
- package/src/v4/core/to-json-schema.ts +23 -11
- package/src/v4/mini/schemas.ts +2 -2
- package/src/v4/mini/tests/string.test.ts +6 -0
- package/v4/classic/schemas.d.cts +2 -1
- package/v4/classic/schemas.d.ts +2 -1
- package/v4/core/registries.cjs +4 -0
- package/v4/core/registries.js +4 -0
- package/v4/core/schemas.cjs +18 -5
- package/v4/core/schemas.d.cts +35 -9
- package/v4/core/schemas.d.ts +35 -9
- package/v4/core/schemas.js +18 -5
- package/v4/core/to-json-schema.cjs +10 -8
- package/v4/core/to-json-schema.d.cts +5 -1
- package/v4/core/to-json-schema.d.ts +5 -1
- package/v4/core/to-json-schema.js +10 -8
- package/v4/mini/schemas.d.cts +1 -1
- package/v4/mini/schemas.d.ts +1 -1
package/v4/core/schemas.d.cts
CHANGED
|
@@ -32,7 +32,6 @@ export interface _$ZodTypeInternals {
|
|
|
32
32
|
/** Schema definition. */
|
|
33
33
|
def: $ZodTypeDef;
|
|
34
34
|
/** @internal Randomly generated ID for this schema. */
|
|
35
|
-
id: string;
|
|
36
35
|
/** @internal List of deferred initializers. */
|
|
37
36
|
deferred: util.AnyFunc[] | undefined;
|
|
38
37
|
/** @internal Parses input and runs all checks (refinements). */
|
|
@@ -516,11 +515,13 @@ export interface $ZodArrayDef<T extends SomeType = $ZodType> extends $ZodTypeDef
|
|
|
516
515
|
type: "array";
|
|
517
516
|
element: T;
|
|
518
517
|
}
|
|
519
|
-
export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals
|
|
518
|
+
export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends _$ZodTypeInternals {
|
|
520
519
|
def: $ZodArrayDef<T>;
|
|
521
520
|
isst: errors.$ZodIssueInvalidType;
|
|
521
|
+
output: core.output<T>[];
|
|
522
|
+
input: core.input<T>[];
|
|
522
523
|
}
|
|
523
|
-
export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<
|
|
524
|
+
export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<any, any, $ZodArrayInternals<T>> {
|
|
524
525
|
}
|
|
525
526
|
export declare const $ZodArray: core.$constructor<$ZodArray>;
|
|
526
527
|
type OptionalOutSchema = {
|
|
@@ -533,12 +534,12 @@ type OptionalInSchema = {
|
|
|
533
534
|
optin: "optional";
|
|
534
535
|
};
|
|
535
536
|
};
|
|
536
|
-
export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? Record<string, unknown> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
537
|
+
export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : Record<string, core.output<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
537
538
|
-readonly [k in keyof T as T[k] extends OptionalOutSchema ? never : k]: T[k]["_zod"]["output"];
|
|
538
539
|
} & {
|
|
539
540
|
-readonly [k in keyof T as T[k] extends OptionalOutSchema ? k : never]?: T[k]["_zod"]["output"];
|
|
540
541
|
} & Extra>;
|
|
541
|
-
export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? Record<string, unknown> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
542
|
+
export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : Record<string, core.input<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
542
543
|
-readonly [k in keyof T as T[k] extends OptionalInSchema ? never : k]: T[k]["_zod"]["input"];
|
|
543
544
|
} & {
|
|
544
545
|
-readonly [k in keyof T as T[k] extends OptionalInSchema ? k : never]?: T[k]["_zod"]["input"];
|
|
@@ -598,12 +599,19 @@ export interface $ZodUnionDef<Options extends readonly SomeType[] = readonly $Zo
|
|
|
598
599
|
type: "union";
|
|
599
600
|
options: Options;
|
|
600
601
|
}
|
|
601
|
-
|
|
602
|
+
type IsOptionalIn<T extends SomeType> = T extends OptionalInSchema ? true : false;
|
|
603
|
+
type IsOptionalOut<T extends SomeType> = T extends OptionalOutSchema ? true : false;
|
|
604
|
+
export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends _$ZodTypeInternals {
|
|
602
605
|
def: $ZodUnionDef<T>;
|
|
603
606
|
isst: errors.$ZodIssueInvalidUnion;
|
|
604
607
|
pattern: T[number]["_zod"]["pattern"];
|
|
608
|
+
values: T[number]["_zod"]["values"];
|
|
609
|
+
output: $InferUnionOutput<T[number]>;
|
|
610
|
+
input: $InferUnionInput<T[number]>;
|
|
611
|
+
optin: IsOptionalIn<T[number]> extends false ? "optional" | undefined : "optional";
|
|
612
|
+
optout: IsOptionalOut<T[number]> extends false ? "optional" | undefined : "optional";
|
|
605
613
|
}
|
|
606
|
-
export interface $ZodUnion<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodType {
|
|
614
|
+
export interface $ZodUnion<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodType<any, any, $ZodUnionInternals<T>> {
|
|
607
615
|
_zod: $ZodUnionInternals<T>;
|
|
608
616
|
}
|
|
609
617
|
export declare const $ZodUnion: core.$constructor<$ZodUnion>;
|
|
@@ -627,6 +635,8 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
|
|
|
627
635
|
export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
|
|
628
636
|
def: $ZodIntersectionDef<A, B>;
|
|
629
637
|
isst: never;
|
|
638
|
+
optin: A["_zod"]["optin"] | B["_zod"]["optin"];
|
|
639
|
+
optout: A["_zod"]["optout"] | B["_zod"]["optout"];
|
|
630
640
|
}
|
|
631
641
|
export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
|
632
642
|
_zod: $ZodIntersectionInternals<A, B>;
|
|
@@ -673,12 +683,17 @@ export interface $ZodRecordDef<Key extends $ZodRecordKey = $ZodRecordKey, Value
|
|
|
673
683
|
keyType: Key;
|
|
674
684
|
valueType: Value;
|
|
675
685
|
}
|
|
676
|
-
export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> =
|
|
677
|
-
export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> =
|
|
686
|
+
export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = Key extends $partial ? Partial<Record<core.output<Key>, core.output<Value>>> : Record<core.output<Key>, core.output<Value>>;
|
|
687
|
+
export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = Key extends $partial ? Partial<Record<core.input<Key>, core.input<Value>>> : Record<core.input<Key>, core.input<Value>>;
|
|
678
688
|
export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
|
|
679
689
|
def: $ZodRecordDef<Key, Value>;
|
|
680
690
|
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
|
|
691
|
+
optin?: "optional" | undefined;
|
|
692
|
+
optout?: "optional" | undefined;
|
|
681
693
|
}
|
|
694
|
+
export type $partial = {
|
|
695
|
+
"~~partial": true;
|
|
696
|
+
};
|
|
682
697
|
export interface $ZodRecord<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodType {
|
|
683
698
|
_zod: $ZodRecordInternals<Key, Value>;
|
|
684
699
|
}
|
|
@@ -691,6 +706,8 @@ export interface $ZodMapDef<Key extends SomeType = $ZodType, Value extends SomeT
|
|
|
691
706
|
export interface $ZodMapInternals<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodTypeInternals<Map<core.output<Key>, core.output<Value>>, Map<core.input<Key>, core.input<Value>>> {
|
|
692
707
|
def: $ZodMapDef<Key, Value>;
|
|
693
708
|
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey | errors.$ZodIssueInvalidElement<unknown>;
|
|
709
|
+
optin?: "optional" | undefined;
|
|
710
|
+
optout?: "optional" | undefined;
|
|
694
711
|
}
|
|
695
712
|
export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodType {
|
|
696
713
|
_zod: $ZodMapInternals<Key, Value>;
|
|
@@ -703,6 +720,8 @@ export interface $ZodSetDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
|
|
|
703
720
|
export interface $ZodSetInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<Set<core.output<T>>, Set<core.input<T>>> {
|
|
704
721
|
def: $ZodSetDef<T>;
|
|
705
722
|
isst: errors.$ZodIssueInvalidType;
|
|
723
|
+
optin?: "optional" | undefined;
|
|
724
|
+
optout?: "optional" | undefined;
|
|
706
725
|
}
|
|
707
726
|
export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
|
|
708
727
|
_zod: $ZodSetInternals<T>;
|
|
@@ -815,6 +834,7 @@ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeD
|
|
|
815
834
|
export interface $ZodDefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
|
|
816
835
|
def: $ZodDefaultDef<T>;
|
|
817
836
|
optin: "optional";
|
|
837
|
+
optout?: "optional" | undefined;
|
|
818
838
|
isst: never;
|
|
819
839
|
values: T["_zod"]["values"];
|
|
820
840
|
}
|
|
@@ -831,6 +851,7 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
|
|
|
831
851
|
export interface $ZodPrefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
|
|
832
852
|
def: $ZodPrefaultDef<T>;
|
|
833
853
|
optin: "optional";
|
|
854
|
+
optout?: "optional" | undefined;
|
|
834
855
|
isst: never;
|
|
835
856
|
values: T["_zod"]["values"];
|
|
836
857
|
}
|
|
@@ -846,6 +867,8 @@ export interface $ZodNonOptionalInternals<T extends SomeType = $ZodType> extends
|
|
|
846
867
|
def: $ZodNonOptionalDef<T>;
|
|
847
868
|
isst: errors.$ZodIssueInvalidType;
|
|
848
869
|
values: T["_zod"]["values"];
|
|
870
|
+
optin: "optional" | undefined;
|
|
871
|
+
optout: "optional" | undefined;
|
|
849
872
|
}
|
|
850
873
|
export interface $ZodNonOptional<T extends SomeType = $ZodType> extends $ZodType {
|
|
851
874
|
_zod: $ZodNonOptionalInternals<T>;
|
|
@@ -858,6 +881,8 @@ export interface $ZodSuccessDef<T extends SomeType = $ZodType> extends $ZodTypeD
|
|
|
858
881
|
export interface $ZodSuccessInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<boolean, core.input<T>> {
|
|
859
882
|
def: $ZodSuccessDef<T>;
|
|
860
883
|
isst: never;
|
|
884
|
+
optin: T["_zod"]["optin"];
|
|
885
|
+
optout: "optional" | undefined;
|
|
861
886
|
}
|
|
862
887
|
export interface $ZodSuccess<T extends SomeType = $ZodType> extends $ZodType {
|
|
863
888
|
_zod: $ZodSuccessInternals<T>;
|
|
@@ -924,6 +949,7 @@ export interface $ZodReadonlyInternals<T extends SomeType = $ZodType> extends $Z
|
|
|
924
949
|
optout: T["_zod"]["optout"];
|
|
925
950
|
isst: never;
|
|
926
951
|
propValues: T["_zod"]["propValues"];
|
|
952
|
+
values: T["_zod"]["values"];
|
|
927
953
|
}
|
|
928
954
|
export interface $ZodReadonly<T extends SomeType = $ZodType> extends $ZodType {
|
|
929
955
|
_zod: $ZodReadonlyInternals<T>;
|
package/v4/core/schemas.d.ts
CHANGED
|
@@ -32,7 +32,6 @@ export interface _$ZodTypeInternals {
|
|
|
32
32
|
/** Schema definition. */
|
|
33
33
|
def: $ZodTypeDef;
|
|
34
34
|
/** @internal Randomly generated ID for this schema. */
|
|
35
|
-
id: string;
|
|
36
35
|
/** @internal List of deferred initializers. */
|
|
37
36
|
deferred: util.AnyFunc[] | undefined;
|
|
38
37
|
/** @internal Parses input and runs all checks (refinements). */
|
|
@@ -516,11 +515,13 @@ export interface $ZodArrayDef<T extends SomeType = $ZodType> extends $ZodTypeDef
|
|
|
516
515
|
type: "array";
|
|
517
516
|
element: T;
|
|
518
517
|
}
|
|
519
|
-
export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals
|
|
518
|
+
export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends _$ZodTypeInternals {
|
|
520
519
|
def: $ZodArrayDef<T>;
|
|
521
520
|
isst: errors.$ZodIssueInvalidType;
|
|
521
|
+
output: core.output<T>[];
|
|
522
|
+
input: core.input<T>[];
|
|
522
523
|
}
|
|
523
|
-
export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<
|
|
524
|
+
export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<any, any, $ZodArrayInternals<T>> {
|
|
524
525
|
}
|
|
525
526
|
export declare const $ZodArray: core.$constructor<$ZodArray>;
|
|
526
527
|
type OptionalOutSchema = {
|
|
@@ -533,12 +534,12 @@ type OptionalInSchema = {
|
|
|
533
534
|
optin: "optional";
|
|
534
535
|
};
|
|
535
536
|
};
|
|
536
|
-
export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? Record<string, unknown> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
537
|
+
export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : Record<string, core.output<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
537
538
|
-readonly [k in keyof T as T[k] extends OptionalOutSchema ? never : k]: T[k]["_zod"]["output"];
|
|
538
539
|
} & {
|
|
539
540
|
-readonly [k in keyof T as T[k] extends OptionalOutSchema ? k : never]?: T[k]["_zod"]["output"];
|
|
540
541
|
} & Extra>;
|
|
541
|
-
export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? Record<string, unknown> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
542
|
+
export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : Record<string, core.input<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
|
|
542
543
|
-readonly [k in keyof T as T[k] extends OptionalInSchema ? never : k]: T[k]["_zod"]["input"];
|
|
543
544
|
} & {
|
|
544
545
|
-readonly [k in keyof T as T[k] extends OptionalInSchema ? k : never]?: T[k]["_zod"]["input"];
|
|
@@ -598,12 +599,19 @@ export interface $ZodUnionDef<Options extends readonly SomeType[] = readonly $Zo
|
|
|
598
599
|
type: "union";
|
|
599
600
|
options: Options;
|
|
600
601
|
}
|
|
601
|
-
|
|
602
|
+
type IsOptionalIn<T extends SomeType> = T extends OptionalInSchema ? true : false;
|
|
603
|
+
type IsOptionalOut<T extends SomeType> = T extends OptionalOutSchema ? true : false;
|
|
604
|
+
export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends _$ZodTypeInternals {
|
|
602
605
|
def: $ZodUnionDef<T>;
|
|
603
606
|
isst: errors.$ZodIssueInvalidUnion;
|
|
604
607
|
pattern: T[number]["_zod"]["pattern"];
|
|
608
|
+
values: T[number]["_zod"]["values"];
|
|
609
|
+
output: $InferUnionOutput<T[number]>;
|
|
610
|
+
input: $InferUnionInput<T[number]>;
|
|
611
|
+
optin: IsOptionalIn<T[number]> extends false ? "optional" | undefined : "optional";
|
|
612
|
+
optout: IsOptionalOut<T[number]> extends false ? "optional" | undefined : "optional";
|
|
605
613
|
}
|
|
606
|
-
export interface $ZodUnion<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodType {
|
|
614
|
+
export interface $ZodUnion<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodType<any, any, $ZodUnionInternals<T>> {
|
|
607
615
|
_zod: $ZodUnionInternals<T>;
|
|
608
616
|
}
|
|
609
617
|
export declare const $ZodUnion: core.$constructor<$ZodUnion>;
|
|
@@ -627,6 +635,8 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
|
|
|
627
635
|
export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
|
|
628
636
|
def: $ZodIntersectionDef<A, B>;
|
|
629
637
|
isst: never;
|
|
638
|
+
optin: A["_zod"]["optin"] | B["_zod"]["optin"];
|
|
639
|
+
optout: A["_zod"]["optout"] | B["_zod"]["optout"];
|
|
630
640
|
}
|
|
631
641
|
export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
|
632
642
|
_zod: $ZodIntersectionInternals<A, B>;
|
|
@@ -673,12 +683,17 @@ export interface $ZodRecordDef<Key extends $ZodRecordKey = $ZodRecordKey, Value
|
|
|
673
683
|
keyType: Key;
|
|
674
684
|
valueType: Value;
|
|
675
685
|
}
|
|
676
|
-
export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> =
|
|
677
|
-
export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> =
|
|
686
|
+
export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = Key extends $partial ? Partial<Record<core.output<Key>, core.output<Value>>> : Record<core.output<Key>, core.output<Value>>;
|
|
687
|
+
export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = Key extends $partial ? Partial<Record<core.input<Key>, core.input<Value>>> : Record<core.input<Key>, core.input<Value>>;
|
|
678
688
|
export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
|
|
679
689
|
def: $ZodRecordDef<Key, Value>;
|
|
680
690
|
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
|
|
691
|
+
optin?: "optional" | undefined;
|
|
692
|
+
optout?: "optional" | undefined;
|
|
681
693
|
}
|
|
694
|
+
export type $partial = {
|
|
695
|
+
"~~partial": true;
|
|
696
|
+
};
|
|
682
697
|
export interface $ZodRecord<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodType {
|
|
683
698
|
_zod: $ZodRecordInternals<Key, Value>;
|
|
684
699
|
}
|
|
@@ -691,6 +706,8 @@ export interface $ZodMapDef<Key extends SomeType = $ZodType, Value extends SomeT
|
|
|
691
706
|
export interface $ZodMapInternals<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodTypeInternals<Map<core.output<Key>, core.output<Value>>, Map<core.input<Key>, core.input<Value>>> {
|
|
692
707
|
def: $ZodMapDef<Key, Value>;
|
|
693
708
|
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey | errors.$ZodIssueInvalidElement<unknown>;
|
|
709
|
+
optin?: "optional" | undefined;
|
|
710
|
+
optout?: "optional" | undefined;
|
|
694
711
|
}
|
|
695
712
|
export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodType {
|
|
696
713
|
_zod: $ZodMapInternals<Key, Value>;
|
|
@@ -703,6 +720,8 @@ export interface $ZodSetDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
|
|
|
703
720
|
export interface $ZodSetInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<Set<core.output<T>>, Set<core.input<T>>> {
|
|
704
721
|
def: $ZodSetDef<T>;
|
|
705
722
|
isst: errors.$ZodIssueInvalidType;
|
|
723
|
+
optin?: "optional" | undefined;
|
|
724
|
+
optout?: "optional" | undefined;
|
|
706
725
|
}
|
|
707
726
|
export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
|
|
708
727
|
_zod: $ZodSetInternals<T>;
|
|
@@ -815,6 +834,7 @@ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeD
|
|
|
815
834
|
export interface $ZodDefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
|
|
816
835
|
def: $ZodDefaultDef<T>;
|
|
817
836
|
optin: "optional";
|
|
837
|
+
optout?: "optional" | undefined;
|
|
818
838
|
isst: never;
|
|
819
839
|
values: T["_zod"]["values"];
|
|
820
840
|
}
|
|
@@ -831,6 +851,7 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
|
|
|
831
851
|
export interface $ZodPrefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
|
|
832
852
|
def: $ZodPrefaultDef<T>;
|
|
833
853
|
optin: "optional";
|
|
854
|
+
optout?: "optional" | undefined;
|
|
834
855
|
isst: never;
|
|
835
856
|
values: T["_zod"]["values"];
|
|
836
857
|
}
|
|
@@ -846,6 +867,8 @@ export interface $ZodNonOptionalInternals<T extends SomeType = $ZodType> extends
|
|
|
846
867
|
def: $ZodNonOptionalDef<T>;
|
|
847
868
|
isst: errors.$ZodIssueInvalidType;
|
|
848
869
|
values: T["_zod"]["values"];
|
|
870
|
+
optin: "optional" | undefined;
|
|
871
|
+
optout: "optional" | undefined;
|
|
849
872
|
}
|
|
850
873
|
export interface $ZodNonOptional<T extends SomeType = $ZodType> extends $ZodType {
|
|
851
874
|
_zod: $ZodNonOptionalInternals<T>;
|
|
@@ -858,6 +881,8 @@ export interface $ZodSuccessDef<T extends SomeType = $ZodType> extends $ZodTypeD
|
|
|
858
881
|
export interface $ZodSuccessInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<boolean, core.input<T>> {
|
|
859
882
|
def: $ZodSuccessDef<T>;
|
|
860
883
|
isst: never;
|
|
884
|
+
optin: T["_zod"]["optin"];
|
|
885
|
+
optout: "optional" | undefined;
|
|
861
886
|
}
|
|
862
887
|
export interface $ZodSuccess<T extends SomeType = $ZodType> extends $ZodType {
|
|
863
888
|
_zod: $ZodSuccessInternals<T>;
|
|
@@ -924,6 +949,7 @@ export interface $ZodReadonlyInternals<T extends SomeType = $ZodType> extends $Z
|
|
|
924
949
|
optout: T["_zod"]["optout"];
|
|
925
950
|
isst: never;
|
|
926
951
|
propValues: T["_zod"]["propValues"];
|
|
952
|
+
values: T["_zod"]["values"];
|
|
927
953
|
}
|
|
928
954
|
export interface $ZodReadonly<T extends SomeType = $ZodType> extends $ZodType {
|
|
929
955
|
_zod: $ZodReadonlyInternals<T>;
|
package/v4/core/schemas.js
CHANGED
|
@@ -8,8 +8,6 @@ import { version } from "./versions.js";
|
|
|
8
8
|
export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def) => {
|
|
9
9
|
var _a;
|
|
10
10
|
inst ?? (inst = {});
|
|
11
|
-
// avoids issues with using Math.random() in Next.js caching
|
|
12
|
-
util.defineLazy(inst._zod, "id", () => def.type + "_" + util.randomString(10));
|
|
13
11
|
inst._zod.def = def; // set _def property
|
|
14
12
|
inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
|
|
15
13
|
inst._zod.version = version;
|
|
@@ -158,7 +156,9 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
|
|
|
158
156
|
$ZodStringFormat.init(inst, def);
|
|
159
157
|
inst._zod.check = (payload) => {
|
|
160
158
|
try {
|
|
161
|
-
const
|
|
159
|
+
const orig = payload.value;
|
|
160
|
+
const url = new URL(orig);
|
|
161
|
+
const href = url.href;
|
|
162
162
|
if (def.hostname) {
|
|
163
163
|
def.hostname.lastIndex = 0;
|
|
164
164
|
if (!def.hostname.test(url.hostname)) {
|
|
@@ -187,6 +187,13 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
|
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
+
// payload.value = url.href;
|
|
191
|
+
if (!orig.endsWith("/") && href.endsWith("/")) {
|
|
192
|
+
payload.value = href.slice(0, -1);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
payload.value = href;
|
|
196
|
+
}
|
|
190
197
|
return;
|
|
191
198
|
}
|
|
192
199
|
catch (_) {
|
|
@@ -515,6 +522,8 @@ export const $ZodUndefined = /*@__PURE__*/ core.$constructor("$ZodUndefined", (i
|
|
|
515
522
|
$ZodType.init(inst, def);
|
|
516
523
|
inst._zod.pattern = regexes.undefined;
|
|
517
524
|
inst._zod.values = new Set([undefined]);
|
|
525
|
+
inst._zod.optin = "optional";
|
|
526
|
+
inst._zod.optout = "optional";
|
|
518
527
|
inst._zod.parse = (payload, _ctx) => {
|
|
519
528
|
const input = payload.value;
|
|
520
529
|
if (typeof input === "undefined")
|
|
@@ -718,8 +727,9 @@ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, d
|
|
|
718
727
|
};
|
|
719
728
|
doc.write(`const input = payload.value;`);
|
|
720
729
|
const ids = Object.create(null);
|
|
730
|
+
let counter = 0;
|
|
721
731
|
for (const key of normalized.keys) {
|
|
722
|
-
ids[key] =
|
|
732
|
+
ids[key] = `key_${counter++}`;
|
|
723
733
|
}
|
|
724
734
|
// A: preserve key order {
|
|
725
735
|
doc.write(`const newResult = {}`);
|
|
@@ -878,6 +888,8 @@ function handleUnionResults(results, final, inst, ctx) {
|
|
|
878
888
|
}
|
|
879
889
|
export const $ZodUnion = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def) => {
|
|
880
890
|
$ZodType.init(inst, def);
|
|
891
|
+
util.defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
|
|
892
|
+
util.defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
|
|
881
893
|
util.defineLazy(inst._zod, "values", () => {
|
|
882
894
|
if (def.options.every((o) => o._zod.values)) {
|
|
883
895
|
return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
@@ -1519,7 +1531,7 @@ export const $ZodSuccess = /*@__PURE__*/ core.$constructor("$ZodSuccess", (inst,
|
|
|
1519
1531
|
});
|
|
1520
1532
|
export const $ZodCatch = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
|
|
1521
1533
|
$ZodType.init(inst, def);
|
|
1522
|
-
|
|
1534
|
+
inst._zod.optin = "optional";
|
|
1523
1535
|
util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
1524
1536
|
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
1525
1537
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -1591,6 +1603,7 @@ function handlePipeResult(left, def, ctx) {
|
|
|
1591
1603
|
export const $ZodReadonly = /*@__PURE__*/ core.$constructor("$ZodReadonly", (inst, def) => {
|
|
1592
1604
|
$ZodType.init(inst, def);
|
|
1593
1605
|
util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
1606
|
+
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
1594
1607
|
util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
1595
1608
|
util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
1596
1609
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -36,7 +36,7 @@ class JSONSchemaGenerator {
|
|
|
36
36
|
return seen.schema;
|
|
37
37
|
}
|
|
38
38
|
// initialize
|
|
39
|
-
const result = { schema: {}, count: 1, cycle: undefined };
|
|
39
|
+
const result = { schema: {}, count: 1, cycle: undefined, path: _params.path };
|
|
40
40
|
this.seen.set(schema, result);
|
|
41
41
|
// custom method overrides default behavior
|
|
42
42
|
const overrideSchema = schema._zod.toJSONSchema?.();
|
|
@@ -141,11 +141,6 @@ class JSONSchemaGenerator {
|
|
|
141
141
|
}
|
|
142
142
|
break;
|
|
143
143
|
}
|
|
144
|
-
case "undefined": {
|
|
145
|
-
const json = _json;
|
|
146
|
-
json.type = "null";
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
144
|
case "null": {
|
|
150
145
|
_json.type = "null";
|
|
151
146
|
break;
|
|
@@ -156,8 +151,10 @@ class JSONSchemaGenerator {
|
|
|
156
151
|
case "unknown": {
|
|
157
152
|
break;
|
|
158
153
|
}
|
|
159
|
-
case "
|
|
160
|
-
|
|
154
|
+
case "undefined": {
|
|
155
|
+
if (this.unrepresentable === "throw") {
|
|
156
|
+
throw new Error("Undefined cannot be represented in JSON Schema");
|
|
157
|
+
}
|
|
161
158
|
break;
|
|
162
159
|
}
|
|
163
160
|
case "void": {
|
|
@@ -166,6 +163,10 @@ class JSONSchemaGenerator {
|
|
|
166
163
|
}
|
|
167
164
|
break;
|
|
168
165
|
}
|
|
166
|
+
case "never": {
|
|
167
|
+
_json.not = {};
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
169
170
|
case "date": {
|
|
170
171
|
if (this.unrepresentable === "throw") {
|
|
171
172
|
throw new Error("Date cannot be represented in JSON Schema");
|
|
@@ -654,6 +655,7 @@ class JSONSchemaGenerator {
|
|
|
654
655
|
this.override({
|
|
655
656
|
zodSchema: zodSchema,
|
|
656
657
|
jsonSchema: schema,
|
|
658
|
+
path: seen.path ?? [],
|
|
657
659
|
});
|
|
658
660
|
};
|
|
659
661
|
for (const entry of [...this.seen.entries()].reverse()) {
|
|
@@ -17,9 +17,10 @@ interface JSONSchemaGeneratorParams {
|
|
|
17
17
|
override?: (ctx: {
|
|
18
18
|
zodSchema: schemas.$ZodTypes;
|
|
19
19
|
jsonSchema: JSONSchema.BaseSchema;
|
|
20
|
+
path: (string | number)[];
|
|
20
21
|
}) => void;
|
|
21
22
|
/** Whether to extract the `"input"` or `"output"` type. Relevant to transforms, Error converting schema to JSONz, defaults, coerced primitives, etc.
|
|
22
|
-
* - `"output" —
|
|
23
|
+
* - `"output"` — Default. Convert the output schema.
|
|
23
24
|
* - `"input"` — Convert the input schema. */
|
|
24
25
|
io?: "input" | "output";
|
|
25
26
|
}
|
|
@@ -54,6 +55,8 @@ interface Seen {
|
|
|
54
55
|
cycle?: (string | number)[] | undefined;
|
|
55
56
|
isParent?: boolean | undefined;
|
|
56
57
|
ref?: schemas.$ZodType | undefined | null;
|
|
58
|
+
/** JSON Schema property path for this schema */
|
|
59
|
+
path?: (string | number)[] | undefined;
|
|
57
60
|
}
|
|
58
61
|
export declare class JSONSchemaGenerator {
|
|
59
62
|
metadataRegistry: $ZodRegistry<Record<string, any>>;
|
|
@@ -62,6 +65,7 @@ export declare class JSONSchemaGenerator {
|
|
|
62
65
|
override: (ctx: {
|
|
63
66
|
zodSchema: schemas.$ZodTypes;
|
|
64
67
|
jsonSchema: JSONSchema.BaseSchema;
|
|
68
|
+
path: (string | number)[];
|
|
65
69
|
}) => void;
|
|
66
70
|
io: "input" | "output";
|
|
67
71
|
counter: number;
|
|
@@ -17,9 +17,10 @@ interface JSONSchemaGeneratorParams {
|
|
|
17
17
|
override?: (ctx: {
|
|
18
18
|
zodSchema: schemas.$ZodTypes;
|
|
19
19
|
jsonSchema: JSONSchema.BaseSchema;
|
|
20
|
+
path: (string | number)[];
|
|
20
21
|
}) => void;
|
|
21
22
|
/** Whether to extract the `"input"` or `"output"` type. Relevant to transforms, Error converting schema to JSONz, defaults, coerced primitives, etc.
|
|
22
|
-
* - `"output" —
|
|
23
|
+
* - `"output"` — Default. Convert the output schema.
|
|
23
24
|
* - `"input"` — Convert the input schema. */
|
|
24
25
|
io?: "input" | "output";
|
|
25
26
|
}
|
|
@@ -54,6 +55,8 @@ interface Seen {
|
|
|
54
55
|
cycle?: (string | number)[] | undefined;
|
|
55
56
|
isParent?: boolean | undefined;
|
|
56
57
|
ref?: schemas.$ZodType | undefined | null;
|
|
58
|
+
/** JSON Schema property path for this schema */
|
|
59
|
+
path?: (string | number)[] | undefined;
|
|
57
60
|
}
|
|
58
61
|
export declare class JSONSchemaGenerator {
|
|
59
62
|
metadataRegistry: $ZodRegistry<Record<string, any>>;
|
|
@@ -62,6 +65,7 @@ export declare class JSONSchemaGenerator {
|
|
|
62
65
|
override: (ctx: {
|
|
63
66
|
zodSchema: schemas.$ZodTypes;
|
|
64
67
|
jsonSchema: JSONSchema.BaseSchema;
|
|
68
|
+
path: (string | number)[];
|
|
65
69
|
}) => void;
|
|
66
70
|
io: "input" | "output";
|
|
67
71
|
counter: number;
|
|
@@ -32,7 +32,7 @@ export class JSONSchemaGenerator {
|
|
|
32
32
|
return seen.schema;
|
|
33
33
|
}
|
|
34
34
|
// initialize
|
|
35
|
-
const result = { schema: {}, count: 1, cycle: undefined };
|
|
35
|
+
const result = { schema: {}, count: 1, cycle: undefined, path: _params.path };
|
|
36
36
|
this.seen.set(schema, result);
|
|
37
37
|
// custom method overrides default behavior
|
|
38
38
|
const overrideSchema = schema._zod.toJSONSchema?.();
|
|
@@ -137,11 +137,6 @@ export class JSONSchemaGenerator {
|
|
|
137
137
|
}
|
|
138
138
|
break;
|
|
139
139
|
}
|
|
140
|
-
case "undefined": {
|
|
141
|
-
const json = _json;
|
|
142
|
-
json.type = "null";
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
140
|
case "null": {
|
|
146
141
|
_json.type = "null";
|
|
147
142
|
break;
|
|
@@ -152,8 +147,10 @@ export class JSONSchemaGenerator {
|
|
|
152
147
|
case "unknown": {
|
|
153
148
|
break;
|
|
154
149
|
}
|
|
155
|
-
case "
|
|
156
|
-
|
|
150
|
+
case "undefined": {
|
|
151
|
+
if (this.unrepresentable === "throw") {
|
|
152
|
+
throw new Error("Undefined cannot be represented in JSON Schema");
|
|
153
|
+
}
|
|
157
154
|
break;
|
|
158
155
|
}
|
|
159
156
|
case "void": {
|
|
@@ -162,6 +159,10 @@ export class JSONSchemaGenerator {
|
|
|
162
159
|
}
|
|
163
160
|
break;
|
|
164
161
|
}
|
|
162
|
+
case "never": {
|
|
163
|
+
_json.not = {};
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
165
166
|
case "date": {
|
|
166
167
|
if (this.unrepresentable === "throw") {
|
|
167
168
|
throw new Error("Date cannot be represented in JSON Schema");
|
|
@@ -650,6 +651,7 @@ export class JSONSchemaGenerator {
|
|
|
650
651
|
this.override({
|
|
651
652
|
zodSchema: zodSchema,
|
|
652
653
|
jsonSchema: schema,
|
|
654
|
+
path: seen.path ?? [],
|
|
653
655
|
});
|
|
654
656
|
};
|
|
655
657
|
for (const entry of [...this.seen.entries()].reverse()) {
|
package/v4/mini/schemas.d.cts
CHANGED
|
@@ -234,7 +234,7 @@ export interface ZodMiniRecord<Key extends core.$ZodRecordKey = core.$ZodRecordK
|
|
|
234
234
|
}
|
|
235
235
|
export declare const ZodMiniRecord: core.$constructor<ZodMiniRecord>;
|
|
236
236
|
export declare function record<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<Key, Value>;
|
|
237
|
-
export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<
|
|
237
|
+
export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<Key & core.$partial, Value>;
|
|
238
238
|
export interface ZodMiniMap<Key extends SomeType = core.$ZodType, Value extends SomeType = core.$ZodType> extends _ZodMiniType<core.$ZodMapInternals<Key, Value>> {
|
|
239
239
|
}
|
|
240
240
|
export declare const ZodMiniMap: core.$constructor<ZodMiniMap>;
|
package/v4/mini/schemas.d.ts
CHANGED
|
@@ -234,7 +234,7 @@ export interface ZodMiniRecord<Key extends core.$ZodRecordKey = core.$ZodRecordK
|
|
|
234
234
|
}
|
|
235
235
|
export declare const ZodMiniRecord: core.$constructor<ZodMiniRecord>;
|
|
236
236
|
export declare function record<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<Key, Value>;
|
|
237
|
-
export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<
|
|
237
|
+
export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<Key & core.$partial, Value>;
|
|
238
238
|
export interface ZodMiniMap<Key extends SomeType = core.$ZodType, Value extends SomeType = core.$ZodType> extends _ZodMiniType<core.$ZodMapInternals<Key, Value>> {
|
|
239
239
|
}
|
|
240
240
|
export declare const ZodMiniMap: core.$constructor<ZodMiniMap>;
|