Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update @hapi/joi to the latest version 🚀 #378

Merged
merged 2 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions configValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ const Joi = require('@hapi/joi');
// Schema Configuration
// schema.indexName: populated by defaults if not overridden
// esclient: object, validation performed by elasticsearch module
const schema = Joi.object().keys({
schema: {
indexName: Joi.string(),
typeName: Joi.string()
},
esclient: Joi.object()
}).requiredKeys(
'schema', 'schema.indexName', 'schema.typeName', 'esclient'
).unknown(true);
const schema = Joi.object().required().keys({
schema: Joi.object().required().keys({
indexName: Joi.string().required(),
typeName: Joi.string().required()
}),
esclient: Joi.object().required()
}).unknown(true);

module.exports = {
validate: function validate(config) {
Joi.validate(config, schema, err => {
if (err) {
throw new Error(err.details[0].message);
}
});
const validated = schema.validate(config);
if (validated.error) {
throw new Error(validated.error.details[0].message);
}
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"elasticsearch": ">=1.1.1"
},
"dependencies": {
"@hapi/joi": "^15.1.1",
"@hapi/joi": "^16.1.8",
"colors": "^1.1.2",
"elasticsearch": "^16.0.0",
"lodash": "^4.17.15",
Expand Down
10 changes: 5 additions & 5 deletions test/configValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports.tests.interface = function(test, common) {

t.throws(function() {
configValidation.validate(config);
}, /"indexName" is required/, 'schema.indexName should exist');
}, /"schema.indexName" is required/, 'schema.indexName should exist');
t.end();

});
Expand All @@ -38,7 +38,7 @@ module.exports.tests.interface = function(test, common) {

t.throws(function () {
configValidation.validate(config);
}, /"typeName" is required/, 'schema.typeName should exist');
}, /"schema.typeName" is required/, 'schema.typeName should exist');
t.end();

});
Expand All @@ -55,7 +55,7 @@ module.exports.tests.interface = function(test, common) {

t.throws(function() {
configValidation.validate(config);
}, /"indexName" must be a string/, 'schema.indexName should be a string');
}, /"schema.indexName" must be a string/, 'schema.indexName should be a string');

});

Expand All @@ -75,7 +75,7 @@ module.exports.tests.interface = function(test, common) {

t.throws(function () {
configValidation.validate(config);
}, /"typeName" must be a string/, 'schema.typeName should be a string');
}, /"schema.typeName" must be a string/, 'schema.typeName should be a string');

});

Expand All @@ -95,7 +95,7 @@ module.exports.tests.interface = function(test, common) {

t.throws(function() {
configValidation.validate(config);
}, /"esclient" must be an object/, 'esclient should be an object');
}, /"esclient" must be of type object/, 'esclient should be an object');

});

Expand Down