feat(NotEmptyValidator): improving notEmpty validator to work with empty strings, arrays and objects
Description of Change
In this PR, we have enhanced the capabilities of our existing notEmpty validator within our validation framework. This update broadens the scope of the validator to include checks for empty values in arrays, objects, strings, and to detect undefined or null values.
The purpose of this enhancement is to fortify our input validation processes by ensuring that a variety of input types are not just present but also hold meaningful content. The updated notEmpty validator is now more versatile, able to handle different types of inputs with the same stringent criteria.
Use Case Implementation
An example of where this enhanced validator is now used is in the user password validation process. The userValidator utilizes the updated notEmpty validator to confirm that the password field is filled with valid and substantial content, reinforcing the security measures in our system.
Code Example
const userValidator = V.notEmpty().next(V.object({
properties: {
password1: V.string().next(V.pattern(/[A-Z]/), V.pattern(/[a-z]/), V.pattern(/[0-9]/), V.size(8, 32)),
password2: V.string(),
},
}));
const result = await userValidator.validate({});
console.log(result.getViolations());
console output:
[
Violation {
path: Path { path: [] },
type: 'NotEmpty',
invalidValue: undefined
}
]
Related Issue
Motivation and Context
We have been working on an important feature in our team that requires this validator or similar to be implemented. For example, when all properties of an object are optional, but at least one of them is required and we don't know which one is, it is important to have such validation option in place, and this validator solves the problem.
How Has This Been Tested?
Added a bunch of tests in the code to check that this works as expected.