Comparing version 17.7.0 to 17.9.1
@@ -58,2 +58,4 @@ 'use strict'; | ||
} | ||
this.mainstay.snapshot(); | ||
} | ||
@@ -67,2 +69,4 @@ | ||
} | ||
this.mainstay.restore(); | ||
} | ||
@@ -69,0 +73,0 @@ }; |
@@ -70,3 +70,6 @@ 'use strict'; | ||
let root = result.value; | ||
for (const { method, path, label } of mainstay.externals) { | ||
const errors = []; | ||
for (const external of mainstay.externals) { | ||
const path = external.state.path; | ||
const linked = external.schema.type === 'link' ? mainstay.links.get(external.schema) : null; | ||
let node = root; | ||
@@ -76,5 +79,15 @@ let key; | ||
const ancestors = path.length ? [root] : []; | ||
const original = path.length ? Reach(value, path) : value; | ||
if (path.length) { | ||
key = path[path.length - 1]; | ||
parent = Reach(root, path.slice(0, -1)); | ||
let current = root; | ||
for (const segment of path.slice(0, -1)) { | ||
current = current[segment]; | ||
ancestors.unshift(current); | ||
} | ||
parent = ancestors[0]; | ||
node = parent[key]; | ||
@@ -84,3 +97,15 @@ } | ||
try { | ||
const output = await method(node, { prefs }); | ||
const createError = (code, local) => (linked || external.schema).$_createError(code, node, local, external.state, settings); | ||
const output = await external.method(node, { | ||
schema: external.schema, | ||
linked, | ||
state: external.state, | ||
prefs, | ||
original, | ||
error: createError, | ||
errorsArray: internals.errorsArray, | ||
warn: (code, local) => mainstay.warnings.push((linked || external.schema).$_createError(code, node, local, external.state, settings)), | ||
message: (messages, local) => (linked || external.schema).$_createError('external', node, local, external.state, settings, { messages }) | ||
}); | ||
if (output === undefined || | ||
@@ -92,6 +117,31 @@ output === node) { | ||
if (output instanceof Errors.Report) { | ||
mainstay.tracer.log(external.schema, external.state, 'rule', 'external', 'error'); | ||
errors.push(output); | ||
if (settings.abortEarly) { | ||
break; | ||
} | ||
continue; | ||
} | ||
if (Array.isArray(output) && | ||
output[Common.symbols.errors]) { | ||
mainstay.tracer.log(external.schema, external.state, 'rule', 'external', 'error'); | ||
errors.push(...output); | ||
if (settings.abortEarly) { | ||
break; | ||
} | ||
continue; | ||
} | ||
if (parent) { | ||
mainstay.tracer.value(external.state, 'rule', node, output, 'external'); | ||
parent[key] = output; | ||
} | ||
else { | ||
mainstay.tracer.value(external.state, 'rule', root, output, 'external'); | ||
root = output; | ||
@@ -102,3 +152,3 @@ } | ||
if (settings.errors.label) { | ||
err.message += ` (${label})`; // Change message to include path | ||
err.message += ` (${(external.label)})`; // Change message to include path | ||
} | ||
@@ -111,2 +161,12 @@ | ||
result.value = root; | ||
if (errors.length) { | ||
result.error = Errors.process(errors, value, settings); | ||
if (mainstay.debug) { | ||
result.error.debug = mainstay.debug; | ||
} | ||
throw result.error; | ||
} | ||
} | ||
@@ -138,2 +198,34 @@ | ||
internals.Mainstay = class { | ||
constructor(tracer, debug, links) { | ||
this.externals = []; | ||
this.warnings = []; | ||
this.tracer = tracer; | ||
this.debug = debug; | ||
this.links = links; | ||
this.shadow = null; | ||
this.artifacts = null; | ||
this._snapshots = []; | ||
} | ||
snapshot() { | ||
this._snapshots.push({ | ||
externals: this.externals.slice(), | ||
warnings: this.warnings.slice() | ||
}); | ||
} | ||
restore() { | ||
const snapshot = this._snapshots.pop(); | ||
this.externals = snapshot.externals; | ||
this.warnings = snapshot.warnings; | ||
} | ||
}; | ||
internals.entry = function (value, schema, prefs) { | ||
@@ -146,3 +238,3 @@ | ||
const links = schema._ids._schemaChain ? new Map() : null; | ||
const mainstay = { externals: [], warnings: [], tracer, debug, links }; | ||
const mainstay = new internals.Mainstay(tracer, debug, links); | ||
const schemas = schema._ids._schemaChain ? [{ schema }] : null; | ||
@@ -525,3 +617,3 @@ const state = new State([], [], { mainstay, schemas }); | ||
for (const { method } of schema.$_terms.externals) { | ||
state.mainstay.externals.push({ method, path: state.path, label: Errors.label(schema._flags, state, prefs) }); | ||
state.mainstay.externals.push({ method, schema, state, label: Errors.label(schema._flags, state, prefs) }); | ||
} | ||
@@ -528,0 +620,0 @@ } |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "17.7.0", | ||
"version": "17.9.1", | ||
"repository": "git://github.com/hapijs/joi", | ||
@@ -21,3 +21,3 @@ "main": "lib/index.js", | ||
"@sideway/address": "^4.1.3", | ||
"@sideway/formula": "^3.0.0", | ||
"@sideway/formula": "^3.0.1", | ||
"@sideway/pinpoint": "^2.0.0" | ||
@@ -24,0 +24,0 @@ }, |
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
531249
9811
Updated@sideway/formula@^3.0.1