Comparing version 17.3.0 to 17.4.0
'use strict'; | ||
const Assert = require('@hapi/hoek/lib/assert'); | ||
const Merge = require('@hapi/hoek/lib/merge'); | ||
@@ -47,4 +48,3 @@ const Any = require('./any'); | ||
if (schema._flags.match) { | ||
let hits = 0; | ||
let matched; | ||
const matched = []; | ||
@@ -58,4 +58,3 @@ for (let i = 0; i < schema.$_terms.matches.length; ++i) { | ||
if (!result.errors) { | ||
++hits; | ||
matched = result.value; | ||
matched.push(result.value); | ||
} | ||
@@ -67,3 +66,3 @@ else { | ||
if (!hits) { | ||
if (matched.length === 0) { | ||
return { errors: error('alternatives.any') }; | ||
@@ -73,6 +72,11 @@ } | ||
if (schema._flags.match === 'one') { | ||
return hits === 1 ? { value: matched } : { errors: error('alternatives.one') }; | ||
return matched.length === 1 ? { value: matched[0] } : { errors: error('alternatives.one') }; | ||
} | ||
return hits === schema.$_terms.matches.length ? { value } : { errors: error('alternatives.all') }; | ||
if (matched.length !== schema.$_terms.matches.length) { | ||
return { errors: error('alternatives.all') }; | ||
} | ||
const allobj = schema.$_terms.matches.reduce((acc, v) => acc && v.schema.type === 'object', true); | ||
return allobj ? { value: matched.reduce((acc, v) => Merge(acc, v, { mergeArrays: false })) } : { value: matched[matched.length - 1] }; | ||
} | ||
@@ -79,0 +83,0 @@ |
@@ -345,2 +345,6 @@ 'use strict'; | ||
internals.fillOrderedErrors(schema, errors, ordereds, value, state, prefs); | ||
if (!errors.length) { | ||
internals.fillDefault(ordereds, value, state, prefs); | ||
} | ||
} | ||
@@ -681,2 +685,29 @@ | ||
internals.fillDefault = function (ordereds, value, state, prefs) { | ||
const overrides = []; | ||
let trailingUndefined = true; | ||
for (let i = ordereds.length - 1; i >= 0; --i) { | ||
const ordered = ordereds[i]; | ||
const ancestors = [value, ...state.ancestors]; | ||
const override = ordered.$_validate(undefined, state.localize(state.path, ancestors, ordered), prefs).value; | ||
if (trailingUndefined) { | ||
if (override === undefined) { | ||
continue; | ||
} | ||
trailingUndefined = false; | ||
} | ||
overrides.unshift(override); | ||
} | ||
if (overrides.length) { | ||
value.push(...overrides); | ||
} | ||
}; | ||
internals.fastSplice = function (arr, i) { | ||
@@ -683,0 +714,0 @@ |
@@ -115,2 +115,6 @@ 'use strict'; | ||
if (result.value !== undefined) { | ||
value[key] = result.value; | ||
} | ||
errors.push(...result.errors); | ||
@@ -604,3 +608,3 @@ } | ||
for (const peer of peers) { | ||
Assert(typeof peer === 'string', rel, 'peers must be a string or a reference'); | ||
Assert(typeof peer === 'string', rel, 'peers must be strings'); | ||
paths.push(Compile.ref(peer, { separator, ancestor: 0, prefix: false })); | ||
@@ -607,0 +611,0 @@ } |
@@ -650,7 +650,8 @@ 'use strict'; | ||
if (match) { | ||
if (domain) { | ||
const matched = match[1] || match[2]; | ||
if (!Domain.isValid(matched, domain)) { | ||
return helpers.error('string.domain', { value: matched }); | ||
} | ||
const matched = match[1] || match[2]; | ||
if (domain && | ||
(!options.allowRelative || matched) && | ||
!Domain.isValid(matched, domain)) { | ||
return helpers.error('string.domain', { value: matched }); | ||
} | ||
@@ -657,0 +658,0 @@ |
@@ -0,0 +0,0 @@ 'use strict'; |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "17.3.0", | ||
"version": "17.4.0", | ||
"repository": "git://github.com/sideway/joi", | ||
@@ -25,7 +25,7 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"typescript": "4.0.x", | ||
"@hapi/bourne": "2.x.x", | ||
"@hapi/code": "8.x.x", | ||
"@hapi/joi-legacy-test": "npm:@hapi/joi@15.x.x", | ||
"@hapi/lab": "24.x.x", | ||
"@hapi/joi-legacy-test": "npm:@hapi/joi@15.x.x" | ||
"typescript": "4.0.x" | ||
}, | ||
@@ -32,0 +32,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
9554
515094