@splitsoftware/splitio-commons 1.13.2-rc.4 → 1.13.2-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/cjs/evaluator/Engine.js +5 -6
  2. package/cjs/evaluator/combiners/ifelseif.js +2 -3
  3. package/cjs/evaluator/condition/index.js +2 -3
  4. package/cjs/evaluator/index.js +4 -5
  5. package/cjs/evaluator/matchers/all.js +1 -3
  6. package/cjs/evaluator/matchers/between.js +1 -3
  7. package/cjs/evaluator/matchers/boolean.js +1 -3
  8. package/cjs/evaluator/matchers/cont_all.js +1 -3
  9. package/cjs/evaluator/matchers/cont_any.js +1 -3
  10. package/cjs/evaluator/matchers/cont_str.js +1 -3
  11. package/cjs/evaluator/matchers/dependency.js +1 -1
  12. package/cjs/evaluator/matchers/eq.js +1 -3
  13. package/cjs/evaluator/matchers/eq_set.js +1 -3
  14. package/cjs/evaluator/matchers/ew.js +1 -3
  15. package/cjs/evaluator/matchers/gte.js +1 -3
  16. package/cjs/evaluator/matchers/index.js +1 -1
  17. package/cjs/evaluator/matchers/lte.js +3 -5
  18. package/cjs/evaluator/matchers/part_of.js +1 -3
  19. package/cjs/evaluator/matchers/segment.js +1 -6
  20. package/cjs/evaluator/matchers/semver_between.js +3 -3
  21. package/cjs/evaluator/matchers/semver_eq.js +1 -1
  22. package/cjs/evaluator/matchers/semver_gte.js +1 -1
  23. package/cjs/evaluator/matchers/semver_inlist.js +5 -2
  24. package/cjs/evaluator/matchers/semver_lte.js +3 -3
  25. package/cjs/evaluator/matchers/string.js +1 -3
  26. package/cjs/evaluator/matchers/sw.js +1 -3
  27. package/cjs/evaluator/matchers/whitelist.js +3 -4
  28. package/cjs/evaluator/matchersTransform/index.js +5 -8
  29. package/cjs/evaluator/matchersTransform/whitelist.js +1 -2
  30. package/cjs/evaluator/parser/index.js +8 -4
  31. package/cjs/logger/constants.js +4 -19
  32. package/cjs/logger/index.js +8 -1
  33. package/cjs/logger/messages/debug.js +4 -19
  34. package/cjs/logger/messages/warn.js +1 -1
  35. package/esm/evaluator/Engine.js +5 -5
  36. package/esm/evaluator/combiners/ifelseif.js +2 -2
  37. package/esm/evaluator/condition/index.js +2 -2
  38. package/esm/evaluator/index.js +4 -4
  39. package/esm/evaluator/matchers/all.js +1 -3
  40. package/esm/evaluator/matchers/between.js +1 -3
  41. package/esm/evaluator/matchers/boolean.js +1 -3
  42. package/esm/evaluator/matchers/cont_all.js +1 -3
  43. package/esm/evaluator/matchers/cont_any.js +1 -3
  44. package/esm/evaluator/matchers/cont_str.js +1 -3
  45. package/esm/evaluator/matchers/dependency.js +1 -1
  46. package/esm/evaluator/matchers/eq.js +1 -3
  47. package/esm/evaluator/matchers/eq_set.js +1 -3
  48. package/esm/evaluator/matchers/ew.js +1 -3
  49. package/esm/evaluator/matchers/gte.js +1 -3
  50. package/esm/evaluator/matchers/index.js +1 -1
  51. package/esm/evaluator/matchers/lte.js +3 -5
  52. package/esm/evaluator/matchers/part_of.js +1 -3
  53. package/esm/evaluator/matchers/segment.js +1 -6
  54. package/esm/evaluator/matchers/semver_between.js +3 -3
  55. package/esm/evaluator/matchers/semver_eq.js +1 -1
  56. package/esm/evaluator/matchers/semver_gte.js +1 -1
  57. package/esm/evaluator/matchers/semver_inlist.js +6 -3
  58. package/esm/evaluator/matchers/semver_lte.js +3 -3
  59. package/esm/evaluator/matchers/string.js +1 -3
  60. package/esm/evaluator/matchers/sw.js +1 -3
  61. package/esm/evaluator/matchers/whitelist.js +4 -5
  62. package/esm/evaluator/matchersTransform/index.js +5 -8
  63. package/esm/evaluator/matchersTransform/whitelist.js +1 -2
  64. package/esm/evaluator/parser/index.js +9 -5
  65. package/esm/logger/constants.js +1 -16
  66. package/esm/logger/index.js +9 -2
  67. package/esm/logger/messages/debug.js +4 -19
  68. package/esm/logger/messages/warn.js +1 -1
  69. package/package.json +1 -1
  70. package/src/evaluator/Engine.ts +5 -6
  71. package/src/evaluator/combiners/ifelseif.ts +2 -2
  72. package/src/evaluator/condition/index.ts +2 -2
  73. package/src/evaluator/index.ts +4 -4
  74. package/src/evaluator/matchers/all.ts +1 -5
  75. package/src/evaluator/matchers/between.ts +3 -7
  76. package/src/evaluator/matchers/boolean.ts +2 -6
  77. package/src/evaluator/matchers/cont_all.ts +1 -5
  78. package/src/evaluator/matchers/cont_any.ts +1 -5
  79. package/src/evaluator/matchers/cont_str.ts +2 -6
  80. package/src/evaluator/matchers/dependency.ts +1 -1
  81. package/src/evaluator/matchers/eq.ts +2 -6
  82. package/src/evaluator/matchers/eq_set.ts +1 -5
  83. package/src/evaluator/matchers/ew.ts +2 -6
  84. package/src/evaluator/matchers/gte.ts +2 -6
  85. package/src/evaluator/matchers/index.ts +1 -1
  86. package/src/evaluator/matchers/lte.ts +3 -7
  87. package/src/evaluator/matchers/part_of.ts +1 -5
  88. package/src/evaluator/matchers/segment.ts +1 -8
  89. package/src/evaluator/matchers/semver_between.ts +3 -4
  90. package/src/evaluator/matchers/semver_eq.ts +1 -2
  91. package/src/evaluator/matchers/semver_gte.ts +1 -2
  92. package/src/evaluator/matchers/semver_inlist.ts +6 -4
  93. package/src/evaluator/matchers/semver_lte.ts +3 -4
  94. package/src/evaluator/matchers/string.ts +1 -6
  95. package/src/evaluator/matchers/sw.ts +2 -6
  96. package/src/evaluator/matchers/whitelist.ts +5 -7
  97. package/src/evaluator/matchersTransform/index.ts +6 -10
  98. package/src/evaluator/matchersTransform/whitelist.ts +3 -4
  99. package/src/evaluator/parser/index.ts +10 -5
  100. package/src/evaluator/types.ts +1 -2
  101. package/src/logger/constants.ts +1 -16
  102. package/src/logger/index.ts +8 -2
  103. package/src/logger/messages/debug.ts +4 -19
  104. package/src/logger/messages/warn.ts +1 -1
  105. package/types/evaluator/matchers/all.d.ts +1 -2
  106. package/types/evaluator/matchers/between.d.ts +1 -2
  107. package/types/evaluator/matchers/boolean.d.ts +1 -2
  108. package/types/evaluator/matchers/cont_all.d.ts +1 -2
  109. package/types/evaluator/matchers/cont_any.d.ts +1 -2
  110. package/types/evaluator/matchers/cont_str.d.ts +1 -2
  111. package/types/evaluator/matchers/dependency.d.ts +1 -1
  112. package/types/evaluator/matchers/eq.d.ts +1 -2
  113. package/types/evaluator/matchers/eq_set.d.ts +1 -2
  114. package/types/evaluator/matchers/ew.d.ts +1 -2
  115. package/types/evaluator/matchers/gte.d.ts +1 -2
  116. package/types/evaluator/matchers/lte.d.ts +1 -2
  117. package/types/evaluator/matchers/part_of.d.ts +1 -2
  118. package/types/evaluator/matchers/segment.d.ts +1 -2
  119. package/types/evaluator/matchers/semver_between.d.ts +1 -2
  120. package/types/evaluator/matchers/semver_eq.d.ts +1 -2
  121. package/types/evaluator/matchers/semver_gte.d.ts +1 -2
  122. package/types/evaluator/matchers/semver_inlist.d.ts +1 -3
  123. package/types/evaluator/matchers/semver_lte.d.ts +1 -2
  124. package/types/evaluator/matchers/string.d.ts +1 -2
  125. package/types/evaluator/matchers/sw.d.ts +1 -2
  126. package/types/evaluator/matchers/whitelist.d.ts +1 -3
  127. package/types/evaluator/matchersTransform/set.d.ts +2 -2
  128. package/types/evaluator/matchersTransform/whitelist.d.ts +2 -2
  129. package/types/evaluator/types.d.ts +1 -2
  130. package/types/logger/constants.d.ts +1 -16
  131. package/cjs/evaluator/matchersTransform/set.js +0 -10
  132. package/esm/evaluator/matchersTransform/set.js +0 -6
  133. package/src/evaluator/matchersTransform/set.ts +0 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.13.2-rc.4",
