UNPKG

@clickup/ent-framework

Version:

A PostgreSQL graph-database-alike library with microsharding and row-level security

36 lines 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CanDeleteOutgoingEdge = void 0; const Predicate_1 = require("./Predicate"); /** * Checks that an Ent available via a field can be deleted, or Ent doesn't exist * (e.g. Ent is orphaned). See CanReadOutgoingEdge comments for more details. */ class CanDeleteOutgoingEdge { 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.IDsCacheDeletable); if (cache.has(toID)) { return true; } // Load the target Ent and check that it's deletable. const toEnt = await this.toEntClass.loadNullable(vc, toID); if (toEnt === null) { return true; } await this.toEntClass.VALIDATION.validateDelete(vc, toEnt); // Sill here and not thrown? save to the cache. cache.add(toID); return true; } } exports.CanDeleteOutgoingEdge = CanDeleteOutgoingEdge; //# sourceMappingURL=CanDeleteOutgoingEdge.js.map