@palmares/schemas
Version:
This defines a default schema definition for validation of data, it abstract popular schema validation libraries like zod, yup, valibot and others"
34 lines • 1.02 kB
TypeScript
import { Response } from '@palmares/server';
import type { Schema } from './schema/schema';
import type { Infer } from './types';
import type { Request } from '@palmares/server';
/**
* Validates the request body and returns a response automatically, don't need to do anything else.
*/
export declare function schemaHandler<TInput extends Schema<any, any>, TOutput extends Schema<{
input: Infer<TInput, 'output'>;
internal: any;
output: any;
representation: any;
validate: any;
}, any> = TInput>(input: TInput, output?: TOutput): (request: Request<any, {
body: Infer<TInput, "input">;
headers: unknown & {
"content-type": "application/json";
};
}>) => Promise<Response<any, {
context: undefined;
headers: object & {
"Content-Type": string;
};
status: 200 | 201;
}> | Response<{
errors: any[];
}, {
context: undefined;
headers: object & {
"Content-Type": string;
};
status: 400;
}>>;
//# sourceMappingURL=middleware.d.ts.map