All files / packages/validation/src types.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28                                7x         10x   10x        
export type ValidationFieldPath<T extends object> =
  | "root"
  | Extract<keyof T, string>
  | `${Extract<keyof T, string>}.${string}`;
 
export type ValidationFieldErrors<T extends object> = Partial<
  Record<ValidationFieldPath<T>, string>
>;
 
export interface ValidationResult<T extends object> {
  isValid: boolean;
  fieldErrors: ValidationFieldErrors<T>;
}
 
export type FormValidator<T extends object> = (data: T) => ValidationResult<T>;
 
export const validationSuccess = <T extends object>(): ValidationResult<T> => ({
  isValid: true,
  fieldErrors: {},
});
 
export const validationFailure = <T extends object>(
  fieldErrors: ValidationFieldErrors<T>,
): ValidationResult<T> => ({
  isValid: false,
  fieldErrors,
});