breaking
test
functions are no longer passedpath
andcontext
as arguments, Instead they are now values onthis
inside the test function.- test functions are longer called with the schema as their
this
value, usethis.schema
instead.
other changes
- test functions are call with with a new context object, including, options, parent and
createError
for dynamically altering validation errors.
- document
stripUnknown
- add
recursive
option - add
noUnknown()
test to objects
- default for objects now adds keys for all fields, not just fields with non empty defaults
- bug fix
breaking
test
functions are now passedpath
andcontext
values along with the field value. Only breaks if using the callback style of defining custom validations
breaking
- the
validation()
method has been renamed totest()
and has a new signature requiring aname
argument - exclusive validations now trump the previous one instead of defering to it e.g:
string().max(10).max(15)
has a max of15
instead of10
other changes
- expose advanced signature for custom validation tests, gives finer grained control over how tests are added
- added the
abortEarly
(default:true
) option - transforms are passed an addition parameter: 'originalValue' you allow recovering from a bad transform further up the chain (provided no one mutated the value)
- fix
concat()
method and add tests
- fix validations where nullable fields were failing due to
null
values e.gstring.max()
- fix export error
breaking
- Removed the
extend
andcreate
methods. Use whatever javascript inheritance patterns you want instead. - the resolution order of defaults and coercions has changed. as well as the general handling of
null
values.- Number:
null
will coerce tofalse
whennullable()
is not specified.NaN
values will now failisType()
checks - String:
null
will coerce to''
whennullable()
is not specified - Date: Invalid dates will not be coerced to
null
, but left as invalid date, This is probably not a problem for anyone as invalid dates will also failisType()
checks
- Number:
- default values are cloned everytime they are returned, so it is impossible to share references to defaults across schemas. No one should be doing that anyway
- stopped pretending that using schemas as conditions in
when()
actually worked (it didn't)
other changes
transform()
now passes the original value to each transformer. Allowing you to recover from a bad transform.- added the
equals()
alias foroneOf
breaking
- isValid is now async, provide a node style callback, or use the promise the method returns to read the validity. This change allows for more robust validations, specifically remote ones for client code (or db queries for server code). The cast method is still, and will remain, synchronous.
other changes
- added validate method (also async) which resolves to the value, and rejects with a new ValidationError