From e57ab78b650b78810211a5a52b7bcdacbcd3c47b Mon Sep 17 00:00:00 2001 From: rycont Date: Fri, 30 Jan 2026 02:27:59 +0900 Subject: [PATCH 1/3] feat: support literal & lazy --- packages/zod/src/components/RenderTemplate.tsx | 13 +++++++++++++ packages/zod/src/components/types.ts | 1 + packages/zod/src/utils/generateInitialData.ts | 13 +++++++++++++ packages/zod/src/utils/unwrapSchema.ts | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/packages/zod/src/components/RenderTemplate.tsx b/packages/zod/src/components/RenderTemplate.tsx index 706d482..beba048 100644 --- a/packages/zod/src/components/RenderTemplate.tsx +++ b/packages/zod/src/components/RenderTemplate.tsx @@ -1,4 +1,5 @@ import React from "react"; +import type * as z from "zod/v4/core"; import { RenderTemplateProps } from "./types"; import { useTemplates } from ".."; import { unwrapSchema } from "../utils"; @@ -24,6 +25,7 @@ export const RenderTemplate: React.FC = ({ UnionTemplate, TupleTemplate, EnumTemplate, + LiteralTemplate, } = useTemplates(); // Let's first unwrap the schema to get to the core type @@ -62,6 +64,17 @@ export const RenderTemplate: React.FC = ({ case "tuple": return ; + case "literal": + return ; + + case "lazy": { + // Lazy schemas contain a getter function that returns the actual schema + const lazySchema = coreSchema as z.$ZodLazy; + const actualSchema = lazySchema._zod.def.getter(); + // Recursively render the actual schema + return ; + } + default: // Unknown or unsupported schema type console.error( diff --git a/packages/zod/src/components/types.ts b/packages/zod/src/components/types.ts index 484c244..a83a6b9 100644 --- a/packages/zod/src/components/types.ts +++ b/packages/zod/src/components/types.ts @@ -74,6 +74,7 @@ export type Templates = { UnionTemplate: React.FC<{ schema: z.$ZodType; path: string[] }>; TupleTemplate: React.FC<{ schema: z.$ZodType; path: string[] }>; EnumTemplate: React.FC<{ schema: z.$ZodType; path: string[] }>; + LiteralTemplate: React.FC<{ schema: z.$ZodType; path: string[] }>; }; /** diff --git a/packages/zod/src/utils/generateInitialData.ts b/packages/zod/src/utils/generateInitialData.ts index a59dab7..b3438d8 100644 --- a/packages/zod/src/utils/generateInitialData.ts +++ b/packages/zod/src/utils/generateInitialData.ts @@ -104,6 +104,19 @@ export function generateInitialData(schema: z.$ZodType): ZeroState { return enumDef.entries[firstKey]; } + case "literal": { + const literalSchema = coreSchema as z.$ZodLiteral; + return Array.from(literalSchema._zod.def.values)[0]; + } + + case "lazy": { + // Lazy schemas contain a getter function that returns the actual schema + const lazySchema = coreSchema as z.$ZodLazy; + const actualSchema = lazySchema._zod.def.getter(); + // Recursively generate initial data for the actual schema + return generateInitialData(actualSchema); + } + default: console.error(`Unsupported schema type: ${def.type}`); return undefined; diff --git a/packages/zod/src/utils/unwrapSchema.ts b/packages/zod/src/utils/unwrapSchema.ts index 1ccaf27..fefba37 100644 --- a/packages/zod/src/utils/unwrapSchema.ts +++ b/packages/zod/src/utils/unwrapSchema.ts @@ -40,6 +40,12 @@ export function unwrapSchema(schema: z.$ZodType): z.$ZodTypes { return unwrapSchema(nonOptionalSchema._zod.def.innerType); } + case "lazy": { + const lazySchema = typedSchema as z.$ZodLazy; + const actualSchema = lazySchema._zod.def.getter(); + return unwrapSchema(actualSchema); + } + default: return typedSchema; } From 6a47cb5c2e4693d5d2dc173aa6d4e2e34210ca56 Mon Sep 17 00:00:00 2001 From: rycont Date: Fri, 30 Jan 2026 11:37:37 +0900 Subject: [PATCH 2/3] chore(zod): add prepare script for git installs --- packages/zod/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/zod/package.json b/packages/zod/package.json index 2b722f6..4fffdb8 100644 --- a/packages/zod/package.json +++ b/packages/zod/package.json @@ -29,6 +29,7 @@ ], "scripts": { "build": "vite build && tsc", + "prepare": "npm run build", "prepublishOnly": "npm run build", "analyze": "vite build --mode analyze" }, From ad3fd65624435d3468db15907ac5a81a62b41eb0 Mon Sep 17 00:00:00 2001 From: rycont Date: Fri, 30 Jan 2026 11:39:42 +0900 Subject: [PATCH 3/3] chore: build core before zod prepare --- packages/core/package.json | 1 + packages/zod/package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/package.json b/packages/core/package.json index 370a29d..f886b54 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -34,6 +34,7 @@ ], "scripts": { "build": "vite build && tsc", + "prepare": "npm run build", "prepublishOnly": "npm run build", "analyze": "vite build --mode analyze", "test": "vitest", diff --git a/packages/zod/package.json b/packages/zod/package.json index 4fffdb8..7495a6d 100644 --- a/packages/zod/package.json +++ b/packages/zod/package.json @@ -29,7 +29,7 @@ ], "scripts": { "build": "vite build && tsc", - "prepare": "npm run build", + "prepare": "pnpm -C ../.. build:core && pnpm run build", "prepublishOnly": "npm run build", "analyze": "vite build --mode analyze" },