zod 3.14.4 → 3.15.1

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/types.d.ts CHANGED
@@ -15,15 +15,7 @@ export declare type ZodTypeAny = ZodType<any, any, any>;
15
15
  export declare type TypeOf<T extends ZodType<any, any, any>> = T["_output"];
16
16
  export declare type input<T extends ZodType<any, any, any>> = T["_input"];
17
17
  export declare type output<T extends ZodType<any, any, any>> = T["_output"];
18
- declare type allKeys<T> = T extends any ? keyof T : never;
19
- export declare type TypeOfFlattenedError<T extends ZodType<any, any, any>, U = string> = {
20
- formErrors: U[];
21
- fieldErrors: {
22
- [P in allKeys<TypeOf<T>>]?: U[];
23
- };
24
- };
25
- export declare type TypeOfFormErrors<T extends ZodType<any, any, any>> = TypeOfFlattenedError<T>;
26
- export type { TypeOf as infer, TypeOfFlattenedError as inferFlattenedErrors, TypeOfFormErrors as inferFormErrors, };
18
+ export type { TypeOf as infer };
27
19
  export declare type CustomErrorParams = Partial<util.Omit<ZodCustomIssue, "code">>;
28
20
  export interface ZodTypeDef {
29
21
  errorMap?: ZodErrorMap;
@@ -79,7 +71,7 @@ export declare abstract class ZodType<Output = any, Def extends ZodTypeDef = Zod
79
71
  promise(): ZodPromise<this>;
80
72
  or<T extends ZodTypeAny>(option: T): ZodUnion<[this, T]>;
81
73
  and<T extends ZodTypeAny>(incoming: T): ZodIntersection<this, T>;
82
- transform<NewOut>(transform: (arg: Output) => NewOut | Promise<NewOut>): ZodEffects<this, NewOut>;
74
+ transform<NewOut>(transform: (arg: Output, ctx: RefinementCtx) => NewOut | Promise<NewOut>): ZodEffects<this, NewOut>;
83
75
  default(def: util.noUndefined<Input>): ZodDefault<this>;
84
76
  default(def: () => util.noUndefined<Input>): ZodDefault<this>;
85
77
  describe(description: string): this;
@@ -275,38 +267,30 @@ export declare class ZodArray<T extends ZodTypeAny, Cardinality extends ArrayCar
275
267
  }
276
268
  export declare type ZodNonEmptyArray<T extends ZodTypeAny> = ZodArray<T, "atleastone">;
