diff --git a/.travis.yml b/.travis.yml index eb451e4..b6e9f03 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: node_js node_js: + - "12" + - "11" - "10" - "8" - - "7" - - "6" after_success: - npm run coveralls diff --git a/CHANGELOG.md b/CHANGELOG.md index e49b072..698f5f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ## CHANGELOG Date format is DD/MM/YYYY +## 1.0.0 (13/06/2019) +* Migrated from `joi` to `@hapi/joi`. +* Dropped Node.js 6 & 7 support (@hapi/joi forces this) +* Update dev dependencies. + ## 0.3.0 (29/09/2018) * Add response validation * Update dependencies diff --git a/README.md b/README.md index d2af912..ef6caad 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # express-joi-validation ![TravisCI](https://travis-ci.org/evanshortiss/express-joi-validation.svg) -[![npm version](https://badge.fury.io/js/express-joi-validation.svg)](https://badge.fury.io/js/express-joi-validation) [![Coverage Status](https://coveralls.io/repos/github/evanshortiss/express-joi-validation/badge.svg?branch=master)](https://coveralls.io/github/evanshortiss/express-joi-validation?branch=master) -[![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/ellerbrock/typescript-badges/) +[![npm version](https://badge.fury.io/js/express-joi-validation.svg)](https://www.npmjs.com/package/express-joi-validation) +[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-blue.svg)](http://www.typescriptlang.org/) +[![npm downloads](https://img.shields.io/npm/dm/express-joi-validation.svg?style=flat)](https://www.npmjs.com/package/express-joi-validation) +[![Known Vulnerabilities](https://snyk.io//test/github/evanshortiss/express-joi-validation/badge.svg?targetFile=package.json)](https://snyk.io//test/github/evanshortiss/express-joi-validation?targetFile=package.json) A middleware for validating express inputs using Joi schemas. Fills some of the voids I found that other Joi middleware miss such as: @@ -45,7 +47,12 @@ folder of this repository. ```js const Joi = require('joi') const app = require('express')() -const validator = require('express-joi-validation')({}) +const validator = require('express-joi-validation')({ + // You can pass a specific Joi instance using this option. By default the + // module will load the @hapi/joi version you have in your package.json + // so 99% of the time you won't need this option + // joi: require('joi') +}) const querySchema = Joi.object({ type: Joi.string().required().valid('food', 'drinks', 'entertainment') @@ -66,7 +73,7 @@ app.get('/orders', validator.query(querySchema, {joi: joiOpts}), (req, res, next ### Joi Versioning This module uses `peerDependencies` for the Joi version being used. This means -whatever Joi version is in the `dependencies` of your `package.json` will be +whatever `@hapi/joi` version is in the `dependencies` of your `package.json` will be used by this module. ### Validation Ordering diff --git a/express-joi-validation.js b/express-joi-validation.js index a466c63..fab3de6 100644 --- a/express-joi-validation.js +++ b/express-joi-validation.js @@ -62,7 +62,7 @@ function buildErrorString(err, container) { module.exports = function generateJoiMiddlewareInstance(cfg) { cfg = cfg || {} // default to an empty config - const Joi = cfg.joi || require('joi') + const Joi = cfg.joi || require('@hapi/joi') // We'll return this instance of the middleware const instance = { diff --git a/index.test.js b/index.test.js index a9fb5a7..e784e83 100644 --- a/index.test.js +++ b/index.test.js @@ -1,6 +1,6 @@ 'use strict' -const Joi = require('joi') +const Joi = require('@hapi/joi') const sinon = require('sinon') const supertest = require('supertest') const expect = require('chai').expect diff --git a/package.json b/package.json index d3dd046..da6e411 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-joi-validation", - "version": "0.3.0", + "version": "1.0.0", "description": "validate express application inputs and parameters using joi", "main": "express-joi-validation.js", "scripts": { @@ -34,6 +34,7 @@ "author": "Evan Shortiss", "license": "MIT", "devDependencies": { + "@hapi/joi": "~15.0.3", "@types/express": "~4.0.39", "@types/joi": "~13.6.0", "@types/node": "^6.0.117", @@ -44,12 +45,11 @@ "express": "~4.16.3", "express-formidable": "~1.0.0", "husky": "~1.0.1", - "joi": "~13.6.0", "lodash": "~4.17.4", "mocha": "~5.2.0", "mocha-lcov-reporter": "~1.3.0", "nodemon": "~1.11.0", - "nyc": "~13.0.1", + "nyc": "~14.1.1", "prettier": "~1.14.3", "proxyquire": "~1.7.11", "sinon": "~1.17.7", @@ -57,9 +57,9 @@ "typescript": "~2.5.3" }, "peerDependencies": { - "joi": "*" + "@hapi/joi": "*" }, "engines": { - "node": ">=6.0.0" + "node": ">=8.0.0" } }