zod 4.0.3 → 4.0.5

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.0.3",
3
+ "version": "4.0.5",
4
4
  "type": "module",
5
5
  "author": "Colin McDonnell <zod@colinhacks.com>",
6
6
  "description": "TypeScript-first schema declaration and validation library with static type inference",
@@ -65,3 +65,6 @@ export type {
65
65
 
66
66
  /** Included for Zod 3 compatibility */
67
67
  export type ZodRawShape = core.$ZodShape;
68
+
69
+ /** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
70
+ export enum ZodFirstPartyTypeKind {}
@@ -61,7 +61,8 @@ export interface ZodType<
61
61
 
62
62
  // refinements
63
63
  refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
64
- /** @deprecated Use `.check()` instead. */
64
+ /** @deprecated Use [`.check()`](https://zod.dev/api?id=check) instead.
65
+ */
65
66
  superRefine(
66
67
  refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>
67
68
  ): this;
@@ -1074,17 +1075,7 @@ export interface ZodObject<
1074
1075
  ): ZodObject<util.Extend<Shape, U>, Config>;
1075
1076
 
1076
1077
  /**
1077
- * @deprecated Use spread syntax and the `.shape` property to combine two object schemas:
1078
- *
1079
- * ```ts
1080
- * const A = z.object({ a: z.string() });
1081
- * const B = z.object({ b: z.number() });
1082
- *
1083
- * const C = z.object({
1084
- * ...A.shape,
1085
- * ...B.shape
1086
- * });
1087
- * ```
1078
+ * @deprecated Use [`A.extend(B.shape)`](https://zod.dev/api?id=extend) instead.
1088
1079
  */
1089
1080
  merge<U extends ZodObject>(other: U): ZodObject<util.Extend<Shape, U["shape"]>, U["_zod"]["config"]>;
1090
1081
 
@@ -617,3 +617,32 @@ test("readonly literal discriminator", () => {
617
617
  discUnion.parse({ type: "c", a: "hello" });
618
618
  }).toThrow();
619
619
  });
620
+
621
+ test("pipes", () => {
622
+ const schema = z
623
+ .object({
624
+ type: z.literal("foo"),
625
+ })
626
+ .transform((s) => ({ ...s, v: 2 }));
627
+
628
+ expect(schema._zod.propValues).toMatchInlineSnapshot(`
629
+ {
630
+ "type": Set {
631
+ "foo",
632
+ },
633
+ }
634
+ `);
635
+
636
+ const schema2 = z.object({
637
+ type: z.literal("bar"),
638
+ });
639
+
640
+ const combinedSchema = z.discriminatedUnion("type", [schema, schema2], {
641
+ unionFallback: false,
642
+ });
643
+
644
+ combinedSchema.parse({
645
+ type: "foo",
646
+ v: 2,
647
+ });
648
+ });
@@ -2039,7 +2039,7 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
2039
2039
  const opts = def.options as $ZodTypeDiscriminable[];
2040
2040
  const map: Map<util.Primitive, $ZodType> = new Map();
