Skip to content

Commit 2309ba9

Browse files
yfrancisgreghuels
authored andcommitted
Move evaluation details construction into helper
1 parent c23636b commit 2309ba9

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';
@@ -963,28 +963,13 @@ export default class EppoClient {
963963
const flagEvaluationDetailsBuilder = this.newFlagEvaluationDetailsBuilder(flagKey);
964964
const overrideVariation = this.overridesStore?.get(flagKey);
965965
if (overrideVariation) {
966-
const overrideAllocationKey = 'override-' + overrideVariation.key;
967-
const flagEvaluationDetails = flagEvaluationDetailsBuilder
968-
.setMatch(
969-
0,
970-
overrideVariation,
971-
{ key: overrideAllocationKey, splits: [], doLog: false },
972-
null,
973-
undefined,
974-
)
975-
.build('MATCH', 'Flag override applied');
976-
977-
return {
966+
return overrideResult(
978967
flagKey,
979968
subjectKey,
980-
variation: overrideVariation,
981969
subjectAttributes,
982-
flagEvaluationDetails,
983-
doLog: false,
984-
format: '',
985-
allocationKey: 'override',
986-
extraLogging: {},
987-
};
970+
overrideVariation,
971+
flagEvaluationDetailsBuilder,
972+
);
988973
}
989974

990975
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)