import { AnyComponentSchema } from '@open-formulieren/types'; import { z } from 'zod'; import { GetValidationSchemaContext } from './registry/types'; import { JSONObject, JSONValue } from './types'; export type KeySchemaPair = [string, z.ZodFirstPartySchemaTypes]; export type SchemaRecord = Record; /** * Process key-value pairs where keys are Formio component keys that may have dots in * them and values are zod schemas. * * The keys are transformed into a tree structure that represents the shape of the * submission data, and for each leaf node the respective zod validation schema is * assigned. Finally, this tree is converted into a zod.object schema tree ready to use * as validator. */ export declare const composeValidationSchemas: (pairs: KeySchemaPair[]) => z.ZodObject; /** * Build the ZOD validation schema (recursively) for the provided component definitions. */ export declare const buildValidationSchema: (components: AnyComponentSchema[], context: GetValidationSchemaContext) => z.ZodObject; type Schema = z.ZodSchema; /** * Validate an object against a Zod validation schema. * * @throws ValidationError if the object does not conform to the validation schema. */ export declare const validate: (schema: Schema, obj: T) => Promise; export interface UseValidationSchema { /** * Setter to update the validation schema to use in the validate call. * * It is guaranteed to have a stable identity. */ setSchema: (newSchema: Schema) => void; /** * Validation callback to pass to Formik's `validationSchema` prop. Throws * zod-formik-adapter's ValidationError when there are schema parsing errors. * * It is guaranteed to have a stable identity. */ validate: (obj: JSONObject) => Promise; } export declare const useValidationSchema: (schema: Schema) => UseValidationSchema; export interface UseValidationSchemas { /** * Setter to update the validation schema to use in the validate call. * * It is guaranteed to have a stable identity. */ setSchema: (index: number, newSchema: Schema) => void; /** * Validation callback to pass to Formik's `validationSchema` prop. Throws * zod-formik-adapter's ValidationError when there are schema parsing errors. * * It is guaranteed to have a stable identity. */ validate: (index: number, obj: JSONObject) => Promise; } /** * Multi-schema variant of useValidationSchema, suitable for edit grids/array values. */ export declare const useValidationSchemas: (schemas: Schema[]) => UseValidationSchemas; /** * The result/outcome of a single plugin validation call. * * The result is either valid (i.e. the provided value is considered valid) or not * valid and reports back validation error messages. */ export type PluginValidationResult = { valid: true; messages?: never; } | { valid: false; messages: string[]; }; /** * The interface for async plugin validation. * * Callers of the formio-renderer need to provide an implementation conforming to * the specified call signature. */ export type ValidatePluginCallback = (plugin: string, value: JSONValue) => Promise; /** * Fallback implementation in case no callback is provided. It will always fail * validation to prevent accidentally letting through values that could possibly be * blocked by the specified validation plugins, which would otherwise silently pass. */ export declare const fallbackValidatePlugin: ValidatePluginCallback; /** * Call the specified validation plugins asynchronously with the provided field value. * * The value is considered valid as soon as one plugin considers it valid (OR-behaviour). * * @returns `undefined` if there are no validation issues, or a newline-separated string * containing the validation error(s). * * @todo Cache validation result? */ export declare const validatePlugins: (validatePlugin: ValidatePluginCallback, plugins: string[], value: JSONValue | undefined) => Promise; export {};