UNPKG

@clickup/ent-framework

Version:

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

46 lines 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Or = void 0; const misc_1 = require("../../internal/misc"); const EntAccessError_1 = require("../errors/EntAccessError"); const Predicate_1 = require("./Predicate"); /** * Checks that at least one of the children predicates succeed. */ class Or { constructor(...predicates) { this.name = this.constructor.name; this.predicates = predicates.map((predicate) => predicate instanceof Function ? new Predicate_1.FuncToPredicate(predicate) : predicate); } async check(vc, input) { const errorEntNames = new Set(); const results = await (0, misc_1.mapJoin)(this.predicates, async (predicate) => { try { return { predicate, res: await predicate.check(vc, input), }; } catch (e) { if (e instanceof EntAccessError_1.EntAccessError) { errorEntNames.add(e.entName); return { predicate, res: e }; } else { throw e; } } }); if (results.some(({ res }) => res === true)) { return true; } throw new EntAccessError_1.EntAccessError([...errorEntNames].join("|"), results .map(({ predicate, res }) => `${predicate.name}: ` + (typeof res === "boolean" ? res : res.message)) .join("\n")); } } exports.Or = Or; //# sourceMappingURL=Or.js.map