zod 4.2.0-canary.20250911T051520 → 4.2.0-canary.20250920T163917

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.2.0-canary.20250911T051520",
3
+ "version": "4.2.0-canary.20250920T163917",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -146,16 +146,14 @@ export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$construct
146
146
  // base methods
147
147
  inst.check = (...checks) => {
148
148
  return inst.clone(
149
- {
150
- ...def,
149
+ util.mergeDefs(def, {
151
150
  checks: [
152
151
  ...(def.checks ?? []),
153
152
  ...checks.map((ch) =>
154
153
  typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
155
154
  ),
156
155
  ],
157
- }
158
- // { parent: true }
156
+ })
159
157
  );
160
158
  };
161
159
  inst.clone = (def, params) => core.clone(inst, def, params);
@@ -1196,7 +1194,10 @@ export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$const
1196
1194
  core.$ZodObjectJIT.init(inst, def);
1197
1195
  ZodType.init(inst, def);
1198
1196
 
1199
- util.defineLazy(inst, "shape", () => def.shape);
1197
+ util.defineLazy(inst, "shape", () => {
1198
+ return def.shape;
1199
+ });
1200
+
1200
1201
  inst.keyof = () => _enum(Object.keys(inst._zod.def.shape)) as any;
1201
1202
  inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall as any as core.$ZodType }) as any;
1202
1203
  inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
