Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v10.16
v14
4 changes: 2 additions & 2 deletions src/evaluator/combiners/and.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { ILogger } from '../../logger/types';
import thenable from '../../utils/promise/thenable';
import { MaybeThenable } from '../../dtos/types';
import { IMatcher } from '../types';
import { DEBUG_ENGINE_COMBINER_AND } from '../../logger/constants';
import { ENGINE_COMBINER_AND } from '../../logger/constants';

export default function andCombinerContext(log: ILogger, matchers: IMatcher[]) {

function andResults(results: boolean[]): boolean {
// Array.prototype.every is supported by target environments
const hasMatchedAll = results.every(value => value);

log.debug(DEBUG_ENGINE_COMBINER_AND, [hasMatchedAll]);
log.debug(ENGINE_COMBINER_AND, [hasMatchedAll]);
return hasMatchedAll;
}

Expand Down
8 changes: 4 additions & 4 deletions src/evaluator/combiners/ifelseif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import * as LabelsConstants from '../../utils/labels';
import { CONTROL } from '../../utils/constants';
import { SplitIO } from '../../types';
import { IEvaluation, IEvaluator, ISplitEvaluator } from '../types';
import { DEBUG_1, DEBUG_2, ERROR_0 } from '../../logger/constants';
import { ENGINE_COMBINER_IFELSEIF, ENGINE_COMBINER_IFELSEIF_NO_TREATMENT, ERROR_ENGINE_COMBINER_IFELSEIF } from '../../logger/constants';

export default function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]): IEvaluator {

function unexpectedInputHandler() {
log.error(ERROR_0);
log.error(ERROR_ENGINE_COMBINER_IFELSEIF);

return {
treatment: CONTROL,
Expand All @@ -25,13 +25,13 @@ export default function ifElseIfCombinerContext(log: ILogger, predicates: IEvalu
const evaluation = predicateResults[i];

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

return evaluation;
}
}

log.debug(DEBUG_2);
log.debug(ENGINE_COMBINER_IFELSEIF_NO_TREATMENT);
return undefined;
}

Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/condition/engineUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEBUG_3 } from '../../logger/constants';
import { ENGINE_BUCKET } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { bucket } from '../../utils/murmur3/murmur3';

Expand All @@ -10,7 +10,7 @@ export function getTreatment(log: ILogger, key: string, seed: number, treatments

const treatment = treatments.getTreatmentFor(_bucket);

log.debug(DEBUG_3, [_bucket, key, seed, treatment]);
log.debug(ENGINE_BUCKET, [_bucket, key, seed, treatment]);

return treatment;
}
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/all.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DEBUG_4 } from '../../logger/constants';
import { ENGINE_MATCHER_ALL } from '../../logger/constants';
import { ILogger } from '../../logger/types';

