Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
5d0b8e9
updated logger method names
EmilianoSanchez Feb 24, 2021
ce4a83d
injected logger across evaluator modules
EmilianoSanchez Feb 25, 2021
cfead7e
added support for message codes
EmilianoSanchez Feb 25, 2021
449654f
injected logger in all modules
EmilianoSanchez Feb 25, 2021
b9e7393
Merge branch 'logger_inject' into logger_support_message_codes
EmilianoSanchez Feb 26, 2021
b50092a
polishing to automatically migrate string messages to code messages
EmilianoSanchez Mar 1, 2021
c8208b5
refactor splitHttpClient to simplify its interface
EmilianoSanchez Mar 2, 2021
761e377
updated fetchers to pass down no-cache header flag
EmilianoSanchez Mar 2, 2021
27c5c23
updated syncTasks
EmilianoSanchez Mar 2, 2021
fa8a385
polishing and refactors
EmilianoSanchez Mar 2, 2021
8feca41
changes in streaming modules
EmilianoSanchez Mar 2, 2021
79fb73a
removed unused files
EmilianoSanchez Mar 2, 2021
2408e39
push manager variants
EmilianoSanchez Mar 3, 2021
853f774
bug fix for corner case
EmilianoSanchez Mar 3, 2021
eacff0d
updated version
EmilianoSanchez Mar 3, 2021
6ad2222
rollback shorten methods
EmilianoSanchez Mar 3, 2021
8fe9cf8
added log for sdk ready
EmilianoSanchez Mar 3, 2021
d5c71a8
updating UTs
EmilianoSanchez Mar 3, 2021
b93e2f7
removed noopLogger
EmilianoSanchez Mar 3, 2021
a972551
validate logger at settings
EmilianoSanchez Mar 4, 2021
2304881
Merge branch 'logger_inject' into logger_support_message_codes
EmilianoSanchez Mar 4, 2021
79534e1
replaced ICodes by a single Map
EmilianoSanchez Mar 4, 2021
a3ca2fc
rollback logErrorsAsInfo
EmilianoSanchez Mar 4, 2021
d3f7282
polishing
EmilianoSanchez Mar 5, 2021
1ced58e
polishing
EmilianoSanchez Mar 5, 2021
b0c208c
Merge branch 'logger_inject' into logger_support_message_codes
EmilianoSanchez Mar 5, 2021
fddce07
removed displayAllErrors option
EmilianoSanchez Mar 5, 2021
f21f43b
updated InLocalStorage module to use injected log
EmilianoSanchez Mar 8, 2021
3908621
Merge pull request #2 from splitio/streaming_updates_services
EmilianoSanchez Mar 9, 2021
79938d2
Merge pull request #3 from splitio/streaming_updates_multiple_refactors
EmilianoSanchez Mar 9, 2021
ed1e04e
Merge branch 'streaming_updates_baseline' into streaming_updates_core
EmilianoSanchez Mar 9, 2021
efb99f2
updated version
EmilianoSanchez Mar 9, 2021
cb5e557
feedback on variable name
EmilianoSanchez Mar 9, 2021
27cae28
Merge pull request #4 from splitio/streaming_updates_core
EmilianoSanchez Mar 9, 2021
e2e909b
Merge pull request #7 from splitio/streaming_updates_baseline
EmilianoSanchez Mar 9, 2021
e253074
Merge branch 'development' into logger_refactor_baseline
EmilianoSanchez Mar 9, 2021
b4ea59e
separete builin from pluggable logger validation
EmilianoSanchez Mar 9, 2021
db5f025
Merge branch 'logger_refactor_baseline' into logger_inject
EmilianoSanchez Mar 9, 2021
1ac4568
Merge branch 'logger_inject' into logger_builtin_and_pluggable
EmilianoSanchez Mar 9, 2021
44779db
Merge branch 'logger_builtin_and_pluggable' into logger_support_messa…
EmilianoSanchez Mar 9, 2021
cbda12d
updated UTs
EmilianoSanchez Mar 9, 2021
71bb96b
Merge branch 'logger_inject' into logger_builtin_and_pluggable
EmilianoSanchez Mar 9, 2021
2e46c0c
updated UTs
EmilianoSanchez Mar 9, 2021
f241d31
Merge branch 'logger_builtin_and_pluggable' into logger_support_messa…
EmilianoSanchez Mar 9, 2021
c955dbf
polishing
EmilianoSanchez Mar 10, 2021
dabadb2
putting back a commented log
EmilianoSanchez Mar 10, 2021
765ce1c
polishing
EmilianoSanchez Mar 10, 2021
6302aa1
Merge branch 'logger_inject' into logger_builtin_and_pluggable
EmilianoSanchez Mar 10, 2021
09cc206
added setLogLevel method to logger
EmilianoSanchez Mar 10, 2021
7d7eca8
Merge branch 'logger_builtin_and_pluggable' into logger_support_messa…
EmilianoSanchez Mar 10, 2021
71c59c1
using constants to extract string literals into separete files
EmilianoSanchez Mar 10, 2021
4872815
extracted strings into constants file
EmilianoSanchez Mar 10, 2021
1044911
polishing
EmilianoSanchez Mar 10, 2021
9437950
feedback
EmilianoSanchez Mar 11, 2021
453e82c
polishing on tests
EmilianoSanchez Mar 11, 2021
efe3490
Merge branch 'logger_inject' into logger_builtin_and_pluggable
EmilianoSanchez Mar 11, 2021
40ad2e0
polishing
EmilianoSanchez Mar 11, 2021
38ced46
more polishing
EmilianoSanchez Mar 11, 2021
d6b71d3
polishing
EmilianoSanchez Mar 11, 2021
8fa1e22
eslint rule for throwing error objects
EmilianoSanchez Mar 11, 2021
6f7c7f0
Merge pull request #9 from splitio/logger_builtin_and_pluggable
EmilianoSanchez Mar 11, 2021
14cc78a
Merge pull request #5 from splitio/logger_inject
EmilianoSanchez Mar 11, 2021
2b52063
Merge branch 'logger_refactor_baseline' into logger_extract_strings
EmilianoSanchez Mar 11, 2021
5c562dc
pluggable loggers
EmilianoSanchez Mar 16, 2021
b556119
removed unused comments
EmilianoSanchez Mar 16, 2021
7430171
Merge pull request #10 from splitio/logger_extract_strings
EmilianoSanchez Mar 16, 2021
3481ba1
Merge branch 'logger_refactor_baseline' into logger_support_message_c…
EmilianoSanchez Mar 16, 2021
940a9c7
some comment updates
EmilianoSanchez Mar 16, 2021
832c0eb
optimized concat call
EmilianoSanchez Mar 16, 2021
bca3fd4
polishing and test updates
EmilianoSanchez Mar 17, 2021
adfc981
update for review
EmilianoSanchez Mar 17, 2021
d46e31f
polishing settings and readiness related log messages
EmilianoSanchez Mar 18, 2021
8bb385c
reusing tags in log messages
EmilianoSanchez Mar 18, 2021
6aaf046
added log prefix to remaining logs
EmilianoSanchez Mar 18, 2021
b1e2d7a
remove some message codes for simplicity
EmilianoSanchez Mar 18, 2021
88b9c4f
comments
EmilianoSanchez Mar 19, 2021
c7f43f1
moved category to logger options, and optimized methods
EmilianoSanchez Mar 19, 2021
8758d56
logger validator UTs
EmilianoSanchez Mar 19, 2021
7c52907
added UTs
EmilianoSanchez Mar 19, 2021
ba357d6
refactor Logger functions
EmilianoSanchez Mar 19, 2021
82f41b5
fix: using prefix in error logs related to invalid api key
EmilianoSanchez Mar 22, 2021
f1a855f
Merge branch 'logger_polishing_log_messages' into logger_improvements
EmilianoSanchez Mar 22, 2021
6598744
feedback
EmilianoSanchez Mar 23, 2021
c9f2943
polishing
EmilianoSanchez Mar 23, 2021
cada7ef
nico's feedback
EmilianoSanchez Mar 25, 2021
7d2d1f1
Merge pull request #12 from splitio/logger_polishing_log_messages
EmilianoSanchez Mar 25, 2021
f990827
Merge branch 'logger_refactor_baseline' into logger_improvements
EmilianoSanchez Mar 25, 2021
2d3de2e
renamed constants
EmilianoSanchez Mar 25, 2021
0d08ebd
Merge pull request #13 from splitio/logger_improvements
EmilianoSanchez Mar 25, 2021
15093c9
feedback
EmilianoSanchez Mar 25, 2021
3426f1d
cleanup imports
EmilianoSanchez Mar 26, 2021
4811f19
ordered constant values
EmilianoSanchez Mar 26, 2021
55d299d
polishing on UTs
EmilianoSanchez Mar 26, 2021
6fca710
Merge pull request #14 from splitio/logger_polishing
EmilianoSanchez Mar 26, 2021
50301e0
updated package version
EmilianoSanchez Mar 26, 2021
ea32113
comment
EmilianoSanchez Mar 26, 2021
c2b6f69
Merge pull request #8 from splitio/logger_refactor_baseline
EmilianoSanchez Mar 26, 2021
fda0f98
prepare for stable release
EmilianoSanchez Mar 30, 2021
8a1c7f9
update
EmilianoSanchez Mar 30, 2021
edb985d
upgraded jest to avoid vulnerability on package dependency
EmilianoSanchez Mar 30, 2021
96e9560
Merge pull request #15 from splitio/release_v0.1.0
EmilianoSanchez Mar 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
],
"rules": {
"no-restricted-syntax": ["error", "ForOfStatement", "ForInStatement", "ArrayPattern"],
"compat/compat": ["error", "defaults, not ie < 10, not node < 6"]
"compat/compat": ["error", "defaults, not ie < 10, not node < 6"],
"no-throw-literal": "error"
},
"parserOptions": {
"ecmaVersion": 2015,
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v10.16
v14
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0.0.1-beta1 (February 5, 2021)
0.1.0 (March 30, 2021)
- Initial public release. It includes common modules to be consumed by the different Split implementations written in JavaScript. Based on the original JS SDK in the `javascript-client` repository.
- It's designed with a modular approach, with the following goals in mind:
- Dependents should be able to include the modules that are needed for, as an example, a storage.
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
preset: 'ts-jest',

// Test files are .js and .ts files inside of __tests__ folders and with a suffix of .test or .spec
testMatch: ['**/__tests__/**/?(*.)+(spec|test).[jt]s'],
testMatch: ['<rootDir>/src/**/__tests__/**/?(*.)+(spec|test).[jt]s'],

// Included files for test coverage (npm run test:coverage)
collectCoverageFrom: [
Expand Down
3,639 changes: 2,389 additions & 1,250 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio-commons",
"version": "0.0.1-beta1",
"version": "0.1.0",
"description": "Split Javascript SDK common components",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand All @@ -24,7 +24,8 @@
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs --importHelpers",
"test": "jest",
"test:coverage": "jest --coverage",
"publish:rc": "npm run check && npm run test && npm run build && npm publish --tag rc"
"publish:rc": "npm run check && npm run test && npm run build && npm publish --tag rc",
"publish:stable": "npm run check && npm run test && npm run build && npm publish"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -61,7 +62,7 @@
"eslint-plugin-compat": "3.7.0",
"fetch-mock": "^9.10.7",
"ioredis": "4.18.0",
"jest": "^26.4.2",
"jest": "^26.6.3",
"jest-localstorage-mock": "^2.4.3",
"js-yaml": "^3.14.0",
"lodash": "^4.17.20",
Expand Down
5 changes: 3 additions & 2 deletions src/evaluator/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ISplit, MaybeThenable } from '../dtos/types';
import { SplitIO } from '../types';
import { IStorageAsync, IStorageSync } from '../storages/types';
import { IEvaluation, IEvaluationResult, IEvaluator, ISplitEvaluator } from './types';
import { ILogger } from '../logger/types';

function evaluationResult(result: IEvaluation | undefined, defaultTreatment: string): IEvaluationResult {
return {
Expand All @@ -26,9 +27,9 @@ export default class Engine {
}
}

static parse(splitFlatStructure: ISplit, storage: IStorageSync | IStorageAsync) {
static parse(log: ILogger, splitFlatStructure: ISplit, storage: IStorageSync | IStorageAsync) {
const conditions = splitFlatStructure.conditions;
const evaluator = parser(conditions, storage);
const evaluator = parser(log, conditions, storage);

return new Engine(splitFlatStructure, evaluator);
}
Expand Down
31 changes: 21 additions & 10 deletions src/evaluator/__tests__/evaluate-feature.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-nocheck
import { evaluateFeature } from '../index';
import * as LabelsConstants from '../../utils/labels';
import { loggerMock } from '../../logger/__tests__/sdkLogger.mock';

const splitsMock = {
regular: '{"changeNumber":1487277320548,"trafficAllocationSeed":1667452163,"trafficAllocation":100,"trafficTypeName":"user","name":"always-on","seed":1684183541,"configurations":{},"status":"ACTIVE","killed":false,"defaultTreatment":"off","conditions":[{"conditionType":"ROLLOUT","matcherGroup":{"combiner":"AND","matchers":[{"keySelector":{"trafficType":"user","attribute":""},"matcherType":"ALL_KEYS","negate":false,"userDefinedSegmentMatcherData":{"segmentName":""},"unaryNumericMatcherData":{"dataType":"","value":0},"whitelistMatcherData":{"whitelist":null},"betweenMatcherData":{"dataType":"","start":0,"end":0}}]},"partitions":[{"treatment":"on","size":100},{"treatment":"off","size":0}],"label":"in segment all"}]}',
Expand Down Expand Up @@ -31,10 +32,11 @@ test('EVALUATOR / should return label exception, treatment control and config nu
config: null
};
const evaluationPromise = evaluateFeature(
loggerMock,
'fake-key',
'throw_exception',
null,
mockStorage
mockStorage,
);

// This validation is async because the only exception possible when retrieving a Split would happen with Async storages.
Expand All @@ -54,79 +56,88 @@ test('EVALUATOR / should return right label, treatment and config if storage ret
};

const evaluationWithConfig = evaluateFeature(
loggerMock,
'fake-key',
'config',
null,
mockStorage
mockStorage,
);
expect(evaluationWithConfig).toEqual(expectedOutput); // If the split is retrieved successfully we should get the right evaluation result, label and config.

const evaluationNotFound = evaluateFeature(
loggerMock,
'fake-key',
'not_existent_split',
null,
mockStorage
mockStorage,
);
expect(evaluationNotFound).toEqual(expectedOutputControl); // If the split is not retrieved successfully because it does not exist, we should get the right evaluation result, label and config.

const evaluation = evaluateFeature(
loggerMock,
'fake-key',
'regular',
null,
mockStorage
mockStorage,
);
expect(evaluation).toEqual({ ...expectedOutput, config: null }); // If the split is retrieved successfully we should get the right evaluation result, label and config. If Split has no config it should have config equal null.

const evaluationKilled = evaluateFeature(
loggerMock,
'fake-key',
'killed',
null,
mockStorage
mockStorage,
);
expect(evaluationKilled).toEqual({ ...expectedOutput, treatment: 'off', config: null, label: LabelsConstants.SPLIT_KILLED });
// If the split is retrieved but is killed, we should get the right evaluation result, label and config.

const evaluationArchived = evaluateFeature(
loggerMock,
'fake-key',
'archived',
null,
mockStorage
mockStorage,
);
expect(evaluationArchived).toEqual({ ...expectedOutput, treatment: 'control', label: LabelsConstants.SPLIT_ARCHIVED, config: null });
// If the split is retrieved but is archived, we should get the right evaluation result, label and config.

const evaluationtrafficAlocation1 = evaluateFeature(
loggerMock,
'fake-key',
'trafficAlocation1',
null,
mockStorage
mockStorage,
);
expect(evaluationtrafficAlocation1).toEqual({ ...expectedOutput, label: LabelsConstants.NOT_IN_SPLIT, config: null, treatment: 'off' });
// If the split is retrieved but is not in split (out of Traffic Allocation), we should get the right evaluation result, label and config.

const evaluationKilledWithConfig = evaluateFeature(
loggerMock,
'fake-key',
'killedWithConfig',
null,
mockStorage
mockStorage,
);
expect(evaluationKilledWithConfig).toEqual({ ...expectedOutput, treatment: 'off', label: LabelsConstants.SPLIT_KILLED });
// If the split is retrieved but is killed, we should get the right evaluation result, label and config.

const evaluationArchivedWithConfig = evaluateFeature(
loggerMock,
'fake-key',
'archivedWithConfig',
null,
mockStorage
mockStorage,
);
expect(evaluationArchivedWithConfig).toEqual({ ...expectedOutput, treatment: 'control', label: LabelsConstants.SPLIT_ARCHIVED, config: null });
// If the split is retrieved but is archived, we should get the right evaluation result, label and config.

const evaluationtrafficAlocation1WithConfig = evaluateFeature(
loggerMock,
'fake-key',
'trafficAlocation1WithConfig',
null,
mockStorage
mockStorage,
);
expect(evaluationtrafficAlocation1WithConfig).toEqual({ ...expectedOutput, label: LabelsConstants.NOT_IN_SPLIT, treatment: 'off' });
// If the split is retrieved but is not in split (out of Traffic Allocation), we should get the right evaluation result, label and config.
Expand Down
7 changes: 5 additions & 2 deletions src/evaluator/__tests__/evaluate-features.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-nocheck
import { evaluateFeatures } from '../index';
import * as LabelsConstants from '../../utils/labels';
import { loggerMock } from '../../logger/__tests__/sdkLogger.mock';

const splitsMock = {
regular: '{"changeNumber":1487277320548,"trafficAllocationSeed":1667452163,"trafficAllocation":100,"trafficTypeName":"user","name":"always-on","seed":1684183541,"configurations":{},"status":"ACTIVE","killed":false,"defaultTreatment":"off","conditions":[{"conditionType":"ROLLOUT","matcherGroup":{"combiner":"AND","matchers":[{"keySelector":{"trafficType":"user","attribute":""},"matcherType":"ALL_KEYS","negate":false,"userDefinedSegmentMatcherData":{"segmentName":""},"unaryNumericMatcherData":{"dataType":"","value":0},"whitelistMatcherData":{"whitelist":null},"betweenMatcherData":{"dataType":"","start":0,"end":0}}]},"partitions":[{"treatment":"on","size":100},{"treatment":"off","size":0}],"label":"in segment all"}]}',
Expand Down Expand Up @@ -43,10 +44,11 @@ test('EVALUATOR - Multiple evaluations at once / should return label exception,

// This validation is async because the only exception possible when retrieving a Split would happen with Async storages.
const evaluation = await evaluateFeatures(
loggerMock,
'fake-key',
['throw_exception'],
null,
mockStorage
mockStorage,
);

expect(evaluation).toEqual(expectedOutput); // If there was an error on the `getSplits` we should get the results for exception.
Expand All @@ -66,10 +68,11 @@ test('EVALUATOR - Multiple evaluations at once / should return right labels, tre
};

const multipleEvaluationAtOnce = await evaluateFeatures(
loggerMock,
'fake-key',
['config', 'not_existent_split', 'regular', 'killed', 'archived', 'trafficAlocation1', 'killedWithConfig', 'archivedWithConfig', 'trafficAlocation1WithConfig'],
null,
mockStorage
mockStorage,
);
// assert evaluationWithConfig
expect(multipleEvaluationAtOnce['config']).toEqual(expectedOutput['config']); // If the split is retrieved successfully we should get the right evaluation result, label and config.
Expand Down
5 changes: 3 additions & 2 deletions src/evaluator/combiners/__tests__/and.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import andCombiner from '../and';
import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock';

test('COMBINER AND / should always return true', async function () {

let AND = andCombiner([() => true, () => true, () => true]);
let AND = andCombiner(loggerMock, [() => true, () => true, () => true]);

expect(await AND('always true')).toBe(true); // should always return true
});

test('COMBINER AND / should always return false', async function () {

let AND = andCombiner([() => true, () => true, () => false]);
let AND = andCombiner(loggerMock, [() => true, () => true, () => false]);

expect(await AND('always false')).toBe(false); // should always return false
});
7 changes: 4 additions & 3 deletions src/evaluator/combiners/__tests__/ifelseif.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-nocheck
import ifElseIfCombinerFactory from '../ifelseif';
import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock';

test('IF ELSE IF COMBINER / should correctly propagate context parameters and predicates returns value', async function () {
let inputKey = 'sample';
Expand All @@ -16,7 +17,7 @@ test('IF ELSE IF COMBINER / should correctly propagate context parameters and pr
}

let predicates = [evaluator];
let ifElseIfEvaluator = ifElseIfCombinerFactory(predicates);
let ifElseIfEvaluator = ifElseIfCombinerFactory(loggerMock, predicates);

expect(await ifElseIfEvaluator(inputKey, inputSeed, inputAttributes) === evaluationResult).toBe(true);
console.log(`evaluator should return ${evaluationResult}`);
Expand All @@ -35,7 +36,7 @@ test('IF ELSE IF COMBINER / should stop evaluating when one matcher return a tre
}
];

let ifElseIfEvaluator = ifElseIfCombinerFactory(predicates);
let ifElseIfEvaluator = ifElseIfCombinerFactory(loggerMock, predicates);

expect(await ifElseIfEvaluator()).toBe('exclude'); // exclude treatment found
});
Expand All @@ -53,7 +54,7 @@ test('IF ELSE IF COMBINER / should return undefined if there is none matching ru
}
];

const ifElseIfEvaluator = ifElseIfCombinerFactory(predicates);
const ifElseIfEvaluator = ifElseIfCombinerFactory(loggerMock, predicates);

expect(await ifElseIfEvaluator() === undefined).toBe(true);
});
18 changes: 9 additions & 9 deletions src/evaluator/combiners/and.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { findIndex } from '../../utils/lang';
import { logFactory } from '../../logger/sdkLogger';
const log = logFactory('splitio-engine:combiner');
import { ILogger } from '../../logger/types';
import thenable from '../../utils/promise/thenable';
import { MaybeThenable } from '../../dtos/types';
import { IMatcher } from '../types';
import { ENGINE_COMBINER_AND } from '../../logger/constants';

function andResults(results: boolean[]): boolean {
// Array.prototype.every is supported by target environments
const hasMatchedAll = results.every(value => value);
export default function andCombinerContext(log: ILogger, matchers: IMatcher[]) {

log.debug(`[andCombiner] evaluates to ${hasMatchedAll}`);
return hasMatchedAll;
}
function andResults(results: boolean[]): boolean {
// Array.prototype.every is supported by target environments
const hasMatchedAll = results.every(value => value);

export default function andCombinerContext(matchers: IMatcher[]) {
log.debug(ENGINE_COMBINER_AND, [hasMatchedAll]);
return hasMatchedAll;
}

return function andCombiner(...params: any): MaybeThenable<boolean> {
const matcherResults = matchers.map(matcher => matcher(...params));
Expand Down
44 changes: 22 additions & 22 deletions src/evaluator/combiners/ifelseif.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import { findIndex } from '../../utils/lang';
import { logFactory } from '../../logger/sdkLogger';
const log = logFactory('splitio-engine:combiner');
import { ILogger } from '../../logger/types';
import thenable from '../../utils/promise/thenable';
import * as LabelsConstants from '../../utils/labels';
import { CONTROL } from '../../utils/constants';
import { SplitIO } from '../../types';
import { IEvaluation, IEvaluator, ISplitEvaluator } from '../types';
import { ENGINE_COMBINER_IFELSEIF, ENGINE_COMBINER_IFELSEIF_NO_TREATMENT, ERROR_ENGINE_COMBINER_IFELSEIF } from '../../logger/constants';

function unexpectedInputHandler() {
log.error('Invalid Split provided, no valid conditions found');
export default function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]): IEvaluator {

return {
treatment: CONTROL,
label: LabelsConstants.EXCEPTION
};
}
function unexpectedInputHandler() {
log.error(ERROR_ENGINE_COMBINER_IFELSEIF);

function computeTreatment(predicateResults: Array<IEvaluation | undefined>) {
const len = predicateResults.length;
return {
treatment: CONTROL,
label: LabelsConstants.EXCEPTION
};
}

for (let i = 0; i < len; i++) {
const evaluation = predicateResults[i];
function computeTreatment(predicateResults: Array<IEvaluation | undefined>) {
const len = predicateResults.length;

if (evaluation !== undefined) {
log.debug(`Treatment found: ${evaluation.treatment}`);
for (let i = 0; i < len; i++) {
const evaluation = predicateResults[i];

return evaluation;
}
}
if (evaluation !== undefined) {
log.debug(ENGINE_COMBINER_IFELSEIF, [evaluation.treatment]);

log.debug('All predicates evaluated, no treatment found.');
return undefined;
}
return evaluation;
}
}

export default function ifElseIfCombinerContext(predicates: IEvaluator[]): IEvaluator {
log.debug(ENGINE_COMBINER_IFELSEIF_NO_TREATMENT);
return undefined;
}

function ifElseIfCombiner(key: SplitIO.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
// In Async environments we are going to have async predicates. There is none way to know
Expand Down
5 changes: 3 additions & 2 deletions src/evaluator/condition/__tests__/engineUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as engineUtils from '../engineUtils';
import Treatments from '../../treatments';
import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock';

const treatmentsMock = Treatments.parse([{
treatment: 'on',
Expand All @@ -15,7 +16,7 @@ test('ENGINE / should always evaluate to "off"', () => {

let startTime = Date.now();

expect(engineUtils.getTreatment(bucketingKey, seed, treatmentsMock) === 'off').toBe(true); // treatment should be 'off'
expect(engineUtils.getTreatment(loggerMock, bucketingKey, seed, treatmentsMock) === 'off').toBe(true); // treatment should be 'off'


let endTime = Date.now();
Expand All @@ -29,7 +30,7 @@ test('ENGINE / should always evaluate to "on"', () => {

let startTime = Date.now();

expect(engineUtils.getTreatment(bucketingKey, seed, treatmentsMock) === 'on').toBe(true); // treatment should be 'on'
expect(engineUtils.getTreatment(loggerMock, bucketingKey, seed, treatmentsMock) === 'on').toBe(true); // treatment should be 'on'

let endTime = Date.now();

Expand Down
Loading