zod 3.26.0-canary.20250703T215303 → 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.
@@ -1023,11 +1023,11 @@ export function partialRecord<Key extends core.$ZodRecordKey, Value extends Some
1023
1023
  keyType: Key,
1024
1024
  valueType: Value,
1025
1025
  params?: string | core.$ZodRecordParams
1026
- ): ZodMiniRecord<ZodMiniUnion<[Key, ZodMiniNever]>, Value> {
1026
+ ): ZodMiniRecord<Key & core.$partial, Value> {
1027
1027
  return new ZodMiniRecord({
1028
1028
  type: "record",
1029
1029
  keyType: union([keyType, never()]),
1030
- valueType: valueType as any as core.$ZodType,
1030
+ valueType: valueType as any,
1031
1031
  ...util.normalizeParams(params),
1032
1032
  }) as any;
1033
1033
  }
@@ -99,6 +99,12 @@ test("z.url", () => {
99
99
  expect(a.parse("http://localhost:3000")).toEqual("http://localhost:3000");
100
100
  expect(a.parse("https://localhost:3000")).toEqual("https://localhost:3000");
101
101
 
102
+ // test trimming
103
+ expect(a.parse(" http://example.com ")).toEqual("http://example.com");
104
+ expect(a.parse(" http://example.com/")).toEqual("http://example.com/");
105
+ expect(a.parse(" http://example.com")).toEqual("http://example.com");
106
+ expect(a.parse(" http://example.com//")).toEqual("http://example.com//");
107
+
102
108
  // invalid URLs
103
109
  expect(() => a.parse("not-a-url")).toThrow();
104
110
  // expect(() => a.parse("http:/example.com")).toThrow();
@@ -151,6 +151,7 @@ export interface ZodString extends _ZodString<core.$ZodStringInternals<string>>
151
151
  }
152
152
  export declare const ZodString: core.$constructor<ZodString>;
153
153
  export declare function string(params?: string | core.$ZodStringParams): ZodString;
154
+ export declare function string<T extends string>(params?: string | core.$ZodStringParams): core.$ZodType<T, T>;
154
155
  export interface ZodStringFormat<Format extends string = string> extends _ZodString<core.$ZodStringFormatInternals<Format>> {
155
156
  }
156
157
  export declare const ZodStringFormat: core.$constructor<ZodStringFormat>;
@@ -474,7 +475,7 @@ export interface ZodRecord<Key extends core.$ZodRecordKey = core.$ZodRecordKey,
474
475
  }
475
476
  export declare const ZodRecord: core.$constructor<ZodRecord>;
476
477
  export declare function record<Key extends core.$ZodRecordKey, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodRecord<Key, Value>;
477
- export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodRecord<ZodUnion<[Key, ZodNever]>, Value>;
478
+ export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodRecord<Key & core.$partial, Value>;
478
479
  export interface ZodMap<Key extends core.SomeType = core.$ZodType, Value extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodMapInternals<Key, Value>>, core.$ZodMap<Key, Value> {
479
480
  keyType: Key;
480
481
  valueType: Value;
@@ -151,6 +151,7 @@ export interface ZodString extends _ZodString<core.$ZodStringInternals<string>>
151
151
  }
152
152
  export declare const ZodString: core.$constructor<ZodString>;
153
153
  export declare function string(params?: string | core.$ZodStringParams): ZodString;
154
+ export declare function string<T extends string>(params?: string | core.$ZodStringParams): core.$ZodType<T, T>;
154
155
  export interface ZodStringFormat<Format extends string = string> extends _ZodString<core.$ZodStringFormatInternals<Format>> {
155
156
  }
156
157
  export declare const ZodStringFormat: core.$constructor<ZodStringFormat>;
@@ -474,7 +475,7 @@ export interface ZodRecord<Key extends core.$ZodRecordKey = core.$ZodRecordKey,
474
475
  }
475
476
  export declare const ZodRecord: core.$constructor<ZodRecord>;
476
477
  export declare function record<Key extends core.$ZodRecordKey, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodRecord<Key, Value>;
