UNPKG

@omnia/tooling-composers

Version:

Provide tooling to work with manifest things.

55 lines (54 loc) 2.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SecurityProviderCombinableRuleComposer = void 0; const Enums_1 = require("./models/Enums"); const Utils_1 = require("./Utils"); class SecurityProviderCombinableRuleComposer { constructor(newRuleCb, composerForDone) { this.newRuleCb = newRuleCb; this.composerForDone = composerForDone; this.rules = []; this.selectedLogicalOperator = null; this.done = () => { this.newRuleCb(this.rules); return this.composerForDone; }; this.hasAccessToProvider = (securityProviderId) => { if (!securityProviderId) { throw new Error("Can't add security provider rule with id null/empty/undefined"); } if (!Utils_1.Utils.isValidGuid(securityProviderId)) { throw new Error("Can't add security provider rule with id: " + securityProviderId + " must be a valid Guid"); } if (this.selectedLogicalOperator == null && this.rules.length > 0) { throw new Error("Can't add additional security provider rule without first selecting logical operator."); } if (this.selectedLogicalOperator == null) { //Default to and for first rule this.selectedLogicalOperator = Enums_1.RuleLogicalOperator.And; } let resolvableRule = { logicalOperator: this.selectedLogicalOperator, providerId: securityProviderId }; //Reset this.selectedLogicalOperator = null; this.rules.push(resolvableRule); this.newRuleCb(this.rules); return this; }; this.and = () => { this.selectedLogicalOperator = Enums_1.RuleLogicalOperator.And; return this; }; this.or = () => { this.selectedLogicalOperator = Enums_1.RuleLogicalOperator.Or; return this; }; if (!newRuleCb) { throw new Error("Unexpected, SecurityProviderCombinableRuleComposer needs a new rule callback, one was not provided"); } } } exports.SecurityProviderCombinableRuleComposer = SecurityProviderCombinableRuleComposer;