UNPKG

@speckle/shared

Version:

Shared code between various Speckle JS packages

42 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isMinimumWorkspaceRole = exports.isMinimumServerRole = exports.isMinimumProjectRole = void 0; const constants_js_1 = require("../../../core/constants.js"); const errors_js_1 = require("../errors.js"); const isMinimumProjectRole = (role, targetRole) => { if (!(role in constants_js_1.RoleInfo.Stream)) { throw new errors_js_1.InvalidRoleError(`Invalid role ${role}`); } if (!(targetRole in constants_js_1.RoleInfo.Stream)) { throw new errors_js_1.InvalidRoleError(`Invalid target role ${targetRole}`); } const roleWeight = constants_js_1.RoleInfo.Stream[role].weight; const targetRoleWeight = constants_js_1.RoleInfo.Stream[targetRole].weight; return roleWeight >= targetRoleWeight; }; exports.isMinimumProjectRole = isMinimumProjectRole; const isMinimumServerRole = (role, targetRole) => { if (!(role in constants_js_1.RoleInfo.Server)) { throw new errors_js_1.InvalidRoleError(`Invalid role ${role}`); } if (!(targetRole in constants_js_1.RoleInfo.Server)) { throw new errors_js_1.InvalidRoleError(`Invalid target role ${targetRole}`); } const roleWeight = constants_js_1.RoleInfo.Server[role].weight; const targetRoleWeight = constants_js_1.RoleInfo.Server[targetRole].weight; return roleWeight >= targetRoleWeight; }; exports.isMinimumServerRole = isMinimumServerRole; const isMinimumWorkspaceRole = (role, targetRole) => { if (!(role in constants_js_1.RoleInfo.Workspace)) { throw new errors_js_1.InvalidRoleError(`Invalid role ${role}`); } if (!(targetRole in constants_js_1.RoleInfo.Workspace)) { throw new errors_js_1.InvalidRoleError(`Invalid target role ${targetRole}`); } const roleWeight = constants_js_1.RoleInfo.Workspace[role].weight; const targetRoleWeight = constants_js_1.RoleInfo.Workspace[targetRole].weight; return roleWeight >= targetRoleWeight; }; exports.isMinimumWorkspaceRole = isMinimumWorkspaceRole; //# sourceMappingURL=roles.js.map