moeralib
Version:
Library to interact with Moera decentralized social network
21 lines (20 loc) • 826 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateSchemaFromMap = exports.formatSchemaErrors = exports.isSchemaValid = void 0;
function isSchemaValid(schema, data) {
return schema(data);
}
exports.isSchemaValid = isSchemaValid;
function formatSchemaErrors(errors) {
return errors != null ? errors.map(({ message }) => message).join(", ") : "";
}
exports.formatSchemaErrors = formatSchemaErrors;
function validateSchemaFromMap(validators, schemaName, data) {
const schema = validators[schemaName];
if (schema == null) {
return { valid: false, errors: [{ message: `Schema ${schemaName} is not found` }] };
}
const valid = isSchemaValid(schema, data);
return { valid, errors: schema.errors };
}
exports.validateSchemaFromMap = validateSchemaFromMap;