2020-08-26 01:57:08 +02:00
|
|
|
// eslint-disable-next-line import/default
|
2021-02-26 04:58:33 +01:00
|
|
|
import validators from '../dist/validators';
|
2020-08-26 01:57:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} schemaId
|
|
|
|
* @param {formatData~config} config
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
export default (schemaId, config = {}) => {
|
2021-02-26 04:58:33 +01:00
|
|
|
const validate = validators[schemaId];
|
|
|
|
if (!validate(config)) {
|
|
|
|
const errors = validate.errors.map((error) => {
|
2020-08-26 01:57:08 +02:00
|
|
|
return {
|
|
|
|
dataPath: error.dataPath,
|
|
|
|
message: error.message,
|
|
|
|
params: error.params,
|
2021-02-26 04:58:33 +01:00
|
|
|
schemaPath: error.schemaPath,
|
2020-08-26 01:57:08 +02:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
console.log('config', config);
|
|
|
|
console.log('errors', errors);
|
|
|
|
/* eslint-enable no-console */
|
|
|
|
|
|
|
|
throw new Error('Invalid config.');
|
|
|
|
}
|
|
|
|
};
|