3
+ "version": "1.13.2-rc.6",
4
4
  "description": "Split JavaScript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -2,7 +2,7 @@ import { get } from '../utils/lang';
2
2
  import { parser } from './parser';
3
3
  import { keyParser } from '../utils/key';
4
4
  import { thenable } from '../utils/promise/thenable';
5
- import * as LabelsConstants from '../utils/labels';
5
+ import { EXCEPTION, NO_CONDITION_MATCH, SPLIT_ARCHIVED, SPLIT_KILLED } from '../utils/labels';
6
6
  import { CONTROL } from '../utils/constants';
7
7
  import { ISplit, MaybeThenable } from '../dtos/types';
8
8
  import { SplitIO } from '../types';
@@ -13,7 +13,7 @@ import { ILogger } from '../logger/types';
13
13
  function evaluationResult(result: IEvaluation | undefined, defaultTreatment: string): IEvaluationResult {
14
14
  return {
15
15
  treatment: get(result, 'treatment', defaultTreatment),
16
- label: get(result, 'label', LabelsConstants.NO_CONDITION_MATCH)
16
+ label: get(result, 'label', NO_CONDITION_MATCH)
17
17
  };
18
18
  }
19
19
 
@@ -55,16 +55,16 @@ export class Engine {
55
55
  } catch (err) {
56
56
  return {
57
57
  treatment: CONTROL,
58
- label: LabelsConstants.EXCEPTION
58
+ label: EXCEPTION
59
59
  };
60
60
  }