2041
2041
  for (const o of opts) {
2042
- const values = o._zod.propValues[def.discriminator];
2042
+ const values = o._zod.propValues?.[def.discriminator];
2043
2043
  if (!values || values.size === 0)
2044
2044
  throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
2045
2045
  for (const v of values) {
@@ -3429,6 +3429,7 @@ export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends Some
3429
3429
  values: A["_zod"]["values"];
3430
3430
  optin: A["_zod"]["optin"];
3431
3431
  optout: B["_zod"]["optout"];
3432
+ propValues: A["_zod"]["propValues"];
3432
3433
  }
3433
3434
 
3434
3435
  export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
@@ -3440,6 +3441,7 @@ export const $ZodPipe: core.$constructor<$ZodPipe> = /*@__PURE__*/ core.$constru
3440
3441
  util.defineLazy(inst._zod, "values", () => def.in._zod.values);
3441
3442
  util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
3442
3443
  util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
3444
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
3443
3445
 
3444
3446
  inst._zod.parse = (payload, ctx) => {
3445
3447
  const left = def.in._zod.run(payload, ctx);
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 0,
4
- patch: 3 as number,
4
+ patch: 5 as number,
5
5
  } as const;
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  return result;
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.config = exports.$brand = exports.ZodIssueCode = void 0;
27
+ exports.ZodFirstPartyTypeKind = exports.config = exports.$brand = exports.ZodIssueCode = void 0;
28
28
  exports.setErrorMap = setErrorMap;
29
29
  exports.getErrorMap = getErrorMap;
30
30
  const core = __importStar(require("../core/index.cjs"));
@@ -55,3 +55,7 @@ function setErrorMap(map) {
55
55
  function getErrorMap() {
56
56
  return core.config().customError;
57
57
  }
58
+ /** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
59
+ var ZodFirstPartyTypeKind;
60
+ (function (ZodFirstPartyTypeKind) {
61
+ })(ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = ZodFirstPartyTypeKind = {}));
@@ -45,3 +45,6 @@ ZodType as ZodSchema,
45
45
  ZodType as Schema, };
46
46
  /** Included for Zod 3 compatibility */
47
47
  export type ZodRawShape = core.$ZodShape;
48
+ /** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
49
+ export declare enum ZodFirstPartyTypeKind {
50
+ }
@@ -45,3 +45,6 @@ ZodType as ZodSchema,
45
45
  ZodType as Schema, };
46
46
  /** Included for Zod 3 compatibility */
47
47
  export type ZodRawShape = core.$ZodShape;
48
+ /** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
49
+ export declare enum ZodFirstPartyTypeKind {
50
+ }
@@ -25,3 +25,7 @@ export function setErrorMap(map) {
25
25
  export function getErrorMap() {
26
26
  return core.config().customError;
27
27
  }
28
+ /** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
29
+ export var ZodFirstPartyTypeKind;
30
+ (function (ZodFirstPartyTypeKind) {
31
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
@@ -25,7 +25,8 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
25
25
  safeParseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<parse.ZodSafeParseResult<core.output<this>>>;
26
26
  spa: (data: unknown, params?: core.ParseContext<core.$ZodIssue>) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
27
27
  refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
28
- /** @deprecated Use `.check()` instead. */
28
+ /** @deprecated Use [`.check()`](https://zod.dev/api?id=check) instead.
29
+ */
29
30
  superRefine(refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>): this;
30
31
  overwrite(fn: (x: core.output<this>) => core.output<this>): this;
31
32
  optional(): ZodOptional<this>;
@@ -416,17 +417,7 @@ out Shape extends core.$ZodShape = core.$ZodLooseShape, out Config extends core.
416
417
  strip(): ZodObject<Shape, core.$strip>;
417
418
  extend<U extends core.$ZodLooseShape & Partial<Record<keyof Shape, core.SomeType>>>(shape: U): ZodObject<util.Extend<Shape, U>, Config>;
418
419
  /**
419
- * @deprecated Use spread syntax and the `.shape` property to combine two object schemas:
420
- *
421
- * ```ts
422
- * const A = z.object({ a: z.string() });
423
- * const B = z.object({ b: z.number() });
424
- *
425
- * const C = z.object({
426
- * ...A.shape,
427
- * ...B.shape
428
- * });
429
- * ```
420
+ * @deprecated Use [`A.extend(B.shape)`](https://zod.dev/api?id=extend) instead.
430
421
  */
431
422
  merge<U extends ZodObject>(other: U): ZodObject<util.Extend<Shape, U["shape"]>, U["_zod"]["config"]>;
432
423
  pick<M extends util.Mask<keyof Shape>>(mask: M): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, Config>;
@@ -25,7 +25,8 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
25
25
  safeParseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<parse.ZodSafeParseResult<core.output<this>>>;
26
26
  spa: (data: unknown, params?: core.ParseContext<core.$ZodIssue>) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
27
27
  refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
28
- /** @deprecated Use `.check()` instead. */
28
+ /** @deprecated Use [`.check()`](https://zod.dev/api?id=check) instead.
29
+ */
29
30
  superRefine(refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>): this;
30
31
  overwrite(fn: (x: core.output<this>) => core.output<this>): this;
31
32
  optional(): ZodOptional<this>;
@@ -416,17 +417,7 @@ out Shape extends core.$ZodShape = core.$ZodLooseShape, out Config extends core.
416
417
  strip(): ZodObject<Shape, core.$strip>;
417
418
  extend<U extends core.$ZodLooseShape & Partial<Record<keyof Shape, core.SomeType>>>(shape: U): ZodObject<util.Extend<Shape, U>, Config>;
418
419
  /**
419
- * @deprecated Use spread syntax and the `.shape` property to combine two object schemas:
420
- *
421
- * ```ts
422
- * const A = z.object({ a: z.string() });
423
- * const B = z.object({ b: z.number() });
424
- *
425
- * const C = z.object({
426
- * ...A.shape,
427
- * ...B.shape
428
- * });
429
- * ```
420
+ * @deprecated Use [`A.extend(B.shape)`](https://zod.dev/api?id=extend) instead.
430
421
  */
431
422
  merge<U extends ZodObject>(other: U): ZodObject<util.Extend<Shape, U["shape"]>, U["_zod"]["config"]>;
432
423
  pick<M extends util.Mask<keyof Shape>>(mask: M): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, Config>;
@@ -984,7 +984,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
984
984
  const opts = def.options;
985
985
  const map = new Map();
986
986
  for (const o of opts) {
987
- const values = o._zod.propValues[def.discriminator];
987
+ const values = o._zod.propValues?.[def.discriminator];
988
988
  if (!values || values.size === 0)
989
989
  throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
990
990
  for (const v of values) {
@@ -1617,6 +1617,7 @@ exports.$ZodPipe = core.$constructor("$ZodPipe", (inst, def) => {
1617
1617
  util.defineLazy(inst._zod, "values", () => def.in._zod.values);
1618
1618
  util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1619
1619
  util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1620
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
1620
1621
  inst._zod.parse = (payload, ctx) => {
1621
1622
  const left = def.in._zod.run(payload, ctx);
1622
1623
  if (left instanceof Promise) {
@@ -935,6 +935,7 @@ export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends Some
935
935
  values: A["_zod"]["values"];
936
936
  optin: A["_zod"]["optin"];
937
937
  optout: B["_zod"]["optout"];
938
+ propValues: A["_zod"]["propValues"];
938
939
  }
939
940
  export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
940
941
  _zod: $ZodPipeInternals<A, B>;
@@ -935,6 +935,7 @@ export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends Some
935
935
  values: A["_zod"]["values"];
936
936
  optin: A["_zod"]["optin"];
937
937
  optout: B["_zod"]["optout"];
938
+ propValues: A["_zod"]["propValues"];
938
939
  }
939
940
  export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
940
941
  _zod: $ZodPipeInternals<A, B>;
@@ -953,7 +953,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
953
953
  const opts = def.options;
954
954
  const map = new Map();
955
955
  for (const o of opts) {
956
- const values = o._zod.propValues[def.discriminator];
956
+ const values = o._zod.propValues?.[def.discriminator];
957
957
  if (!values || values.size === 0)
958
958
  throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
959
959
  for (const v of values) {
@@ -1586,6 +1586,7 @@ export const $ZodPipe = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def)
1586
1586
  util.defineLazy(inst._zod, "values", () => def.in._zod.values);
1587
1587
  util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1588
1588
  util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1589
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
1589
1590
  inst._zod.parse = (payload, ctx) => {
1590
1591
  const left = def.in._zod.run(payload, ctx);
1591
1592
  if (left instanceof Promise) {
@@ -4,5 +4,5 @@ exports.version = void 0;
4
4
  exports.version = {
5
5
  major: 4,
6
6
  minor: 0,
7
- patch: 3,
7
+ patch: 5,
8
8
  };
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 0,
4
- patch: 3,
4
+ patch: 5,
5
5
  };