zod 4.1.0-canary.20250710T200141 → 4.1.0-canary.20250711T052917

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.1.0-canary.20250710T200141",
3
+ "version": "4.1.0-canary.20250711T052917",
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 {}
@@ -1,6 +1,5 @@
1
1
  import { expect, expectTypeOf, test } from "vitest";
2
2
  import { z } from "zod/v4";
3
- import type { util } from "zod/v4/core";
4
3
 
5
4
  test("basic catch", () => {
6
5
  expect(z.string().catch("default").parse(undefined)).toBe("default");
@@ -45,7 +44,7 @@ test("catch with transform", () => {
45
44
  expect(stringWithDefault.unwrap().out).toBeInstanceOf(z.ZodTransform);
46
45
 
47
46
  type inp = z.input<typeof stringWithDefault>;
48
- expectTypeOf<inp>().toEqualTypeOf<string | util.Whatever>();
47
+ expectTypeOf<inp>().toEqualTypeOf<string>();
49
48
  type out = z.output<typeof stringWithDefault>;
50
49
  expectTypeOf<out>().toEqualTypeOf<string>();
51
50
  });
@@ -59,7 +58,7 @@ test("catch on existing optional", () => {
59
58
  expect(stringWithDefault.unwrap().unwrap()).toBeInstanceOf(z.ZodString);
60
59
 
61
60
  type inp = z.input<typeof stringWithDefault>;
62
- expectTypeOf<inp>().toEqualTypeOf<string | undefined | util.Whatever>();
61
+ expectTypeOf<inp>().toEqualTypeOf<string | undefined>();
63
62
  type out = z.output<typeof stringWithDefault>;
64
63
  expectTypeOf<out>().toEqualTypeOf<string | undefined>();
65
64
  });
@@ -68,7 +67,7 @@ test("optional on catch", () => {
68
67
  const stringWithDefault = z.string().catch("asdf").optional();
69
68
 
70
69
  type inp = z.input<typeof stringWithDefault>;
71
- expectTypeOf<inp>().toEqualTypeOf<string | util.Whatever>();
70
+ expectTypeOf<inp>().toEqualTypeOf<string | undefined>();
72
71
  type out = z.output<typeof stringWithDefault>;
73
72
  expectTypeOf<out>().toEqualTypeOf<string | undefined>();
74
73
  });
@@ -102,7 +101,7 @@ test("nested", () => {
102
101
  inner: "asdf",
103
102
  });
104
103
  type input = z.input<typeof outer>;
105
- expectTypeOf<input>().toEqualTypeOf<{ inner: string | util.Whatever } | util.Whatever>();
104
+ expectTypeOf<input>().toEqualTypeOf<{ inner: string }>();
106
105
  type out = z.output<typeof outer>;
107
106
 
108
107
  expectTypeOf<out>().toEqualTypeOf<{ inner: string }>();
@@ -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) {
@@ -3315,11 +3315,8 @@ export interface $ZodCatchDef<T extends SomeType = $ZodType> extends $ZodTypeDef
3315
3315
  }
3316
3316
 
3317
3317
  export interface $ZodCatchInternals<T extends SomeType = $ZodType>
3318
- extends $ZodTypeInternals<core.output<T>, core.input<T> | util.Whatever> {
3318
+ extends $ZodTypeInternals<core.output<T>, core.input<T>> {
3319
3319
  def: $ZodCatchDef<T>;
3320
- // qin: T["_zod"]["qin"];
3321
- // qout: T["_zod"]["qout"];
3322
-
3323
3320
  optin: T["_zod"]["optin"];
3324
3321
  optout: T["_zod"]["optout"];
3325
3322
  isst: never;
@@ -3429,6 +3426,7 @@ export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends Some
3429
3426
  values: A["_zod"]["values"];
3430
3427
  optin: A["_zod"]["optin"];
3431
3428
  optout: B["_zod"]["optout"];
3429
+ propValues: A["_zod"]["propValues"];
3432
3430
  }
3433
3431
 
3434
3432
  export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
@@ -3440,6 +3438,7 @@ export const $ZodPipe: core.$constructor<$ZodPipe> = /*@__PURE__*/ core.$constru
3440
3438
  util.defineLazy(inst._zod, "values", () => def.in._zod.values);
3441
3439
  util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
3442
3440
  util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
3441
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
3443
3442
 
3444
3443
  inst._zod.parse = (payload, ctx) => {
3445
3444
  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 = {}));
@@ -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) {
@@ -902,7 +902,7 @@ export interface $ZodCatchDef<T extends SomeType = $ZodType> extends $ZodTypeDef
902
902
  innerType: T;
903
903
  catchValue: (ctx: $ZodCatchCtx) => unknown;
904
904
  }
905
- export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T> | util.Whatever> {
905
+ export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T>> {
906
906
  def: $ZodCatchDef<T>;
907
907
  optin: T["_zod"]["optin"];
908
908
  optout: T["_zod"]["optout"];
@@ -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>;
@@ -902,7 +902,7 @@ export interface $ZodCatchDef<T extends SomeType = $ZodType> extends $ZodTypeDef
902
902
  innerType: T;
903
903
  catchValue: (ctx: $ZodCatchCtx) => unknown;
904
904
  }
905
- export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T> | util.Whatever> {
905
+ export interface $ZodCatchInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<T>, core.input<T>> {
906
906
  def: $ZodCatchDef<T>;
907
907
  optin: T["_zod"]["optin"];
908
908
  optout: T["_zod"]["optout"];
@@ -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
  };