export default function allMatcherContext(log: ILogger) {
return function allMatcher(runtimeAttr: string): boolean {
log.debug(DEBUG_4);
log.debug(ENGINE_MATCHER_ALL);

return runtimeAttr != null;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/between.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { IBetweenMatcherData } from '../../dtos/types';
import { DEBUG_5 } from '../../logger/constants';
import { ENGINE_MATCHER_BETWEEN } from '../../logger/constants';
import { ILogger } from '../../logger/types';

export default function betweenMatcherContext(log: ILogger, ruleVO: IBetweenMatcherData) /*: Function */ {
return function betweenMatcher(runtimeAttr: number): boolean {

let isBetween = runtimeAttr >= ruleVO.start && runtimeAttr <= ruleVO.end;

log.debug(DEBUG_5, [runtimeAttr, ruleVO.start, ruleVO.end, isBetween]);
log.debug(ENGINE_MATCHER_BETWEEN, [runtimeAttr, ruleVO.start, ruleVO.end, isBetween]);

return isBetween;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/boolean.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DEBUG_6 } from '../../logger/constants';
import { ENGINE_MATCHER_BOOLEAN } from '../../logger/constants';
import { ILogger } from '../../logger/types';

export default function booleanMatcherContext(log: ILogger, ruleAttr: boolean) /*: Function */ {
return function booleanMatcher(runtimeAttr: boolean): boolean {
let booleanMatches = ruleAttr === runtimeAttr;

log.debug(DEBUG_6, [ruleAttr, runtimeAttr]);
log.debug(ENGINE_MATCHER_BOOLEAN, [ruleAttr, runtimeAttr]);

return booleanMatches;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/cont_all.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEBUG_7 } from '../../logger/constants';
import { ENGINE_MATCHER_CONTAINS_ALL } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { findIndex } from '../../utils/lang';

Expand All @@ -15,7 +15,7 @@ export default function containsAllMatcherContext(log: ILogger, ruleAttr: string
}
}

log.debug(DEBUG_7, [runtimeAttr, ruleAttr, containsAll]);
log.debug(ENGINE_MATCHER_CONTAINS_ALL, [runtimeAttr, ruleAttr, containsAll]);

return containsAll;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/cont_any.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEBUG_8 } from '../../logger/constants';
import { ENGINE_MATCHER_CONTAINS_ANY } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { findIndex } from '../../utils/lang';

Expand All @@ -10,7 +10,7 @@ export default function containsAnyMatcherContext(log: ILogger, ruleAttr: string
if (findIndex(runtimeAttr, e => e === ruleAttr[i]) >= 0) containsAny = true;
}

log.debug(DEBUG_8, [runtimeAttr, ruleAttr, containsAny]);
log.debug(ENGINE_MATCHER_CONTAINS_ANY, [runtimeAttr, ruleAttr, containsAny]);

return containsAny;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/cont_str.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { isString } from '../../utils/lang';
import { ILogger } from '../../logger/types';
import { DEBUG_9 } from '../../logger/constants';
import { ENGINE_MATCHER_CONTAINS_STRING } from '../../logger/constants';

export default function containsStringMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
return function containsStringMatcher(runtimeAttr: string): boolean {
let contains = ruleAttr.some(e => isString(runtimeAttr) && runtimeAttr.indexOf(e) > -1);

log.debug(DEBUG_9, [runtimeAttr, ruleAttr, contains]);
log.debug(ENGINE_MATCHER_CONTAINS_STRING, [runtimeAttr, ruleAttr, contains]);

return contains;
};
Expand Down
6 changes: 3 additions & 3 deletions src/evaluator/matchers/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IStorageAsync, IStorageSync } from '../../storages/types';
import { ILogger } from '../../logger/types';
import thenable from '../../utils/promise/thenable';
import { IDependencyMatcherValue, IEvaluation, ISplitEvaluator } from '../types';
import { DEBUG_10, DEBUG_11 } from '../../logger/constants';
import { ENGINE_MATCHER_DEPENDENCY, ENGINE_MATCHER_DEPENDENCY_PRE } from '../../logger/constants';

export default function dependencyMatcherContext(log: ILogger, { split, treatments }: IDependencyMatcherData, storage: IStorageSync | IStorageAsync) {

Expand All @@ -14,13 +14,13 @@ export default function dependencyMatcherContext(log: ILogger, { split, treatmen
matches = acceptableTreatments.indexOf(evaluation.treatment as string) !== -1;
}

log.debug(DEBUG_10, [parentName, evaluation.treatment, evaluation.label, parentName, acceptableTreatments, matches]);
log.debug(ENGINE_MATCHER_DEPENDENCY, [parentName, evaluation.treatment, evaluation.label, parentName, acceptableTreatments, matches]);

return matches;
}

return function dependencyMatcher({ key, attributes }: IDependencyMatcherValue, splitEvaluator: ISplitEvaluator): MaybeThenable<boolean> {
log.debug(DEBUG_11, [split, JSON.stringify(key), attributes ? '\n attributes: ' + JSON.stringify(attributes) : '']);
log.debug(ENGINE_MATCHER_DEPENDENCY_PRE, [split, JSON.stringify(key), attributes ? '\n attributes: ' + JSON.stringify(attributes) : '']);
const evaluation = splitEvaluator(log, key, split, attributes, storage);

if (thenable(evaluation)) {
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/eq.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DEBUG_12 } from '../../logger/constants';
import { ENGINE_MATCHER_EQUAL } from '../../logger/constants';
import { ILogger } from '../../logger/types';

export default function equalToMatcherContext(log: ILogger, ruleAttr: number) /*: Function */ {
return function equalToMatcher(runtimeAttr: number): boolean {
let isEqual = runtimeAttr === ruleAttr;

log.debug(DEBUG_12, [runtimeAttr, ruleAttr, isEqual]);
log.debug(ENGINE_MATCHER_EQUAL, [runtimeAttr, ruleAttr, isEqual]);

return isEqual;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/eq_set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEBUG_13 } from '../../logger/constants';
import { ENGINE_MATCHER_EQUAL_TO_SET } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { findIndex } from '../../utils/lang';

Expand All @@ -12,7 +12,7 @@ export default function equalToSetMatcherContext(log: ILogger, ruleAttr: string[
if (findIndex(ruleAttr, e => e === runtimeAttr[i]) < 0) isEqual = false;
}

log.debug(DEBUG_13, [runtimeAttr, ruleAttr, isEqual]);
log.debug(ENGINE_MATCHER_EQUAL_TO_SET, [runtimeAttr, ruleAttr, isEqual]);

return isEqual;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/ew.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DEBUG_14 } from '../../logger/constants';
import { ENGINE_MATCHER_ENDS_WITH } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { endsWith as strEndsWith } from '../../utils/lang';

export default function endsWithMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
return function endsWithMatcher(runtimeAttr: string): boolean {
let endsWith = ruleAttr.some(e => strEndsWith(runtimeAttr, e));

log.debug(DEBUG_14, [runtimeAttr, ruleAttr, endsWith]);
log.debug(ENGINE_MATCHER_ENDS_WITH, [runtimeAttr, ruleAttr, endsWith]);

return endsWith;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/gte.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DEBUG_15 } from '../../logger/constants';
import { ENGINE_MATCHER_GREATER } from '../../logger/constants';
import { ILogger } from '../../logger/types';

export default function greaterThanEqualMatcherContext(log: ILogger, ruleAttr: number) /*: Function */ {
return function greaterThanEqualMatcher(runtimeAttr: number): boolean {
let isGreaterEqualThan = runtimeAttr >= ruleAttr;

log.debug(DEBUG_15, [runtimeAttr, ruleAttr, isGreaterEqualThan]);
log.debug(ENGINE_MATCHER_GREATER, [runtimeAttr, ruleAttr, isGreaterEqualThan]);

return isGreaterEqualThan;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/lte.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DEBUG_16 } from '../../logger/constants';
import { ENGINE_MATCHER_LESS } from '../../logger/constants';
import { ILogger } from '../../logger/types';

export default function lessThanEqualMatcherContext(log: ILogger, ruleAttr: number) /*: function */ {
return function lessThanEqualMatcher(runtimeAttr: number): boolean {
let isLessEqualThan = runtimeAttr <= ruleAttr;

log.debug(DEBUG_16, [runtimeAttr, ruleAttr, isLessEqualThan]);
log.debug(ENGINE_MATCHER_LESS, [runtimeAttr, ruleAttr, isLessEqualThan]);

return isLessEqualThan;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/part_of.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { findIndex } from '../../utils/lang';
import { ILogger } from '../../logger/types';
import { DEBUG_17 } from '../../logger/constants';
import { ENGINE_MATCHER_PART_OF } from '../../logger/constants';

export default function partOfMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
return function partOfMatcher(runtimeAttr: string[]): boolean {
Expand All @@ -12,7 +12,7 @@ export default function partOfMatcherContext(log: ILogger, ruleAttr: string[]) /
if (findIndex(ruleAttr, e => e === runtimeAttr[i]) < 0) isPartOf = false;
}

log.debug(DEBUG_17, [runtimeAttr, ruleAttr, isPartOf]);
log.debug(ENGINE_MATCHER_PART_OF, [runtimeAttr, ruleAttr, isPartOf]);

return isPartOf;
};
Expand Down
6 changes: 3 additions & 3 deletions src/evaluator/matchers/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MaybeThenable } from '../../dtos/types';
import { ISegmentsCacheBase } from '../../storages/types';
import { ILogger } from '../../logger/types';
import thenable from '../../utils/promise/thenable';
import { DEBUG_18, DEBUG_19 } from '../../logger/constants';
import { ENGINE_MATCHER_SEGMENT_ASYNC, ENGINE_MATCHER_SEGMENT } from '../../logger/constants';

export default function matcherSegmentContext(log: ILogger, segmentName: string, storage: { segments: ISegmentsCacheBase }) {

Expand All @@ -11,12 +11,12 @@ export default function matcherSegmentContext(log: ILogger, segmentName: string,

if (thenable(isInSegment)) {
isInSegment.then(result => {
log.debug(DEBUG_18, [segmentName, key, isInSegment]);
log.debug(ENGINE_MATCHER_SEGMENT_ASYNC, [segmentName, key, isInSegment]);

return result;
});
} else {
log.debug(DEBUG_19, [segmentName, key, isInSegment]);
log.debug(ENGINE_MATCHER_SEGMENT, [segmentName, key, isInSegment]);
}

return isInSegment;
Expand Down
6 changes: 3 additions & 3 deletions src/evaluator/matchers/string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEBUG_21, DEBUG_20 } from '../../logger/constants';
import { ENGINE_MATCHER_STRING_INVALID, ENGINE_MATCHER_STRING } from '../../logger/constants';
import { ILogger } from '../../logger/types';

export default function stringMatcherContext(log: ILogger, ruleAttr: string) /*: Function */ {
Expand All @@ -8,14 +8,14 @@ export default function stringMatcherContext(log: ILogger, ruleAttr: string) /*:
try {
re = new RegExp(ruleAttr);
} catch (e) {
log.debug(DEBUG_21, [ruleAttr]);
log.debug(ENGINE_MATCHER_STRING_INVALID, [ruleAttr]);

return false;
}

let regexMatches = re.test(runtimeAttr);

log.debug(DEBUG_20, [runtimeAttr, ruleAttr, regexMatches ? 'yes' : 'no']);
log.debug(ENGINE_MATCHER_STRING, [runtimeAttr, ruleAttr, regexMatches ? 'yes' : 'no']);

return regexMatches;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/sw.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DEBUG_22 } from '../../logger/constants';
import { ENGINE_MATCHER_STARTS_WITH } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { startsWith } from '../../utils/lang';

export default function startsWithMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
return function startsWithMatcher(runtimeAttr: string): boolean {
let matches = ruleAttr.some(e => startsWith(runtimeAttr, e));

log.debug(DEBUG_22, [runtimeAttr, ruleAttr, matches]);
log.debug(ENGINE_MATCHER_STARTS_WITH, [runtimeAttr, ruleAttr, matches]);

return matches;
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/whitelist.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { setToArray, ISet } from '../../utils/lang/sets';
import { ILogger } from '../../logger/types';
import { DEBUG_23 } from '../../logger/constants';
import { ENGINE_MATCHER_WHITELIST } from '../../logger/constants';

export default function whitelistMatcherContext(log: ILogger, ruleAttr: ISet<string>) /*: Function */ {
return function whitelistMatcher(runtimeAttr: string): boolean {
let isInWhitelist = ruleAttr.has(runtimeAttr);

log.debug(DEBUG_23, [runtimeAttr, setToArray(ruleAttr).join(','), isInWhitelist]);
log.debug(ENGINE_MATCHER_WHITELIST, [runtimeAttr, setToArray(ruleAttr).join(','), isInWhitelist]);

return isInWhitelist;
};
Expand Down
8 changes: 4 additions & 4 deletions src/evaluator/value/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { SplitIO } from '../../types';
import { IMatcherDto } from '../types';
import { ILogger } from '../../logger/types';
import sanitizeValue from './sanitize';
import { DEBUG_24, WARN_ENGINE_NO_ATTRIBUTES, WARN_ENGINE_INVALID_VALUE } from '../../logger/constants';
import { ENGINE_VALUE, ENGINE_VALUE_NO_ATTRIBUTES, ENGINE_VALUE_INVALID } from '../../logger/constants';

function parseValue(log: ILogger, key: string, attributeName: string | null, attributes: SplitIO.Attributes) {
let value = undefined;
if (attributeName) {
if (attributes) {
value = attributes[attributeName];
log.debug(DEBUG_24, [attributeName, value]);
log.debug(ENGINE_VALUE, [attributeName, value]);
} else {
log.warn(WARN_ENGINE_NO_ATTRIBUTES, [attributeName]);
log.warn(ENGINE_VALUE_NO_ATTRIBUTES, [attributeName]);
}
} else {
value = key;
Expand All @@ -31,7 +31,7 @@ export default function value(log: ILogger, key: string, matcherDto: IMatcherDto
if (sanitizedValue !== undefined) {
return sanitizedValue;
} else {
log.warn(WARN_ENGINE_INVALID_VALUE, [valueToMatch + (attributeName ? ' for attribute ' + attributeName : '')]);
log.warn(ENGINE_VALUE_INVALID, [valueToMatch + (attributeName ? ' for attribute ' + attributeName : '')]);
return;
}
}
4 changes: 2 additions & 2 deletions src/evaluator/value/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ILogger } from '../../logger/types';
import { isObject, uniq, toString, toNumber } from '../../utils/lang';
import { zeroSinceHH, zeroSinceSS } from '../convertions';
import { matcherTypes, dataTypes } from '../matchers/matcherTypes';
import { DEBUG_25 } from '../../logger/constants';
import { ENGINE_SANITIZE } from '../../logger/constants';

function sanitizeNumber(val: any): number | undefined {
const num = toNumber(val);
Expand Down Expand Up @@ -99,7 +99,7 @@ export default function sanitize(log: ILogger, matcherTypeID: number, value: str
sanitizedValue = processor(sanitizedValue, attributes);
}

log.debug(DEBUG_25, [value, dataType, sanitizedValue instanceof Object ? JSON.stringify(sanitizedValue) : sanitizedValue]);
log.debug(ENGINE_SANITIZE, [value, dataType, sanitizedValue instanceof Object ? JSON.stringify(sanitizedValue) : sanitizedValue]);

return sanitizedValue;
}
Loading