Skip to content

Commit 60d1d72

Browse files
committed
Move evaluation details construction into helper
1 parent ea0f897 commit 60d1d72

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

src/client/eppo-client.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
} from '../constants';
3131
import { decodeFlag } from '../decoding';
3232
import { EppoValue } from '../eppo_value';
33-
import { Evaluator, FlagEvaluation, noneResult } from '../evaluator';
33+
import { Evaluator, FlagEvaluation, noneResult, overrideResult } from '../evaluator';
3434
import { BoundedEventQueue } from '../events/bounded-event-queue';
3535
import EventDispatcher from '../events/event-dispatcher';
3636
import NoOpEventDispatcher from '../events/no-op-event-dispatcher';
@@ -948,28 +948,13 @@ export default class EppoClient {
948948
const flagEvaluationDetailsBuilder = this.newFlagEvaluationDetailsBuilder(flagKey);
949949
const overrideVariation = this.overridesStore?.get(flagKey);
950950
if (overrideVariation) {
951-
const overrideAllocationKey = 'override-' + overrideVariation.key;
952-
const flagEvaluationDetails = flagEvaluationDetailsBuilder
953-
.setMatch(
954-
0,
955-
overrideVariation,
956-
{ key: overrideAllocationKey, splits: [], doLog: false },
957-
null,
958-
undefined,
959-
)
960-
.build('MATCH', 'Flag override applied');
961-
962-
return {
951+
return overrideResult(
963952
flagKey,
964953
subjectKey,
965-
variation: overrideVariation,
966954
subjectAttributes,
967-
flagEvaluationDetails,
968-
doLog: false,
969-
format: '',
970-
allocationKey: 'override',
971-
extraLogging: {},
972-
};
955+
overrideVariation,
956+
flagEvaluationDetailsBuilder,
957+
);
973958
}
974959

975960
const configDetails = this.getConfigDetails();

src/evaluator.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,34 @@ export function matchesRules(
259259
matchedRule: null,
260260
};
261261
}
262+
263+
export function overrideResult(
264+
flagKey: string,
265+
subjectKey: string,
266+
subjectAttributes: Attributes,
267+
overrideVariation: Variation,
268+
flagEvaluationDetailsBuilder: FlagEvaluationDetailsBuilder,
269+
): FlagEvaluation {
270+
const overrideAllocationKey = 'override-' + overrideVariation.key;
271+
const flagEvaluationDetails = flagEvaluationDetailsBuilder
272+
.setMatch(
273+
0,
274+
overrideVariation,
275+
{ key: overrideAllocationKey, splits: [], doLog: false },
276+
null,
277+
undefined,
278+
)
279+
.build('MATCH', 'Flag override applied');
280+
281+
return {
282+
flagKey,
283+
subjectKey,
284+
variation: overrideVariation,
285+
subjectAttributes,
286+
flagEvaluationDetails,
287+
doLog: false,
288+
format: '',
289+
allocationKey: overrideAllocationKey,
290+
extraLogging: {},
291+
};
292+
}

0 commit comments

Comments
 (0)