mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
21 lines
738 B
TypeScript
21 lines
738 B
TypeScript
import { BadDataError } from '../../error';
|
|
|
|
const MAX_COMPLEXITY = 30000;
|
|
|
|
export const validateQueryComplexity = (
|
|
environmentsCount: number,
|
|
featuresCount: number,
|
|
contextCombinationsCount: number,
|
|
limit = MAX_COMPLEXITY,
|
|
): void => {
|
|
const totalCount =
|
|
environmentsCount * featuresCount * contextCombinationsCount;
|
|
|
|
const reason = `Rejecting evaluation as it would generate ${totalCount} combinations exceeding ${limit} limit. `;
|
|
const action = `Please reduce the number of selected environments (${environmentsCount}), features (${featuresCount}), context field combinations (${contextCombinationsCount}).`;
|
|
|
|
if (totalCount > limit) {
|
|
throw new BadDataError(reason + action);
|
|
}
|
|
};
|