Break out of loop to allow result object to be updated after failing fast

This commit is contained in:
Michael B. Gale
2026-07-13 14:47:38 +01:00
parent 3f1e4da48d
commit 0c2cea31ba
2 changed files with 13 additions and 6 deletions

6
lib/entry-points.js generated
View File

@@ -144556,14 +144556,14 @@ function checkSchema(schema, obj, options = {}, path29 = "") {
if (validator.required && !hasKey) {
result.valid = false;
if (options.failFast) {
return result;
break;
}
continue;
}
if (validator.required && (obj[key] === void 0 || obj[key] === null)) {
result.valid = false;
if (options.failFast) {
return result;
break;
}
continue;
}
@@ -144577,7 +144577,7 @@ function checkSchema(schema, obj, options = {}, path29 = "") {
if (!checkResult.valid) {
result.valid = false;
if (options.failFast) {
return result;
break;
}
continue;
}

View File

@@ -264,9 +264,16 @@ export function checkSchema<S extends Schema>(
path: string = "",
): CheckSchemaResult {
const result: CheckSchemaResult = successfulCheckSchema();
// Track the set of input keys. We remove keys from this set as we recognise them
// during validation.
const inputKeys = new Set(Object.keys(obj));
// Track keys that have failed validation, starting with the empty set.
const invalidKeys = new Set();
// Loop through all keys in the object schema and validate that the given object
// satisfies the schema key.
for (const [key, validator] of Object.entries(schema)) {
const hasKey = key in obj;
@@ -282,7 +289,7 @@ export function checkSchema<S extends Schema>(
result.valid = false;
if (options.failFast) {
return result;
break;
}
continue;
}
@@ -292,7 +299,7 @@ export function checkSchema<S extends Schema>(
result.valid = false;
if (options.failFast) {
return result;
break;
}
continue;
}
@@ -314,7 +321,7 @@ export function checkSchema<S extends Schema>(
result.valid = false;
if (options.failFast) {
return result;
break;
}
continue;
}