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