import { JsonValue } from "cojson"; import { z } from "../zodReExport.js"; // Copied from https://github.com/colinhacks/zod/blob/7e7e3461aceecf3633e158df50d6bc852e7cdf45/packages/zod/src/v4/core/schemas.ts#L1591, // since this type is not exported by Zod type OptionalInSchema = { _zod: { optin: "optional"; }; }; /** * Get type from Zod schema definition. * * Similar to `z.infer`, but we manually traverse Zod types to ensure we only allow what we can handle */ export type TypeOfZodSchema = S extends z.core.$ZodOptional ? TypeOfZodSchema | undefined : S extends z.core.$ZodNullable ? TypeOfZodSchema | null : S extends z.ZodJSONSchema ? JsonValue : S extends z.core.$ZodUnion< infer Members extends readonly z.core.$ZodType[] > ? TypeOfZodSchema : S extends z.core.$ZodIntersection< infer Left extends z.core.$ZodType, infer Right extends z.core.$ZodType > ? TypeOfZodSchema & TypeOfZodSchema : S extends z.core.$ZodObject ? /** * Cannot use {@link PartialOnUndefined} because evaluating TypeOfZodSchema * to know if the value can be undefined does not work with recursive types. */ { -readonly [key in keyof Shape as Shape[key] extends OptionalInSchema ? never : key]: TypeOfZodSchema; } & { -readonly [key in keyof Shape as Shape[key] extends OptionalInSchema ? key : never]?: TypeOfZodSchema; } : S extends z.core.$ZodRecord< infer Key, infer Value extends z.core.$ZodType > ? Key extends z.core.$partial ? Partial, TypeOfZodSchema>> : Record, TypeOfZodSchema> : S extends z.core.$ZodArray ? TypeOfZodSchema[] : S extends z.core.$ZodTuple< infer Items extends readonly z.core.$ZodType[] > ? { [key in keyof Items]: TypeOfZodSchema; } : S extends z.core.$ZodString ? string : S extends z.core.$ZodNumber ? number : S extends z.core.$ZodBoolean ? boolean : S extends z.core.$ZodLiteral ? Literal : S extends z.core.$ZodDate ? Date : S extends z.core.$ZodEnum ? Enum[keyof Enum] : S extends z.core.$ZodTemplateLiteral< infer pattern > ? pattern : S extends z.core.$ZodReadonly< infer Inner extends z.core.$ZodType > ? TypeOfZodSchema : S extends z.core.$ZodDefault< infer Default extends z.core.$ZodType > ? TypeOfZodSchema : S extends z.core.$ZodCodec< any, infer Out extends z.core.$ZodType > ? Out["_zod"]["output"] : S extends z.core.$ZodCatch< infer Catch extends z.core.$ZodType > ? TypeOfZodSchema : never;