zod 4.0.0-beta.20250503T014749 → 4.0.0-beta.20250504T224201

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/src/schemas.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as core from "@zod/core";
2
2
  import { util } from "@zod/core";
3
+
3
4
  import * as checks from "./checks.js";
4
5
  import * as iso from "./iso.js";
5
6
  import * as parse from "./parse.js";
@@ -23,12 +24,12 @@ export interface ZodType<out Output = unknown, out Input = unknown> extends core
23
24
  def: this["_zod"]["def"];
24
25
  /** @deprecated Use `.def` instead. */
25
26
  _def: this["_zod"]["def"];
26
- /** @deprecated Use `z.output<typeof schema>` instead. */
27
- _output: this["_zod"]["output"];
28
- /** @deprecated Use `z.input<typeof schema>` instead. */
29
- _input: this["_zod"]["input"];
27
+ // /** @deprecated Use `z.output<typeof schema>` instead. */
28
+ _output: core.output<this>;
29
+ // /** @deprecated Use `z.input<typeof schema>` instead. */
30
+ _input: core.input<this>;
30
31
  // base methods
31
- check(...checks: (core.CheckFn<this["_zod"]["output"]> | core.$ZodCheck<this["_zod"]["output"]>)[]): this;
32
+ check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
32
33
  clone(def?: this["_zod"]["def"]): this;
33
34
  register<R extends core.$ZodRegistry>(
34
35
  registry: R,
@@ -38,9 +39,10 @@ export interface ZodType<out Output = unknown, out Input = unknown> extends core
38
39
  : [core.$ZodRegistry<R["_meta"], this>["_meta"]]
39
40
  : ["Incompatible schema"]
40
41
  ): this;
42
+
41
43
  brand<T extends PropertyKey = PropertyKey>(
42
44
  value?: T
43
- ): this & Record<"_zod", Record<"output", this["_zod"]["output"] & core.$brand<T>>>;
45
+ ): PropertyKey extends T ? this : this & Record<"_zod", Record<"~output", core.output<this> & core.$brand<T>>>;
44
46
 
45
47
  // parsing
46
48
  parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
@@ -1006,258 +1008,20 @@ export function array<T extends core.$ZodType>(element: core.$ZodType, params?:
1006
1008
  return core._array(ZodArray, element, params) as any;
1007
1009
  }
1008
1010
 
1009
- // ZodObjectLike
1010
- export interface ZodObjectLike<out O = object, out I = object> extends ZodType {
1011
- _zod: core.$ZodObjectLikeInternals<O, I>;
1012
- }
1013
- export const ZodObjectLike: core.$constructor<ZodObjectLike> = /*@__PURE__*/ core.$constructor(
1014
- "ZodObjectLike",
1015
- (inst, def) => {
1016
- core.$ZodObjectLike.init(inst, def);
1017
- ZodType.init(inst, def);
1018
- }
1019
- );
1020
-
1021
1011
  // .keyof
