|
|
|
@ -72,14 +72,34 @@ module.exports = function generateValidator(rule, name = "<unknown>", registry)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} else if (rule._isCustomRegistryType) {
|
|
|
|
|
/* HACK: We performantly memoize the validator for a registry-stored alias, by storing it in the validator generation scope. */
|
|
|
|
|
let aliasValidator;
|
|
|
|
|
|
|
|
|
|
baseRule = function (value) {
|
|
|
|
|
/* FIXME: Better error when the type is unknown */
|
|
|
|
|
if (registry._types.get(rule._name)._validator.call(this, value) === true) {
|
|
|
|
|
let actualType = registry._types.get(rule._name);
|
|
|
|
|
|
|
|
|
|
if (actualType._isCustomType) {
|
|
|
|
|
if (actualType._validator.call(this, value) === true) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
/* FIXME: Add support for registry rules to getValueType */
|
|
|
|
|
return new errors.ValidationError(`Expected ${getValueType(rule)}, got ${getValueType(value)} instead`);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (aliasValidator == null) {
|
|
|
|
|
aliasValidator = generateValidator(actualType._alias, name, registry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let validatorResult = aliasValidator.call(this, value);
|
|
|
|
|
|
|
|
|
|
if (validatorResult === true) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
// return new errors.ValidationError(`Expected ${getValueType(actualType._alias)}, got ${getValueType(value)} instead`);
|
|
|
|
|
/* FIXME: Possible this is done wrong elsewhere too, swallowing the actual validation error? */
|
|
|
|
|
return validatorResult;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} else if (rule._isTrait === true) {
|
|
|
|
|
baseRule = function (value) {
|
|
|
|
|