277
269
  export declare namespace objectUtil {
278
- export type MergeShapes<U extends ZodRawShape, V extends ZodRawShape> = {
270
+ type MergeShapes<U extends ZodRawShape, V extends ZodRawShape> = {
279
271
  [k in Exclude<keyof U, keyof V>]: U[k];
280
272
  } & V;
281
- type optionalKeys<T extends object> = {
282
- [k in keyof T]: undefined extends T[k] ? k : never;
283
- }[keyof T];
284
273
  type requiredKeys<T extends object> = {
285
274
  [k in keyof T]: undefined extends T[k] ? never : k;
286
275
  }[keyof T];
287
- export type addQuestionMarks<T extends object> = {
288
- [k in optionalKeys<T>]?: T[k];
276
+ type addQuestionMarks<T extends object> = {
277
+ [k in keyof T]?: T[k];
289
278
  } & {
290
279
  [k in requiredKeys<T>]: T[k];
291
280
  };
292
- export type identity<T> = T;
293
- export type flatten<T extends object> = identity<{
281
+ type identity<T> = T;
282
+ type flatten<T extends object> = identity<{
294
283
  [k in keyof T]: T[k];
295
284
  }>;
296
- export type noNeverKeys<T extends ZodRawShape> = {
285
+ type noNeverKeys<T extends ZodRawShape> = {
297
286
  [k in keyof T]: [T[k]] extends [never] ? never : k;
298
287
  }[keyof T];
299
- export type noNever<T extends ZodRawShape> = identity<{
288
+ type noNever<T extends ZodRawShape> = identity<{
300
289
  [k in noNeverKeys<T>]: k extends keyof T ? T[k] : never;
301
290
  }>;
302
- export const mergeShapes: <U extends ZodRawShape, T extends ZodRawShape>(first: U, second: T) => T & U;
303
- export {};
291
+ const mergeShapes: <U extends ZodRawShape, T extends ZodRawShape>(first: U, second: T) => T & U;
304
292
  }
305
- export declare type extendShape<A, B> = {
306
- [k in Exclude<keyof A, keyof B>]: A[k];
307
- } & {
308
- [k in keyof B]: B[k];
309
- };
293
+ export declare type extendShape<A, B> = Omit<A, keyof B> & B;
310
294
  declare type UnknownKeysParam = "passthrough" | "strict" | "strip";
311
295
  export interface ZodObjectDef<T extends ZodRawShape = ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
312
296
  typeName: ZodFirstPartyTypeKind.ZodObject;
@@ -361,14 +345,10 @@ export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends Unknow
361
345
  catchall<Index extends ZodTypeAny>(index: Index): ZodObject<T, UnknownKeys, Index>;
362
346
  pick<Mask extends {
363
347
  [k in keyof T]?: true;
364
- }>(mask: Mask): ZodObject<objectUtil.noNever<{
365
- [k in keyof Mask]: k extends keyof T ? T[k] : never;
366
- }>, UnknownKeys, Catchall>;
348
+ }>(mask: Mask): ZodObject<Pick<T, Extract<keyof T, keyof Mask>>, UnknownKeys, Catchall>;
367
349
  omit<Mask extends {
368
350
  [k in keyof T]?: true;
369
- }>(mask: Mask): ZodObject<objectUtil.noNever<{
370
- [k in keyof T]: k extends keyof Mask ? never : T[k];
371
- }>, UnknownKeys, Catchall>;
351
+ }>(mask: Mask): ZodObject<Omit<T, keyof Mask>, UnknownKeys, Catchall>;
372
352
  deepPartial(): partialUtil.DeepPartial<this>;
373
353
  partial(): ZodObject<{
374
354
  [k in keyof T]: ZodOptional<T[k]>;
@@ -589,7 +569,7 @@ export declare type RefinementEffect<T> = {
589
569
  };
590
570
  export declare type TransformEffect<T> = {
591
571
  type: "transform";
592
- transform: (arg: T) => any;
572
+ transform: (arg: T, ctx: RefinementCtx) => any;
593
573
  };
594
574
  export declare type PreprocessEffect<T> = {
595
575
  type: "preprocess";
package/lib/types.js CHANGED
@@ -223,8 +223,6 @@ class ZodType {
223
223
  });
224
224
  }
225
225
  optional() {
226
- ("");
227
- ("asdf");
228
226
  return ZodOptional.create(this);
229
227
  }
230
228
  nullable() {
@@ -2117,22 +2115,22 @@ class ZodEffects extends ZodType {
2117
2115
  });
2118
2116
  }
2119
2117
  }
2118
+ const checkCtx = {
2119
+ addIssue: (arg) => {
2120
+ (0, parseUtil_1.addIssueToContext)(ctx, arg);
2121
+ if (arg.fatal) {
2122
+ status.abort();
2123
+ }
2124
+ else {
2125
+ status.dirty();
2126
+ }
2127
+ },
2128
+ get path() {
2129
+ return ctx.path;
2130
+ },
2131
+ };
2132
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
2120
2133
  if (effect.type === "refinement") {
2121
- const checkCtx = {
2122
- addIssue: (arg) => {
2123
- (0, parseUtil_1.addIssueToContext)(ctx, arg);
2124
- if (arg.fatal) {
2125
- status.abort();
2126
- }
2127
- else {
2128
- status.dirty();
2129
- }
2130
- },
2131
- get path() {
2132
- return ctx.path;
2133
- },
2134
- };
2135
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
2136
2134
  const executeRefinement = (acc
2137
2135
  // effect: RefinementEffect<any>
2138
2136
  ) => {
@@ -2186,11 +2184,11 @@ class ZodEffects extends ZodType {
2186
2184
  // }
2187
2185
  if (!(0, parseUtil_1.isValid)(base))
2188
2186
  return base;
2189
- const result = effect.transform(base.value);
2187
+ const result = effect.transform(base.value, checkCtx);
2190
2188
  if (result instanceof Promise) {
2191
2189
  throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
2192
2190
  }
2193
- return (0, parseUtil_1.OK)(result);
2191
+ return { status: status.value, value: result };
2194
2192
  }
2195
2193
  else {
2196
2194
  return this._def.schema
@@ -2202,7 +2200,7 @@ class ZodEffects extends ZodType {
2202
2200
  // if (base.status === "dirty") {
2203
2201
  // return { status: "dirty", value: base.value };
2204
2202
  // }
2205
- return Promise.resolve(effect.transform(base.value)).then(parseUtil_1.OK);
2203
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then(parseUtil_1.OK);
2206
2204
  });
2207
2205
  }
2208
2206
  }
package/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.14.4",
3
+ "version": "3.15.1",
4
4
  "description": "TypeScript-first schema declaration and validation library with static type inference",
5
5
  "main": "./lib/index.js",
6
- "types": "./lib/index.d.ts",
6
+ "types": "./index.d.ts",
7
7
  "module": "./lib/index.mjs",
8
8
  "dependencies": {},
9
9
  "exports": {
10
10
  ".": {
11
11
  "require": "./lib/index.js",
12
12
  "import": "./lib/index.mjs",
13
- "types": "./lib/index.d.ts"
13
+ "types": "./index.d.ts"
14
14
  },
15
15
  "./package.json": "./package.json"
16
16
  },
17
17
  "files": [
18
- "/lib"
18
+ "/lib",
19
+ "/index.d.ts"
19
20
  ],
20
21
  "repository": {
21
22
  "type": "git",
@@ -86,6 +87,7 @@
86
87
  "pretty-quick": "^3.1.3",
87
88
  "rollup": "^2.70.1",
88
89
  "ts-jest": "^27.1.3",
90
+ "ts-morph": "^14.0.0",
89
91
  "ts-node": "^10.7.0",
90
92
  "tslib": "^2.3.1",
91
93
  "typescript": "^4.6.2"