UNPKG

@athenna/http

Version:

The Athenna Http server. Built on top of fastify.

32 lines (31 loc) 1.28 kB
/** * @athenna/http * * (c) João Lenon <lenon@athenna.io> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import type { ZodAny } from 'zod'; import type { FastifyReply, FastifyRequest, FastifySchema } from 'fastify'; type ZodRequestSchema = Partial<Record<'body' | 'headers' | 'params' | 'querystring', ZodAny>>; type ZodResponseSchema = Record<number | string, ZodAny>; export type RouteSchemaOptions = FastifySchema & { body?: FastifySchema['body'] | ZodAny; headers?: FastifySchema['headers'] | ZodAny; params?: FastifySchema['params'] | ZodAny; querystring?: FastifySchema['querystring'] | ZodAny; response?: FastifySchema['response'] | ZodResponseSchema; }; export type RouteZodSchemas = { request: ZodRequestSchema; response: ZodResponseSchema; }; export declare function normalizeRouteSchema(options: RouteSchemaOptions): { schema: FastifySchema; swaggerSchema: FastifySchema; zod: RouteZodSchemas | null; }; export declare function parseRequestWithZod(req: FastifyRequest, schemas: RouteZodSchemas): Promise<void>; export declare function parseResponseWithZod(reply: FastifyReply, payload: any, schemas: RouteZodSchemas): Promise<any>; export {};