zod 3.20.3 → 3.20.4
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 +41 -13
- package/lib/index.umd.js +41 -13
- package/lib/types.d.ts +33 -18
- package/lib/types.js +41 -13
- package/package.json +1 -1
package/lib/index.mjs
CHANGED
|
@@ -1802,15 +1802,6 @@ var objectUtil;
|
|
|
1802
1802
|
};
|
|
1803
1803
|
};
|
|
1804
1804
|
})(objectUtil || (objectUtil = {}));
|
|
1805
|
-
const AugmentFactory = (def) => (augmentation) => {
|
|
1806
|
-
return new ZodObject({
|
|
1807
|
-
...def,
|
|
1808
|
-
shape: () => ({
|
|
1809
|
-
...def.shape(),
|
|
1810
|
-
...augmentation,
|
|
1811
|
-
}),
|
|
1812
|
-
});
|
|
1813
|
-
};
|
|
1814
1805
|
function deepPartialify(schema) {
|
|
1815
1806
|
if (schema instanceof ZodObject) {
|
|
1816
1807
|
const newShape = {};
|
|
@@ -1848,8 +1839,10 @@ class ZodObject extends ZodType {
|
|
|
1848
1839
|
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
1849
1840
|
*/
|
|
1850
1841
|
this.nonstrict = this.passthrough;
|
|
1851
|
-
|
|
1852
|
-
|
|
1842
|
+
/**
|
|
1843
|
+
* @deprecated Use `.extend` instead
|
|
1844
|
+
* */
|
|
1845
|
+
this.augment = this.extend;
|
|
1853
1846
|
}
|
|
1854
1847
|
_getCached() {
|
|
1855
1848
|
if (this._cached !== null)
|
|
@@ -1986,14 +1979,25 @@ class ZodObject extends ZodType {
|
|
|
1986
1979
|
unknownKeys: "passthrough",
|
|
1987
1980
|
});
|
|
1988
1981
|
}
|
|
1989
|
-
|
|
1990
|
-
|
|
1982
|
+
// augment = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
|
|
1983
|
+
// extend = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
|
|
1984
|
+
extend(augmentation) {
|
|
1985
|
+
return new ZodObject({
|
|
1986
|
+
...this._def,
|
|
1987
|
+
shape: () => ({
|
|
1988
|
+
...this._def.shape(),
|
|
1989
|
+
...augmentation,
|
|
1990
|
+
}),
|
|
1991
|
+
});
|
|
1991
1992
|
}
|
|
1992
1993
|
/**
|
|
1993
1994
|
* Prior to zod@1.0.12 there was a bug in the
|
|
1994
1995
|
* inferred type of merged objects. Please
|
|
1995
1996
|
* upgrade if you are experiencing issues.
|
|
1996
1997
|
*/
|
|
1998
|
+
// merge<Incoming extends AnyZodObject>(merging: Incoming) {
|
|
1999
|
+
// return this.extend(merging.shape as Incoming["shape"]);
|
|
2000
|
+
// }
|
|
1997
2001
|
merge(merging) {
|
|
1998
2002
|
// const mergedShape = objectUtil.mergeShapes(
|
|
1999
2003
|
// this._def.shape(),
|
|
@@ -2007,6 +2011,30 @@ class ZodObject extends ZodType {
|
|
|
2007
2011
|
});
|
|
2008
2012
|
return merged;
|
|
2009
2013
|
}
|
|
2014
|
+
setKey(key, schema) {
|
|
2015
|
+
return this.augment({ [key]: schema });
|
|
2016
|
+
}
|
|
2017
|
+
// merge<Incoming extends AnyZodObject>(
|
|
2018
|
+
// merging: Incoming
|
|
2019
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2020
|
+
// ZodObject<
|
|
2021
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2022
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2023
|
+
// Incoming["_def"]["catchall"]
|
|
2024
|
+
// > {
|
|
2025
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
2026
|
+
// // this._def.shape(),
|
|
2027
|
+
// // merging._def.shape()
|
|
2028
|
+
// // );
|
|
2029
|
+
// const merged: any = new ZodObject({
|
|
2030
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2031
|
+
// catchall: merging._def.catchall,
|
|
2032
|
+
// shape: () =>
|
|
2033
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2034
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2035
|
+
// }) as any;
|
|
2036
|
+
// return merged;
|
|
2037
|
+
// }
|
|
2010
2038
|
catchall(index) {
|
|
2011
2039
|
return new ZodObject({
|
|
2012
2040
|
...this._def,
|
package/lib/index.umd.js
CHANGED
|
@@ -1808,15 +1808,6 @@
|
|
|
1808
1808
|
};
|
|
1809
1809
|
};
|
|
1810
1810
|
})(exports.objectUtil || (exports.objectUtil = {}));
|
|
1811
|
-
const AugmentFactory = (def) => (augmentation) => {
|
|
1812
|
-
return new ZodObject({
|
|
1813
|
-
...def,
|
|
1814
|
-
shape: () => ({
|
|
1815
|
-
...def.shape(),
|
|
1816
|
-
...augmentation,
|
|
1817
|
-
}),
|
|
1818
|
-
});
|
|
1819
|
-
};
|
|
1820
1811
|
function deepPartialify(schema) {
|
|
1821
1812
|
if (schema instanceof ZodObject) {
|
|
1822
1813
|
const newShape = {};
|
|
@@ -1854,8 +1845,10 @@
|
|
|
1854
1845
|
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
1855
1846
|
*/
|
|
1856
1847
|
this.nonstrict = this.passthrough;
|
|
1857
|
-
|
|
1858
|
-
|
|
1848
|
+
/**
|
|
1849
|
+
* @deprecated Use `.extend` instead
|
|
1850
|
+
* */
|
|
1851
|
+
this.augment = this.extend;
|
|
1859
1852
|
}
|
|
1860
1853
|
_getCached() {
|
|
1861
1854
|
if (this._cached !== null)
|
|
@@ -1992,14 +1985,25 @@
|
|
|
1992
1985
|
unknownKeys: "passthrough",
|
|
1993
1986
|
});
|
|
1994
1987
|
}
|
|
1995
|
-
|
|
1996
|
-
|
|
1988
|
+
// augment = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
|
|
1989
|
+
// extend = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
|
|
1990
|
+
extend(augmentation) {
|
|
1991
|
+
return new ZodObject({
|
|
1992
|
+
...this._def,
|
|
1993
|
+
shape: () => ({
|
|
1994
|
+
...this._def.shape(),
|
|
1995
|
+
...augmentation,
|
|
1996
|
+
}),
|
|
1997
|
+
});
|
|
1997
1998
|
}
|
|
1998
1999
|
/**
|
|
1999
2000
|
* Prior to zod@1.0.12 there was a bug in the
|
|
2000
2001
|
* inferred type of merged objects. Please
|
|
2001
2002
|
* upgrade if you are experiencing issues.
|
|
2002
2003
|
*/
|
|
2004
|
+
// merge<Incoming extends AnyZodObject>(merging: Incoming) {
|
|
2005
|
+
// return this.extend(merging.shape as Incoming["shape"]);
|
|
2006
|
+
// }
|
|
2003
2007
|
merge(merging) {
|
|
2004
2008
|
// const mergedShape = objectUtil.mergeShapes(
|
|
2005
2009
|
// this._def.shape(),
|
|
@@ -2013,6 +2017,30 @@
|
|
|
2013
2017
|
});
|
|
2014
2018
|
return merged;
|
|
2015
2019
|
}
|
|
2020
|
+
setKey(key, schema) {
|
|
2021
|
+
return this.augment({ [key]: schema });
|
|
2022
|
+
}
|
|
2023
|
+
// merge<Incoming extends AnyZodObject>(
|
|
2024
|
+
// merging: Incoming
|
|
2025
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2026
|
+
// ZodObject<
|
|
2027
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2028
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2029
|
+
// Incoming["_def"]["catchall"]
|
|
2030
|
+
// > {
|
|
2031
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
2032
|
+
// // this._def.shape(),
|
|
2033
|
+
// // merging._def.shape()
|
|
2034
|
+
// // );
|
|
2035
|
+
// const merged: any = new ZodObject({
|
|
2036
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2037
|
+
// catchall: merging._def.catchall,
|
|
2038
|
+
// shape: () =>
|
|
2039
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2040
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2041
|
+
// }) as any;
|
|
2042
|
+
// return merged;
|
|
2043
|
+
// }
|
|
2016
2044
|
catchall(index) {
|
|
2017
2045
|
return new ZodObject({
|
|
2018
2046
|
...this._def,
|
package/lib/types.d.ts
CHANGED
|
@@ -405,7 +405,7 @@ export declare namespace objectUtil {
|
|
|
405
405
|
export const mergeShapes: <U extends ZodRawShape, T extends ZodRawShape>(first: U, second: T) => T & U;
|
|
406
406
|
export {};
|
|
407
407
|
}
|
|
408
|
-
export declare type extendShape<A, B> = Omit<A, keyof B> & B
|
|
408
|
+
export declare type extendShape<A, B> = util.flatten<Omit<A, keyof B> & B>;
|
|
409
409
|
export declare type UnknownKeysParam = "passthrough" | "strict" | "strip";
|
|
410
410
|
export interface ZodObjectDef<T extends ZodRawShape = ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
|
|
411
411
|
typeName: ZodFirstPartyTypeKind.ZodObject;
|
|
@@ -413,10 +413,14 @@ export interface ZodObjectDef<T extends ZodRawShape = ZodRawShape, UnknownKeys e
|
|
|
413
413
|
catchall: Catchall;
|
|
414
414
|
unknownKeys: UnknownKeys;
|
|
415
415
|
}
|
|
416
|
-
export declare type
|
|
416
|
+
export declare type mergeTypes<A, B> = {
|
|
417
|
+
[k in keyof A | keyof B]: k extends keyof B ? B[k] : k extends keyof A ? A[k] : never;
|
|
418
|
+
};
|
|
419
|
+
export declare type processType<T extends object> = util.flatten<objectUtil.addQuestionMarks<T>>;
|
|
420
|
+
export declare type baseObjectOutputType<Shape extends ZodRawShape> = objectUtil.addQuestionMarks<{
|
|
417
421
|
[k in keyof Shape]: Shape[k]["_output"];
|
|
418
|
-
}
|
|
419
|
-
export declare type objectOutputType<Shape extends ZodRawShape, Catchall extends ZodTypeAny> = ZodTypeAny extends Catchall ? baseObjectOutputType<Shape
|
|
422
|
+
}>;
|
|
423
|
+
export declare type objectOutputType<Shape extends ZodRawShape, Catchall extends ZodTypeAny> = ZodTypeAny extends Catchall ? objectUtil.flatten<baseObjectOutputType<Shape>> : objectUtil.flatten<baseObjectOutputType<Shape> & {
|
|
420
424
|
[k: string]: Catchall["_output"];
|
|
421
425
|
}>;
|
|
422
426
|
export declare type baseObjectInputType<Shape extends ZodRawShape> = objectUtil.flatten<objectUtil.addQuestionMarks<{
|
|
@@ -433,7 +437,7 @@ export declare type objectKeyMask<Obj> = {
|
|
|
433
437
|
export declare type noUnrecognized<Obj extends object, Shape extends object> = {
|
|
434
438
|
[k in keyof Obj]: k extends keyof Shape ? Obj[k] : never;
|
|
435
439
|
};
|
|
436
|
-
export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny, Output = objectOutputType<T, Catchall>, Input = objectInputType<T, Catchall>> extends ZodType<Output, ZodObjectDef<T, UnknownKeys, Catchall>, Input> {
|
|
440
|
+
export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny, Output = objectOutputType<T, Catchall>, Input = objectInputType<T, Catchall>> extends ZodType<Output, ZodObjectDef<T, UnknownKeys, Catchall>, Input> {
|
|
437
441
|
private _cached;
|
|
438
442
|
_getCached(): {
|
|
439
443
|
shape: T;
|
|
@@ -449,17 +453,28 @@ export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends Unknow
|
|
|
449
453
|
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
450
454
|
*/
|
|
451
455
|
nonstrict: () => ZodObject<T, "passthrough", Catchall>;
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
[k in
|
|
456
|
-
}, UnknownKeys, 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>;
|
|
461
|
+
/**
|
|
462
|
+
* @deprecated Use `.extend` instead
|
|
463
|
+
* */
|
|
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>;
|
|
457
465
|
/**
|
|
458
466
|
* Prior to zod@1.0.12 there was a bug in the
|
|
459
467
|
* inferred type of merged objects. Please
|
|
460
468
|
* upgrade if you are experiencing issues.
|
|
461
469
|
*/
|
|
462
|
-
merge<Incoming extends AnyZodObject
|
|
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>;
|
|
475
|
+
setKey<Key extends string, Schema extends ZodTypeAny>(key: Key, schema: Schema): ZodObject<T & {
|
|
476
|
+
[k in Key]: Schema;
|
|
477
|
+
}, UnknownKeys, Catchall>;
|
|
463
478
|
catchall<Index extends ZodTypeAny>(index: Index): ZodObject<T, UnknownKeys, Index>;
|
|
464
479
|
pick<Mask extends objectKeyMask<T>>(mask: noUnrecognized<Mask, T>): ZodObject<Pick<T, Extract<keyof T, keyof Mask>>, UnknownKeys, Catchall>;
|
|
465
480
|
omit<Mask extends objectKeyMask<T>>(mask: noUnrecognized<Mask, objectKeyMask<T>>): ZodObject<Omit<T, keyof Mask>, UnknownKeys, Catchall>;
|
|
@@ -477,9 +492,9 @@ export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends Unknow
|
|
|
477
492
|
[k in keyof T]: k extends keyof Mask ? deoptional<T[k]> : T[k];
|
|
478
493
|
}>, UnknownKeys, Catchall>;
|
|
479
494
|
keyof(): ZodEnum<enumUtil.UnionToTupleString<keyof T>>;
|
|
480
|
-
static create: <T_1 extends ZodRawShape>(shape: T_1, params?: RawCreateParams) => ZodObject<T_1, "strip", ZodTypeAny, { [
|
|
481
|
-
static strictCreate: <T_1 extends ZodRawShape>(shape: T_1, params?: RawCreateParams) => ZodObject<T_1, "strict", ZodTypeAny, { [
|
|
482
|
-
static lazycreate: <T_1 extends ZodRawShape>(shape: () => T_1, params?: RawCreateParams) => ZodObject<T_1, "strip", ZodTypeAny, { [
|
|
495
|
+
static create: <T_1 extends ZodRawShape>(shape: T_1, params?: RawCreateParams) => ZodObject<T_1, "strip", ZodTypeAny, { [k in keyof baseObjectOutputType<T_1>]: baseObjectOutputType<T_1>[k]; }, { [k_2 in keyof objectUtil.addQuestionMarks<{ [k_1 in keyof T_1]: T_1[k_1]["_input"]; }>]: objectUtil.addQuestionMarks<{ [k_1 in keyof T_1]: T_1[k_1]["_input"]; }>[k_2]; }>;
|
|
496
|
+
static strictCreate: <T_1 extends ZodRawShape>(shape: T_1, params?: RawCreateParams) => ZodObject<T_1, "strict", ZodTypeAny, { [k in keyof baseObjectOutputType<T_1>]: baseObjectOutputType<T_1>[k]; }, { [k_2 in keyof objectUtil.addQuestionMarks<{ [k_1 in keyof T_1]: T_1[k_1]["_input"]; }>]: objectUtil.addQuestionMarks<{ [k_1 in keyof T_1]: T_1[k_1]["_input"]; }>[k_2]; }>;
|
|
497
|
+
static lazycreate: <T_1 extends ZodRawShape>(shape: () => T_1, params?: RawCreateParams) => ZodObject<T_1, "strip", ZodTypeAny, { [k in keyof baseObjectOutputType<T_1>]: baseObjectOutputType<T_1>[k]; }, { [k_2 in keyof objectUtil.addQuestionMarks<{ [k_1 in keyof T_1]: T_1[k_1]["_input"]; }>]: objectUtil.addQuestionMarks<{ [k_1 in keyof T_1]: T_1[k_1]["_input"]; }>[k_2]; }>;
|
|
483
498
|
}
|
|
484
499
|
export declare type AnyZodObject = ZodObject<any, any, any>;
|
|
485
500
|
export declare type ZodUnionOptions = Readonly<[ZodTypeAny, ...ZodTypeAny[]]>;
|
|
@@ -760,7 +775,7 @@ export interface ZodCatchDef<T extends ZodTypeAny = ZodTypeAny, C extends T["_in
|
|
|
760
775
|
catchValue: () => C;
|
|
761
776
|
typeName: ZodFirstPartyTypeKind.ZodCatch;
|
|
762
777
|
}
|
|
763
|
-
export declare class ZodCatch<T extends ZodTypeAny> extends ZodType<T["_output"], ZodCatchDef<T>,
|
|
778
|
+
export declare class ZodCatch<T extends ZodTypeAny> extends ZodType<T["_output"], ZodCatchDef<T>, unknown> {
|
|
764
779
|
_parse(input: ParseInput): ParseReturnType<this["_output"]>;
|
|
765
780
|
removeCatch(): T;
|
|
766
781
|
static create: <T_1 extends ZodTypeAny>(type: T_1, params: {
|
|
@@ -805,7 +820,7 @@ export declare class ZodPipeline<A extends ZodTypeAny, B extends ZodTypeAny> ext
|
|
|
805
820
|
export declare const custom: <T>(check?: ((data: unknown) => any) | undefined, params?: Parameters<ZodTypeAny["refine"]>[1], fatal?: boolean | undefined) => ZodType<T, ZodTypeDef, T>;
|
|
806
821
|
export { ZodType as Schema, ZodType as ZodSchema };
|
|
807
822
|
export declare const late: {
|
|
808
|
-
object: <T extends ZodRawShape>(shape: () => T, params?: RawCreateParams) => ZodObject<T, "strip", ZodTypeAny, { [
|
|
823
|
+
object: <T extends ZodRawShape>(shape: () => T, params?: RawCreateParams) => ZodObject<T, "strip", ZodTypeAny, { [k in keyof baseObjectOutputType<T>]: baseObjectOutputType<T>[k]; }, { [k_2 in keyof objectUtil.addQuestionMarks<{ [k_1 in keyof T]: T[k_1]["_input"]; }>]: objectUtil.addQuestionMarks<{ [k_1 in keyof T]: T[k_1]["_input"]; }>[k_2]; }>;
|
|
809
824
|
};
|
|
810
825
|
export declare enum ZodFirstPartyTypeKind {
|
|
811
826
|
ZodString = "ZodString",
|
|
@@ -898,8 +913,8 @@ declare const unknownType: (params?: RawCreateParams) => ZodUnknown;
|
|
|
898
913
|
declare const neverType: (params?: RawCreateParams) => ZodNever;
|
|
899
914
|
declare const voidType: (params?: RawCreateParams) => ZodVoid;
|
|
900
915
|
declare const arrayType: <T extends ZodTypeAny>(schema: T, params?: RawCreateParams) => ZodArray<T, "many">;
|
|
901
|
-
declare const objectType: <T extends ZodRawShape>(shape: T, params?: RawCreateParams) => ZodObject<T, "strip", ZodTypeAny, { [
|
|
902
|
-
declare const strictObjectType: <T extends ZodRawShape>(shape: T, params?: RawCreateParams) => ZodObject<T, "strict", ZodTypeAny, { [
|
|
916
|
+
declare const objectType: <T extends ZodRawShape>(shape: T, params?: RawCreateParams) => ZodObject<T, "strip", ZodTypeAny, { [k in keyof baseObjectOutputType<T>]: baseObjectOutputType<T>[k]; }, { [k_2 in keyof objectUtil.addQuestionMarks<{ [k_1 in keyof T]: T[k_1]["_input"]; }>]: objectUtil.addQuestionMarks<{ [k_1 in keyof T]: T[k_1]["_input"]; }>[k_2]; }>;
|
|
917
|
+
declare const strictObjectType: <T extends ZodRawShape>(shape: T, params?: RawCreateParams) => ZodObject<T, "strict", ZodTypeAny, { [k in keyof baseObjectOutputType<T>]: baseObjectOutputType<T>[k]; }, { [k_2 in keyof objectUtil.addQuestionMarks<{ [k_1 in keyof T]: T[k_1]["_input"]; }>]: objectUtil.addQuestionMarks<{ [k_1 in keyof T]: T[k_1]["_input"]; }>[k_2]; }>;
|
|
903
918
|
declare const unionType: <T extends readonly [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]]>(types: T, params?: RawCreateParams) => ZodUnion<T>;
|
|
904
919
|
declare const discriminatedUnionType: typeof ZodDiscriminatedUnion.create;
|
|
905
920
|
declare const intersectionType: <T extends ZodTypeAny, U extends ZodTypeAny>(left: T, right: U, params?: RawCreateParams) => ZodIntersection<T, U>;
|
package/lib/types.js
CHANGED
|
@@ -1345,15 +1345,6 @@ var objectUtil;
|
|
|
1345
1345
|
};
|
|
1346
1346
|
};
|
|
1347
1347
|
})(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
|
|
1348
|
-
const AugmentFactory = (def) => (augmentation) => {
|
|
1349
|
-
return new ZodObject({
|
|
1350
|
-
...def,
|
|
1351
|
-
shape: () => ({
|
|
1352
|
-
...def.shape(),
|
|
1353
|
-
...augmentation,
|
|
1354
|
-
}),
|
|
1355
|
-
});
|
|
1356
|
-
};
|
|
1357
1348
|
function deepPartialify(schema) {
|
|
1358
1349
|
if (schema instanceof ZodObject) {
|
|
1359
1350
|
const newShape = {};
|
|
@@ -1391,8 +1382,10 @@ class ZodObject extends ZodType {
|
|
|
1391
1382
|
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
1392
1383
|
*/
|
|
1393
1384
|
this.nonstrict = this.passthrough;
|
|
1394
|
-
|
|
1395
|
-
|
|
1385
|
+
/**
|
|
1386
|
+
* @deprecated Use `.extend` instead
|
|
1387
|
+
* */
|
|
1388
|
+
this.augment = this.extend;
|
|
1396
1389
|
}
|
|
1397
1390
|
_getCached() {
|
|
1398
1391
|
if (this._cached !== null)
|
|
@@ -1530,14 +1523,25 @@ class ZodObject extends ZodType {
|
|
|
1530
1523
|
unknownKeys: "passthrough",
|
|
1531
1524
|
});
|
|
1532
1525
|
}
|
|
1533
|
-
|
|
1534
|
-
|
|
1526
|
+
// augment = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
|
|
1527
|
+
// extend = AugmentFactory<ZodObjectDef<T, UnknownKeys, Catchall>>(this._def);
|
|
1528
|
+
extend(augmentation) {
|
|
1529
|
+
return new ZodObject({
|
|
1530
|
+
...this._def,
|
|
1531
|
+
shape: () => ({
|
|
1532
|
+
...this._def.shape(),
|
|
1533
|
+
...augmentation,
|
|
1534
|
+
}),
|
|
1535
|
+
});
|
|
1535
1536
|
}
|
|
1536
1537
|
/**
|
|
1537
1538
|
* Prior to zod@1.0.12 there was a bug in the
|
|
1538
1539
|
* inferred type of merged objects. Please
|
|
1539
1540
|
* upgrade if you are experiencing issues.
|
|
1540
1541
|
*/
|
|
1542
|
+
// merge<Incoming extends AnyZodObject>(merging: Incoming) {
|
|
1543
|
+
// return this.extend(merging.shape as Incoming["shape"]);
|
|
1544
|
+
// }
|
|
1541
1545
|
merge(merging) {
|
|
1542
1546
|
// const mergedShape = objectUtil.mergeShapes(
|
|
1543
1547
|
// this._def.shape(),
|
|
@@ -1551,6 +1555,30 @@ class ZodObject extends ZodType {
|
|
|
1551
1555
|
});
|
|
1552
1556
|
return merged;
|
|
1553
1557
|
}
|
|
1558
|
+
setKey(key, schema) {
|
|
1559
|
+
return this.augment({ [key]: schema });
|
|
1560
|
+
}
|
|
1561
|
+
// merge<Incoming extends AnyZodObject>(
|
|
1562
|
+
// merging: Incoming
|
|
1563
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
1564
|
+
// ZodObject<
|
|
1565
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
1566
|
+
// Incoming["_def"]["unknownKeys"],
|
|
1567
|
+
// Incoming["_def"]["catchall"]
|
|
1568
|
+
// > {
|
|
1569
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
1570
|
+
// // this._def.shape(),
|
|
1571
|
+
// // merging._def.shape()
|
|
1572
|
+
// // );
|
|
1573
|
+
// const merged: any = new ZodObject({
|
|
1574
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
1575
|
+
// catchall: merging._def.catchall,
|
|
1576
|
+
// shape: () =>
|
|
1577
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
1578
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1579
|
+
// }) as any;
|
|
1580
|
+
// return merged;
|
|
1581
|
+
// }
|
|
1554
1582
|
catchall(index) {
|
|
1555
1583
|
return new ZodObject({
|
|
1556
1584
|
...this._def,
|