Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test(type, ...args) {
const cache = this.get('_testValidatorCache');
const unsupportedTypes = ['alias', 'belongs-to', 'dependent', 'has-many'];
if (unsupportedTypes.includes(type)) {
throw new Error(
`[ember-cp-validations] The \`test\` API does not support validators of type: ${type}.`
);
}
cache[type] = cache[type] || lookupValidator(getOwner(this), type).create();
const result = cache[type].validate(...args);
if (isPromise(result)) {
return result.then(r => new TestResult(r), r => new TestResult(r));
}
return new TestResult(result);
}
});
validate(value, ...args) {
if (value) {
if (isPromise(value)) {
return value.then(model => this.validate(model, ...args));
}
return get(value, 'validations');
}
return true;
}
});
validate(value, ...args) {
if (value) {
if (isPromise(value)) {
return value.then(models => this.validate(models, ...args));
}
return value.map(m => get(m, 'validations'));
}
return true;
}
});