From b8f91963c4e3ce3268f19019743dd3f03140df7f Mon Sep 17 00:00:00 2001 From: Lloyd Benson Date: Mon, 3 Aug 2020 11:13:40 -0500 Subject: [PATCH] update lab and switch joi to validate --- lib/directory.js | 24 ++++++++++++------------ lib/file.js | 30 +++++++++++++++--------------- lib/index.js | 8 ++++---- package.json | 4 ++-- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/directory.js b/lib/directory.js index e677c12..9118009 100755 --- a/lib/directory.js +++ b/lib/directory.js @@ -5,7 +5,7 @@ const Path = require('path'); const Boom = require('@hapi/boom'); const Bounce = require('@hapi/bounce'); const Hoek = require('@hapi/hoek'); -const Joi = require('@hapi/joi'); +const Validate = require('@hapi/validate'); const File = require('./file'); const Fs = require('./fs'); @@ -14,16 +14,16 @@ const Fs = require('./fs'); const internals = {}; -internals.schema = Joi.object({ - path: Joi.alternatives(Joi.array().items(Joi.string()).single(), Joi.func()).required(), - index: Joi.alternatives(Joi.boolean(), Joi.array().items(Joi.string()).single()).default(true), - listing: Joi.boolean(), - showHidden: Joi.boolean(), - redirectToSlash: Joi.boolean(), - lookupCompressed: Joi.boolean(), - lookupMap: Joi.object().min(1).pattern(/.+/, Joi.string()), - etagMethod: Joi.string().valid('hash', 'simple').allow(false), - defaultExtension: Joi.string().alphanum() +internals.schema = Validate.object({ + path: Validate.alternatives(Validate.array().items(Validate.string()).single(), Validate.func()).required(), + index: Validate.alternatives(Validate.boolean(), Validate.array().items(Validate.string()).single()).default(true), + listing: Validate.boolean(), + showHidden: Validate.boolean(), + redirectToSlash: Validate.boolean(), + lookupCompressed: Validate.boolean(), + lookupMap: Validate.object().min(1).pattern(/.+/, Validate.string()), + etagMethod: Validate.string().valid('hash', 'simple').allow(false), + defaultExtension: Validate.string().alphanum() }); @@ -47,7 +47,7 @@ internals.resolvePathOption = function (result) { exports.handler = function (route, options) { - const settings = Joi.attempt(options, internals.schema, 'Invalid directory handler options (' + route.path + ')'); + const settings = Validate.attempt(options, internals.schema, 'Invalid directory handler options (' + route.path + ')'); Hoek.assert(route.path[route.path.length - 1] === '}', 'The route path for a directory handler must end with a parameter:', route.path); const paramName = /\w+/.exec(route.path.slice(route.path.lastIndexOf('{')))[0]; diff --git a/lib/file.js b/lib/file.js index 27863d2..43169ea 100755 --- a/lib/file.js +++ b/lib/file.js @@ -6,7 +6,7 @@ const Ammo = require('@hapi/ammo'); const Boom = require('@hapi/boom'); const Bounce = require('@hapi/bounce'); const Hoek = require('@hapi/hoek'); -const Joi = require('@hapi/joi'); +const Validate = require('@hapi/validate'); const Etag = require('./etag'); const Fs = require('./fs'); @@ -20,19 +20,19 @@ internals.defaultMap = { }; -internals.schema = Joi.alternatives([ - Joi.string(), - Joi.func(), - Joi.object({ - path: Joi.alternatives(Joi.string(), Joi.func()).required(), - confine: Joi.alternatives(Joi.string(), Joi.boolean()).default(true), - filename: Joi.string(), - mode: Joi.string().valid('attachment', 'inline').allow(false), - lookupCompressed: Joi.boolean(), - lookupMap: Joi.object().min(1).pattern(/.+/, Joi.string()), - etagMethod: Joi.string().valid('hash', 'simple').allow(false), - start: Joi.number().integer().min(0).default(0), - end: Joi.number().integer().min(Joi.ref('start')) +internals.schema = Validate.alternatives([ + Validate.string(), + Validate.func(), + Validate.object({ + path: Validate.alternatives(Validate.string(), Validate.func()).required(), + confine: Validate.alternatives(Validate.string(), Validate.boolean()).default(true), + filename: Validate.string(), + mode: Validate.string().valid('attachment', 'inline').allow(false), + lookupCompressed: Validate.boolean(), + lookupMap: Validate.object().min(1).pattern(/.+/, Validate.string()), + etagMethod: Validate.string().valid('hash', 'simple').allow(false), + start: Validate.number().integer().min(0).default(0), + end: Validate.number().integer().min(Validate.ref('start')) }) .with('filename', 'mode') ]); @@ -40,7 +40,7 @@ internals.schema = Joi.alternatives([ exports.handler = function (route, options) { - let settings = Joi.attempt(options, internals.schema, 'Invalid file handler options (' + route.path + ')'); + let settings = Validate.attempt(options, internals.schema, 'Invalid file handler options (' + route.path + ')'); settings = (typeof options !== 'object' ? { path: options, confine: '.' } : settings); settings.confine = settings.confine === true ? '.' : settings.confine; Hoek.assert(typeof settings.path !== 'string' || settings.path[settings.path.length - 1] !== '/', 'File path cannot end with a \'/\':', route.path); diff --git a/lib/index.js b/lib/index.js index 483d522..18e77e3 100755 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,7 @@ 'use strict'; const Hoek = require('@hapi/hoek'); -const Joi = require('@hapi/joi'); +const Validate = require('@hapi/validate'); const Directory = require('./directory'); const Etag = require('./etag'); @@ -9,8 +9,8 @@ const File = require('./file'); const internals = { - schema: Joi.object({ - etagsCacheMaxSize: Joi.number().integer().min(0).default(1000) + schema: Validate.object({ + etagsCacheMaxSize: Validate.number().integer().min(0).default(1000) }).required() }; @@ -41,7 +41,7 @@ exports.plugin = { register(server, options) { Hoek.assert(Object.keys(options).length === 0, 'Inert does not support registration options'); - const settings = Joi.attempt(Hoek.reach(server.settings.plugins, 'inert') || {}, internals.schema, 'Invalid "inert" server options'); + const settings = Validate.attempt(Hoek.reach(server.settings.plugins, 'inert') || {}, internals.schema, 'Invalid "inert" server options'); server.expose('_etags', settings.etagsCacheMaxSize > 0 ? new Etag.Cache(settings.etagsCacheMaxSize) : null); diff --git a/package.json b/package.json index 3b1ad0b..bdc4176 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,14 @@ "@hapi/boom": "9.x.x", "@hapi/bounce": "2.x.x", "@hapi/hoek": "9.x.x", - "@hapi/joi": "17.x.x", + "@hapi/validate": "1.x.x", "lru-cache": "5.x.x" }, "devDependencies": { "@hapi/code": "8.x.x", "@hapi/file": "2.x.x", "@hapi/hapi": "19.x.x", - "@hapi/lab": "22.x.x" + "@hapi/lab": "23.x.x" }, "scripts": { "test": "lab -f -a @hapi/code -t 100 -L",