import { identity, type NonEmptyArray, type GetAllObjectPaths, type Reader, } from '@under-control/core'; import type { PathValidator, GlobalValidator, Validator } from '../../types'; export type FormValidators = NonEmptyArray>; export type FormValidatorUtils = { path:

>( path: P, fn: PathValidator['fn'], ) => PathValidator; global: (fn: GlobalValidator) => GlobalValidator; }; export type FormValidatorsList = | FormValidators | Reader, FormValidators | Validator> | undefined; export function useFormValidatorsSelector( validatorsGetter: FormValidatorsList, ): FormValidators | undefined { if (typeof validatorsGetter === 'function') { const result = validatorsGetter({ global: identity, path: (path, fn) => ({ path, fn, }), }); return Array.isArray(result) ? result : [result]; } return validatorsGetter; }