477
- export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodRecord<ZodUnion<[Key, ZodNever]>, Value>;
478
+ export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodRecord<Key & core.$partial, Value>;
478
479
  export interface ZodMap<Key extends core.SomeType = core.$ZodType, Value extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodMapInternals<Key, Value>>, core.$ZodMap<Key, Value> {
479
480
  keyType: Key;
480
481
  valueType: Value;
@@ -21,6 +21,10 @@ class $ZodRegistry {
21
21
  return this;
22
22
  }
23
23
  remove(schema) {
24
+ const meta = this._map.get(schema);
25
+ if (meta && typeof meta === "object" && "id" in meta) {
26
+ this._idmap.delete(meta.id);
27
+ }
24
28
  this._map.delete(schema);
25
29
  return this;
26
30
  }
@@ -17,6 +17,10 @@ export class $ZodRegistry {
17
17
  return this;
18
18
  }
19
19
  remove(schema) {
20
+ const meta = this._map.get(schema);
21
+ if (meta && typeof meta === "object" && "id" in meta) {
22
+ this._idmap.delete(meta.id);
23
+ }
20
24
  this._map.delete(schema);
21
25
  return this;
22
26
  }
@@ -38,8 +38,6 @@ const versions_js_1 = require("./versions.cjs");
38
38
  exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
39
39
  var _a;
40
40
  inst ?? (inst = {});
41
- // avoids issues with using Math.random() in Next.js caching
42
- util.defineLazy(inst._zod, "id", () => def.type + "_" + util.randomString(10));
43
41
  inst._zod.def = def; // set _def property
44
42
  inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
45
43
  inst._zod.version = versions_js_1.version;
@@ -189,7 +187,9 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
189
187
  exports.$ZodStringFormat.init(inst, def);
190
188
  inst._zod.check = (payload) => {
191
189
  try {
192
- const url = new URL(payload.value);
190
+ const orig = payload.value;
191
+ const url = new URL(orig);
192
+ const href = url.href;
193
193
  if (def.hostname) {
194
194
  def.hostname.lastIndex = 0;
195
195
  if (!def.hostname.test(url.hostname)) {
@@ -218,6 +218,13 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
218
218
  });
219
219
  }
220
220
  }
221
+ // payload.value = url.href;
222
+ if (!orig.endsWith("/") && href.endsWith("/")) {
223
+ payload.value = href.slice(0, -1);
224
+ }
225
+ else {
226
+ payload.value = href;
227
+ }
221
228
  return;
222
229
  }
223
230
  catch (_) {
@@ -751,8 +758,9 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
751
758
  };
752
759
  doc.write(`const input = payload.value;`);
753
760
  const ids = Object.create(null);
761
+ let counter = 0;
754
762
  for (const key of normalized.keys) {
755
- ids[key] = util.randomString(15);
763
+ ids[key] = `key_${counter++}`;
756
764
  }
757
765
  // A: preserve key order {
758
766
  doc.write(`const newResult = {}`);
