@infect/infect-rda-sample-importer
Version:
INFECT Sample Data Importer
41 lines (28 loc) • 872 B
JavaScript
import { validate as isUuid } from 'uuid';
import FieldProcessor from './FieldProcessor.js';
export default class UniqueIdentifierProcessor extends FieldProcessor {
constructor() {
super({
name: 'UniqueIdentifier',
fieldName: 'unique-identifier',
required: true,
});
}
/**
* process and validate the given field of the import
*
* @param {*} value The value
*/
async process(value) {
if (isUuid(value)) {
// valid uuid v4
return value;
} else if (/[a-z0-9]{32}/i.test(value)) {
// valid md5 hash
return value;
} else {
// soft fail, mark the record as invalid
this.failValidation(`Invalid value '${value}': expected a MD5 hash or a valid uuid v4!`);
}
}
}