@strapi/utils
Version:
Shared utilities for the Strapi packages
29 lines • 1.24 kB
TypeScript
import * as z from 'zod/v4';
/**
* Re-export of the Zod v4 schema builder from the same version Strapi uses
* internally. Use this for building schemas passed to content API param
* registration (addQueryParams / addInputParams) so your code stays compatible
* across Strapi minor/patch updates.
*
* @example
* import { z } from '@strapi/utils';
* strapi.contentAPI.addQueryParams({
* search: {
* schema: z.string().max(200).optional(),
* matchRoute: (route) => route.path.includes('articles'),
* },
* });
*/
export { z };
export declare const validateZodSchema: <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>(schema: T) => (data: unknown, errorMessage?: string) => z.infer<T>;
type FormErrors = Record<string, string>;
/**
* Converts a ZodError into form-compatible errors matching
* getYupValidationErrors from @strapi/admin Form component.
*
* Returns a flat object with dot-path keys and string error messages.
* Only the first error per path is kept (matches Yup behavior).
* Root-level errors (path = []) are stored under the empty string key ''.
*/
export declare const getZodValidationErrors: (error: z.ZodError) => FormErrors;
//# sourceMappingURL=zod.d.ts.map