feature: return promise from validation only if necessary and validate sync if possible #2417
Labels
flag: needs discussion
Issues which needs discussion before implementation.
type: feature
Issues related to new features.
Description
The validator has public methods for asynchronous validation (
validate
andvalidateOrReject
) and for synchronous validation (validateSync
).Unfortunately the synchronous method ignores all async validations while the asynchronous methods always return a pending promise.
It is therefore not possible to write a function which conditionally returns synchronously if possible and a promise if necessary.
Proposed solution
Add a method
validateSyncIfPossible
to classValidator
which returns immediately withValidationError[]
if there are no awaiting promises and otherwise returns withPromise<ValidationError[]>
.The text was updated successfully, but these errors were encountered: