import type { FormValue, ParsedFormValue, ValidationTargets } from '../types'; import type { UnionToIntersection } from '../utils/types'; /** * Checks if T is a literal union type (e.g., 'asc' | 'desc') * that should be preserved in input types. * Returns true for union literals, false for single literals or wide types. */ export type IsLiteralUnion = [Exclude] extends [Base] ? [Exclude] extends [UnionToIntersection>] ? false : true : false; type IsOptionalUnion = [unknown] extends [T] ? false : undefined extends T ? true : false; type SimplifyDeep = { [K in keyof T]: T[K]; } & {}; type InferInputInner = SimplifyDeep<{ [K in keyof Output]: IsLiteralUnion extends true ? Output[K] : IsOptionalUnion extends true ? Output[K] : Target extends 'form' ? T | T[] : Target extends 'query' ? string | string[] : Target extends 'param' ? string : Target extends 'header' ? string : Target extends 'cookie' ? string : unknown; }>; /** * Utility type to infer input types for validation targets. * Preserves literal union types (e.g., 'asc' | 'desc') while using * the default ValidationTargets type for other values. * * @example * ```ts * // In @hono/zod-validator or similar: * type Input = InferInput, 'query'> * // { orderBy: 'asc' | 'desc', page: string | string[] } * ``` */ export type InferInput = [Exclude] extends [never] ? {} : [Exclude] extends [object] ? undefined extends Output ? SimplifyDeep, Target, T>> | undefined : SimplifyDeep> : {}; export {};