zod 3.20.4 → 3.20.6

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/lib/index.mjs CHANGED
@@ -1839,6 +1839,39 @@ class ZodObject extends ZodType {
1839
1839
  * If you want to pass through unknown properties, use `.passthrough()` instead.
1840
1840
  */
1841
1841
  this.nonstrict = this.passthrough;
1842
+ // extend<
1843
+ // Augmentation extends ZodRawShape,
1844
+ // NewOutput extends util.flatten<{
1845
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
1846
+ // ? Augmentation[k]["_output"]
1847
+ // : k extends keyof Output
1848
+ // ? Output[k]
1849
+ // : never;
1850
+ // }>,
1851
+ // NewInput extends util.flatten<{
1852
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
1853
+ // ? Augmentation[k]["_input"]
1854
+ // : k extends keyof Input
1855
+ // ? Input[k]
1856
+ // : never;
1857
+ // }>
1858
+ // >(
1859
+ // augmentation: Augmentation
1860
+ // ): ZodObject<
1861
+ // extendShape<T, Augmentation>,
1862
+ // UnknownKeys,
1863
+ // Catchall,
1864
+ // NewOutput,
1865
+ // NewInput
1866
+ // > {
1867
+ // return new ZodObject({
1868
+ // ...this._def,
1869
+ // shape: () => ({
1870
+ // ...this._def.shape(),
1871
+ // ...augmentation,
1872
+ // }),
1873
+ // }) as any;
1874
+ // }
1842
1875
  /**
1843
1876
  * @deprecated Use `.extend` instead
1844
1877
  * */
@@ -1979,8 +2012,23 @@ class ZodObject extends ZodType {
1979
2012
  unknownKeys: "passthrough",
1980
2013
  });
1981
2014
  }
