Skip to content

Validation Utilities

Helpers for class-validator error mapping.

ts
import { ValidationUtil, type ValidationPropertyErrors } from '@querry-kit/nest-util';

ValidationUtil.mapValidationErrorsToObject(errors)

Maps class-validator ValidationError[] into a nested object keyed by property name.

ts
const result: ValidationPropertyErrors = ValidationUtil.mapValidationErrorsToObject(errors);

Each constraint entry includes the validator name and configured static constraint values:

ts
{
  email: [{ name: 'isEmail', constraints: [] }]
}

Nested validation errors are represented as nested objects.

Types

ValidationErrorDescription describes one failed validator:

ts
type ValidationErrorDescription = {
  name: string;
  constraints: string[];
};

ValidationPropertyErrors is the recursive object returned by mapValidationErrorsToObject.

Released under the MIT License.