Releases: feathersjs-ecosystem/validate-joi
Export Typescript Definitions
- Change: Updated and exported typescript type definition file in
package.json
- Chore: Updated dependency
@feathersjs/[email protected]
->4.5.11
- Chore: Updated devDependencies:
mocha
,eslint
,eslint-plugin-react
,eslint-plugin-jsx-a11y
Package Name Change
4.0.0
- Breaking: NPM package name changed from
@featherjs-plus/validate-joi
->feathers-validate-joi
- Breaking: Changed core dependency from
@hapi/joi
->joi
- Change: Migrate to
nyc
fromistanbul
- Change: Migrate to
github-actions
fromtravis
(future proofing) - Change: Added dependabot config (future proofing)
- Change: Removed yarn lockfile
- Change: Added .github templates
🎁 More context in errors
Thanks to a pull request by @mkovel, errors now include valuable debugging information from the hook context:
path
type
(before or after hook)method
TypeScript Definitions!
Thanks to the work of @digitalcortex, version 3.3.0 of @feathers-plus/validate-joi
now includes TypeScript definitions. 🥳
🎁 validateProvidedData Hook
Introducing the validateProvidedData
Hook
The validateProvidedData
hook is just like validate.form
, but it only validates the attributes from the schema which are actually present in the request's data
object. In short, it allows partial validation of the schema attributes. Using it as a hook looks like this:
const validate = require('@featehrs-plus/validate-joi')
const attrs = require('./faqs.model')
const hooks = {
before: {
patch: [
validate.validateProvidedData(attrs, { abortEarly: false })
]
}
}
The above example supposes that you have an /faqs
service with a model that looks like the following. Notice how the attrs
are defined as a separate object, then they are used in the schema and made available in the export. The validateProvidedData
hook uses the individual attrs to validate each individual item in the request's data
object.
// src/services/faqs/faqs.model.js
const Joi = require('@hapi/joi')
const { objectId } = require('@feathers-plus/validate-joi-mongodb')
const attrs = {
_id: objectId(),
question: Joi.string().disallow(null).required(),
answer: Joi.string().disallow(null).required(),
isPublic: Joi.boolean().default(false),
createdBy: objectId().disallow(null).required()
}
module.exports = {
attrs,
schema: Joi.object(attrs)
}
🎁 Validate anything in context
Use the getContext and setContext methods to validate anything in context. 😎
const options = {
convert: true,
getContext(context) {
return context.params.query;
},
setContext(context, newValues) {
Object.assign(context.params.query, newValues);
},
}
const hooks = {
before: {
get: [
validate.form(schema, options)
]
}
}
🎁 FeathersJS v4 support + Big Update
Lots of updates in this release.
- 🙌 Updated to work with latest @hapi/joi.
- 🎁 Support for asynchronous validations.
- 🚀 Support for FeathersJS V4.
- 🤷♂️ It might still support FeathersJS V3, because the callback syntax is still supported.
Since Joi.validate() has been removed, all validations now use schema.validateAsync(), which means this package now supports asynchronous validations.