Skip to content

Commit

Permalink
Merge pull request #4 from petey/updateDeps
Browse files Browse the repository at this point in the history
BREAKING CHANGE: update joi and other dependencies
  • Loading branch information
petey authored Nov 30, 2019
2 parents 5a79f24 + e17b836 commit c707d3f
Show file tree
Hide file tree
Showing 4 changed files with 2,346 additions and 2,788 deletions.
57 changes: 34 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// See the included LICENSE file for terms.

const retry = require('retry');
const joi = require('joi');
const joi = require('@hapi/joi');

/**
* Executes retry operation
Expand All @@ -17,9 +17,11 @@ const joi = require('joi');
function execRetry(config, callback) {
const c = config;

c.shouldRetry = c.shouldRetry || function shouldRetry() {
return true;
};
c.shouldRetry =
c.shouldRetry ||
function shouldRetry() {
return true;
};
c.options = c.options || {};
c.arguments = c.arguments || [];
c.context = c.context || null;
Expand Down Expand Up @@ -51,30 +53,39 @@ function execRetry(config, callback) {
* @private
*/
function validateRetry(config, callback) {
const schema = joi.object().keys({
options: joi.object().keys({
retries: joi.number().optional(),
factor: joi.number().optional(),
minTimeout: joi.number().optional(),
maxTimeout: joi.number().optional(),
randomize: joi.boolean().optional()
}).optional(),
context: joi.object().optional(),
arguments: joi.array().optional(),
shouldRetry: joi.func().optional(),
method: joi.func().required()
}).required();
const schema = joi
.object()
.keys({
options: joi
.object()
.keys({
retries: joi.number().optional(),
factor: joi.number().optional(),
minTimeout: joi.number().optional(),
maxTimeout: joi.number().optional(),
randomize: joi.boolean().optional()
})
.optional(),
context: joi.object().optional(),
arguments: joi.array().optional(),
shouldRetry: joi.func().optional(),
method: joi.func().required()
})
.required();

if (typeof callback !== 'function') {
throw new Error('"callback" must be a function');
}

joi.validate(config, schema, (err) => {
if (err) {
throw new Error(err.details.map(detail => detail.message).join(','));
}
execRetry(config, callback);
});
const result = schema.validate(config);

if (result.error) {
throw new Error(
result.error.details.map(detail => detail.message).join(',')
);
}

execRetry(config, callback);
}

/**
Expand Down
Loading

0 comments on commit c707d3f

Please sign in to comment.