import type { $ZodType } from 'zod/v4/core'; import type { UseFormSetError } from 'react-hook-form'; /** * Wraps a form `onSubmit` handler with `schemaLite` client-side validation. * * Runs `schemaLite.safeParse(normalizeFormValues(data))` before calling the * original handler. On failure, maps each validation issue to the corresponding * RHF field via `setError`. On success, delegates to `onSubmit` unchanged. * * Used by optimization-level codegen output to perform fast per-field * validation with a trimmed schema that omits cross-field refinements. * * @param schemaLite - The stripped Zod schema produced by `walkSchema` at optimization level 1+. * @param setError - RHF's `setError` function from `useFormContext`. * @param onSubmit - The original submit handler to call on successful validation. * @returns A wrapped submit handler with the same signature as `onSubmit`. * * @useWhen * - You are using codegen output with `validationLevel: 1` or higher and need the lite schema to run before your submit handler — this is the only function that wires `schemaLite` into RHF's `handleSubmit` flow * * @avoidWhen * - You are using the default `zodResolver` path (no `validationLevel`) — validation is handled by RHF's resolver and adding this wrapper causes double-validation with no benefit * * @never * - NEVER pass the full schema as `schemaLite` — it defeats the optimization and adds * double-validation overhead; FIX: only pass the schema produced by `walkSchema`'s * `result.schemaLite` field (never the original `z.object({...})`) * - NEVER use this with schemas that have root-level `.superRefine()` — root refinements * are stripped from `schemaLite` by design and will not run through this wrapper; * FIX: use full `zodResolver` path and skip `wrapWithSchemaLite` entirely * * @remarks * The wrapper calls `normalizeFormValues()` on the data before passing it to `schemaLite.safeParse()`. * This ensures empty strings from HTML inputs are converted to `undefined`, matching Zod's `.optional()` expectation. * Each validation issue's `path` array is joined with `.` to produce the RHF field path for `setError`. * * @throws Never — validation errors are mapped to RHF's `setError` rather than thrown. * * @example * ```ts * const handleSubmit = wrapWithSchemaLite(schemaLite, setError, async (data) => { * await fetch('/api/submit', { method: 'POST', body: JSON.stringify(data) }); * }); * // Pass handleSubmit to RHF's form.handleSubmit(handleSubmit) * ``` * * @category Optimization */ export declare function wrapWithSchemaLite>(schemaLite: $ZodType, setError: UseFormSetError, onSubmit: (data: TData) => void | Promise): (data: TData) => void | Promise; //# sourceMappingURL=SchemaLiteSubmit.d.ts.map