Skip to content

Releases: feathersjs-ecosystem/validate-joi

Export Typescript Definitions

23 Dec 04:55
e914d74
Compare
Choose a tag to compare
  • Change: Updated and exported typescript type definition file in package.json
  • Chore: Updated dependency @feathersjs/errors@4.5.3 -> 4.5.11
  • Chore: Updated devDependencies: mocha, eslint, eslint-plugin-react, eslint-plugin-jsx-a11y

Package Name Change

23 Dec 00:28
acd73b2
Compare
Choose a tag to compare

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 from istanbul
  • Change: Migrate to github-actions from travis (future proofing)
  • Change: Added dependabot config (future proofing)
  • Change: Removed yarn lockfile
  • Change: Added .github templates

🎁 More context in errors

22 Jun 21:56
Compare
Choose a tag to compare

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!

02 Jun 03:47
Compare
Choose a tag to compare

Thanks to the work of @digitalcortex, version 3.3.0 of @feathers-plus/validate-joi now includes TypeScript definitions. 🥳

🎁 validateProvidedData Hook

14 Apr 00:15
Compare
Choose a tag to compare

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

18 Feb 17:46
Compare
Choose a tag to compare

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

18 Feb 17:48
Compare
Choose a tag to compare

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.