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 2b722f6..7495a6d 100644 --- a/packages/zod/package.json +++ b/packages/zod/package.json @@ -29,6 +29,7 @@ ], "scripts": { "build": "vite build && tsc", + "prepare": "pnpm -C ../.. build:core && pnpm run build", "prepublishOnly": "npm run build", "analyze": "vite build --mode analyze" }, 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; }