next-server-action-validation
Version:
[](https://www.npmjs.com/package/next-server-action-validation) [](https://opensource.org/licenses/MIT)
10 lines (9 loc) • 553 B
TypeScript
import { ZodSchema } from 'zod';
import { ValidationError } from './types';
/**
* Validates the data with the given zod schema, and if it is valid, runs the given function.
* @param schema The zod schema to validate the data with
* @param func The function to run if the data is valid
* @returns The function to run if the data is valid, or a function that returns a promise of a validation error
*/
export declare function withValidation<T, F extends (_data: T) => any>(schema: ZodSchema<T>, func: F): F | ((data: T) => Promise<ValidationError>);