1982
- // augment = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
1983
- // extend = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
2015
+ // const AugmentFactory =
2016
+ // <Def extends ZodObjectDef>(def: Def) =>
2017
+ // <Augmentation extends ZodRawShape>(
2018
+ // augmentation: Augmentation
2019
+ // ): ZodObject<
2020
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2021
+ // Def["unknownKeys"],
2022
+ // Def["catchall"]
2023
+ // > => {
2024
+ // return new ZodObject({
2025
+ // ...def,
2026
+ // shape: () => ({
2027
+ // ...def.shape(),
2028
+ // ...augmentation,
2029
+ // }),
2030
+ // }) as any;
2031
+ // };
1984
2032
  extend(augmentation) {
1985
2033
  return new ZodObject({
1986
2034
  ...this._def,
@@ -1995,14 +2043,7 @@ class ZodObject extends ZodType {
1995
2043
  * inferred type of merged objects. Please
1996
2044
  * upgrade if you are experiencing issues.
1997
2045
  */
1998
- // merge<Incoming extends AnyZodObject>(merging: Incoming) {
1999
- // return this.extend(merging.shape as Incoming["shape"]);
2000
- // }
2001
2046
  merge(merging) {
2002
- // const mergedShape = objectUtil.mergeShapes(
2003
- // this._def.shape(),
2004
- // merging._def.shape()
2005
- // );
2006
2047
  const merged = new ZodObject({
2007
2048
  unknownKeys: merging._def.unknownKeys,
2008
2049
  catchall: merging._def.catchall,
@@ -2011,6 +2052,41 @@ class ZodObject extends ZodType {
2011
2052
  });
2012
2053
  return merged;
2013
2054
  }
2055
+ // merge<
2056
+ // Incoming extends AnyZodObject,
2057
+ // Augmentation extends Incoming["shape"],
2058
+ // NewOutput extends {
2059
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2060
+ // ? Augmentation[k]["_output"]
2061
+ // : k extends keyof Output
2062
+ // ? Output[k]
2063
+ // : never;
2064
+ // },
2065
+ // NewInput extends {
2066
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2067
+ // ? Augmentation[k]["_input"]
2068
+ // : k extends keyof Input
2069
+ // ? Input[k]
2070
+ // : never;
2071
+ // }
2072
+ // >(
2073
+ // merging: Incoming
2074
+ // ): ZodObject<
2075
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2076
+ // Incoming["_def"]["unknownKeys"],
2077
+ // Incoming["_def"]["catchall"],
2078
+ // NewOutput,
2079
+ // NewInput
2080
+ // > {
2081
+ // const merged: any = new ZodObject({
2082
+ // unknownKeys: merging._def.unknownKeys,
2083
+ // catchall: merging._def.catchall,
2084
+ // shape: () =>
2085
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2086
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2087
+ // }) as any;
2088
+ // return merged;
2089
+ // }
2014
2090
  setKey(key, schema) {
2015
2091
  return this.augment({ [key]: schema });
2016
2092
  }
package/lib/index.umd.js CHANGED
@@ -1845,6 +1845,39 @@
1845
1845
  * If you want to pass through unknown properties, use `.passthrough()` instead.
1846
1846
  */
1847
1847
  this.nonstrict = this.passthrough;
1848
+ // extend<
1849
+ // Augmentation extends ZodRawShape,
1850
+ // NewOutput extends util.flatten<{
1851
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
1852
+ // ? Augmentation[k]["_output"]
1853
+ // : k extends keyof Output
1854
+ // ? Output[k]
1855
+ // : never;
1856
+ // }>,
1857
+ // NewInput extends util.flatten<{
1858
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
1859
+ // ? Augmentation[k]["_input"]
1860
+ // : k extends keyof Input
1861
+ // ? Input[k]
1862
+ // : never;
1863
+ // }>
1864
+ // >(
1865
+ // augmentation: Augmentation
1866
+ // ): ZodObject<
1867
+ // extendShape<T, Augmentation>,
1868
+ // UnknownKeys,
1869
+ // Catchall,
1870
+ // NewOutput,
1871
+ // NewInput
1872
+ // > {
1873
+ // return new ZodObject({
1874
+ // ...this._def,
1875
+ // shape: () => ({
1876
+ // ...this._def.shape(),
1877
+ // ...augmentation,
1878
+ // }),
1879
+ // }) as any;
1880
+ // }
1848
1881
  /**
1849
1882
  * @deprecated Use `.extend` instead
1850
1883
  * */
@@ -1985,8 +2018,23 @@
1985
2018
  unknownKeys: "passthrough",
1986
2019
  });
1987
2020
  }
1988
- // augment = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
1989
- // extend = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
2021
+ // const AugmentFactory =
2022
+ // <Def extends ZodObjectDef>(def: Def) =>
2023
+ // <Augmentation extends ZodRawShape>(
2024
+ // augmentation: Augmentation
2025
+ // ): ZodObject<
2026
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2027
+ // Def["unknownKeys"],
2028
+ // Def["catchall"]
2029
+ // > => {
2030
+ // return new ZodObject({
2031
+ // ...def,
2032
+ // shape: () => ({
2033
+ // ...def.shape(),
2034
+ // ...augmentation,
2035
+ // }),
2036
+ // }) as any;
2037
+ // };
1990
2038
  extend(augmentation) {
1991
2039
  return new ZodObject({
1992
2040
  ...this._def,
@@ -2001,14 +2049,7 @@
2001
2049
  * inferred type of merged objects. Please
2002
2050
  * upgrade if you are experiencing issues.
2003
2051
  */
2004
- // merge<Incoming extends AnyZodObject>(merging: Incoming) {
2005
- // return this.extend(merging.shape as Incoming["shape"]);
2006
- // }
2007
2052
  merge(merging) {
2008
- // const mergedShape = objectUtil.mergeShapes(
2009
- // this._def.shape(),
2010
- // merging._def.shape()
2011
- // );
2012
2053
  const merged = new ZodObject({
2013
2054
  unknownKeys: merging._def.unknownKeys,
2014
2055
  catchall: merging._def.catchall,
@@ -2017,6 +2058,41 @@
2017
2058
  });
2018
2059
  return merged;
2019
2060
  }
2061
+ // merge<
2062
+ // Incoming extends AnyZodObject,
2063
+ // Augmentation extends Incoming["shape"],
2064
+ // NewOutput extends {
2065
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2066
+ // ? Augmentation[k]["_output"]
2067
+ // : k extends keyof Output
2068
+ // ? Output[k]
2069
+ // : never;
2070
+ // },
2071
+ // NewInput extends {
2072
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2073
+ // ? Augmentation[k]["_input"]
2074
+ // : k extends keyof Input
2075
+ // ? Input[k]
2076
+ // : never;
2077
+ // }
2078
+ // >(
2079
+ // merging: Incoming
2080
+ // ): ZodObject<
2081
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2082
+ // Incoming["_def"]["unknownKeys"],
2083
+ // Incoming["_def"]["catchall"],
2084
+ // NewOutput,
2085
+ // NewInput
2086
+ // > {
2087
+ // const merged: any = new ZodObject({
2088
+ // unknownKeys: merging._def.unknownKeys,
2089
+ // catchall: merging._def.catchall,
2090
+ // shape: () =>
2091
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2092
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2093
+ // }) as any;
2094
+ // return merged;
2095
+ // }
2020
2096
  setKey(key, schema) {
2021
2097
  return this.augment({ [key]: schema });
2022
2098
  }
package/lib/types.d.ts CHANGED
@@ -453,25 +453,17 @@ export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends Unknow
453
453
  * If you want to pass through unknown properties, use `.passthrough()` instead.
454
454
  */
455
455
  nonstrict: () => ZodObject<T, "passthrough", Catchall>;
456
- extend<Augmentation extends ZodRawShape, NewOutput extends util.flatten<{
457
- [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation ? Augmentation[k]["_output"] : k extends keyof Output ? Output[k] : never;
458
- }>, NewInput extends util.flatten<{
459
- [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation ? Augmentation[k]["_input"] : k extends keyof Input ? Input[k] : never;
460
- }>>(augmentation: Augmentation): ZodObject<extendShape<T, Augmentation>, UnknownKeys, Catchall, NewOutput, NewInput>;
456
+ extend<Augmentation extends ZodRawShape>(augmentation: Augmentation): ZodObject<extendShape<T, Augmentation>, UnknownKeys, Catchall>;
461
457
  /**
462
458
  * @deprecated Use `.extend` instead
463
459
  * */
464
- augment: <Augmentation extends ZodRawShape, NewOutput extends { [k_1 in keyof { [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation ? Augmentation[k]["_output"] : k extends keyof Output ? Output[k] : never; }]: { [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation ? Augmentation[k]["_output"] : k extends keyof Output ? Output[k] : never; }[k_1]; }, NewInput extends { [k_3 in keyof { [k_2 in keyof Augmentation | keyof Input]: k_2 extends keyof Augmentation ? Augmentation[k_2]["_input"] : k_2 extends keyof Input ? Input[k_2] : never; }]: { [k_2 in keyof Augmentation | keyof Input]: k_2 extends keyof Augmentation ? Augmentation[k_2]["_input"] : k_2 extends keyof Input ? Input[k_2] : never; }[k_3]; }>(augmentation: Augmentation) => ZodObject<{ [k_4 in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k_4]; }, UnknownKeys, Catchall, NewOutput, NewInput>;
460
+ augment: <Augmentation extends ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, UnknownKeys, Catchall, objectOutputType<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, Catchall>, objectInputType<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, Catchall>>;
465
461
  /**
466
462
  * Prior to zod@1.0.12 there was a bug in the
467
463
  * inferred type of merged objects. Please
468
464
  * upgrade if you are experiencing issues.
469
465
  */
470
- merge<Incoming extends AnyZodObject, Augmentation extends Incoming["shape"], NewOutput extends {
471
- [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation ? Augmentation[k]["_output"] : k extends keyof Output ? Output[k] : never;
472
- }, NewInput extends {
473
- [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation ? Augmentation[k]["_input"] : k extends keyof Input ? Input[k] : never;
474
- }>(merging: Incoming): ZodObject<extendShape<T, ReturnType<Incoming["_def"]["shape"]>>, Incoming["_def"]["unknownKeys"], Incoming["_def"]["catchall"], NewOutput, NewInput>;
466
+ merge<Incoming extends AnyZodObject, Augmentation extends Incoming["shape"]>(merging: Incoming): ZodObject<extendShape<T, Augmentation>, Incoming["_def"]["unknownKeys"], Incoming["_def"]["catchall"]>;
475
467
  setKey<Key extends string, Schema extends ZodTypeAny>(key: Key, schema: Schema): ZodObject<T & {
476
468
  [k in Key]: Schema;
477
469
  }, UnknownKeys, Catchall>;
@@ -671,6 +663,7 @@ export declare type Writeable<T> = {
671
663
  -readonly [P in keyof T]: T[P];
672
664
  };
673
665
  export declare type FilterEnum<Values, ToExclude> = Values extends [] ? [] : Values extends [infer Head, ...infer Rest] ? Head extends ToExclude ? FilterEnum<Rest, ToExclude> : [Head, ...FilterEnum<Rest, ToExclude>] : never;
666
+ export declare type typecast<A, T> = A extends T ? A : never;
674
667
  declare function createZodEnum<U extends string, T extends Readonly<[U, ...U[]]>>(values: T, params?: RawCreateParams): ZodEnum<Writeable<T>>;
675
668
  declare function createZodEnum<U extends string, T extends [U, ...U[]]>(values: T, params?: RawCreateParams): ZodEnum<T>;
676
669
  export declare class ZodEnum<T extends [string, ...string[]]> extends ZodType<T[number], ZodEnumDef<T>> {
@@ -680,7 +673,7 @@ export declare class ZodEnum<T extends [string, ...string[]]> extends ZodType<T[
680
673
  get Values(): Values<T>;
681
674
  get Enum(): Values<T>;
682
675
  extract<ToExtract extends readonly [T[number], ...T[number][]]>(values: ToExtract): ZodEnum<Writeable<ToExtract>>;
683
- exclude<ToExclude extends readonly [T[number], ...T[number][]]>(values: ToExclude): ZodEnum<Writeable<FilterEnum<T, ToExclude[number]>>>;
676
+ exclude<ToExclude extends readonly [T[number], ...T[number][]]>(values: ToExclude): ZodEnum<typecast<Writeable<FilterEnum<T, ToExclude[number]>>, [string, ...string[]]>>;
684
677
  static create: typeof createZodEnum;
685
678
  }
686
679
  export interface ZodNativeEnumDef<T extends EnumLike = EnumLike> extends ZodTypeDef {
package/lib/types.js CHANGED
@@ -1382,6 +1382,39 @@ class ZodObject extends ZodType {
1382
1382
  * If you want to pass through unknown properties, use `.passthrough()` instead.
1383
1383
  */
1384
1384
  this.nonstrict = this.passthrough;
1385
+ // extend<
1386
+ // Augmentation extends ZodRawShape,
1387
+ // NewOutput extends util.flatten<{
1388
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
1389
+ // ? Augmentation[k]["_output"]
1390
+ // : k extends keyof Output
1391
+ // ? Output[k]
1392
+ // : never;
1393
+ // }>,
1394
+ // NewInput extends util.flatten<{
1395
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
1396
+ // ? Augmentation[k]["_input"]
1397
+ // : k extends keyof Input
1398
+ // ? Input[k]
1399
+ // : never;
1400
+ // }>
1401
+ // >(
1402
+ // augmentation: Augmentation
1403
+ // ): ZodObject<
1404
+ // extendShape<T, Augmentation>,
1405
+ // UnknownKeys,
1406
+ // Catchall,
1407
+ // NewOutput,
1408
+ // NewInput
1409
+ // > {
1410
+ // return new ZodObject({
1411
+ // ...this._def,
1412
+ // shape: () => ({
1413
+ // ...this._def.shape(),
1414
+ // ...augmentation,
1415
+ // }),
1416
+ // }) as any;
1417
+ // }
1385
1418
  /**
1386
1419
  * @deprecated Use `.extend` instead
1387
1420
  * */
@@ -1523,8 +1556,23 @@ class ZodObject extends ZodType {
1523
1556
  unknownKeys: "passthrough",
1524
1557
  });
1525
1558
  }
1526
- // augment = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
1527
- // extend = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
1559
+ // const AugmentFactory =
1560
+ // <Def extends ZodObjectDef>(def: Def) =>
1561
+ // <Augmentation extends ZodRawShape>(
1562
+ // augmentation: Augmentation
1563
+ // ): ZodObject<
1564
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
1565
+ // Def["unknownKeys"],
1566
+ // Def["catchall"]
1567
+ // > => {
1568
+ // return new ZodObject({
1569
+ // ...def,
1570
+ // shape: () => ({
1571
+ // ...def.shape(),
1572
+ // ...augmentation,
1573
+ // }),
1574
+ // }) as any;
1575
+ // };
1528
1576
  extend(augmentation) {
1529
1577
  return new ZodObject({
1530
1578
  ...this._def,
@@ -1539,14 +1587,7 @@ class ZodObject extends ZodType {
1539
1587
  * inferred type of merged objects. Please
1540
1588
  * upgrade if you are experiencing issues.
1541
1589
  */
1542
- // merge<Incoming extends AnyZodObject>(merging: Incoming) {
1543
- // return this.extend(merging.shape as Incoming["shape"]);
1544
- // }
1545
1590
  merge(merging) {
1546
- // const mergedShape = objectUtil.mergeShapes(
1547
- // this._def.shape(),
1548
- // merging._def.shape()
1549
- // );
1550
1591
  const merged = new ZodObject({
1551
1592
  unknownKeys: merging._def.unknownKeys,
1552
1593
  catchall: merging._def.catchall,
@@ -1555,6 +1596,41 @@ class ZodObject extends ZodType {
1555
1596
  });
1556
1597
  return merged;
1557
1598
  }
1599
+ // merge<
1600
+ // Incoming extends AnyZodObject,
1601
+ // Augmentation extends Incoming["shape"],
1602
+ // NewOutput extends {
1603
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
1604
+ // ? Augmentation[k]["_output"]
1605
+ // : k extends keyof Output
1606
+ // ? Output[k]
1607
+ // : never;
1608
+ // },
1609
+ // NewInput extends {
1610
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
1611
+ // ? Augmentation[k]["_input"]
1612
+ // : k extends keyof Input
1613
+ // ? Input[k]
1614
+ // : never;
1615
+ // }
1616
+ // >(
1617
+ // merging: Incoming
1618
+ // ): ZodObject<
1619
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
1620
+ // Incoming["_def"]["unknownKeys"],
1621
+ // Incoming["_def"]["catchall"],
1622
+ // NewOutput,
1623
+ // NewInput
1624
+ // > {
1625
+ // const merged: any = new ZodObject({
1626
+ // unknownKeys: merging._def.unknownKeys,
1627
+ // catchall: merging._def.catchall,
1628
+ // shape: () =>
1629
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1630
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
1631
+ // }) as any;
1632
+ // return merged;
1633
+ // }
1558
1634
  setKey(key, schema) {
1559
1635
  return this.augment({ [key]: schema });
1560
1636
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.20.4",
3
+ "version": "3.20.6",
4
4
  "description": "TypeScript-first schema declaration and validation library with static type inference",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./index.d.ts",