@@ -1223,10 +1224,7 @@ export function object<T extends core.$ZodLooseShape = Partial<Record<never, cor
1223
1224
  ): ZodObject<util.Writeable<T>, core.$strip> {
1224
1225
  const def: core.$ZodObjectDef = {
1225
1226
  type: "object",
1226
- get shape() {
1227
- util.assignProp(this, "shape", shape ? util.objectClone(shape) : {});
1228
- return this.shape;
1229
- },
1227
+ shape: shape!,
1230
1228
  ...util.normalizeParams(params),
1231
1229
  };
1232
1230
  return new ZodObject(def) as any;
@@ -1240,10 +1238,7 @@ export function strictObject<T extends core.$ZodLooseShape>(
1240
1238
  ): ZodObject<T, core.$strict> {
1241
1239
  return new ZodObject({
1242
1240
  type: "object",
1243
- get shape() {
1244
- util.assignProp(this, "shape", util.objectClone(shape));
1245
- return this.shape;
1246
- },
1241
+ shape,
1247
1242
  catchall: never(),
1248
1243
  ...util.normalizeParams(params),
1249
1244
  }) as any;
@@ -1257,10 +1252,7 @@ export function looseObject<T extends core.$ZodLooseShape>(
1257
1252
  ): ZodObject<T, core.$loose> {
1258
1253
  return new ZodObject({
1259
1254
  type: "object",
1260
- get shape() {
1261
- util.assignProp(this, "shape", util.objectClone(shape));
1262
- return this.shape;
1263
- },
1255
+ shape,
1264
1256
  catchall: unknown(),
1265
1257
  ...util.normalizeParams(params),
1266
1258
  }) as any;
@@ -537,3 +537,46 @@ export type RecursiveA = z.ZodUnion<
537
537
  }>,
538
538
  ]
539
539
  >;
540
+
541
+ test("recursive type with `id` meta", () => {
542
+ const AType = z.object({
543
+ type: z.literal("a"),
544
+ name: z.string(),
545
+ });
546
+
547
+ const BType = z.object({
548
+ type: z.literal("b"),
549
+ name: z.string(),
550
+ });
551
+
552
+ const CType = z.object({
553
+ type: z.literal("c"),
554
+ name: z.string(),
555
+ });
556
+
557
+ const Schema = z.object({
558
+ type: z.literal("special").meta({ description: "Type" }),
559
+ config: z.object({
560
+ title: z.string().meta({ description: "Title" }),
561
+ get elements() {
562
+ return z.array(z.discriminatedUnion("type", [AType, BType, CType])).meta({
563
+ id: "SpecialElements",
564
+ title: "SpecialElements",
565
+ description: "Array of elements",
566
+ });
567
+ },
568
+ }),
569
+ });
570
+
571
+ Schema.parse({
572
+ type: "special",
573
+ config: {
574
+ title: "Special",
575
+ elements: [
576
+ { type: "a", name: "John" },
577
+ { type: "b", name: "Jane" },
578
+ { type: "c", name: "Jim" },
579
+ ],
580
+ },
581
+ });
582
+ });
@@ -920,6 +920,8 @@ test("CIDR v6 validation", () => {
920
920
  expect(cidrV6.safeParse("not a cidr").success).toBe(false); // Invalid format
921
921
  expect(cidrV6.safeParse("192.168.0.0/24").success).toBe(false); // IPv4 CIDR in v6 validation
922
922
  expect(cidrV6.safeParse("2001:0db8:85a3::/64/whatever-after").success).toBe(false);
923
+ expect(cidrV6.safeParse("22d9:f4a8:6a90:f3bf:dcaa:2beb:5fba:0000/112").success).toBe(true);
924
+ expect(cidrV6.safeParse("22d9:f4a8:6a90:f3bf:dcaa:2beb:5fba:0000/112/268").success).toBe(false);
923
925
  });
924
926
 
925
927
  test("E.164 validation", () => {
@@ -27,7 +27,7 @@ type MetadataType = object | undefined;
27
27
  export class $ZodRegistry<Meta extends MetadataType = MetadataType, Schema extends $ZodType = $ZodType> {
28
28
  _meta!: Meta;
29
29
  _schema!: Schema;
30
- _map: Map<Schema, $replace<Meta, Schema>> = new Map();
30
+ _map: WeakMap<Schema, $replace<Meta, Schema>> = new WeakMap();
31
31
  _idmap: Map<string, Schema> = new Map();
32
32
 
33
33
  add<S extends Schema>(
@@ -46,7 +46,7 @@ export class $ZodRegistry<Meta extends MetadataType = MetadataType, Schema exten
46
46
  }
47
47
 
48
48
  clear(): this {
49
- this._map = new Map();
49
+ this._map = new WeakMap();
50
50
  this._idmap = new Map();
51
51
  return this;
52
52
  }
@@ -830,10 +830,11 @@ export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$con
830
830
  $ZodStringFormat.init(inst, def);
831
831
 
832
832
  inst._zod.check = (payload) => {
833
- const segments = payload.value.split("/");
834
- const [address, prefix] = segments;
833
+ const parts = payload.value.split("/");
835
834
  try {
836
- if (segments.length !== 2) throw new Error();
835
+ if (parts.length !== 2) throw new Error();
836
+ const [address, prefix] = parts;
837
+ if (!prefix) throw new Error();
837
838
  const prefixNum = Number(prefix);
838
839
  if (`${prefixNum}` !== prefix) throw new Error();
839
840
  if (prefixNum < 0 || prefixNum > 128) throw new Error();
@@ -1738,7 +1739,7 @@ export interface $ZodObjectDef<Shape extends $ZodShape = $ZodShape> extends $Zod
1738
1739
 
1739
1740
  export interface $ZodObjectInternals<
1740
1741
  /** @ts-ignore Cast variance */
1741
- out Shape extends Readonly<$ZodShape> = Readonly<$ZodShape>,
1742
+ out Shape extends $ZodShape = $ZodShape,
1742
1743
  out Config extends $ZodObjectConfig = $ZodObjectConfig,
1743
1744
  > extends _$ZodTypeInternals {
1744
1745
  def: $ZodObjectDef<Shape>;
@@ -1763,7 +1764,7 @@ export interface $ZodObject<
1763
1764
  function normalizeDef(def: $ZodObjectDef) {
1764
1765
  const keys = Object.keys(def.shape);
1765
1766
  for (const k of keys) {
1766
- if (!def.shape[k]._zod.traits.has("$ZodType")) {
1767
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
1767
1768
  throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1768
1769
  }
1769
1770
  }
@@ -1824,6 +1825,21 @@ function handleCatchall(
1824
1825
  export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
1825
1826
  // requires cast because technically $ZodObject doesn't extend
1826
1827
  $ZodType.init(inst, def);
1828
+ // const sh = def.shape;
1829
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
1830
+ if (!desc!.get) {
1831
+ const sh = def.shape;
1832
+ Object.defineProperty(def, "shape", {
1833
+ get: () => {
1834
+ const newSh = { ...sh };
1835
+ Object.defineProperty(def, "shape", {
1836
+ value: newSh,
1837
+ });
1838
+
1839
+ return newSh;
1840
+ },
1841
+ });
1842
+ }
1827
1843
 
1828
1844
  const _normalized = util.cached(() => normalizeDef(def));
1829
1845
 
@@ -1852,7 +1868,6 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
1852
1868
  payload.issues.push({
1853
1869
  expected: "object",
1854
1870
  code: "invalid_type",
1855
-
1856
1871
  input,
1857
1872
  inst,
1858
1873
  });
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 1,
4
- patch: 6 as number,
4
+ patch: 9 as number,
5
5
  } as const;
@@ -769,10 +769,7 @@ export function object<T extends core.$ZodLooseShape = Record<never, SomeType>>(
769
769
  ): ZodMiniObject<T, core.$strip> {
770
770
  const def: core.$ZodObjectDef = {
771
771
  type: "object",
772
- get shape() {
773
- util.assignProp(this, "shape", { ...shape });
774
- return this.shape;
775
- },
772
+ shape: shape!,
776
773
  ...util.normalizeParams(params),
777
774
  };
778
775
  return new ZodMiniObject(def) as any;
@@ -785,11 +782,7 @@ export function strictObject<T extends core.$ZodLooseShape>(
785
782
  ): ZodMiniObject<T, core.$strict> {
786
783
  return new ZodMiniObject({
787
784
  type: "object",
788
- // shape: shape as core.$ZodLooseShape,
789
- get shape() {
790
- util.assignProp(this, "shape", { ...shape });
791
- return this.shape;
792
- },
785
+ shape,
793
786
  catchall: never(),
794
787
  ...util.normalizeParams(params),
795
788
  }) as any;
@@ -802,14 +795,7 @@ export function looseObject<T extends core.$ZodLooseShape>(
802
795
  ): ZodMiniObject<T, core.$loose> {
803
796
  return new ZodMiniObject({
804
797
  type: "object",
805
- // shape: shape as core.$ZodLooseShape,
806
- get shape() {
807
- util.assignProp(this, "shape", { ...shape });
808
- return this.shape;
809
- },
810
- // get optional() {
811
- // return util.optionalKeys(shape);
812
- // },
798
+ shape,
813
799
  catchall: unknown(),
814
800
  ...util.normalizeParams(params),
815
801
  }) as any;
@@ -127,15 +127,12 @@ exports.ZodType = core.$constructor("ZodType", (inst, def) => {
127
127
  Object.defineProperty(inst, "_def", { value: def });
128
128
  // base methods
129
129
  inst.check = (...checks) => {
130
- return inst.clone({
131
- ...def,
130
+ return inst.clone(index_js_1.util.mergeDefs(def, {
132
131
  checks: [
133
132
  ...(def.checks ?? []),
134
133
  ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
135
134
  ],
136
- }
137
- // { parent: true }
138
- );
135
+ }));
139
136
  };
140
137
  inst.clone = (def, params) => core.clone(inst, def, params);
141
138
  inst.brand = () => inst;
@@ -631,7 +628,9 @@ function keyof(schema) {
631
628
  exports.ZodObject = core.$constructor("ZodObject", (inst, def) => {
632
629
  core.$ZodObjectJIT.init(inst, def);
633
630
  exports.ZodType.init(inst, def);
634
- index_js_1.util.defineLazy(inst, "shape", () => def.shape);
631
+ index_js_1.util.defineLazy(inst, "shape", () => {
632
+ return def.shape;
633
+ });
635
634
  inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
636
635
  inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall });
637
636
  inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
@@ -653,10 +652,7 @@ exports.ZodObject = core.$constructor("ZodObject", (inst, def) => {
653
652
  function object(shape, params) {
654
653
  const def = {
655
654
  type: "object",
656
- get shape() {
657
- index_js_1.util.assignProp(this, "shape", shape ? index_js_1.util.objectClone(shape) : {});
658
- return this.shape;
659
- },
655
+ shape: shape,
660
656
  ...index_js_1.util.normalizeParams(params),
661
657
  };
662
658
  return new exports.ZodObject(def);
@@ -665,10 +661,7 @@ function object(shape, params) {
665
661
  function strictObject(shape, params) {
666
662
  return new exports.ZodObject({
667
663
  type: "object",
668
- get shape() {
669
- index_js_1.util.assignProp(this, "shape", index_js_1.util.objectClone(shape));
670
- return this.shape;
671
- },
664
+ shape,
672
665
  catchall: never(),
673
666
  ...index_js_1.util.normalizeParams(params),
674
667
  });
@@ -677,10 +670,7 @@ function strictObject(shape, params) {
677
670
  function looseObject(shape, params) {
678
671
  return new exports.ZodObject({
679
672
  type: "object",
680
- get shape() {
681
- index_js_1.util.assignProp(this, "shape", index_js_1.util.objectClone(shape));
682
- return this.shape;
683
- },
673
+ shape,
684
674
  catchall: unknown(),
685
675
  ...index_js_1.util.normalizeParams(params),
686
676
  });
@@ -10,15 +10,12 @@ export const ZodType = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) =>
10
10
  Object.defineProperty(inst, "_def", { value: def });
11
11
  // base methods
12
12
  inst.check = (...checks) => {
13
- return inst.clone({
14
- ...def,
13
+ return inst.clone(util.mergeDefs(def, {
15
14
  checks: [
16
15
  ...(def.checks ?? []),
17
16
  ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
18
17
  ],
19
- }
20
- // { parent: true }
21
- );
18
+ }));
22
19
  };
23
20
  inst.clone = (def, params) => core.clone(inst, def, params);
24
21
  inst.brand = () => inst;
@@ -517,7 +514,9 @@ export function keyof(schema) {
517
514
  export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def) => {
518
515
  core.$ZodObjectJIT.init(inst, def);
519
516
  ZodType.init(inst, def);
520
- util.defineLazy(inst, "shape", () => def.shape);
517
+ util.defineLazy(inst, "shape", () => {
518
+ return def.shape;
519
+ });
521
520
  inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
522
521
  inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall });
523
522
  inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
@@ -539,10 +538,7 @@ export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def
539
538
  export function object(shape, params) {
540
539
  const def = {
541
540
  type: "object",
542
- get shape() {
543
- util.assignProp(this, "shape", shape ? util.objectClone(shape) : {});
544
- return this.shape;
545
- },
541
+ shape: shape,
546
542
  ...util.normalizeParams(params),
547
543
  };
548
544
  return new ZodObject(def);
@@ -551,10 +547,7 @@ export function object(shape, params) {
551
547
  export function strictObject(shape, params) {
552
548
  return new ZodObject({
553
549
  type: "object",
554
- get shape() {
555
- util.assignProp(this, "shape", util.objectClone(shape));
556
- return this.shape;
557
- },
550
+ shape,
558
551
  catchall: never(),
559
552
  ...util.normalizeParams(params),
560
553
  });
@@ -563,10 +556,7 @@ export function strictObject(shape, params) {
563
556
  export function looseObject(shape, params) {
564
557
  return new ZodObject({
565
558
  type: "object",
566
- get shape() {
567
- util.assignProp(this, "shape", util.objectClone(shape));
568
- return this.shape;
569
- },
559
+ shape,
570
560
  catchall: unknown(),
571
561
  ...util.normalizeParams(params),
572
562
  });
@@ -6,7 +6,7 @@ exports.$output = Symbol("ZodOutput");
6
6
  exports.$input = Symbol("ZodInput");
7
7
  class $ZodRegistry {
8
8
  constructor() {
9
- this._map = new Map();
9
+ this._map = new WeakMap();
10
10
  this._idmap = new Map();
11
11
  }
12
12
  add(schema, ..._meta) {
@@ -21,7 +21,7 @@ class $ZodRegistry {
21
21
  return this;
22
22
  }
23
23
  clear() {
24
- this._map = new Map();
24
+ this._map = new WeakMap();
25
25
  this._idmap = new Map();
26
26
  return this;
27
27
  }
@@ -13,7 +13,7 @@ type MetadataType = object | undefined;
13
13
  export declare class $ZodRegistry<Meta extends MetadataType = MetadataType, Schema extends $ZodType = $ZodType> {
14
14
  _meta: Meta;
15
15
  _schema: Schema;
16
- _map: Map<Schema, $replace<Meta, Schema>>;
16
+ _map: WeakMap<Schema, $replace<Meta, Schema>>;
17
17
  _idmap: Map<string, Schema>;
18
18
  add<S extends Schema>(schema: S, ..._meta: undefined extends Meta ? [$replace<Meta, S>?] : [$replace<Meta, S>]): this;
19
19
  clear(): this;
@@ -13,7 +13,7 @@ type MetadataType = object | undefined;
13
13
  export declare class $ZodRegistry<Meta extends MetadataType = MetadataType, Schema extends $ZodType = $ZodType> {
14
14
  _meta: Meta;
15
15
  _schema: Schema;
16
- _map: Map<Schema, $replace<Meta, Schema>>;
16
+ _map: WeakMap<Schema, $replace<Meta, Schema>>;
17
17
  _idmap: Map<string, Schema>;
18
18
  add<S extends Schema>(schema: S, ..._meta: undefined extends Meta ? [$replace<Meta, S>?] : [$replace<Meta, S>]): this;
19
19
  clear(): this;
@@ -2,7 +2,7 @@ export const $output = Symbol("ZodOutput");
2
2
  export const $input = Symbol("ZodInput");
3
3
  export class $ZodRegistry {
4
4
  constructor() {
5
- this._map = new Map();
5
+ this._map = new WeakMap();
6
6
  this._idmap = new Map();
7
7
  }
8
8
  add(schema, ..._meta) {
@@ -17,7 +17,7 @@ export class $ZodRegistry {
17
17
  return this;
18
18
  }
19
19
  clear() {
20
- this._map = new Map();
20
+ this._map = new WeakMap();
21
21
  this._idmap = new Map();
22
22
  return this;
23
23
  }
@@ -364,10 +364,12 @@ exports.$ZodCIDRv6 = core.$constructor("$ZodCIDRv6", (inst, def) => {
364
364
  def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
365
365
  exports.$ZodStringFormat.init(inst, def);
366
366
  inst._zod.check = (payload) => {
367
- const segments = payload.value.split("/");
368
- const [address, prefix] = segments;
367
+ const parts = payload.value.split("/");
369
368
  try {
370
- if (segments.length !== 2)
369
+ if (parts.length !== 2)
370
+ throw new Error();
371
+ const [address, prefix] = parts;
372
+ if (!prefix)
371
373
  throw new Error();
372
374
  const prefixNum = Number(prefix);
373
375
  if (`${prefixNum}` !== prefix)
@@ -747,7 +749,7 @@ function handlePropertyResult(result, final, key, input) {
747
749
  function normalizeDef(def) {
748
750
  const keys = Object.keys(def.shape);
749
751
  for (const k of keys) {
750
- if (!def.shape[k]._zod.traits.has("$ZodType")) {
752
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
751
753
  throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
752
754
  }
753
755
  }
@@ -798,6 +800,20 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
798
800
  exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
799
801
  // requires cast because technically $ZodObject doesn't extend
800
802
  exports.$ZodType.init(inst, def);
803
+ // const sh = def.shape;
804
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
805
+ if (!desc.get) {
806
+ const sh = def.shape;
807
+ Object.defineProperty(def, "shape", {
808
+ get: () => {
809
+ const newSh = { ...sh };
810
+ Object.defineProperty(def, "shape", {
811
+ value: newSh,
812
+ });
813
+ return newSh;
814
+ },
815
+ });
816
+ }
801
817
  const _normalized = util.cached(() => normalizeDef(def));
802
818
  util.defineLazy(inst._zod, "propValues", () => {
803
819
  const shape = def.shape;
@@ -584,7 +584,7 @@ export interface $ZodObjectDef<Shape extends $ZodShape = $ZodShape> extends $Zod
584
584
  }
585
585
  export interface $ZodObjectInternals<
586
586
  /** @ts-ignore Cast variance */
587
- out Shape extends Readonly<$ZodShape> = Readonly<$ZodShape>, out Config extends $ZodObjectConfig = $ZodObjectConfig> extends _$ZodTypeInternals {
587
+ out Shape extends $ZodShape = $ZodShape, out Config extends $ZodObjectConfig = $ZodObjectConfig> extends _$ZodTypeInternals {
588
588
  def: $ZodObjectDef<Shape>;
589
589
  config: Config;
590
590
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueUnrecognizedKeys;
@@ -584,7 +584,7 @@ export interface $ZodObjectDef<Shape extends $ZodShape = $ZodShape> extends $Zod
584
584
  }
585
585
  export interface $ZodObjectInternals<
586
586
  /** @ts-ignore Cast variance */
587
- out Shape extends Readonly<$ZodShape> = Readonly<$ZodShape>, out Config extends $ZodObjectConfig = $ZodObjectConfig> extends _$ZodTypeInternals {
587
+ out Shape extends $ZodShape = $ZodShape, out Config extends $ZodObjectConfig = $ZodObjectConfig> extends _$ZodTypeInternals {
588
588
  def: $ZodObjectDef<Shape>;
589
589
  config: Config;
590
590
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueUnrecognizedKeys;
@@ -333,10 +333,12 @@ export const $ZodCIDRv6 = /*@__PURE__*/ core.$constructor("$ZodCIDRv6", (inst, d
333
333
  def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
334
334
  $ZodStringFormat.init(inst, def);
335
335
  inst._zod.check = (payload) => {
336
- const segments = payload.value.split("/");
337
- const [address, prefix] = segments;
336
+ const parts = payload.value.split("/");
338
337
  try {
339
- if (segments.length !== 2)
338
+ if (parts.length !== 2)
339
+ throw new Error();
340
+ const [address, prefix] = parts;
341
+ if (!prefix)
340
342
  throw new Error();
341
343
  const prefixNum = Number(prefix);
342
344
  if (`${prefixNum}` !== prefix)
@@ -716,7 +718,7 @@ function handlePropertyResult(result, final, key, input) {
716
718
  function normalizeDef(def) {
717
719
  const keys = Object.keys(def.shape);
718
720
  for (const k of keys) {
719
- if (!def.shape[k]._zod.traits.has("$ZodType")) {
721
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
720
722
  throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
721
723
  }
722
724
  }
@@ -767,6 +769,20 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
767
769
  export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
768
770
  // requires cast because technically $ZodObject doesn't extend
769
771
  $ZodType.init(inst, def);
772
+ // const sh = def.shape;
773
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
774
+ if (!desc.get) {
775
+ const sh = def.shape;
776
+ Object.defineProperty(def, "shape", {
777
+ get: () => {
778
+ const newSh = { ...sh };
779
+ Object.defineProperty(def, "shape", {
780
+ value: newSh,
781
+ });
782
+ return newSh;
783
+ },
784
+ });
785
+ }
770
786
  const _normalized = util.cached(() => normalizeDef(def));
771
787
  util.defineLazy(inst._zod, "propValues", () => {
772
788
  const shape = def.shape;
@@ -4,5 +4,5 @@ exports.version = void 0;
4
4
  exports.version = {
5
5
  major: 4,
6
6
  minor: 1,
7
- patch: 6,
7
+ patch: 9,
8
8
  };
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 1,
4
- patch: 6,
4
+ patch: 9,
5
5
  };
@@ -474,10 +474,7 @@ exports.ZodMiniObject = core.$constructor("ZodMiniObject", (inst, def) => {
474
474
  function object(shape, params) {
475
475
  const def = {
476
476
  type: "object",
477
- get shape() {
478
- index_js_1.util.assignProp(this, "shape", { ...shape });
479
- return this.shape;
480
- },
477
+ shape: shape,
481
478
  ...index_js_1.util.normalizeParams(params),
482
479
  };
483
480
  return new exports.ZodMiniObject(def);
@@ -486,11 +483,7 @@ function object(shape, params) {
486
483
  function strictObject(shape, params) {
487
484
  return new exports.ZodMiniObject({
488
485
  type: "object",
489
- // shape: shape as core.$ZodLooseShape,
490
- get shape() {
491
- index_js_1.util.assignProp(this, "shape", { ...shape });
492
- return this.shape;
493
- },
486
+ shape,
494
487
  catchall: never(),
495
488
  ...index_js_1.util.normalizeParams(params),
496
489
  });
@@ -499,14 +492,7 @@ function strictObject(shape, params) {
499
492
  function looseObject(shape, params) {
500
493
  return new exports.ZodMiniObject({
501
494
  type: "object",
502
- // shape: shape as core.$ZodLooseShape,
503
- get shape() {
504
- index_js_1.util.assignProp(this, "shape", { ...shape });
505
- return this.shape;
506
- },
507
- // get optional() {
508
- // return util.optionalKeys(shape);
509
- // },
495
+ shape,
510
496
  catchall: unknown(),
511
497
  ...index_js_1.util.normalizeParams(params),
512
498
  });
@@ -353,10 +353,7 @@ export const ZodMiniObject = /*@__PURE__*/ core.$constructor("ZodMiniObject", (i
353
353
  export function object(shape, params) {
354
354
  const def = {
355
355
  type: "object",
356
- get shape() {
357
- util.assignProp(this, "shape", { ...shape });
358
- return this.shape;
359
- },
356
+ shape: shape,
360
357
  ...util.normalizeParams(params),
361
358
  };
362
359
  return new ZodMiniObject(def);
@@ -365,11 +362,7 @@ export function object(shape, params) {
365
362
  export function strictObject(shape, params) {
366
363
  return new ZodMiniObject({
367
364
  type: "object",
368
- // shape: shape as core.$ZodLooseShape,
369
- get shape() {
370
- util.assignProp(this, "shape", { ...shape });
371
- return this.shape;
372
- },
365
+ shape,
373
366
  catchall: never(),
374
367
  ...util.normalizeParams(params),
375
368
  });
@@ -378,14 +371,7 @@ export function strictObject(shape, params) {
378
371
  export function looseObject(shape, params) {
379
372
  return new ZodMiniObject({
380
373
  type: "object",
381
- // shape: shape as core.$ZodLooseShape,
382
- get shape() {
383
- util.assignProp(this, "shape", { ...shape });
384
- return this.shape;
385
- },
386
- // get optional() {
387
- // return util.optionalKeys(shape);
388
- // },
374
+ shape,
389
375
  catchall: unknown(),
390
376
  ...util.normalizeParams(params),
391
377
  });