UNPKG

next-server-action-validation

Version:

[![npm version](https://badge.fury.io/js/next-server-action-validation.svg)](https://www.npmjs.com/package/next-server-action-validation) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

10 lines (9 loc) 553 B
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>);