1022
- export function keyof<T extends ZodObject>(schema: T): ZodLiteral<keyof T["_zod"]["def"]["shape"]>;
1023
- export function keyof<T extends ZodInterface>(schema: T): ZodLiteral<keyof T["_zod"]["output"]>;
1024
- export function keyof(schema: ZodObjectLike) {
1025
- const shape =
1026
- schema._zod.def.type === "interface"
1027
- ? util.cleanInterfaceShape(schema._zod.def.shape).shape
1028
- : schema._zod.def.shape;
1029
-
1012
+ export function keyof<T extends ZodObject>(schema: T): ZodLiteral<keyof T["_zod"]["output"]> {
1013
+ const shape = schema._zod.def.shape;
1030
1014
  return literal(Object.keys(shape)) as any;
1031
1015
  }
1032
1016
 
1033
- // ZodInterface
1034
- type ZodInterfacePartial<
1035
- T extends ZodInterface,
1036
- Keys extends keyof T["_zod"]["def"]["shape"] = keyof T["_zod"]["def"]["shape"],
1037
- > = ZodInterface<
1038
- util.Extend<
1039
- T["_zod"]["def"]["shape"],
1040
- {
1041
- [k in Keys]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
1042
- }
1043
- >,
1044
- {
1045
- optional: T["_zod"]["optional"] | (string & Keys);
1046
- defaulted: T["_zod"]["defaulted"];
1047
- extra: T["_zod"]["extra"];
1048
- }
1049
- >;
1050
-
1051
- type ZodInterfaceRequired<
1052
- T extends ZodInterface,
1053
- Keys extends keyof T["_zod"]["def"]["shape"] = keyof T["_zod"]["def"]["shape"],
1054
- > = ZodInterface<
1055
- util.Extend<
1056
- T["_zod"]["def"]["shape"],
1057
- {
1058
- [k in Keys]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
1059
- }
1060
- >,
1061
- {
1062
- optional: never;
1063
- defaulted: T["_zod"]["defaulted"];
1064
- extra: T["_zod"]["extra"];
1065
- }
1066
- >;
1067
-
1068
- export type MergeInterfaces<A extends ZodInterface, B extends ZodInterface> = ZodInterface<
1069
- util.Extend<A["_zod"]["def"]["shape"], B["_zod"]["def"]["shape"]>,
1070
- util.MergeInterfaceParams<A, B>
1071
- >;
1072
-
1073
- export interface ZodInterface<
1074
- // @ts-ignore cast variance
1075
- out Shape extends core.$ZodLooseShape = core.$ZodLooseShape,
1076
- // @ts-ignore cast variance
1077
- out Params extends core.$ZodInterfaceNamedParams = core.$ZodInterfaceNamedParams,
1078
- > extends ZodType {
1079
- _zod: core.$ZodInterfaceInternals<Shape, Params>;
1080
-
1081
- keyof(): ZodEnum<util.ToEnum<util.InterfaceKeys<string & keyof Shape>>>;
1082
- catchall<T extends core.$ZodType>(
1083
- schema: T
1084
- ): ZodInterface<
1085
- Shape,
1086
- {
1087
- optional: Params["optional"];
1088
- defaulted: Params["defaulted"];
1089
- extra: Record<string, T["_zod"]["output"]>;
1090
- }
1091
- >;
1092
- /** Consider `z.strictObject({ ...A.shape })` instead. */
1093
- strict(): ZodInterface<
1094
- Shape,
1095
- {
1096
- optional: Params["optional"];
1097
- defaulted: Params["defaulted"];
1098
- extra: {};
1099
- }
1100
- >;
1101
-
1102
- loose(): ZodInterface<
1103
- Shape,
1104
- {
1105
- optional: Params["optional"];
1106
- defaulted: Params["defaulted"];
1107
- extra: Record<string, unknown>;
1108
- }
1109
- >;
1110
-
1111
- /** Use `z.looseObject({ ...A.shape })` instead. */
1112
- strip(): ZodInterface<
1113
- Shape,
1114
- {
1115
- optional: Params["optional"];
1116
- defaulted: Params["defaulted"];
1117
- extra: {};
1118
- }
1119
- >;
1120
-
1121
- extend<U extends ZodInterface>(int: U): MergeInterfaces<this, U>;
1122
- extend<U extends core.$ZodLooseShape>(
1123
- shape: U
1124
- ): MergeInterfaces<this, ZodInterface<U, util.InitInterfaceParams<U, {}>>>;
1125
-
1126
- /** @deprecated Use `A.extend(B)` */
1127
- merge<U extends ZodInterface>(incoming: U): MergeInterfaces<this, U>;
1128
-
1129
- pick<const M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1130
- mask: M
1131
- ): ZodInterface<
1132
- util.Flatten<Pick<Shape, keyof Shape & keyof M>>,
1133
- {
1134
- optional: Extract<Params["optional"], keyof M>;
1135
- defaulted: Extract<Params["defaulted"], keyof M>;
1136
- extra: Params["extra"];
1137
- }
1138
- >;
1139
-
1140
- omit<const M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1141
- mask: M
1142
- ): ZodInterface<
1143
- util.Flatten<Omit<Shape, keyof M>>,
1144
- {
1145
- optional: Exclude<Params["optional"], keyof M>;
1146
- defaulted: Exclude<Params["defaulted"], keyof M>;
1147
- extra: Params["extra"];
1148
- }
1149
- >;
1150
-
1151
- partial(): ZodInterfacePartial<this>;
1152
- partial<M extends util.Mask<string & keyof Shape>>(mask: M): ZodInterfacePartial<this, string & keyof M>;
1153
-
1154
- required(): ZodInterfaceRequired<this, string & keyof Shape>;
1155
- required<M extends util.Mask<string & keyof Shape>>(mask: M): ZodInterfaceRequired<this, string & keyof M>;
1156
- }
1157
- export const ZodInterface: core.$constructor<ZodInterface> = /*@__PURE__*/ core.$constructor(
1158
- "ZodInterface",
1159
- (inst, def) => {
1160
- core.$ZodInterface.init(inst, def);
1161
- ZodType.init(inst, def);
1162
- // util.defineLazy(inst._zod, "shape", () => def.shape);
1163
-
1164
- inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
1165
- inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
1166
- inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
1167
- inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
1168
- inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
1169
- inst.extend = (incoming: any) => {
1170
- if (incoming instanceof core.$ZodInterface) return util.extendObjectLike(inst, incoming);
1171
- return util.extendObjectLike(inst, _interface(incoming));
1172
- };
1173
- inst.merge = (other) => util.mergeObjectLike(inst, other);
1174
- inst.pick = (mask) => util.pick(inst, mask) as any;
1175
- inst.omit = (mask) => util.omit(inst, mask);
1176
- inst.partial = (...args: any[]) => util.partialObjectLike(ZodOptional, inst, args[0]);
1177
- inst.required = (...args: any[]) => util.requiredObjectLike(ZodNonOptional, inst, args[0]);
1178
- }
1179
- );
1180
-
1181
- function _interface<T extends core.$ZodLooseShape>(
1182
- shape: T,
1183
- params?: string | core.$ZodInterfaceParams,
1184
- Class: util.Constructor<ZodInterface> = ZodInterface
1185
- ): ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, {}>> {
1186
- const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
1187
- const def: core.$ZodInterfaceDef = {
1188
- type: "interface",
1189
- get shape() {
1190
- // return cleaned.value.shape;
1191
- const _shape = cleaned.value.shape;
1192
- util.assignProp(this, "shape", _shape);
1193
- return _shape;
1194
- },
1195
- get optional() {
1196
- return cleaned.value.optional;
1197
- },
1198
- ...util.normalizeParams(params),
1199
- };
1200
- return new Class(def) as any;
1201
- }
1202
- export { _interface as interface };
1203
-
1204
- // strictInterface
1205
-
1206
- export function strictInterface<T extends core.$ZodLooseShape>(
1207
- shape: T,
1208
- params?: string | core.$ZodInterfaceParams
1209
- ): ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, {}>> {
1210
- const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
1211
- const def: core.$ZodInterfaceDef = {
1212
- type: "interface",
1213
- get shape() {
1214
- // return cleaned.value.shape;
1215
- const _shape = cleaned.value.shape;
1216
- util.assignProp(this, "shape", _shape);
1217
- return _shape;
1218
- },
1219
- get optional() {
1220
- return cleaned.value.optional;
1221
- },
1222
- catchall: never(),
1223
- ...util.normalizeParams(params),
1224
- };
1225
- return new ZodInterface(def) as any;
1226
- }
1227
-
1228
- // looseInterface
1229
-
1230
- export function looseInterface<T extends core.$ZodLooseShape>(
1231
- shape: T,
1232
- params?: string | core.$ZodInterfaceParams
1233
- ): ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, Record<string, unknown>>> {
1234
- const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
1235
- const def: core.$ZodInterfaceDef = {
1236
- type: "interface",
1237
- get optional() {
1238
- return cleaned.value.optional;
1239
- },
1240
- get shape() {
1241
- // return cleaned.value.shape;
1242
- const _shape = cleaned.value.shape;
1243
- util.assignProp(this, "shape", _shape);
1244
- return _shape;
1245
- },
1246
- catchall: unknown(),
1247
- ...util.normalizeParams(params),
1248
- };
1249
- return new ZodInterface(def) as any;
1250
- }
1251
-
1252
1017
  // ZodObject
