1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00
unleash.unleash/src/lib/features/playground/validateQueryComplexity.ts
2023-06-20 14:28:02 +02:00

20 lines
728 B
TypeScript

import { BadDataError } from '../../error';
const MAX_COMPLEXITY = 30000;
export const validateQueryComplexity = (
environmentsCount: number,
featuresCount: number,
contextCombinationsCount: number,
): void => {
const totalCount =
environmentsCount * featuresCount * contextCombinationsCount;
const reason = `Rejecting evaluation as it would generate ${totalCount} combinations exceeding ${MAX_COMPLEXITY} limit. `;
const action = `Please reduce the number of selected environments (${environmentsCount}), features (${featuresCount}), context field combinations (${contextCombinationsCount}).`;
if (totalCount > MAX_COMPLEXITY) {
throw new BadDataError(reason + action);
}
};