61
61
 
62
62
  if (this.isGarbage()) {
63
63
  treatment = CONTROL;
64
- label = LabelsConstants.SPLIT_ARCHIVED;
64
+ label = SPLIT_ARCHIVED;
65
65
  } else if (killed) {
66
66
  treatment = defaultTreatment;
67
- label = LabelsConstants.SPLIT_KILLED;
67
+ label = SPLIT_KILLED;
68
68
  } else {
69
69
  const evaluation = this.evaluator(
70
70
  parsedKey,
@@ -98,4 +98,3 @@ export class Engine {
98
98
  return this.baseInfo.changeNumber;
99
99
  }
100
100
  }
101
-
@@ -1,7 +1,7 @@
1
1
  import { findIndex } from '../../utils/lang';
2
2
  import { ILogger } from '../../logger/types';
3
3
  import { thenable } from '../../utils/promise/thenable';
4
- import * as LabelsConstants from '../../utils/labels';
4
+ import { UNSUPPORTED_MATCHER_TYPE } from '../../utils/labels';
5
5
  import { CONTROL } from '../../utils/constants';
6
6
  import { SplitIO } from '../../types';
7
7
  import { IEvaluation, IEvaluator, ISplitEvaluator } from '../types';
@@ -14,7 +14,7 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
14
14
 
15
15
  return {
16
16
  treatment: CONTROL,
17
- label: LabelsConstants.UNSUPPORTED_MATCHER_TYPE
17
+ label: UNSUPPORTED_MATCHER_TYPE
18
18
  };
19
19
  }
20
20
 
@@ -1,6 +1,6 @@
1
1
  import { getTreatment, shouldApplyRollout } from './engineUtils';
2
2
  import { thenable } from '../../utils/promise/thenable';
3
- import * as LabelsConstants from '../../utils/labels';
3
+ import { NOT_IN_SPLIT } from '../../utils/labels';
4
4
  import { MaybeThenable } from '../../dtos/types';
5
5
  import { IEvaluation, IEvaluator, ISplitEvaluator } from '../types';
6
6
  import { SplitIO } from '../../types';
