Add convenience functions to produce CheckSchemaResult values

This commit is contained in:
Michael B. Gale
2026-07-10 13:18:45 +01:00
parent f8ed33e067
commit aec5441507
2 changed files with 33 additions and 7 deletions

10
lib/entry-points.js generated
View File

@@ -144527,7 +144527,7 @@ function optionalOrNull(validator) {
},
check: (val, path29) => {
if (val === void 0 || val === null) {
return { valid: true, unknownKeys: [] };
return successfulCheckSchema();
}
return validator.check(val, path29);
},
@@ -144538,8 +144538,14 @@ function validateSchema(schema, obj) {
const result = checkSchema(schema, obj, { failFast: true });
return result.valid;
}
function successfulCheckSchema() {
return {
valid: true,
unknownKeys: []
};
}
function checkSchema(schema, obj, options = {}, path29 = "") {
const result = { valid: true, unknownKeys: [] };
const result = successfulCheckSchema();
const inputKeys = new Set(Object.keys(obj));
for (const [key, validator] of Object.entries(schema)) {
const hasKey = key in obj;