+1
-1
| { | ||
| "name": "zod", | ||
| "version": "4.4.2", | ||
| "version": "4.4.3", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -131,4 +131,5 @@ import { expect, expectTypeOf, test } from "vitest"; | ||
| expect(schema.safeParse({}).success).toEqual(false); | ||
| expect(schema.safeParse({}, { jitless: true }).success).toEqual(false); | ||
| // Absent keys flow through to the catch handler. | ||
| expect(schema.parse({})).toEqual({ fruit: Fruits.apple }); | ||
| expect(schema.parse({}, { jitless: true })).toEqual({ fruit: Fruits.apple }); | ||
| expect(schema.parse({ fruit: 15 })).toEqual({ fruit: Fruits.apple }); | ||
@@ -142,4 +143,4 @@ }); | ||
| expect(schema.safeParse({}).success).toEqual(false); | ||
| expect(schema.safeParse({}, { jitless: true }).success).toEqual(false); | ||
| expect(schema.parse({})).toEqual({ fruit: "apple" }); | ||
| expect(schema.parse({}, { jitless: true })).toEqual({ fruit: "apple" }); | ||
| expect(schema.parse({ fruit: true })).toEqual({ fruit: "apple" }); | ||
@@ -281,1 +282,48 @@ expect(schema.parse({ fruit: 15 })).toEqual({ fruit: "apple" }); | ||
| }); | ||
| test("optional clobbers catch through pipe boundaries", () => { | ||
| expect( | ||
| z | ||
| .string() | ||
| .catch("X") | ||
| .transform((s) => s + "!") | ||
| .optional() | ||
| .parse(undefined) | ||
| ).toBeUndefined(); | ||
| expect(z.string().catch("X").pipe(z.string()).optional().parse(undefined)).toBeUndefined(); | ||
| expect( | ||
| z | ||
| .string() | ||
| .catch("X") | ||
| .transform((s) => s + "!") | ||
| .transform((s) => s.toLowerCase()) | ||
| .optional() | ||
| .parse(undefined) | ||
| ).toBeUndefined(); | ||
| expect( | ||
| z | ||
| .object({ | ||
| a: z | ||
| .string() | ||
| .catch("X") | ||
| .transform((s) => s + "!") | ||
| .optional(), | ||
| }) | ||
| .parse({}) | ||
| ).toEqual({}); | ||
| expect( | ||
| z | ||
| .string() | ||
| .catch("X") | ||
| .transform((s) => s + "!") | ||
| .parse("hi") | ||
| ).toBe("hi!"); | ||
| expect( | ||
| z | ||
| .string() | ||
| .catch("X") | ||
| .transform((s) => s + "!") | ||
| .parse(123) | ||
| ).toBe("X!"); | ||
| }); |
@@ -159,26 +159,23 @@ import { expect, expectTypeOf, test } from "vitest"; | ||
| expect(mySchema.safeParse({}).error!.issues).toMatchInlineSnapshot(` | ||
| [ | ||
| { | ||
| "code": "invalid_type", | ||
| "expected": "nonoptional", | ||
| "message": "Invalid input: expected nonoptional, received undefined", | ||
| "path": [ | ||
| "d", | ||
| ], | ||
| }, | ||
| ] | ||
| // Catch (d) and default/prefault (b, c, e, f) handle absent keys gracefully. | ||
| // `a: catch().optional()` short-circuits to undefined when the original | ||
| // input was undefined, so the property is omitted from the output. All | ||
| // other catch/default/prefault keys produce their fallback values. | ||
| expect(mySchema.parse({})).toMatchInlineSnapshot(` | ||
| { | ||
| "b": "default value", | ||
| "c": "prefault value", | ||
| "d": "catch value", | ||
| "e": "default value", | ||
| "f": "prefault value", | ||
| } | ||
| `); | ||
| expect(mySchema.safeParse({}, { jitless: true }).error!.issues).toMatchInlineSnapshot(` | ||
| [ | ||
| { | ||
| "code": "invalid_type", | ||
| "expected": "nonoptional", | ||
| "message": "Invalid input: expected nonoptional, received undefined", | ||
| "path": [ | ||
| "d", | ||
| ], | ||
| }, | ||
| ] | ||
| expect(mySchema.parse({}, { jitless: true })).toMatchInlineSnapshot(` | ||
| { | ||
| "b": "default value", | ||
| "c": "prefault value", | ||
| "d": "catch value", | ||
| "e": "default value", | ||
| "f": "prefault value", | ||
| } | ||
| `); | ||
@@ -185,0 +182,0 @@ |
@@ -284,2 +284,27 @@ import { expect, expectTypeOf, test } from "vitest"; | ||
| test("preprocess accepts absent object keys (4.3 parity)", () => { | ||
| const schema = z.object({ a: z.preprocess((v) => v ?? "X", z.string()) }); | ||
| expect(schema.parse({})).toEqual({ a: "X" }); | ||
| expect(schema.parse({ a: "hi" })).toEqual({ a: "hi" }); | ||
| expect(schema.parse({ a: undefined })).toEqual({ a: "X" }); | ||
| // Outer optional clobbers preprocess output on undefined input | ||
| expect( | ||
| z | ||
| .preprocess((v) => v ?? "X", z.string()) | ||
| .optional() | ||
| .parse(undefined) | ||
| ).toBeUndefined(); | ||
| expect( | ||
| z | ||
| .preprocess((v) => v ?? "X", z.string()) | ||
| .optional() | ||
| .parse("hi") | ||
| ).toBe("hi"); | ||
| expect(z.object({ a: z.preprocess((v) => v ?? "X", z.string()).optional() }).parse({})).toEqual({}); | ||
| // Top-level direct call unchanged | ||
| expect(z.preprocess((v) => v ?? "X", z.string()).parse(undefined)).toBe("X"); | ||
| }); | ||
| // https://github.com/colinhacks/zod/issues/5917 | ||
@@ -286,0 +311,0 @@ test("optional propagates through preprocess inside object", () => { |
| export const version = { | ||
| major: 4, | ||
| minor: 4, | ||
| patch: 2 as number, | ||
| patch: 3 as number, | ||
| } as const; |
@@ -1206,2 +1206,3 @@ "use strict"; | ||
| payload.value = output; | ||
| payload.fallback = true; | ||
| return payload; | ||
@@ -1211,2 +1212,3 @@ }); | ||
| payload.value = output; | ||
| payload.fallback = true; | ||
| return payload; | ||
@@ -1213,0 +1215,0 @@ }; |
@@ -1088,2 +1088,3 @@ import * as core from "../core/index.js"; | ||
| payload.value = output; | ||
| payload.fallback = true; | ||
| return payload; | ||
@@ -1093,2 +1094,3 @@ }); | ||
| payload.value = output; | ||
| payload.fallback = true; | ||
| return payload; | ||
@@ -1095,0 +1097,0 @@ }; |
@@ -28,2 +28,7 @@ import * as checks from "./checks.cjs"; | ||
| aborted?: boolean; | ||
| /** @internal Marks a value as a fallback that an outer wrapper (e.g. | ||
| * $ZodOptional) may override with its own interpretation when input was | ||
| * undefined. Set by $ZodCatch when catchValue substitutes and by every | ||
| * $ZodTransform invocation. */ | ||
| fallback?: boolean | undefined; | ||
| } | ||
@@ -30,0 +35,0 @@ export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>; |
@@ -28,2 +28,7 @@ import * as checks from "./checks.js"; | ||
| aborted?: boolean; | ||
| /** @internal Marks a value as a fallback that an outer wrapper (e.g. | ||
| * $ZodOptional) may override with its own interpretation when input was | ||
| * undefined. Set by $ZodCatch when catchValue substitutes and by every | ||
| * $ZodTransform invocation. */ | ||
| fallback?: boolean | undefined; | ||
| } | ||
@@ -30,0 +35,0 @@ export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>; |
@@ -7,3 +7,3 @@ "use strict"; | ||
| minor: 4, | ||
| patch: 2, | ||
| patch: 3, | ||
| }; |
| export const version = { | ||
| major: 4, | ||
| minor: 4, | ||
| patch: 2, | ||
| patch: 3, | ||
| }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
4558122
0.07%109502
0.09%