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 14.0.0 to 14.0.1

lib/types/state.js

12

lib/types/alternatives/index.js

@@ -33,3 +33,3 @@ 'use strict';

let errors = [];
const errors = [];
const il = this._inner.matches.length;

@@ -66,3 +66,3 @@ const baseType = this._baseType;

errors = errors.concat(result.errors);
errors.push(...result.errors);
}

@@ -87,3 +87,3 @@

if (cast._refs.length) {
obj._refs = obj._refs.concat(cast._refs);
obj._refs.push(...cast._refs);
}

@@ -140,11 +140,11 @@

Ref.push(obj._refs, item.ref);
obj._refs = obj._refs.concat(item.is._refs);
obj._refs.push(...item.is._refs);
}
if (item.then && item.then._refs) {
obj._refs = obj._refs.concat(item.then._refs);
obj._refs.push(...item.then._refs);
}
if (item.otherwise && item.otherwise._refs) {
obj._refs = obj._refs.concat(item.otherwise._refs);
obj._refs.push(...item.otherwise._refs);
}

@@ -151,0 +151,0 @@

@@ -9,5 +9,9 @@ 'use strict';

const Errors = require('../../errors');
const State = require('../state');
const Symbols = require('../symbols');
let Alternatives = null; // Delay-loaded to prevent circular dependencies
// Delay-loaded to prevent circular dependencies
let Alternatives = null;
let Cast = null;
let Schemas = null;

@@ -101,3 +105,3 @@

const Schemas = require('../../schemas');
Schemas = Schemas || require('../../schemas');

@@ -167,4 +171,4 @@ const result = Schemas.options.validate(options);

obj._invalids.merge(schema._invalids, schema._valids);
obj._tests = obj._tests.concat(schema._tests);
obj._refs = obj._refs.concat(schema._refs);
obj._tests.push(...schema._tests);
obj._refs.push(...schema._refs);
Hoek.merge(obj._flags, schema._flags);

@@ -174,6 +178,6 @@

obj._unit = schema._unit || obj._unit;
obj._notes = obj._notes.concat(schema._notes);
obj._tags = obj._tags.concat(schema._tags);
obj._examples = obj._examples.concat(schema._examples);
obj._meta = obj._meta.concat(schema._meta);
obj._notes.push(...schema._notes);
obj._tags.push(...schema._tags);
obj._examples.push(...schema._examples);
obj._meta.push(...schema._meta);

@@ -491,3 +495,4 @@ const inners = Object.keys(schema._inner);

const result = this._validate(value, { key: '', path: [], parent: options.parent || null }, Settings.concat(internals.defaults, options.context ? { context: options.context } : null));
const localState = new State('', [], options.parent || null);
const result = this._validate(value, localState, Settings.concat(internals.defaults, options.context ? { context: options.context } : null));
Hoek.assert(!result.errors, `Bad example at index ${i}:`, result.errors && Errors.process(result.errors, value));

@@ -532,66 +537,18 @@

state = state || { key: '', path: [], parent: null, reference };
state = state || new State('', [], null, reference);
if (this._settings) {
options = Settings.concat(options, this._settings);
}
let errors = [];
const finish = () => {
let finalValue;
if (value !== undefined) {
finalValue = this._flags.raw ? originalValue : value;
const isDefaultOptions = options === internals.defaults;
if (isDefaultOptions && this._settings[Symbols.settingsCache]) {
options = this._settings[Symbols.settingsCache];
}
else if (options.noDefaults) {
finalValue = value;
}
else if (Ref.isRef(this._flags.default)) {
finalValue = this._flags.default(state.parent, options);
}
else if (typeof this._flags.default === 'function' &&
!(this._flags.func && !this._flags.default.description)) {
let args;
if (state.parent !== null &&
this._flags.default.length > 0) {
args = [Hoek.clone(state.parent), options];
}
const defaultValue = internals._try(this._flags.default, args);
finalValue = defaultValue.value;
if (defaultValue.error) {
errors.push(this.createError('any.default', { error: defaultValue.error }, state, options));
}
}
else {
finalValue = Hoek.clone(this._flags.default);
}
if (errors.length && typeof this._flags.error === 'function') {
const change = this._flags.error.call(this, errors);
if (typeof change === 'string') {
errors = [this.createOverrideError('override', { reason: errors }, state, options, change)];
options = Settings.concat(options, this._settings);
if (isDefaultOptions) {
this._settings[Symbols.settingsCache] = options;
}
else {
errors = [].concat(change)
.map((err) => {
return err instanceof Error ?
err :
this.createOverrideError(err.type || 'override', err.context, state, options, err.message, err.template);
});
}
}
}
return {
value: this._flags.strip ? undefined : finalValue,
finalValue,
errors: errors.length ? errors : null
};
};
let errors = [];

@@ -603,3 +560,3 @@ if (this._coerce) {

errors = errors.concat(coerced.errors);
return finish(); // Coerced error always aborts early
return this._finalizeValue(value, originalValue, errors, state, options); // Coerced error always aborts early
}

@@ -624,3 +581,3 @@

else {
return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}

@@ -633,11 +590,11 @@ }

