@clickup/ent-framework
Version:
A PostgreSQL graph-database-alike library with microsharding and row-level security
32 lines • 1.19 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldIs = void 0;
const maybeThrowEntValidationError_1 = require("./internal/maybeThrowEntValidationError");
/**
* Checks that the validator function returns true for the value in some field.
*/
class FieldIs {
constructor(field, validator, message) {
this.name = this.constructor.name + "(" + field + ")";
this.field = field;
this.message = message ?? null;
this.validator = validator;
}
/**
* Returns true if validation succeeds. Returns false if it wants the client
* to use this.message as a validation failure response. Throws an instance of
* EntValidationError when it needs to deliver the detailed error messages
* about multiple fields.
*/
async check(vc, row) {
const res = await this.validator(row[this.field], row, vc);
return (0, maybeThrowEntValidationError_1.maybeThrowEntValidationError)({
name: this.name,
field: this.field,
res,
allowRichResult: this.message === null,
});
}
}
exports.FieldIs = FieldIs;
//# sourceMappingURL=FieldIs.js.map
;