1253
1018
  export interface ZodObject<
1254
1019
  // @ts-ignore cast variance
1255
- out Shape extends core.$ZodShape = core.$ZodShape,
1256
- // @ts-ignore cast variance
1257
- Extra extends Record<string, unknown> = Record<string, unknown>,
1020
+ out Shape extends core.$ZodShape = core.$ZodLooseShape,
1021
+ OutExtra extends Record<string, unknown> = Record<string, unknown>,
1022
+ InExtra extends Record<string, unknown> = Record<string, unknown>,
1258
1023
  > extends ZodType {
1259
- _zod: core.$ZodObjectInternals<Shape, Extra>;
1260
-
1024
+ _zod: core.$ZodObjectInternals<Shape, OutExtra, InExtra>;
1261
1025
  shape: Shape;
1262
1026
 
1263
1027
  keyof(): ZodEnum<util.ToEnum<keyof Shape & string>>;
@@ -1275,33 +1039,52 @@ export interface ZodObject<
1275
1039
  /** This is the default behavior. This method call is likely unnecessary. */
1276
1040
  strip(): ZodObject<Shape, {}>;
1277
1041
 
1278
- extend<const U extends ZodObject>(schema: U): ZodObject<util.Extend<Shape, U["_zod"]["def"]["shape"]>, Extra>;
1279
- extend<U extends core.$ZodShape>(
1042
+ extend<U extends core.$ZodLooseShape>(
1280
1043
  shape: U
1281
1044
  ): ZodObject<
1282
1045
  util.Extend<Shape, U>,
1283
- Extra // & B['_zod']["extra"]
1046
+ OutExtra,
1047
+ InExtra // & B['_zod']["extra"]
1284
1048
  >;
1285
1049
 
1286
- // merge
1287
- /** @deprecated Use `A.extend(B.shape)` */
1288
- merge<U extends ZodObject<any, any>>(
1050
+ /**
1051
+ * @deprecated Use destructuring to merge the shapes:
1052
+ *
1053
+ * ```ts
1054
+ * z.object({
1055
+ * ...A.shape,
1056
+ * ...B.shape
1057
+ * });
1058
+ * ```
1059
+ */
1060
+ merge<U extends ZodObject>(
1289
1061
  other: U
1290
- ): ZodObject<util.Flatten<util.Extend<Shape, U["_zod"]["def"]["shape"]>>, Extra>;
1062
+ ): ZodObject<util.Extend<Shape, U["shape"]>, U["_zod"]["outextra"], U["_zod"]["inextra"]>;
1063
+ /**
1064
+ * @deprecated Use destructuring to merge the shapes:
1065
+ *
1066
+ * ```ts
1067
+ * z.object({
1068
+ * ...A.shape,
1069
+ * ...B.shape
1070
+ * });
1071
+ * ```
1072
+ */
1291
1073
 
1292
1074
  pick<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1293
1075
  mask: M
1294
- ): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, Extra>;
1076
+ ): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, OutExtra, InExtra>;
1295
1077
 
