Skip to content

Commit

Permalink
chore: update dependencies
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Removes support for node < 10
  • Loading branch information
petey committed Nov 30, 2019
1 parent 7bc4862 commit e17b836
Show file tree
Hide file tree
Showing 4 changed files with 2,034 additions and 3,182 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 e17b836

Please sign in to comment.