@@ -1626,6 +1634,7 @@ function handlePipeResult(left, def, ctx) {
1626
1634
  exports.$ZodReadonly = core.$constructor("$ZodReadonly", (inst, def) => {
1627
1635
  exports.$ZodType.init(inst, def);
1628
1636
  util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1637
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1629
1638
  util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1630
1639
  util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1631
1640
  inst._zod.parse = (payload, ctx) => {
@@ -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<core.output<T>[], core.input<T>[]> {
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<core.output<T>[], core.input<T>[], $ZodArrayInternals<T>> {
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"];
@@ -600,14 +601,17 @@ export interface $ZodUnionDef<Options extends readonly SomeType[] = readonly $Zo
600
601
  }
601
602
  type IsOptionalIn<T extends SomeType> = T extends OptionalInSchema ? true : false;
602
603
  type IsOptionalOut<T extends SomeType> = T extends OptionalOutSchema ? true : false;
603
- export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodTypeInternals<$InferUnionOutput<T[number]>, $InferUnionInput<T[number]>> {
604
+ export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends _$ZodTypeInternals {
604
605
  def: $ZodUnionDef<T>;
605
606
  isst: errors.$ZodIssueInvalidUnion;
606
607
  pattern: T[number]["_zod"]["pattern"];
608
+ values: T[number]["_zod"]["values"];
609
+ output: $InferUnionOutput<T[number]>;
610
+ input: $InferUnionInput<T[number]>;
607
611
  optin: IsOptionalIn<T[number]> extends false ? "optional" | undefined : "optional";
608
612
  optout: IsOptionalOut<T[number]> extends false ? "optional" | undefined : "optional";
609
613
  }
610
- 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>> {
611
615
  _zod: $ZodUnionInternals<T>;
612
616
  }
613
617
  export declare const $ZodUnion: core.$constructor<$ZodUnion>;
@@ -631,6 +635,8 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
631
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>> {
632
636
  def: $ZodIntersectionDef<A, B>;
633
637
  isst: never;
638
+ optin: A["_zod"]["optin"] | B["_zod"]["optin"];
639
+ optout: A["_zod"]["optout"] | B["_zod"]["optout"];
634
640
  }
635
641
  export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
636
642
  _zod: $ZodIntersectionInternals<A, B>;
@@ -677,12 +683,17 @@ export interface $ZodRecordDef<Key extends $ZodRecordKey = $ZodRecordKey, Value
677
683
  keyType: Key;
678
684
  valueType: Value;
679
685
  }
680
- export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = undefined extends Key["_zod"]["values"] ? string extends core.output<Key> ? Record<core.output<Key>, core.output<Value>> : number extends core.output<Key> ? Record<core.output<Key>, core.output<Value>> : symbol extends core.output<Key> ? Record<core.output<Key>, core.output<Value>> : Partial<Record<core.output<Key>, core.output<Value>>> : Record<core.output<Key>, core.output<Value>>;
681
- export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = undefined extends Key["_zod"]["values"] ? string extends core.input<Key> ? Record<core.input<Key>, core.input<Value>> : number extends core.input<Key> ? Record<core.input<Key>, core.input<Value>> : symbol extends core.input<Key> ? Record<core.input<Key>, core.input<Value>> : Partial<Record<core.input<Key>, core.input<Value>>> : Record<core.input<Key>, core.input<Value>>;
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>>;
682
688
  export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
683
689
  def: $ZodRecordDef<Key, Value>;
684
690
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
691
+ optin?: "optional" | undefined;
692
+ optout?: "optional" | undefined;
685
693
  }
694
+ export type $partial = {
695
+ "~~partial": true;
696
+ };
686
697
  export interface $ZodRecord<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodType {
687
698
  _zod: $ZodRecordInternals<Key, Value>;
688
699
  }
@@ -695,6 +706,8 @@ export interface $ZodMapDef<Key extends SomeType = $ZodType, Value extends SomeT
695
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>>> {
696
707
  def: $ZodMapDef<Key, Value>;
697
708
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey | errors.$ZodIssueInvalidElement<unknown>;
709
+ optin?: "optional" | undefined;
710
+ optout?: "optional" | undefined;
698
711
  }
699
712
  export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodType {
700
713
  _zod: $ZodMapInternals<Key, Value>;
@@ -707,6 +720,8 @@ export interface $ZodSetDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
707
720
  export interface $ZodSetInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<Set<core.output<T>>, Set<core.input<T>>> {
708
721
  def: $ZodSetDef<T>;
709
722
  isst: errors.$ZodIssueInvalidType;
723
+ optin?: "optional" | undefined;
724
+ optout?: "optional" | undefined;
710
725
  }
711
726
  export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
712
727
  _zod: $ZodSetInternals<T>;
@@ -819,6 +834,7 @@ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeD
819
834
  export interface $ZodDefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
820
835
  def: $ZodDefaultDef<T>;
821
836
  optin: "optional";
837
+ optout?: "optional" | undefined;
822
838
  isst: never;
823
839
  values: T["_zod"]["values"];
824
840
  }
@@ -835,6 +851,7 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
835
851
  export interface $ZodPrefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
836
852
  def: $ZodPrefaultDef<T>;
837
853
  optin: "optional";
854
+ optout?: "optional" | undefined;
838
855
  isst: never;
839
856
  values: T["_zod"]["values"];
840
857
  }
@@ -850,6 +867,8 @@ export interface $ZodNonOptionalInternals<T extends SomeType = $ZodType> extends
850
867
  def: $ZodNonOptionalDef<T>;
851
868
  isst: errors.$ZodIssueInvalidType;
852
869
  values: T["_zod"]["values"];
870
+ optin: "optional" | undefined;
871
+ optout: "optional" | undefined;
853
872
  }
854
873
  export interface $ZodNonOptional<T extends SomeType = $ZodType> extends $ZodType {
855
874
  _zod: $ZodNonOptionalInternals<T>;
@@ -862,6 +881,8 @@ export interface $ZodSuccessDef<T extends SomeType = $ZodType> extends $ZodTypeD
862
881
  export interface $ZodSuccessInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<boolean, core.input<T>> {
863
882
  def: $ZodSuccessDef<T>;
864
883
  isst: never;
884
+ optin: T["_zod"]["optin"];
885
+ optout: "optional" | undefined;
865
886
  }
866
887
  export interface $ZodSuccess<T extends SomeType = $ZodType> extends $ZodType {
867
888
  _zod: $ZodSuccessInternals<T>;
@@ -928,6 +949,7 @@ export interface $ZodReadonlyInternals<T extends SomeType = $ZodType> extends $Z
928
949
  optout: T["_zod"]["optout"];
929
950
  isst: never;
930
951
  propValues: T["_zod"]["propValues"];
952
+ values: T["_zod"]["values"];
931
953
  }
932
954
  export interface $ZodReadonly<T extends SomeType = $ZodType> extends $ZodType {
933
955
  _zod: $ZodReadonlyInternals<T>;
@@ -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<core.output<T>[], core.input<T>[]> {
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<core.output<T>[], core.input<T>[], $ZodArrayInternals<T>> {
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"];
@@ -600,14 +601,17 @@ export interface $ZodUnionDef<Options extends readonly SomeType[] = readonly $Zo
600
601
  }
601
602
  type IsOptionalIn<T extends SomeType> = T extends OptionalInSchema ? true : false;
602
603
  type IsOptionalOut<T extends SomeType> = T extends OptionalOutSchema ? true : false;
603
- export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodTypeInternals<$InferUnionOutput<T[number]>, $InferUnionInput<T[number]>> {
604
+ export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends _$ZodTypeInternals {
604
605
  def: $ZodUnionDef<T>;
605
606
  isst: errors.$ZodIssueInvalidUnion;
606
607
  pattern: T[number]["_zod"]["pattern"];
608
+ values: T[number]["_zod"]["values"];
609
+ output: $InferUnionOutput<T[number]>;
610
+ input: $InferUnionInput<T[number]>;
607
611
  optin: IsOptionalIn<T[number]> extends false ? "optional" | undefined : "optional";
608
612
  optout: IsOptionalOut<T[number]> extends false ? "optional" | undefined : "optional";
609
613
  }
610
- 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>> {
611
615
  _zod: $ZodUnionInternals<T>;
612
616
  }
613
617
  export declare const $ZodUnion: core.$constructor<$ZodUnion>;
@@ -631,6 +635,8 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
631
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>> {
632
636
  def: $ZodIntersectionDef<A, B>;
633
637
  isst: never;
638
+ optin: A["_zod"]["optin"] | B["_zod"]["optin"];
639
+ optout: A["_zod"]["optout"] | B["_zod"]["optout"];
634
640
  }
635
641
  export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
636
642
  _zod: $ZodIntersectionInternals<A, B>;
@@ -677,12 +683,17 @@ export interface $ZodRecordDef<Key extends $ZodRecordKey = $ZodRecordKey, Value
677
683
  keyType: Key;
678
684
  valueType: Value;
679
685
  }
680
- export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = undefined extends Key["_zod"]["values"] ? string extends core.output<Key> ? Record<core.output<Key>, core.output<Value>> : number extends core.output<Key> ? Record<core.output<Key>, core.output<Value>> : symbol extends core.output<Key> ? Record<core.output<Key>, core.output<Value>> : Partial<Record<core.output<Key>, core.output<Value>>> : Record<core.output<Key>, core.output<Value>>;
681
- export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = undefined extends Key["_zod"]["values"] ? string extends core.input<Key> ? Record<core.input<Key>, core.input<Value>> : number extends core.input<Key> ? Record<core.input<Key>, core.input<Value>> : symbol extends core.input<Key> ? Record<core.input<Key>, core.input<Value>> : Partial<Record<core.input<Key>, core.input<Value>>> : Record<core.input<Key>, core.input<Value>>;
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>>;
682
688
  export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
683
689
  def: $ZodRecordDef<Key, Value>;
684
690
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
691
+ optin?: "optional" | undefined;
692
+ optout?: "optional" | undefined;
685
693
  }
694
+ export type $partial = {
695
+ "~~partial": true;
696
+ };
686
697
  export interface $ZodRecord<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodType {
687
698
  _zod: $ZodRecordInternals<Key, Value>;
688
699
  }
@@ -695,6 +706,8 @@ export interface $ZodMapDef<Key extends SomeType = $ZodType, Value extends SomeT
695
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>>> {
696
707
  def: $ZodMapDef<Key, Value>;
697
708
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey | errors.$ZodIssueInvalidElement<unknown>;
709
+ optin?: "optional" | undefined;
710
+ optout?: "optional" | undefined;
698
711
  }
699
712
  export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodType {
700
713
  _zod: $ZodMapInternals<Key, Value>;
@@ -707,6 +720,8 @@ export interface $ZodSetDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
707
720
  export interface $ZodSetInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<Set<core.output<T>>, Set<core.input<T>>> {
708
721
  def: $ZodSetDef<T>;
709
722
  isst: errors.$ZodIssueInvalidType;
723
+ optin?: "optional" | undefined;
724
+ optout?: "optional" | undefined;
710
725
  }
711
726
  export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
712
727
  _zod: $ZodSetInternals<T>;
@@ -819,6 +834,7 @@ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeD
819
834
  export interface $ZodDefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
820
835
  def: $ZodDefaultDef<T>;
821
836
  optin: "optional";
837
+ optout?: "optional" | undefined;
822
838
  isst: never;
823
839
  values: T["_zod"]["values"];
824
840
  }
@@ -835,6 +851,7 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
835
851
  export interface $ZodPrefaultInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
836
852
  def: $ZodPrefaultDef<T>;
837
853
  optin: "optional";
854
+ optout?: "optional" | undefined;
838
855
  isst: never;
839
856
  values: T["_zod"]["values"];
840
857
  }
@@ -850,6 +867,8 @@ export interface $ZodNonOptionalInternals<T extends SomeType = $ZodType> extends
850
867
  def: $ZodNonOptionalDef<T>;
851
868
  isst: errors.$ZodIssueInvalidType;
852
869
  values: T["_zod"]["values"];
870
+ optin: "optional" | undefined;
871
+ optout: "optional" | undefined;
853
872
  }
854
873
  export interface $ZodNonOptional<T extends SomeType = $ZodType> extends $ZodType {
855
874
  _zod: $ZodNonOptionalInternals<T>;
@@ -862,6 +881,8 @@ export interface $ZodSuccessDef<T extends SomeType = $ZodType> extends $ZodTypeD
862
881
  export interface $ZodSuccessInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<boolean, core.input<T>> {
863
882
  def: $ZodSuccessDef<T>;
864
883
  isst: never;
884
+ optin: T["_zod"]["optin"];
885
+ optout: "optional" | undefined;
865
886
  }
866
887
  export interface $ZodSuccess<T extends SomeType = $ZodType> extends $ZodType {
867
888
  _zod: $ZodSuccessInternals<T>;
@@ -928,6 +949,7 @@ export interface $ZodReadonlyInternals<T extends SomeType = $ZodType> extends $Z
928
949
  optout: T["_zod"]["optout"];
929
950
  isst: never;
930
951
  propValues: T["_zod"]["propValues"];
952
+ values: T["_zod"]["values"];
931
953
  }
932
954
  export interface $ZodReadonly<T extends SomeType = $ZodType> extends $ZodType {
933
955
  _zod: $ZodReadonlyInternals<T>;
@@ -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 url = new URL(payload.value);
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 (_) {
@@ -720,8 +727,9 @@ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, d
720
727
  };
721
728
  doc.write(`const input = payload.value;`);
722
729
  const ids = Object.create(null);
730
+ let counter = 0;
723
731
  for (const key of normalized.keys) {
724
- ids[key] = util.randomString(15);
732
+ ids[key] = `key_${counter++}`;
725
733
  }
726
734
  // A: preserve key order {
727
735
  doc.write(`const newResult = {}`);
@@ -1595,6 +1603,7 @@ function handlePipeResult(left, def, ctx) {
1595
1603
  export const $ZodReadonly = /*@__PURE__*/ core.$constructor("$ZodReadonly", (inst, def) => {
1596
1604
  $ZodType.init(inst, def);
1597
1605
  util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1606
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1598
1607
  util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1599
1608
  util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1600
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?.();
@@ -151,9 +151,10 @@ class JSONSchemaGenerator {
151
151
  case "unknown": {
152
152
  break;
153
153
  }
154
- case "undefined":
155
- case "never": {
156
- _json.not = {};
154
+ case "undefined": {
155
+ if (this.unrepresentable === "throw") {
156
+ throw new Error("Undefined cannot be represented in JSON Schema");
157
+ }
157
158
  break;
158
159
  }
159
160
  case "void": {
@@ -162,6 +163,10 @@ class JSONSchemaGenerator {
162
163
  }
163
164
  break;
164
165
  }
166
+ case "never": {
167
+ _json.not = {};
168
+ break;
169
+ }
165
170
  case "date": {
166
171
  if (this.unrepresentable === "throw") {
167
172
  throw new Error("Date cannot be represented in JSON Schema");
@@ -650,6 +655,7 @@ class JSONSchemaGenerator {
650
655
  this.override({
651
656
  zodSchema: zodSchema,
652
657
  jsonSchema: schema,
658
+ path: seen.path ?? [],
653
659
  });
654
660
  };
655
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" — Default. Convert the output schema.
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" — Default. Convert the output schema.
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?.();
@@ -147,9 +147,10 @@ export class JSONSchemaGenerator {
147
147
  case "unknown": {
148
148
  break;
149
149
  }
150
- case "undefined":
151
- case "never": {
152
- _json.not = {};
150
+ case "undefined": {
151
+ if (this.unrepresentable === "throw") {
152
+ throw new Error("Undefined cannot be represented in JSON Schema");
153
+ }
153
154
  break;
154
155
  }
155
156
  case "void": {
@@ -158,6 +159,10 @@ export class JSONSchemaGenerator {
158
159
  }
159
160
  break;
160
161
  }
162
+ case "never": {
163
+ _json.not = {};
164
+ break;
165
+ }
161
166
  case "date": {
162
167
  if (this.unrepresentable === "throw") {
163
168
  throw new Error("Date cannot be represented in JSON Schema");
@@ -646,6 +651,7 @@ export class JSONSchemaGenerator {
646
651
  this.override({
647
652
  zodSchema: zodSchema,
648
653
  jsonSchema: schema,
654
+ path: seen.path ?? [],
649
655
  });
650
656
  };
651
657
  for (const entry of [...this.seen.entries()].reverse()) {
@@ -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<ZodMiniUnion<[Key, ZodMiniNever]>, Value>;
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>;