@pager/minion-joi
Advanced tools
Comparing version 1.0.0 to 1.0.1
30
index.js
@@ -5,3 +5,4 @@ 'use strict' | ||
module.exports = (schema, options = {}) => (handler) => (payload) => { | ||
module.exports = (schema, options = {}) => { | ||
if (!schema) { | ||
@@ -11,14 +12,25 @@ throw Error('joi schema required.') | ||
if (!handler || typeof handler !== 'function') { | ||
throw Error('a function is required.') | ||
const createHandler = (handler) => (payload) => { | ||
const {error, value: message} = joi.validate(payload, schema) | ||
if (error) { | ||
error.requeue = !!options.requeue | ||
throw error | ||
} | ||
return handler(message) | ||
} | ||
const {error, value: message} = joi.validate(payload, schema) | ||
return (handler) => { | ||
if (error) { | ||
error.requeue = !!options.requeue | ||
throw error | ||
if (!handler || typeof handler !== 'function') { | ||
throw Error('a function is required.') | ||
} | ||
const validatedHandler = createHandler(handler) | ||
validatedHandler.settings = handler.settings | ||
return validatedHandler | ||
} | ||
return handler(message) | ||
} |
{ | ||
"name": "@pager/minion-joi", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Joi validation for pager/minion workers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -82,1 +82,19 @@ const test = require('ava') | ||
}) | ||
test('handler keeps settings after wrapped', async t => { | ||
const handler = ({name}) => { | ||
return `Hello ${name}` | ||
} | ||
handler.settings = { | ||
key: 'handler.key' | ||
} | ||
const validate = validation(joi.object({ | ||
name: joi.string() | ||
})) | ||
const newHandler = validate(handler) | ||
t.deepEqual(newHandler.settings, handler.settings) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6240
96