asVerificable
This function wraps provided value
into a Verificable
object.
Verificable
object can be later used with functions like isValid(...)
, getErrors(...)
, ensure(...)
to validate the value against provided predicate
.
Verificable
object is infinitely-deeply nested, with infinite number of properties of all possible names. Each of it's properties is a Verificable
object as well. Each of it's properties corresponds a possible property on passed in value
object. That means you can verify any arbitrary, no matter how deep nested, even not existing ones!
The optional path
parameter allows to define a base path, that will be prepended to all paths in ValidationError
objects coming from this Validatable
.
Examples:
First, let's define an example object user
that we want to verify and wrap it with asVerificable():
Thanks to Verificable
special properties, properties with any name can be accessed on the Verificable
object, and the values of them are Verificable
objects as well. This allows us to verify any level of deep-nested properties:
Even properties that doesn't exist, nested multiple levels down, can be verified - and will return ValidationError
of type missing
with path
specifying the path that was tried to be accessed:
Last updated
Was this helpful?