|
|
|
@ -72,13 +72,33 @@ 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) {
|
|
|
|
|
return true;
|
|
|
|
|
let actualType = registry._types.get(rule._name);
|
|
|
|
|
|
|
|
|
|
if (actualType._isCustomType) {
|
|
|
|
|
if (actualType._validator.call(this, value) === true) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return new errors.ValidationError(`Expected ${getValueType(rule)}, got ${getValueType(value)} instead`);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* FIXME: Add support for registry rules to getValueType */
|
|
|
|
|
return new errors.ValidationError(`Expected ${getValueType(rule)}, got ${getValueType(value)} instead`);
|
|
|
|
|
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) {
|
|
|
|
|