2023-06-20 14:28:02 +02:00
import { BadDataError } from '../../error' ;
const MAX_COMPLEXITY = 30000 ;
export const validateQueryComplexity = (
environmentsCount : number ,
featuresCount : number ,
contextCombinationsCount : number ,
2023-06-22 08:46:13 +02:00
limit = MAX_COMPLEXITY ,
2023-06-20 14:28:02 +02:00
) : void = > {
const totalCount =
environmentsCount * featuresCount * contextCombinationsCount ;
2023-06-22 10:13:17 +02:00
const reason = ` Rejecting evaluation as it would generate ${ totalCount } combinations exceeding ${ limit } limit. ` ;
2023-06-20 14:28:02 +02:00
const action = ` Please reduce the number of selected environments ( ${ environmentsCount } ), features ( ${ featuresCount } ), context field combinations ( ${ contextCombinationsCount } ). ` ;
2023-06-22 08:46:13 +02:00
if ( totalCount > limit ) {
2023-06-20 14:28:02 +02:00
throw new BadDataError ( reason + action ) ;
}
} ;