@@ -7,27 +7,27 @@ import SplitIO from '../../../types/splitio';
77import { ILogger } from '../../logger/types' ;
88
99// Build Evaluation object if and only if matchingResult is true
10- function match ( log : ILogger , matchingResult : boolean , bucketingKey : string | undefined , seed : number | undefined , treatments : { getTreatmentFor : ( x : number ) => string } , label : string ) : IEvaluation | undefined {
10+ function match ( log : ILogger , matchingResult : boolean , bucketingKey : string | undefined , seed ? : number , treatments ? : { getTreatmentFor : ( x : number ) => string } , label ? : string ) : IEvaluation | boolean | undefined {
1111 if ( matchingResult ) {
12- const treatment = getTreatment ( log , bucketingKey as string , seed , treatments ) ;
13-
14- return {
15- treatment ,
16- label
17- } ;
12+ return treatments ? // Feature flag
13+ {
14+ treatment : getTreatment ( log , bucketingKey as string , seed , treatments ) ,
15+ label : label !
16+ } : // Rule-based segment
17+ true ;
1818 }
1919
2020 // else we should notify the engine to continue evaluating
2121 return undefined ;
2222}
2323
2424// Condition factory
25- export function conditionContext ( log : ILogger , matcherEvaluator : ( ... args : any ) => MaybeThenable < boolean > , treatments : { getTreatmentFor : ( x : number ) => string } , label : string , conditionType : 'ROLLOUT' | 'WHITELIST' ) : IEvaluator {
25+ export function conditionContext ( log : ILogger , matcherEvaluator : ( key : SplitIO . SplitKeyObject , attributes ?: SplitIO . Attributes , splitEvaluator ?: ISplitEvaluator ) => MaybeThenable < boolean > , treatments ? : { getTreatmentFor : ( x : number ) => string } , label ? : string , conditionType ? : 'ROLLOUT' | 'WHITELIST' ) : IEvaluator {
2626
27- return function conditionEvaluator ( key : SplitIO . SplitKey , seed ?: number , trafficAllocation ?: number , trafficAllocationSeed ?: number , attributes ?: SplitIO . Attributes , splitEvaluator ?: ISplitEvaluator ) {
27+ return function conditionEvaluator ( key : SplitIO . SplitKeyObject , seed ?: number , trafficAllocation ?: number , trafficAllocationSeed ?: number , attributes ?: SplitIO . Attributes , splitEvaluator ?: ISplitEvaluator ) {
2828
2929 // Whitelisting has more priority than traffic allocation, so we don't apply this filtering to those conditions.
30- if ( conditionType === 'ROLLOUT' && ! shouldApplyRollout ( trafficAllocation as number , ( key as SplitIO . SplitKeyObject ) . bucketingKey as string , trafficAllocationSeed as number ) ) {
30+ if ( conditionType === 'ROLLOUT' && ! shouldApplyRollout ( trafficAllocation ! , key . bucketingKey , trafficAllocationSeed ! ) ) {
3131 return {
3232 treatment : undefined , // treatment value is assigned later
3333 label : NOT_IN_SPLIT
@@ -41,10 +41,10 @@ export function conditionContext(log: ILogger, matcherEvaluator: (...args: any)
4141 const matches = matcherEvaluator ( key , attributes , splitEvaluator ) ;
4242
4343 if ( thenable ( matches ) ) {
44- return matches . then ( result => match ( log , result , ( key as SplitIO . SplitKeyObject ) . bucketingKey , seed , treatments , label ) ) ;
44+ return matches . then ( result => match ( log , result , key . bucketingKey , seed , treatments , label ) ) ;
4545 }
4646
47- return match ( log , matches , ( key as SplitIO . SplitKeyObject ) . bucketingKey , seed , treatments , label ) ;
47+ return match ( log , matches , key . bucketingKey , seed , treatments , label ) ;
4848 } ;
4949
5050}
0 commit comments