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
10 changes: 10 additions & 0 deletions src/evaluator/convertions/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { IBetweenMatcherData } from '../../dtos/types';

export function zeroSinceHH(millisSinceEpoch: number): number {
return new Date(millisSinceEpoch).setUTCHours(0, 0, 0, 0);
}

export function zeroSinceSS(millisSinceEpoch: number): number {
return new Date(millisSinceEpoch).setUTCSeconds(0, 0);
}

export function betweenDateTimeTransform(betweenMatcherData: IBetweenMatcherData): IBetweenMatcherData {
return {
dataType: betweenMatcherData.dataType,
start: zeroSinceSS(betweenMatcherData.start),
end: zeroSinceSS(betweenMatcherData.end)
};
}
7 changes: 3 additions & 4 deletions src/evaluator/matchersTransform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { matcherTypes, matcherTypesMapper, matcherDataTypes } from '../matchers/
import { segmentTransform } from './segment';
import { whitelistTransform } from './whitelist';
import { numericTransform } from './unaryNumeric';
import { zeroSinceHH, zeroSinceSS } from '../convertions';
import { zeroSinceHH, zeroSinceSS, betweenDateTimeTransform } from '../convertions';
import { IBetweenMatcherData, IInLargeSegmentMatcherData, IInSegmentMatcherData, ISplitMatcher, IUnaryNumericMatcherData } from '../../dtos/types';
import { IMatcherDto } from '../types';

Expand Down Expand Up @@ -32,7 +32,7 @@ export function matchersTransform(matchers: ISplitMatcher[]): IMatcherDto[] {
let type = matcherTypesMapper(matcherType);
// As default input data type we use string (even for ALL_KEYS)
let dataType = matcherDataTypes.STRING;
let value = undefined;
let value;

if (type === matcherTypes.IN_SEGMENT) {
value = segmentTransform(userDefinedSegmentMatcherData as IInSegmentMatcherData);
Expand Down Expand Up @@ -60,8 +60,7 @@ export function matchersTransform(matchers: ISplitMatcher[]): IMatcherDto[] {
dataType = matcherDataTypes.NUMBER;

if (value.dataType === 'DATETIME') {
value.start = zeroSinceSS(value.start);
value.end = zeroSinceSS(value.end);
value = betweenDateTimeTransform(value);
dataType = matcherDataTypes.DATETIME;
}
} else if (type === matcherTypes.BETWEEN_SEMVER) {
Expand Down
4 changes: 4 additions & 0 deletions src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class RBSegmentsCacheInLocal implements IRBSegmentsCacheSync {
return item && JSON.parse(item);
}

getAll(): IRBSegment[] {
return this.getNames().map(key => this.get(key)!);
}

contains(names: Set<string>): boolean {
const namesArray = setToArray(names);
const namesInStorage = this.getNames();
Expand Down
4 changes: 4 additions & 0 deletions src/storages/inMemory/RBSegmentsCacheInMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class RBSegmentsCacheInMemory implements IRBSegmentsCacheSync {
return this.cache[name] || null;
}

getAll(): IRBSegment[] {
return this.getNames().map(key => this.get(key)!);
}

contains(names: Set<string>): boolean {
const namesArray = setToArray(names);
const namesInStorage = this.getNames();
Expand Down
6 changes: 5 additions & 1 deletion src/storages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export interface IRBSegmentsCacheSync extends IRBSegmentsCacheBase {
update(toAdd: IRBSegment[], toRemove: IRBSegment[], changeNumber: number): boolean,
get(name: string): IRBSegment | null,
getChangeNumber(): number,
getAll(): IRBSegment[],
clear(): void,
contains(names: Set<string>): boolean,
// Used only for smart pausing in client-side standalone. Returns true if the storage contains a RBSegment using segments or large segments matchers
Expand Down Expand Up @@ -465,7 +466,7 @@ export interface IStorageBase<
telemetry?: TTelemetryCache,
uniqueKeys: TUniqueKeysCache,
destroy(): void | Promise<void>,
shared?: (matchingKey: string, onReadyCb: (error?: any) => void) => this
shared?: (matchingKey: string, onReadyCb?: (error?: any) => void) => this
}

export interface IStorageSync extends IStorageBase<
Expand Down Expand Up @@ -505,6 +506,9 @@ export interface IStorageFactoryParams {
* It is meant for emitting SDK_READY event in consumer mode, and waiting before using the storage in the synchronizer.
*/
onReadyCb: (error?: any) => void,
/**
* For emitting SDK_READY_FROM_CACHE event in consumer mode with Redis to allow immediate evaluations
*/
onReadyFromCacheCb: () => void,
}

Expand Down