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
16 changes: 15 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,21 @@
"plugin:compat/recommended"
],
"rules": {
"no-restricted-syntax": ["error", "ForOfStatement", "ForInStatement"],
"no-restricted-syntax": [
"error",
{
"selector": "ForOfStatement",
"message": "Avoid for-of syntax in favor of a smaller transpiled code"
},
{
"selector": "ForInStatement",
"message": "Don't use for-in syntax in libraries, because it iterates over members inherited from the prototype chain"
},
{
"selector": "TSEnumDeclaration[const=true]",
"message": "Don't declare const enum, because it is not supported by Babel used for building RN SDK"
}
],
"compat/compat": ["error", "defaults, not ie < 10, not node < 6"],
"no-throw-literal": "error"
},
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/matchers/matcherTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const matcherTypes: Record<string, number> = {
MATCHES_STRING: 17
};

export const dataTypes = {
export const matcherDataTypes = {
BOOLEAN: 'BOOLEAN',
STRING: 'STRING',
NUMBER: 'NUMBER',
Expand All @@ -28,7 +28,7 @@ export const dataTypes = {
NOT_SPECIFIED: 'NOT_SPECIFIED'
};

export function mapper(matcherType: string) {
export function matcherTypesMapper(matcherType: string) {
const type = matcherTypes[matcherType];
if (type) return type;
else return matcherTypes.UNDEFINED;
Expand Down
24 changes: 12 additions & 12 deletions src/evaluator/matchersTransform/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { findIndex } from '../../utils/lang';
import { matcherTypes, mapper, dataTypes } from '../matchers/matcherTypes';
import { matcherTypes, matcherTypesMapper, matcherDataTypes } from '../matchers/matcherTypes';
import segmentTransform from './segment';
import whitelistTransform from './whitelist';
import setTransform from './set';
Expand Down Expand Up @@ -28,9 +28,9 @@ export default function matchersTransform(matchers: ISplitMatcher[]): IMatcherDt
} = matcher;

let attribute = keySelector && keySelector.attribute;
let type = mapper(matcherType);
let type = matcherTypesMapper(matcherType);
// As default input data type we use string (even for ALL_KEYS)
let dataType = dataTypes.STRING;
let dataType = matcherDataTypes.STRING;
let value = undefined;

if (type === matcherTypes.IN_SEGMENT) {
Expand All @@ -39,29 +39,29 @@ export default function matchersTransform(matchers: ISplitMatcher[]): IMatcherDt
value = whitelistTransform(whitelistObject as IWhitelistMatcherData);
} else if (type === matcherTypes.EQUAL_TO) {
value = numericTransform(unaryNumericObject as IUnaryNumericMatcherData);
dataType = dataTypes.NUMBER;
dataType = matcherDataTypes.NUMBER;

if ((unaryNumericObject as IUnaryNumericMatcherData).dataType === 'DATETIME') {
value = zeroSinceHH(value);
dataType = dataTypes.DATETIME;
dataType = matcherDataTypes.DATETIME;
}
} else if (type === matcherTypes.GREATER_THAN_OR_EQUAL_TO ||
type === matcherTypes.LESS_THAN_OR_EQUAL_TO) {
value = numericTransform(unaryNumericObject as IUnaryNumericMatcherData);
dataType = dataTypes.NUMBER;
dataType = matcherDataTypes.NUMBER;

if ((unaryNumericObject as IUnaryNumericMatcherData).dataType === 'DATETIME') {
value = zeroSinceSS(value);
dataType = dataTypes.DATETIME;
dataType = matcherDataTypes.DATETIME;
}
} else if (type === matcherTypes.BETWEEN) {
value = betweenObject as IBetweenMatcherData;
dataType = dataTypes.NUMBER;
dataType = matcherDataTypes.NUMBER;

if (value.dataType === 'DATETIME') {
value.start = zeroSinceSS(value.start);
value.end = zeroSinceSS(value.end);
dataType = dataTypes.DATETIME;
dataType = matcherDataTypes.DATETIME;
}
} else if (
type === matcherTypes.EQUAL_TO_SET ||
Expand All @@ -70,7 +70,7 @@ export default function matchersTransform(matchers: ISplitMatcher[]): IMatcherDt
type === matcherTypes.PART_OF_SET
) {
value = setTransform(whitelistObject as IWhitelistMatcherData);
dataType = dataTypes.SET;
dataType = matcherDataTypes.SET;
} else if (
type === matcherTypes.STARTS_WITH ||
type === matcherTypes.ENDS_WITH ||
Expand All @@ -79,9 +79,9 @@ export default function matchersTransform(matchers: ISplitMatcher[]): IMatcherDt
value = setTransform(whitelistObject as IWhitelistMatcherData);
} else if (type === matcherTypes.IN_SPLIT_TREATMENT) {
value = dependencyObject;
dataType = dataTypes.NOT_SPECIFIED;
dataType = matcherDataTypes.NOT_SPECIFIED;
} else if (type === matcherTypes.EQUAL_TO_BOOLEAN) {
dataType = dataTypes.BOOLEAN;
dataType = matcherDataTypes.BOOLEAN;
value = booleanMatcherData;
} else if (type === matcherTypes.MATCHES_STRING) {
value = stringMatcherData;
Expand Down
14 changes: 7 additions & 7 deletions src/evaluator/value/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IDependencyMatcherValue } from '../types';
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 { matcherTypes, matcherDataTypes } from '../matchers/matcherTypes';
import { ENGINE_SANITIZE } from '../../logger/constants';

function sanitizeNumber(val: any): number | undefined {
Expand Down Expand Up @@ -74,20 +74,20 @@ export default function sanitize(log: ILogger, matcherTypeID: number, value: str
let sanitizedValue: string | number | boolean | Array<string | number> | IDependencyMatcherValue | undefined;

switch (dataType) {
case dataTypes.NUMBER:
case dataTypes.DATETIME:
case matcherDataTypes.NUMBER:
case matcherDataTypes.DATETIME:
sanitizedValue = sanitizeNumber(value);
break;
case dataTypes.STRING:
case matcherDataTypes.STRING:
sanitizedValue = sanitizeString(value);
break;
case dataTypes.SET:
case matcherDataTypes.SET:
sanitizedValue = sanitizeArray(value);
break;
case dataTypes.BOOLEAN:
case matcherDataTypes.BOOLEAN:
sanitizedValue = sanitizeBoolean(value);
break;
case dataTypes.NOT_SPECIFIED:
case matcherDataTypes.NOT_SPECIFIED:
sanitizedValue = value;
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/sync/streaming/SSEHandler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export interface IMySegmentsUpdateData {
segmentList?: string[]
}

export const enum Compression {
export enum Compression {
None = 0,
Gzip = 1,
Zlib = 2
}

export const enum UpdateStrategy {
export enum UpdateStrategy {
UnboundedFetchRequest = 0,
BoundedFetchRequest = 1,
KeyList = 2,
Expand Down
13 changes: 3 additions & 10 deletions src/sync/streaming/pushManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,12 @@ export default function pushManagerFactory(
}

forOwn(clients, ({ hash64, worker }) => {
if (added.has(hash64.dec)) {
const add = added.has(hash64.dec) ? true : removed.has(hash64.dec) ? false : undefined;
if (add !== undefined) {
worker.put(parsedData.changeNumber, {
name: parsedData.segmentName,
add: true
add
});
return;
}
if (removed.has(hash64.dec)) {
worker.put(parsedData.changeNumber, {
name: parsedData.segmentName,
add: false
});
return;
}
});
return;
Expand Down
2 changes: 0 additions & 2 deletions src/trackers/impressionObserver/ImpressionObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export default class ImpressionObserver<K extends string | number> implements II
}

testAndSet(impression: ImpressionDTO) {
if (!impression) return;

const hash = this.hasher(impression);
const previous = this.cache.get(hash);
this.cache.set(hash, impression.time);
Expand Down
2 changes: 1 addition & 1 deletion src/trackers/impressionObserver/impressionObserverSS.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ImpressionObserver from './ImpressionObserver';
import { hash128 } from '../../utils/murmur3/murmur3_128';
import { hash128 } from '../../utils/murmur3/murmur3_128_x86';
import { buildKey } from './buildKey';
import { ImpressionDTO } from '../../types';

Expand Down
Loading