1296
1078
  omit<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1297
1079
  mask: M
1298
- ): ZodObject<util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, Extra>;
1080
+ ): ZodObject<util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, OutExtra, InExtra>;
1299
1081
 
1300
1082
  partial(): ZodObject<
1301
1083
  {
1302
1084
  [k in keyof Shape]: ZodOptional<Shape[k]>;
1303
1085
  },
1304
- Extra
1086
+ OutExtra,
1087
+ InExtra
1305
1088
  >;
1306
1089
  partial<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1307
1090
  mask: M
@@ -1309,7 +1092,8 @@ export interface ZodObject<
1309
1092
  {
1310
1093
  [k in keyof Shape]: k extends keyof M ? ZodOptional<Shape[k]> : Shape[k];
1311
1094
  },
1312
- Extra
1095
+ OutExtra,
1096
+ InExtra
1313
1097
  >;
1314
1098
 
1315
1099
  // required
@@ -1317,7 +1101,8 @@ export interface ZodObject<
1317
1101
  {
1318
1102
  [k in keyof Shape]: ZodNonOptional<Shape[k]>;
1319
1103
  },
1320
- Extra
1104
+ OutExtra,
1105
+ InExtra
1321
1106
  >;
1322
1107
  required<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(
1323
1108
  mask: M
@@ -1325,14 +1110,18 @@ export interface ZodObject<
1325
1110
  {
1326
1111
  [k in keyof Shape]: k extends keyof M ? ZodNonOptional<Shape[k]> : Shape[k];
1327
1112
  },
1328
- Extra
1113
+ OutExtra,
1114
+ InExtra
1329
1115
  >;
1330
1116
  }
