import { z } from 'zod'; import type { RouteMethod } from './common'; import type { UploadedFile } from './common'; /** * A type that represents either a Zod schema or a plain object with Zod schema properties. * Used for params since they must always be objects and we allow the simpler syntax. */ type ZodObjectOrPlainObject = T | { [key: string]: z.ZodTypeAny; }; /** * Schema definition structure for route validation */ export type SchemaDefinition = Partial<{ params: ZodObjectOrPlainObject>; }> & Partial<{ [M in RouteMethod]: M extends 'GET' ? { query?: z.ZodObject; response?: z.ZodTypeAny; } : { query?: z.ZodObject; body?: z.ZodTypeAny; files?: z.ZodTypeAny; response?: z.ZodTypeAny; }; }>; /** * Helper to extract inferred type from a Zod schema or plain object */ type InferZodType = T extends z.ZodTypeAny ? z.infer : T extends { [key: string]: z.ZodTypeAny; } ? z.infer> : unknown; /** * Extract params type from schema definition */ type ExtractParams = V extends { params: infer T; } ? InferZodType : unknown; /** * Extract body type from schema definition for a specific method */ type ExtractBody = M extends 'GET' ? unknown : V extends { [K in M]: { body: infer T; }; } ? InferZodType : unknown; /** * Extract query type from schema definition for a specific method * Query must always be a z.ZodObject (not a plain object) */ type ExtractQuery = V extends { [K in M]: { query: infer T; }; } ? T extends z.ZodTypeAny ? z.infer : unknown : unknown; /** * Extract response type from schema definition for a specific method */ type ExtractResponse = V extends { [K in M]: { response: infer T; }; } ? InferZodType : unknown; /** * Extract files type from schema definition for a specific method */ type ExtractFiles = V extends { [K in M]: { files: z.ZodTypeAny; }; } ? UploadedFile[] : unknown; /** * Get schema type for a specific key (body, params, query, response, files) */ export type GetSchemaType = V extends object ? K extends 'params' ? ExtractParams : K extends 'body' ? ExtractBody : K extends 'query' ? ExtractQuery : K extends 'response' ? ExtractResponse : K extends 'files' ? ExtractFiles : unknown : unknown; export {}; //# sourceMappingURL=schema.d.ts.map