errors.push(this.createError('any.required', null, state, options));
return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}
else if (presence === 'forbidden') {
if (value === undefined) {
return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}
errors.push(this.createError('any.unknown', null, state, options));
return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}

@@ -653,3 +610,3 @@

return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}

@@ -662,3 +619,3 @@

return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}

@@ -674,3 +631,3 @@ }

errors = errors.concat(base.errors);
return finish(); // Base error always aborts early
return this._finalizeValue(value, originalValue, errors, state, options); // Base error always aborts early
}

@@ -686,3 +643,3 @@

value = match.value;
return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}

@@ -693,3 +650,3 @@

if (options.abortEarly) {
return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}

@@ -705,3 +662,3 @@ }

if (options.abortEarly) {
return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}

@@ -718,3 +675,3 @@ }

if (options.abortEarly) {
return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}

@@ -727,5 +684,63 @@ }

return finish();
return this._finalizeValue(value, originalValue, errors, state, options);
}
_finalizeValue(value, originalValue, errors, state, options) {
let finalValue;
if (value !== undefined) {
finalValue = this._flags.raw ? originalValue : value;
}
else if (options.noDefaults) {
finalValue = value;
}
else if (Ref.isRef(this._flags.default)) {
finalValue = this._flags.default(state.parent, options);
}
else if (typeof this._flags.default === 'function' &&
!(this._flags.func && !this._flags.default.description)) {
let args;
if (state.parent !== null &&
this._flags.default.length > 0) {
args = [Hoek.clone(state.parent), options];
}
const defaultValue = internals._try(this._flags.default, args);
finalValue = defaultValue.value;
if (defaultValue.error) {
errors.push(this.createError('any.default', { error: defaultValue.error }, state, options));
}
}
else {
finalValue = Hoek.clone(this._flags.default);
}
if (errors.length && typeof this._flags.error === 'function') {
const change = this._flags.error.call(this, errors);
if (typeof change === 'string') {
errors = [this.createOverrideError('override', { reason: errors }, state, options, change)];
}
else {
errors = [].concat(change)
.map((err) => {
return err instanceof Error ?
err :
this.createOverrideError(err.type || 'override', err.context, state, options, err.message, err.template);
});
}
}
return {
value: this._flags.strip ? undefined : finalValue,
finalValue,
errors: errors.length ? errors : null
};
}
_validateWithOptions(value, options, callback) {

@@ -732,0 +747,0 @@

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

const Symbols = require('../symbols');
// Declare internals

@@ -22,16 +24,15 @@

const sKeys = Object.keys(source);
for (let i = 0; i < sKeys.length; ++i) {
const key = sKeys[i];
if (key !== 'language' ||
!obj.hasOwnProperty(key)) {
const language = source.language;
obj[key] = source[key];
}
else {
obj[key] = Hoek.applyToDefaults(obj[key], source[key]);
}
Object.assign(obj, source);
if (language) {
obj.language = Hoek.applyToDefaults(obj.language, language);
}
if (obj[Symbols.settingsCache]) {
delete obj[Symbols.settingsCache];
}
return obj;
};

@@ -5,6 +5,8 @@ 'use strict';

const Hoek = require('hoek');
const Any = require('../any');
const Cast = require('../../cast');
const Ref = require('../../ref');
const Hoek = require('hoek');
const State = require('../state');

@@ -106,3 +108,3 @@

const ordereds = this._inner.ordereds.slice();
const inclusions = this._inner.inclusions.concat(requireds);
const inclusions = [...this._inner.inclusions, ...requireds];

@@ -115,4 +117,4 @@ let il = items.length;

const key = wasArray ? i : state.key;
const path = wasArray ? state.path.concat(i) : state.path;
const localState = { key, path, parent: state.parent, reference: state.reference };
const path = wasArray ? [...state.path, i] : state.path;
const localState = new State(key, path, state.parent, state.reference);
let res;

@@ -535,9 +537,3 @@

if (compare(current.value[0], item)) {
const localState = {
key: state.key,
path: state.path.concat(i),
parent: state.parent,
reference: state.reference
};
const localState = new State(state.key, [...state.path, i], state.parent, state.reference);
const context = {

@@ -562,8 +558,3 @@ pos: i,

if ((!ignoreUndefined || item !== undefined) && records[item] !== undefined) {
const localState = {
key: state.key,
path: state.path.concat(i),
parent: state.parent,
reference: state.reference
};
const localState = new State(state.key, [...state.path, i], state.parent, state.reference);

@@ -570,0 +561,0 @@ const context = {

@@ -93,4 +93,4 @@ 'use strict';

const description = super.describe();
description.truthy = [true].concat(this._inner.truthySet.values());
description.falsy = [false].concat(this._inner.falsySet.values());
description.truthy = [true, ...this._inner.truthySet.values()];
description.falsy = [false, ...this._inner.falsySet.values()];
return description;

@@ -97,0 +97,0 @@ }

@@ -10,2 +10,3 @@ 'use strict';

const Cast = require('../../cast');
const State = require('../state');

@@ -212,3 +213,3 @@

const localState = { key, path: state.path.concat(key), parent: target, reference: state.reference };
const localState = new State(key, [...state.path, key], target, state.reference);
const result = child.schema._validate(item, localState, options);

@@ -243,8 +244,3 @@ if (result.errors) {

for (const key of unprocessed) {
const localState = {
key,
path: state.path.concat(key),
parent: target,
reference: state.reference
};
const localState = new State(key, [...state.path, key], target, state.reference);
const item = target[key];

@@ -305,3 +301,3 @@

key: unprocessedKey,
path: state.path.concat(unprocessedKey)
path: [...state.path, unprocessedKey]
}, options, {}));

@@ -316,3 +312,6 @@ }

const dep = this._inner.dependencies[i];
const err = internals[dep.type].call(this, dep.key !== null && target[dep.key], dep.peers, target, { key: dep.key, path: dep.key === null ? state.path : state.path.concat(dep.key) }, options);
const hasKey = dep.key !== null;
const splitKey = hasKey && dep.key.split('.');
const localState = hasKey ? new State(splitKey[splitKey.length - 1], [...state.path, ...splitKey]) : new State(null, state.path);
const err = internals[dep.type].call(this, dep.key, hasKey && Hoek.reach(target, dep.key), dep.peers, target, localState, options);
if (err instanceof Errors.Err) {

@@ -706,5 +705,3 @@ errors.push(err);

const localState = Hoek.merge({}, state);
localState.key = key;
localState.path = ref.path;
const localState = new State(key, ref.path, state.parent, state.reference);
return this.createError('object.assert', { ref: path, message }, localState, options);

@@ -791,6 +788,6 @@ });

internals.with = function (value, peers, parent, state, options) {
internals.with = function (key, value, peers, parent, state, options) {
if (value === undefined) {
return value;
return;
}

@@ -805,4 +802,4 @@

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

@@ -813,11 +810,9 @@ peerWithLabel: internals.keysToLabels(this, peer)

}
return value;
};
internals.without = function (value, peers, parent, state, options) {
internals.without = function (key, value, peers, parent, state, options) {
if (value === undefined) {
return value;
return;
}

@@ -831,4 +826,4 @@

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

@@ -839,8 +834,6 @@ peerWithLabel: internals.keysToLabels(this, peer)

}
return value;
};
internals.xor = function (value, peers, parent, state, options) {
internals.xor = function (key, value, peers, parent, state, options) {

@@ -858,3 +851,3 @@ const present = [];

if (present.length === 1) {
return value;
return;
}

@@ -875,3 +868,3 @@

internals.or = function (value, peers, parent, state, options) {
internals.or = function (key, value, peers, parent, state, options) {

@@ -882,4 +875,3 @@ for (let i = 0; i < peers.length; ++i) {

if (keysExist !== undefined) {
return value;
return;
}

@@ -895,3 +887,3 @@ }

internals.and = function (value, peers, parent, state, options) {
internals.and = function (key, value, peers, parent, state, options) {

@@ -927,3 +919,3 @@ const missing = [];

internals.nand = function (value, peers, parent, state, options) {
internals.nand = function (key, value, peers, parent, state, options) {

@@ -930,0 +922,0 @@ const present = [];

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

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

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

# API
See the detailed [API Reference](https://github.com/hapijs/joi/blob/v14.0.0/API.md).
See the detailed [API Reference](https://github.com/hapijs/joi/blob/v14.0.1/API.md).

@@ -22,0 +22,0 @@ # Example

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