@clickup/ent-framework
Version:
A PostgreSQL graph-database-alike library with microsharding and row-level security
38 lines • 1.23 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.CanReadOutgoingEdge = void 0;
const Predicate_1 = require("./Predicate");
/**
* Checks that an ent which a field is pointing to is readable:
*
* EntOur[company_id] ---> EntCompany[id]
*
* This predicate delegates the readability permission check for the current ent
* to another ent with ID equals to the value of our ent's field.
*
* - field = user_id in the above example
* - toEntClass = EntCompany in the above example
*/
class CanReadOutgoingEdge {
constructor(field, toEntClass) {
this.field = field;
this.toEntClass = toEntClass;
this.name = this.constructor.name + "(" + this.field + ")";
}
async check(vc, row) {
const toID = row[this.field];
if (!toID) {
return false;
}
const cache = vc.cache(Predicate_1.IDsCacheReadable);
if (cache.has(toID)) {
return true;
}
await this.toEntClass.loadX(vc, toID);
// sill here and not thrown? save to the cache
cache.add(toID);
return true;
}
}
exports.CanReadOutgoingEdge = CanReadOutgoingEdge;
//# sourceMappingURL=CanReadOutgoingEdge.js.map
;