@@ -30,7 +30,7 @@ export function conditionContext(log: ILogger, matcherEvaluator: (...args: any)
30
30
  if (conditionType === 'ROLLOUT' && !shouldApplyRollout(trafficAllocation as number, (key as SplitIO.SplitKeyObject).bucketingKey as string, trafficAllocationSeed as number)) {
31
31
  return {
32
32
  treatment: undefined, // treatment value is assigned later
33
- label: LabelsConstants.NOT_IN_SPLIT
33
+ label: NOT_IN_SPLIT
34
34
  };
35
35
  }
36
36
 
@@ -1,6 +1,6 @@
1
1
  import { Engine } from './Engine';
2
2
  import { thenable } from '../utils/promise/thenable';
3
- import * as LabelsConstants from '../utils/labels';
3
+ import { EXCEPTION, SPLIT_NOT_FOUND } from '../utils/labels';
4
4
  import { CONTROL } from '../utils/constants';
5
5
  import { ISplit, MaybeThenable } from '../dtos/types';
6
6
  import { IStorageAsync, IStorageSync } from '../storages/types';
@@ -12,7 +12,7 @@ import { WARN_FLAGSET_WITHOUT_FLAGS } from '../logger/constants';
12
12
 
13
13
  const treatmentException = {
14
14
  treatment: CONTROL,
15
- label: LabelsConstants.EXCEPTION,
15
+ label: EXCEPTION,
16
16
  config: null
17
17
  };
18
18
 
@@ -143,7 +143,7 @@ function getEvaluation(
143
143
  ): MaybeThenable<IEvaluationResult> {
144
144
  let evaluation: MaybeThenable<IEvaluationResult> = {
145
145
  treatment: CONTROL,
146
- label: LabelsConstants.SPLIT_NOT_FOUND,
146
+ label: SPLIT_NOT_FOUND,
147
147
  config: null
148
148
  };
149
149
 
@@ -151,7 +151,7 @@ function getEvaluation(
151
151
  const split = Engine.parse(log, splitJSON, storage);
152
152
  evaluation = split.getTreatment(key, attributes, evaluateFeature);
153
153
 
154
- // If the storage is async and the evaluated split uses segment, evaluation is thenable
154
+ // If the storage is async and the evaluated feature flag is type IN_SPLIT_TREATMENT or IN_SEGMENT, evaluation is thenable
155
155
  if (thenable(evaluation)) {
156
156
  return evaluation.then(result => {
157
157
  result.changeNumber = split.getChangeNumber();
@@ -1,10 +1,6 @@
1
- import { ENGINE_MATCHER_ALL } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
1
+ export function allMatcherContext() {
3
2
 
4
- export function allMatcherContext(log: ILogger) {
5
3
  return function allMatcher(runtimeAttr: string): boolean {
6
- log.debug(ENGINE_MATCHER_ALL);
7
-
8
4
  return runtimeAttr != null;
9
5
  };
10
6
  }
@@ -1,13 +1,9 @@
1
1
  import { IBetweenMatcherData } from '../../dtos/types';
2
- import { ENGINE_MATCHER_BETWEEN } from '../../logger/constants';
3
- import { ILogger } from '../../logger/types';
4
2
 
5
- export function betweenMatcherContext(log: ILogger, ruleVO: IBetweenMatcherData) {
6
- return function betweenMatcher(runtimeAttr: number): boolean {
7
-
8
- let isBetween = runtimeAttr >= ruleVO.start && runtimeAttr <= ruleVO.end;
3
+ export function betweenMatcherContext(ruleVO: IBetweenMatcherData) {
9
4
 
10
- log.debug(ENGINE_MATCHER_BETWEEN, [runtimeAttr, ruleVO.start, ruleVO.end, isBetween]);
5
+ return function betweenMatcher(runtimeAttr: number): boolean {
6
+ const isBetween = runtimeAttr >= ruleVO.start && runtimeAttr <= ruleVO.end;
11
7
 
12
8
  return isBetween;
13
9
  };
@@ -1,11 +1,7 @@
1
- import { ENGINE_MATCHER_BOOLEAN } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
1
+ export function booleanMatcherContext(ruleAttr: boolean) {
3
2
 
4
- export function booleanMatcherContext(log: ILogger, ruleAttr: boolean) {
5
3
  return function booleanMatcher(runtimeAttr: boolean): boolean {
6
- let booleanMatches = ruleAttr === runtimeAttr;
7
-
8
- log.debug(ENGINE_MATCHER_BOOLEAN, [ruleAttr, runtimeAttr]);
4
+ const booleanMatches = ruleAttr === runtimeAttr;
9
5
 
10
6
  return booleanMatches;
11
7
  };
@@ -1,8 +1,6 @@
1
- import { ENGINE_MATCHER_CONTAINS_ALL } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
3
1
  import { findIndex } from '../../utils/lang';
4
2
 
5
- export function containsAllSetMatcherContext(log: ILogger, ruleAttr: string[]) {
3
+ export function containsAllSetMatcherContext(ruleAttr: string[]) {
6
4
  return function containsAllMatcher(runtimeAttr: string[]): boolean {
7
5
  let containsAll = true;
8
6
 
@@ -15,8 +13,6 @@ export function containsAllSetMatcherContext(log: ILogger, ruleAttr: string[]) {
15
13
  }
16
14
  }
17
15
 
18
- log.debug(ENGINE_MATCHER_CONTAINS_ALL, [runtimeAttr, ruleAttr, containsAll]);
19
-
20
16
  return containsAll;
21
17
  };
22
18
  }
@@ -1,8 +1,6 @@
1
- import { ENGINE_MATCHER_CONTAINS_ANY } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
3
1
  import { findIndex } from '../../utils/lang';
4
2
 
5
- export function containsAnySetMatcherContext(log: ILogger, ruleAttr: string[]) {
3
+ export function containsAnySetMatcherContext(ruleAttr: string[]) {
6
4
  return function containsAnyMatcher(runtimeAttr: string[]): boolean {
7
5
  let containsAny = false;
8
6
 
@@ -10,8 +8,6 @@ export function containsAnySetMatcherContext(log: ILogger, ruleAttr: string[]) {
10
8
  if (findIndex(runtimeAttr, e => e === ruleAttr[i]) >= 0) containsAny = true;
11
9
  }
12
10
 
13
- log.debug(ENGINE_MATCHER_CONTAINS_ANY, [runtimeAttr, ruleAttr, containsAny]);
14
-
15
11
  return containsAny;
16
12
  };
17
13
  }
@@ -1,12 +1,8 @@
1
1
  import { isString } from '../../utils/lang';
2
- import { ILogger } from '../../logger/types';
3
- import { ENGINE_MATCHER_CONTAINS_STRING } from '../../logger/constants';
4
2
 
5
- export function containsStringMatcherContext(log: ILogger, ruleAttr: string[]) {
3
+ export function containsStringMatcherContext(ruleAttr: string[]) {
6
4
  return function containsStringMatcher(runtimeAttr: string): boolean {
7
- let contains = ruleAttr.some(e => isString(runtimeAttr) && runtimeAttr.indexOf(e) > -1);
8
-
9
- log.debug(ENGINE_MATCHER_CONTAINS_STRING, [runtimeAttr, ruleAttr, contains]);
5
+ const contains = ruleAttr.some(e => isString(runtimeAttr) && runtimeAttr.indexOf(e) > -1);
10
6
 
11
7
  return contains;
12
8
  };
@@ -5,7 +5,7 @@ import { thenable } from '../../utils/promise/thenable';
5
5
  import { IDependencyMatcherValue, IEvaluation, ISplitEvaluator } from '../types';
6
6
  import { ENGINE_MATCHER_DEPENDENCY, ENGINE_MATCHER_DEPENDENCY_PRE } from '../../logger/constants';
7
7
 
8
- export function dependencyMatcherContext(log: ILogger, { split, treatments }: IDependencyMatcherData, storage: IStorageSync | IStorageAsync) {
8
+ export function dependencyMatcherContext({ split, treatments }: IDependencyMatcherData, storage: IStorageSync | IStorageAsync, log: ILogger) {
9
9
 
10
10
  function checkTreatment(evaluation: IEvaluation, acceptableTreatments: string[], parentName: string) {
11
11
  let matches = false;
@@ -1,11 +1,7 @@
1
- import { ENGINE_MATCHER_EQUAL } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
1
+ export function equalToMatcherContext(ruleAttr: number) {
3
2
 
4
- export function equalToMatcherContext(log: ILogger, ruleAttr: number) {
5
3
  return function equalToMatcher(runtimeAttr: number): boolean {
6
- let isEqual = runtimeAttr === ruleAttr;
7
-
8
- log.debug(ENGINE_MATCHER_EQUAL, [runtimeAttr, ruleAttr, isEqual]);
4
+ const isEqual = runtimeAttr === ruleAttr;
9
5
 
10
6
  return isEqual;
11
7
  };
@@ -1,8 +1,6 @@
1
- import { ENGINE_MATCHER_EQUAL_TO_SET } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
3
1
  import { findIndex } from '../../utils/lang';
4
2
 
5
- export function equalToSetMatcherContext(log: ILogger, ruleAttr: string[]) {
3
+ export function equalToSetMatcherContext(ruleAttr: string[]) {
6
4
  return function equalToSetMatcher(runtimeAttr: string[]): boolean {
7
5
  // Length being the same is the first condition.
8
6
  let isEqual = runtimeAttr.length === ruleAttr.length;
@@ -12,8 +10,6 @@ export function equalToSetMatcherContext(log: ILogger, ruleAttr: string[]) {
12
10
  if (findIndex(ruleAttr, e => e === runtimeAttr[i]) < 0) isEqual = false;
13
11
  }
14
12
 
15
- log.debug(ENGINE_MATCHER_EQUAL_TO_SET, [runtimeAttr, ruleAttr, isEqual]);
16
-
17
13
  return isEqual;
18
14
  };
19
15
  }
@@ -1,12 +1,8 @@
1
- import { ENGINE_MATCHER_ENDS_WITH } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
3
1
  import { endsWith } from '../../utils/lang';
4
2
 
5
- export function endsWithMatcherContext(log: ILogger, ruleAttr: string[]) {
3
+ export function endsWithMatcherContext(ruleAttr: string[]) {
6
4
  return function endsWithMatcher(runtimeAttr: string): boolean {
7
- let strEndsWith = ruleAttr.some(e => endsWith(runtimeAttr, e));
8
-
9
- log.debug(ENGINE_MATCHER_ENDS_WITH, [runtimeAttr, ruleAttr, strEndsWith]);
5
+ const strEndsWith = ruleAttr.some(e => endsWith(runtimeAttr, e));
10
6
 
11
7
  return strEndsWith;
12
8
  };
@@ -1,11 +1,7 @@
1
- import { ENGINE_MATCHER_GREATER } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
1
+ export function greaterThanEqualMatcherContext(ruleAttr: number) {
3
2
 
4
- export function greaterThanEqualMatcherContext(log: ILogger, ruleAttr: number) {
5
3
  return function greaterThanEqualMatcher(runtimeAttr: number): boolean {
6
- let isGreaterThanEqual = runtimeAttr >= ruleAttr;
7
-
8
- log.debug(ENGINE_MATCHER_GREATER, [runtimeAttr, ruleAttr, isGreaterThanEqual]);
4
+ const isGreaterThanEqual = runtimeAttr >= ruleAttr;
9
5
 
10
6
  return isGreaterThanEqual;
11
7
  };
@@ -61,6 +61,6 @@ export function matcherFactory(log: ILogger, matcherDto: IMatcherDto, storage?:
61
61
 
62
62
  let matcherFn;
63
63
  // @ts-ignore
64
- if (matchers[type]) matcherFn = matchers[type](log, value, storage); // There is no index-out-of-bound exception in JavaScript
64
+ if (matchers[type]) matcherFn = matchers[type](value, storage, log); // There is no index-out-of-bound exception in JavaScript
65
65
  return matcherFn;
66
66
  }
@@ -1,12 +1,8 @@
1
- import { ENGINE_MATCHER_LESS } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
1
+ export function lessThanEqualMatcherContext(ruleAttr: number) {
3
2
 
4
- export function lessThanEqualMatcherContext(log: ILogger, ruleAttr: number) {
5
3
  return function lessThanEqualMatcher(runtimeAttr: number): boolean {
6
- let isLessEqualThan = runtimeAttr <= ruleAttr;
4
+ const isLessThanEqual = runtimeAttr <= ruleAttr;
7
5
 
8
- log.debug(ENGINE_MATCHER_LESS, [runtimeAttr, ruleAttr, isLessEqualThan]);
9
-
10
- return isLessEqualThan;
6
+ return isLessThanEqual;
11
7
  };
12
8
  }
@@ -1,8 +1,6 @@
1
1
  import { findIndex } from '../../utils/lang';
2
- import { ILogger } from '../../logger/types';
3
- import { ENGINE_MATCHER_PART_OF } from '../../logger/constants';
4
2
 
5
- export function partOfSetMatcherContext(log: ILogger, ruleAttr: string[]) {
3
+ export function partOfSetMatcherContext(ruleAttr: string[]) {
6
4
  return function partOfMatcher(runtimeAttr: string[]): boolean {
7
5
  // To be part of the length should be minor or equal.
8
6
  let isPartOf = runtimeAttr.length <= ruleAttr.length;
@@ -12,8 +10,6 @@ export function partOfSetMatcherContext(log: ILogger, ruleAttr: string[]) {
12
10
  if (findIndex(ruleAttr, e => e === runtimeAttr[i]) < 0) isPartOf = false;
13
11
  }
14
12
 
15
- log.debug(ENGINE_MATCHER_PART_OF, [runtimeAttr, ruleAttr, isPartOf]);
16
-
17
13
  return isPartOf;
18
14
  };
19
15
  }
@@ -1,25 +1,18 @@
1
1
  import { MaybeThenable } from '../../dtos/types';
2
2
  import { ISegmentsCacheBase } from '../../storages/types';
3
- import { ILogger } from '../../logger/types';
4
3
  import { thenable } from '../../utils/promise/thenable';
5
- import { ENGINE_MATCHER_SEGMENT } from '../../logger/constants';
6
4
 
7
- export function segmentMatcherContext(log: ILogger, segmentName: string, storage: { segments: ISegmentsCacheBase }) {
5
+ export function segmentMatcherContext(segmentName: string, storage: { segments: ISegmentsCacheBase }) {
8
6
 
9
7
  return function segmentMatcher(key: string): MaybeThenable<boolean> {
10
8
  const isInSegment = storage.segments.isInSegment(segmentName, key);
11
9
 
12
10
  if (thenable(isInSegment)) {
13
11
  isInSegment.then(result => {
14
- log.debug(ENGINE_MATCHER_SEGMENT, [segmentName, key, isInSegment]);
15
-
16
12
  return result;
17
13
  });
18
- } else {
19
- log.debug(ENGINE_MATCHER_SEGMENT, [segmentName, key, isInSegment]);
20
14
  }
21
15
 
22
16
  return isInSegment;
23
17
  };
24
-
25
18
  }
@@ -1,13 +1,12 @@
1
1
  import { IBetweenStringMatcherData } from '../../dtos/types';
2
- import { ILogger } from '../../logger/types';
3
2
  import { Semver } from '../../utils/Semver';
4
3
 
5
- export function betweenSemverMatcherContext(log: ILogger, ruleAttr: IBetweenStringMatcherData) {
4
+ export function betweenSemverMatcherContext(ruleAttr: IBetweenStringMatcherData) {
6
5
  const startSemver = new Semver(ruleAttr.start);
7
6
  const endSemver = new Semver(ruleAttr.end);
8
7
 
9
- return function betweenSemverMatcher(key: string): boolean {
10
- const runtimeSemver = new Semver(key);
8
+ return function betweenSemverMatcher(runtimeAttr: string): boolean {
9
+ const runtimeSemver = new Semver(runtimeAttr);
11
10
 
12
11
  const isBetween = startSemver.compare(runtimeSemver) <= 0 && endSemver.compare(runtimeSemver) >= 0;
13
12
 
@@ -1,7 +1,6 @@
1
- import { ILogger } from '../../logger/types';
2
1
  import { Semver } from '../../utils/Semver';
3
2
 
4
- export function equalToSemverMatcherContext(log: ILogger, ruleAttr: string) {
3
+ export function equalToSemverMatcherContext(ruleAttr: string) {
5
4
  const ruleSemver = new Semver(ruleAttr);
6
5
 
7
6
  return function equalToSemverMatcher(runtimeAttr: string): boolean {
@@ -1,7 +1,6 @@
1
- import { ILogger } from '../../logger/types';
2
1
  import { Semver } from '../../utils/Semver';
3
2
 
4
- export function greaterThanEqualToSemverMatcherContext(log: ILogger, ruleAttr: string) {
3
+ export function greaterThanEqualToSemverMatcherContext(ruleAttr: string) {
5
4
  const ruleSemver = new Semver(ruleAttr);
6
5
 
7
6
  return function greaterThanEqualToSemverMatcher(runtimeAttr: string): boolean {
@@ -1,13 +1,15 @@
1
- import { setToArray, ISet, _Set } from '../../utils/lang/sets';
2
- import { ILogger } from '../../logger/types';
1
+ import { _Set } from '../../utils/lang/sets';
3
2
  import { Semver } from '../../utils/Semver';
4
3
 
5
- export function inListSemverMatcherContext(log: ILogger, ruleAttr: ISet<string>) {
4
+ export function inListSemverMatcherContext(ruleAttr: string[]) {
5
+ // @TODO move eventually to `matchersTransform` and validate for all matchers
6
+ if (!ruleAttr || ruleAttr.length === 0) throw new Error('whitelistMatcherData is required for IN_LIST_SEMVER matcher type');
6
7
 
7
- const listOfSemvers = new _Set(setToArray(ruleAttr).map((version) => new Semver(version).version));
8
+ const listOfSemvers = new _Set(ruleAttr.map((version) => new Semver(version).version));
8
9
 
9
10
  return function inListSemverMatcher(runtimeAttr: string): boolean {
10
11
  const runtimeSemver = new Semver(runtimeAttr).version;
12
+
11
13
  const isInList = listOfSemvers.has(runtimeSemver);
12
14
 
13
15
  return isInList;
@@ -1,14 +1,13 @@
1
- import { ILogger } from '../../logger/types';
2
1
  import { Semver } from '../../utils/Semver';
3
2
 
4
- export function lessThanEqualToSemverMatcherContext(log: ILogger, ruleAttr: string) {
3
+ export function lessThanEqualToSemverMatcherContext(ruleAttr: string) {
5
4
  const ruleSemver = new Semver(ruleAttr);
6
5
 
7
6
  return function lessThanEqualToSemverMatcher(runtimeAttr: string): boolean {
8
7
  const runtimeSemver = new Semver(runtimeAttr);
9
8
 
10
- const isLessThenEqual = runtimeSemver.compare(ruleSemver) <= 0;
9
+ const isLessThanEqual = runtimeSemver.compare(ruleSemver) <= 0;
11
10
 
12
- return isLessThenEqual;
11
+ return isLessThanEqual;
13
12
  };
14
13
  }
@@ -1,14 +1,9 @@
1
- import { ENGINE_MATCHER_STRING } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
3
-
4
- export function stringMatcherContext(log: ILogger, ruleAttr: string) {
1
+ export function stringMatcherContext(ruleAttr: string) {
5
2
  const regex = new RegExp(ruleAttr);
6
3
 
7
4
  return function stringMatcher(runtimeAttr: string): boolean {
8
5
  const regexMatches = regex.test(runtimeAttr);
9
6
 
10
- log.debug(ENGINE_MATCHER_STRING, [runtimeAttr, ruleAttr, regexMatches ? 'yes' : 'no']);
11
-
12
7
  return regexMatches;
13
8
  };
14
9
  }
@@ -1,12 +1,8 @@
1
- import { ENGINE_MATCHER_STARTS_WITH } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
3
1
  import { startsWith } from '../../utils/lang';
4
2
 
5
- export function startsWithMatcherContext(log: ILogger, ruleAttr: string[]) {
3
+ export function startsWithMatcherContext(ruleAttr: string[]) {
6
4
  return function startsWithMatcher(runtimeAttr: string): boolean {
7
- let matches = ruleAttr.some(e => startsWith(runtimeAttr, e));
8
-
9
- log.debug(ENGINE_MATCHER_STARTS_WITH, [runtimeAttr, ruleAttr, matches]);
5
+ const matches = ruleAttr.some(e => startsWith(runtimeAttr, e));
10
6
 
11
7
  return matches;
12
8
  };
@@ -1,12 +1,10 @@
1
- import { setToArray, ISet } from '../../utils/lang/sets';
2
- import { ILogger } from '../../logger/types';
3
- import { ENGINE_MATCHER_WHITELIST } from '../../logger/constants';
1
+ import { _Set } from '../../utils/lang/sets';
4
2
 
5
- export function whitelistMatcherContext(log: ILogger, ruleAttr: ISet<string>) {
6
- return function whitelistMatcher(runtimeAttr: string): boolean {
7
- let isInWhitelist = ruleAttr.has(runtimeAttr);
3
+ export function whitelistMatcherContext(ruleAttr: string[]) {
4
+ const whitelistSet = new _Set(ruleAttr);
8
5
 
9
- log.debug(ENGINE_MATCHER_WHITELIST, [runtimeAttr, setToArray(ruleAttr).join(','), isInWhitelist]);
6
+ return function whitelistMatcher(runtimeAttr: string): boolean {
7
+ const isInWhitelist = whitelistSet.has(runtimeAttr);
10
8
 
11
9
  return isInWhitelist;
12
10
  };
@@ -2,10 +2,9 @@ import { findIndex } from '../../utils/lang';
2
2
  import { matcherTypes, matcherTypesMapper, matcherDataTypes } from '../matchers/matcherTypes';
3
3
  import { segmentTransform } from './segment';
4
4
  import { whitelistTransform } from './whitelist';
5
- import { setTransform } from './set';
6
5
  import { numericTransform } from './unaryNumeric';
7
6
  import { zeroSinceHH, zeroSinceSS } from '../convertions';
8
- import { IBetweenMatcherData, IInSegmentMatcherData, ISplitMatcher, IUnaryNumericMatcherData, IWhitelistMatcherData } from '../../dtos/types';
7
+ import { IBetweenMatcherData, IInSegmentMatcherData, ISplitMatcher, IUnaryNumericMatcherData } from '../../dtos/types';
9
8
  import { IMatcherDto } from '../types';
10
9
 
11
10
  /**
@@ -32,15 +31,10 @@ export function matchersTransform(matchers: ISplitMatcher[]): IMatcherDto[] {
32
31
  let type = matcherTypesMapper(matcherType);
33
32
  // As default input data type we use string (even for ALL_KEYS)
34
33
  let dataType = matcherDataTypes.STRING;
35
- let value = undefined;
34
+ let value: IMatcherDto['value'] = undefined;
36
35
 
37
36
  if (type === matcherTypes.IN_SEGMENT) {
38
37
  value = segmentTransform(userDefinedSegmentMatcherData as IInSegmentMatcherData);
39
- } else if (
40
- type === matcherTypes.WHITELIST ||
41
- type === matcherTypes.IN_LIST_SEMVER
42
- ) {
43
- value = whitelistTransform(whitelistMatcherData as IWhitelistMatcherData);
44
38
  } else if (type === matcherTypes.EQUAL_TO) {
45
39
  value = numericTransform(unaryNumericMatcherData as IUnaryNumericMatcherData);
46
40
  dataType = matcherDataTypes.NUMBER;
@@ -75,14 +69,16 @@ export function matchersTransform(matchers: ISplitMatcher[]): IMatcherDto[] {
75
69
  type === matcherTypes.CONTAINS_ALL_OF_SET ||
76
70
  type === matcherTypes.PART_OF_SET
77
71
  ) {
78
- value = setTransform(whitelistMatcherData as IWhitelistMatcherData);
72
+ value = whitelistTransform(whitelistMatcherData);
79
73
  dataType = matcherDataTypes.SET;
80
74
  } else if (
75
+ type === matcherTypes.WHITELIST ||
76
+ type === matcherTypes.IN_LIST_SEMVER ||
81
77
  type === matcherTypes.STARTS_WITH ||
82
78
  type === matcherTypes.ENDS_WITH ||
83
79
  type === matcherTypes.CONTAINS_STRING
84
80
  ) {
85
- value = setTransform(whitelistMatcherData as IWhitelistMatcherData);
81
+ value = whitelistTransform(whitelistMatcherData);
86
82
  } else if (type === matcherTypes.IN_SPLIT_TREATMENT) {
87
83
  value = dependencyMatcherData;
88
84
  dataType = matcherDataTypes.NOT_SPECIFIED;
@@ -1,9 +1,8 @@
1
- import { IWhitelistMatcherData } from '../../dtos/types';
2
- import { _Set } from '../../utils/lang/sets';
1
+ import { ISplitMatcher } from '../../dtos/types';
3
2
 
4
3
  /**
5
4
  * Extract whitelist as a set. Used by 'WHITELIST' matcher.
6
5
  */
7
- export function whitelistTransform(whitelistObject: IWhitelistMatcherData) {
8
- return new _Set(whitelistObject.whitelist);
6
+ export function whitelistTransform(whitelistObject: ISplitMatcher['whitelistMatcherData']) {
7
+ return whitelistObject && whitelistObject.whitelist;
9
8
  }
@@ -11,7 +11,7 @@ import { ISplitCondition, MaybeThenable } from '../../dtos/types';
11
11
  import { IStorageAsync, IStorageSync } from '../../storages/types';
12
12
  import { SplitIO } from '../../types';
13
13
  import { ILogger } from '../../logger/types';
14
- import { ENGINE_MATCHER_ERROR } from '../../logger/constants';
14
+ import { ENGINE_MATCHER_ERROR, ENGINE_MATCHER_RESULT } from '../../logger/constants';
15
15
 
16
16
  export function parser(log: ILogger, conditions: ISplitCondition[], storage: IStorageSync | IStorageAsync): IEvaluator {
17
17
  let predicates = [];
@@ -45,14 +45,19 @@ export function parser(log: ILogger, conditions: ISplitCondition[], storage: ISt
45
45
  try {
46
46
  result = matcher(value, splitEvaluator);
47
47
  } catch (error) {
48
+ // @TODO should we propagate the error, to create impressions with label EXCEPTION?
48
49
  log.error(ENGINE_MATCHER_ERROR, [matcherGroup.matchers[index].matcherType, error]);
49
50
  }
50
51
  }
51
52
 
52
- if (thenable(result)) { // @ts-ignore
53
- return result.then(res => Boolean(res ^ matcherDto.negate));
54
- } // @ts-ignore
55
- return Boolean(result ^ matcherDto.negate);
53
+ function handleResult(result: boolean) {
54
+ log.debug(ENGINE_MATCHER_RESULT, [matcherGroup.matchers[index].matcherType, result, matcherDto.value, value]); // @ts-ignore
55
+ return Boolean(result ^ matcherDto.negate);
56
+ }
57
+
58
+ return thenable(result) ?
59
+ result.then(handleResult) :
60
+ handleResult(result);
56
61
  };
57
62
  });
58
63
 
@@ -1,6 +1,5 @@
1
1
  import { IBetweenMatcherData, IBetweenStringMatcherData, IDependencyMatcherData, MaybeThenable } from '../dtos/types';
2
2
  import { IStorageAsync, IStorageSync } from '../storages/types';
3
- import { ISet } from '../utils/lang/sets';
4
3
  import { SplitIO } from '../types';
5
4
  import { ILogger } from '../logger/types';
6
5
 
@@ -11,7 +10,7 @@ export interface IDependencyMatcherValue {
11
10
 
12
11
  export interface IMatcherDto {
13
12
  type: number
14
- value?: string | number | boolean | string[] | IDependencyMatcherData | ISet<string> | IBetweenMatcherData | IBetweenStringMatcherData | null
13
+ value?: string | number | boolean | string[] | IDependencyMatcherData | IBetweenMatcherData | IBetweenStringMatcherData | null
15
14
 
16
15
  attribute: string | null
17
16
  negate: boolean