Skip to content

Commit f63ba61

Browse files
committed
update json logic engine to v4
Signed-off-by: Michael Beemer <[email protected]>
1 parent a88708c commit f63ba61

File tree

3 files changed

+1957
-1535
lines changed

3 files changed

+1957
-1535
lines changed

libs/shared/flagd-core/src/lib/targeting/fractional.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { flagKeyPropertyKey, flagdPropertyKey, targetingPropertyKey } from './common';
22
import MurmurHash3 from 'imurmurhash';
33
import type { EvaluationContext, EvaluationContextValue, Logger } from '@openfeature/core';
4-
import { Constants } from 'json-logic-engine';
54

65
export const fractionalRule = 'fractional';
76

87
export function fractionalFactory(logger: Logger) {
9-
return function fractional(
10-
data: unknown,
11-
contextContainer: { [key in typeof Constants.Override]: EvaluationContext },
12-
...remaining: unknown[]
13-
): string | null {
8+
return function fractional(data: unknown, context: EvaluationContext): string | null {
149
if (!Array.isArray(data)) {
1510
return null;
1611
}
@@ -21,11 +16,7 @@ export function fractionalFactory(logger: Logger) {
2116
return null;
2217
}
2318

24-
// Extract context using JSOn Logic Engine override symbol.
25-
console.log('context', contextContainer);
26-
console.log('remaining', remaining);
27-
const context = contextContainer[Constants.Override];
28-
const flagdProperties = context?.[flagdPropertyKey] as { [key: string]: EvaluationContextValue } | undefined;
19+
const flagdProperties = context[flagdPropertyKey] as { [key: string]: EvaluationContextValue } | undefined;
2920
if (!flagdProperties) {
3021
logger.debug('Missing flagd properties, cannot perform fractional targeting');
3122
return null;

libs/shared/flagd-core/src/lib/targeting/targeting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class Targeting {
1717
engine.addMethod(startsWithRule, startsWithHandler);
1818
engine.addMethod(endsWithRule, endsWithHandler);
1919
engine.addMethod(semVerRule, semVerFactory(logger));
20-
engine.addMethod(fractionalRule, fractionalFactory(logger), { useContext: true });
20+
engine.addMethod(fractionalRule, fractionalFactory(logger));
2121

2222
// JSON logic engine returns a generic Function interface, so we cast it to any
2323
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)