Last updated:
0 purchases
palace validators
#GazzaUnderAttack #
Part of Queen Palace 🏰👑 #
Palace Validators #
Motivation #
the palace need to validate the request body throw some rules with easy clean and readable way
inspired from class-validators we built this package to fix this problem
Content #
helper function List<String> validateDto(OBject o) which validate a DTO based on decorations from
queen_validators package
provider validation rules from queen_validators package
example #
class GoodDto {
@MinLength(5)
@MaxLength(200)
final String name = 'queen';
@MinLength(5)
@MaxLength(200)
final String address = 'kingdom palace';
@IsEmail()
final String email = '[email protected]';
}
final failedRules = validateDto(GoodDto());
if(failedRules.isEmpty){
// * the dto passed the validation successfully
}else{
// * the dto has one or more failed rules
failedRules.forEach(print);
// the result will be formatted like this in case of any failed rules
/// '`$fieldName ${rule.errorMsg}'`
/// email failure
/// '`email is not valid email address'`
}
copied to clipboard
Notes #
the palace core package will be responsible for instantiates the Dto form req body
example
final SignInDto dtoInstance = buildDto<SignInDto>({'email':'[email protected]'});
print(dtoInstance is SignInDto) // true
print(dtoInstance.email) // [email protected]
copied to clipboard
License #
The Palace-Validators is open-sourced software licensed under the MIT license.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.