1117
+
1331
1118
  export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def) => {
1332
1119
  core.$ZodObject.init(inst, def);
1333
1120
  ZodType.init(inst, def);
1334
1121
 
1335
- inst.shape = def.shape;
1122
+ util.defineLazy(inst, "shape", () => {
1123
+ return Object.fromEntries(Object.entries(inst._zod.def.shape));
1124
+ });
1336
1125
  inst.keyof = () => _enum(Object.keys(inst._zod.def.shape)) as any;
1337
1126
  inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
1338
1127
  inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
@@ -1342,25 +1131,27 @@ export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$const
1342
1131
  inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
1343
1132
 
1344
1133
  inst.extend = (incoming: any) => {
1345
- if (incoming instanceof ZodObject) return util.extendObjectLike(inst, incoming);
1346
- return util.extendObjectLike(inst, object(incoming));
1134
+ return util.extend(inst, incoming);
1347
1135
  };
1348
- inst.merge = (other) => util.mergeObjectLike(inst, other);
1136
+ inst.merge = (other) => util.merge(inst, other);
1349
1137
  inst.pick = (mask) => util.pick(inst, mask);
1350
1138
  inst.omit = (mask) => util.omit(inst, mask);
1351
- inst.partial = (...args: any[]) => util.partialObjectLike(ZodOptional, inst, args[0] as object);
1352
- inst.required = (...args: any[]) => util.requiredObjectLike(ZodNonOptional, inst, args[0] as object);
1139
+ inst.partial = (...args: any[]) => util.partial(ZodOptional, inst, args[0] as object);
1140
+ inst.required = (...args: any[]) => util.required(ZodNonOptional, inst, args[0] as object);
1353
1141
  });
