Socket
Socket
Sign inDemoInstall

@pager/minion-joi

Package Overview
Dependencies
Maintainers
15
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pager/minion-joi - npm Package Compare versions

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)
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc