@cowwoc/requirements
Version:
A fluent API for enforcing design contracts with automatic message generation.
36 lines • 1.24 kB
JavaScript
import { AbstractValidator, classIsSupertypeOf, classIsSubtypeOf, classIsPrimitive, Type } from "../internal.mjs";
/**
* Default implementation of <code>ClassValidator</code>.
*/
class ClassValidatorImpl extends AbstractValidator {
isPrimitive() {
if (this.value.validationFailed(v => Type.of(v).isPrimitive())) {
this.addRangeError(classIsPrimitive(this).toString());
}
return this;
}
isSupertypeOf(type) {
if (this.value.validationFailed(v => {
const child = Type.of(v);
const parent = Type.of(type);
return child.isSubtypeOf(parent);
})) {
this.failOnUndefinedOrNull();
this.addRangeError(classIsSupertypeOf(this, type).toString());
}
return this;
}
isSubtypeOf(type) {
if (this.value.validationFailed(v => {
const child = Type.of(type);
const parent = Type.of(v);
return child.isSubtypeOf(parent);
})) {
this.failOnUndefinedOrNull();
this.addRangeError(classIsSubtypeOf(this, type).toString());
}
return this;
}
}
export { ClassValidatorImpl };
//# sourceMappingURL=ClassValidatorImpl.mjs.map