UNPKG

moeralib

Version:

Library to interact with Moera decentralized social network

20 lines (19 loc) 733 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isSchemaValid = isSchemaValid; exports.formatSchemaErrors = formatSchemaErrors; exports.validateSchemaFromMap = validateSchemaFromMap; function isSchemaValid(schema, data) { return schema(data); } function formatSchemaErrors(errors) { return errors != null ? errors.map(({ message }) => message).join(", ") : ""; } 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 }; }