1354
- export function object<T extends core.$ZodShape = Record<never, core.$ZodType>>(
1142
+
1143
+ export function object<T extends core.$ZodLooseShape = Record<never, core.$ZodType>>(
1355
1144
  shape?: T,
1356
- params?: string | core.$ZodObjectLikeParams
1357
- ): ZodObject<T, {}> {
1145
+ params?: string | core.$ZodObjectParams
1146
+ ): ZodObject<util.Writeable<T> & {}, {}, {}> {
1358
1147
  const def: core.$ZodObjectDef = {
1359
1148
  type: "object",
1360
- shape: shape ?? {},
1361
- get optional() {
1362
- return util.optionalObjectKeys(shape ?? {});
1149
+
1150
+ get shape() {
1151
+ util.assignProp(this, "shape", { ...shape });
1152
+ return this.shape;
1363
1153
  },
1154
+
1364
1155
  ...util.normalizeParams(params),
1365
1156
  };
1366
1157
  return new ZodObject(def) as any;
@@ -1368,232 +1159,41 @@ export function object<T extends core.$ZodShape = Record<never, core.$ZodType>>(
1368
1159
 
1369
1160
  // strictObject
1370
1161
 
1371
- export function strictObject<T extends core.$ZodShape>(
1162
+ export function strictObject<T extends core.$ZodLooseShape>(
1372
1163
  shape: T,
1373
1164
  params?: string | core.$ZodObjectParams
1374
- ): ZodObject<T, {}> {
1165
+ ): ZodObject<T, {}, {}> {
1375
1166
  return new ZodObject({
1376
1167
  type: "object",
1377
- shape: shape as core.$ZodShape,
1378
- get optional() {
1379
- return util.optionalObjectKeys(shape);
1168
+
1169
+ get shape() {
1170
+ util.assignProp(this, "shape", { ...shape });
1171
+ return this.shape;
1380
1172
  },
1173
+
1381
1174
  catchall: never(),
1382
1175
  ...util.normalizeParams(params),
1383
1176
  }) as any;
1384
1177
  }
1385
1178
 
1386
1179
  // looseObject
1387
-
1388
- export function looseObject<T extends core.$ZodShape>(
1180
+ export function looseObject<T extends core.$ZodLooseShape>(
1389
1181
  shape: T,
1390
1182
  params?: string | core.$ZodObjectParams
1391
- ): ZodObject<T, { [k: string]: unknown }> {
1183
+ ): ZodObject<T, { [k: string]: unknown }, { [k: string]: unknown }> {
1392
1184
  return new ZodObject({
1393
1185
  type: "object",
1394
- shape: shape as core.$ZodShape,
1395
- get optional() {
1396
- return util.optionalObjectKeys(shape);
1186
+
1187
+ get shape() {
1188
+ util.assignProp(this, "shape", { ...shape });
1189
+ return this.shape;
1397
1190
  },
1191
+
1398
1192
  catchall: unknown(),
1399
1193
  ...util.normalizeParams(params),
1400
1194
  }) as any;
1401
1195
  }
1402
1196
 
1403
- // object methods
1404
- export function extend<T extends ZodInterface, U extends ZodInterface>(
1405
- a: T,
1406
- b: U
1407
- ): ZodInterface<util.Extend<T["_zod"]["def"]["shape"], U["_zod"]["def"]["shape"]>, util.MergeInterfaceParams<T, U>>;
1408
- export function extend<T extends ZodObject, U extends ZodObject>(
1409
- a: T,
1410
- b: U
1411
- ): ZodObject<
1412
- util.Extend<T["_zod"]["def"]["shape"], U["_zod"]["def"]["shape"]>,
1413
- U["_zod"]["extra"] & T["_zod"]["extra"]
1414
- >;
1415
- export function extend<T extends ZodObjectLike, U extends core.$ZodLooseShape>(
1416
- schema: T,
1417
- shape: U
1418
- ): T extends ZodInterface<infer TShape, infer TParams>
1419
- ? ZodInterface<util.ExtendInterfaceShape<TShape, U>, util.ExtendInterfaceParams<ZodInterface<TShape, TParams>, U>>
1420
- : ZodObject<util.Extend<T["_zod"]["def"]["shape"], U>, T["_zod"]["extra"]>;
1421
- export function extend(schema: ZodObjectLike, shape: core.$ZodShape): ZodObjectLike {
1422
- if (shape instanceof core.$ZodType) return util.mergeObjectLike(schema, shape as any);
1423
- if (schema instanceof ZodInterface) {
1424
- return util.mergeObjectLike(schema, _interface(shape));
1425
- }
1426
- if (schema instanceof ZodObject) return util.mergeObjectLike(schema, object(shape));
1427
- return util.extend(schema, shape);
1428
- }
1429
-
1430
- export function merge<T extends ZodObjectLike, U extends core.$ZodLooseShape>(
1431
- schema: T,
1432
- shape: U
1433
- ): T["_zod"]["def"]["type"] extends "interface"
1434
- ? // T extends ZodInterface
1435
- ZodInterface<
1436
- util.Extend<T["_zod"]["def"]["shape"], U["_zod"]["def"]["shape"]>,
1437
- {
1438
- extra: T["_zod"]["extra"] & U["_zod"]["extra"];
1439
- optional: Exclude<T["_zod"]["optional"], keyof U["_zod"]["def"]["shape"]> | U["_zod"]["optional"];
1440
- defaulted: Exclude<T["_zod"]["defaulted"], keyof U["_zod"]["def"]["shape"]> | U["_zod"]["defaulted"];
1441
- }
1442
- >
1443
- : ZodObject<util.Extend<T["_zod"]["def"]["shape"], U>, T["_zod"]["extra"]>;
1444
- export function merge(a: ZodObjectLike, b: ZodObjectLike): ZodObjectLike {
1445
- return util.mergeObjectLike(a, b);
1446
- }
1447
-
1448
- // .pick
1449
- export function pick<T extends ZodObjectLike, M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>>(
1450
- schema: T,
1451
- mask: M
1452
- ): T["_zod"]["def"]["type"] extends "interface"
1453
- ? ZodInterface<
1454
- util.Flatten<Pick<T["_zod"]["def"]["shape"], keyof T["_zod"]["def"]["shape"] & keyof M>>,
1455
- {
1456
- optional: Extract<T["_zod"]["optional"], keyof M>;
1457
- defaulted: Extract<T["_zod"]["defaulted"], keyof M>;
1458
- extra: T["_zod"]["extra"];
1459
- }
1460
- >
1461
- : ZodObject<
1462
- util.Flatten<Pick<T["_zod"]["def"]["shape"], keyof T["_zod"]["def"]["shape"] & keyof M>>,
1463
- T["_zod"]["extra"]
1464
- >;
1465
- export function pick(schema: ZodObjectLike, mask: object) {
1466
- // const picked = util.pick(schema, mask);
1467
- return util.pick(schema, mask);
1468
- }
1469
-
1470
- // .omit
1471
- export function omit<
1472
- T extends ZodObjectLike,
1473
- const M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>,
1474
- >(
1475
- schema: T,
1476
- mask: M
1477
- ): T["_zod"]["def"]["type"] extends "interface"
1478
- ? ZodInterface<
1479
- util.Flatten<Omit<T["_zod"]["def"]["shape"], keyof M>>,
1480
- {
1481
- optional: Exclude<T["_zod"]["optional"], keyof M>;
1482
- defaulted: Exclude<T["_zod"]["defaulted"], keyof M>;
1483
- extra: T["_zod"]["extra"];
1484
- }
1485
- >
1486
- : ZodObject<util.Flatten<Omit<T["_zod"]["def"]["shape"], keyof M>>, T["_zod"]["extra"]>;
1487
-
1488
- export function omit(schema: ZodObjectLike, mask: object) {
1489
- return util.omit(schema, mask);
1490
- }
1491
-
1492
- export function partial<T extends ZodObjectLike>(
1493
- schema: T
1494
- ): T["_zod"]["def"]["type"] extends "interface"
1495
- ? ZodInterface<
1496
- // T['_zod']["shape"],
1497
- {
1498
- [k in keyof T["_zod"]["def"]["shape"]]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
1499
- },
1500
- {
1501
- optional: string & keyof T["_zod"]["def"]["shape"];
1502
- defaulted: never;
1503
- extra: T["_zod"]["extra"];
1504
- }
1505
- >
1506
- : ZodObject<
1507
- {
1508
- [k in keyof T["_zod"]["def"]["shape"]]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
1509
- },
1510
- T["_zod"]["extra"]
1511
- >;
1512
- export function partial<T extends ZodObjectLike, M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>>(
1513
- schema: T,
1514
- mask: M
1515
- ): T["_zod"]["def"]["type"] extends "interface"
1516
- ? ZodInterface<
1517
- util.Extend<
1518
- T["_zod"]["def"]["shape"],
1519
- {
1520
- [k in keyof M & keyof T["_zod"]["def"]["shape"]]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
1521
- }
1522
- >,
1523
- {
1524
- optional: string & (T["_zod"]["optional"] | keyof M);
1525
- defaulted: T["_zod"]["defaulted"];
1526
- extra: T["_zod"]["extra"];
1527
- }
1528
- >
1529
- : ZodObject<
1530
- {
1531
- [k in keyof T["_zod"]["def"]["shape"]]: k extends keyof M
1532
- ? ZodOptional<T["_zod"]["def"]["shape"][k]>
1533
- : T["_zod"]["def"]["shape"][k];
1534
- },
1535
- T["_zod"]["extra"]
1536
- >;
1537
-
1538
- export function partial(schema: ZodObjectLike, mask?: object): ZodObjectLike {
1539
- return util.partialObjectLike(ZodOptional, schema, mask);
1540
- }
1541
-
1542
- // .required
1543
- export function required<T extends { _subtype: "object" } & ZodObject>(
1544
- schema: T
1545
- ): ZodObject<{
1546
- [k in keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
1547
- }>;
1548
- export function required<
1549
- T extends { _subtype: "object" } & ZodObject,
1550
- M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>,
1551
- >(
1552
- schema: T,
1553
- mask: M
1554
- ): ZodObject<
1555
- util.Extend<
1556
- T["_zod"]["def"]["shape"],
1557
- {
1558
- [k in keyof M & keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
1559
- }
1560
- >
1561
- >;
1562
- export function required<T extends { _subtype: "interface" } & ZodInterface>(
1563
- schema: T
1564
- ): ZodInterface<
1565
- {
1566
- [k in keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
1567
- },
1568
- {
1569
- optional: never;
1570
- defaulted: T["_zod"]["defaulted"];
1571
- extra: T["_zod"]["extra"];
1572
- }
1573
- >;
1574
- export function required<
1575
- T extends { _subtype: "interface" } & ZodInterface,
1576
- M extends util.Mask<keyof T["_zod"]["output"]>,
1577
- >(
1578
- schema: T,
1579
- mask: M
1580
- ): ZodInterface<
1581
- util.Extend<
1582
- T["_zod"]["def"]["shape"],
1583
- {
1584
- [k in keyof M & keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
1585
- }
1586
- >,
1587
- {
1588
- optional: Exclude<T["_zod"]["optional"], keyof M>;
1589
- defaulted: T["_zod"]["defaulted"];
1590
- extra: T["_zod"]["extra"];
1591
- }
1592
- >;
1593
- export function required(schema: ZodObjectLike, mask?: object): ZodObjectLike {
1594
- return util.requiredObjectLike(ZodNonOptional, schema, mask);
1595
- }
1596
-
1597
1197
  // ZodUnion
1598
1198
  export interface ZodUnion<T extends readonly core.$ZodType[] = readonly core.$ZodType[]> extends ZodType {
1599
1199
  _zod: core.$ZodUnionInternals<T>;