Socket
Socket
Sign inDemoInstall

joi

Package Overview
Dependencies
Maintainers
4
Versions
238
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joi - npm Package Compare versions

Comparing version 10.4.0 to 10.4.1

6

lib/alternatives.js

@@ -61,3 +61,7 @@ 'use strict';

return { errors: errors.length ? errors : this.createError('alternatives.base', null, state, options) };
if (errors.length) {
return { errors: this.createError('alternatives.child', { reason: errors }, state, options) };
}
return { errors: this.createError('alternatives.base', null, state, options) };
}

@@ -64,0 +68,0 @@

19

lib/errors.js

@@ -85,2 +85,16 @@ 'use strict';

format = format || Hoek.reach(localized, this.type) || Hoek.reach(Language.errors, this.type);
let wrapArrays = Hoek.reach(localized, 'messages.wrapArrays');
if (typeof wrapArrays !== 'boolean') {
wrapArrays = Language.errors.messages.wrapArrays;
}
if (format === null) {
const childrenString = internals.stringify(this.context.reason, wrapArrays);
if (wrapArrays) {
return childrenString.slice(1, -1);
}
return childrenString;
}
const hasKey = /\{\{\!?key\}\}/.test(format);

@@ -97,7 +111,2 @@ const skipKey = format.length > 2 && format[0] === '!' && format[1] === '!';

let wrapArrays = Hoek.reach(localized, 'messages.wrapArrays');
if (typeof wrapArrays !== 'boolean') {
wrapArrays = Language.errors.messages.wrapArrays;
}
return format.replace(/\{\{(\!?)([^}]+)\}\}/g, ($0, isSecure, name) => {

@@ -104,0 +113,0 @@

@@ -26,3 +26,4 @@ 'use strict';

alternatives: {
base: 'not matching any of the allowed alternatives'
base: 'not matching any of the allowed alternatives',
child: null
},

@@ -88,9 +89,9 @@ array: {

allowUnknown: '!!"{{!child}}" is not allowed',
with: 'missing required peer "{{peer}}"',
without: 'conflict with forbidden peer "{{peer}}"',
missing: 'must contain at least one of {{peers}}',
xor: 'contains a conflict between exclusive peers {{peers}}',
or: 'must contain at least one of {{peers}}',
and: 'contains {{present}} without its required peers {{missing}}',
nand: '!!"{{main}}" must not exist simultaneously with {{peers}}',
with: '!!"{{mainWithLabel}}" missing required peer "{{peerWithLabel}}"',
without: '!!"{{mainWithLabel}}" conflict with forbidden peer "{{peerWithLabel}}"',
missing: 'must contain at least one of {{peersWithLabels}}',
xor: 'contains a conflict between exclusive peers {{peersWithLabels}}',
or: 'must contain at least one of {{peersWithLabels}}',
and: 'contains {{presentWithLabels}} without its required peers {{missingWithLabels}}',
nand: '!!"{{mainWithLabel}}" must not exist simultaneously with {{peersWithLabels}}',
assert: '!!"{{ref}}" validation failed because "{{ref}}" failed to {{message}}',

@@ -97,0 +98,0 @@ rename: {

@@ -730,2 +730,24 @@ 'use strict';

internals.keysToLabels = function (schema, keys) {
const children = schema._inner.children;
if (!children) {
return keys;
}
const findLabel = function (key) {
const matchingChild = children.find((child) => child.key === key);
return matchingChild ? matchingChild.schema._getLabel(key) : key;
};
if (Array.isArray(keys)) {
return keys.map(findLabel);
}
return findLabel(keys);
};
internals.with = function (value, peers, parent, state, options) {

@@ -742,3 +764,8 @@

return this.createError('object.with', { peer }, state, options);
return this.createError('object.with', {
main: state.key,
mainWithLabel: internals.keysToLabels(this, state.key),
peer,
peerWithLabel: internals.keysToLabels(this, peer)
}, state, options);
}

@@ -762,3 +789,8 @@ }

return this.createError('object.without', { peer }, state, options);
return this.createError('object.without', {
main: state.key,
mainWithLabel: internals.keysToLabels(this, state.key),
peer,
peerWithLabel: internals.keysToLabels(this, peer)
}, state, options);
}

@@ -787,7 +819,9 @@ }

const context = { peers, peersWithLabels: internals.keysToLabels(this, peers) };
if (present.length === 0) {
return this.createError('object.missing', { peers }, state, options);
return this.createError('object.missing', context, state, options);
}
return this.createError('object.xor', { peers }, state, options);
return this.createError('object.xor', context, state, options);
};

@@ -806,3 +840,6 @@

return this.createError('object.missing', { peers }, state, options);
return this.createError('object.missing', {
peers,
peersWithLabels: internals.keysToLabels(this, peers)
}, state, options);
};

@@ -829,3 +866,12 @@

const aon = (missing.length === count || present.length === count);
return !aon ? this.createError('object.and', { present, missing }, state, options) : null;
if (!aon) {
return this.createError('object.and', {
present,
presentWithLabels: internals.keysToLabels(this, present),
missing,
missingWithLabels: internals.keysToLabels(this, missing)
}, state, options);
}
};

@@ -849,3 +895,8 @@

const allPresent = (present.length === peers.length);
return allPresent ? this.createError('object.nand', { main, peers: values }, state, options) : null;
return allPresent ? this.createError('object.nand', {
main,
mainWithLabel: internals.keysToLabels(this, main),
peers: values,
peersWithLabels: internals.keysToLabels(this, values)
}, state, options) : null;
};

@@ -852,0 +903,0 @@

{
"name": "joi",
"description": "Object schema validation",
"version": "10.4.0",
"version": "10.4.1",
"homepage": "https://github.com/hapijs/joi",

@@ -6,0 +6,0 @@ "repository": "git://github.com/hapijs/joi",

@@ -128,3 +128,3 @@ ![joi Logo](https://raw.github.com/hapijs/joi/master/images/joi.png)

# API
See the [API Reference](https://github.com/hapijs/joi/blob/v10.4.0/API.md).
See the [API Reference](https://github.com/hapijs/joi/blob/v10.4.1/API.md).

@@ -131,0 +131,0 @@ # Browsers

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