Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 24 additions & 4 deletions src/storages/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SplitIO from '../../types/splitio';
import { MaybeThenable, ISplit, IRBSegment, IMySegmentsResponse } from '../dtos/types';
import { MaybeThenable, ISplit, IRBSegment, IMySegmentsResponse, IMembershipsResponse, ISegmentChangesResponse, ISplitChangesResponse } from '../dtos/types';
import { MySegmentsData } from '../sync/polling/types';
import { EventDataType, HttpErrors, HttpLatencies, ImpressionDataType, LastSync, Method, MethodExceptions, MethodLatencies, MultiMethodExceptions, MultiMethodLatencies, MultiConfigs, OperationType, StoredEventWithMetadata, StoredImpressionWithMetadata, StreamingEvent, UniqueKeysPayloadCs, UniqueKeysPayloadSs, TelemetryUsageStatsPayload, UpdatesFromSSEEnum } from '../sync/submitters/types';
import { ISettings } from '../types';
Expand Down 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 @@ -496,15 +497,16 @@ export interface IStorageAsync extends IStorageBase<

/** StorageFactory */

export type DataLoader = (storage: IStorageSync, matchingKey: string) => void

export interface IStorageFactoryParams {
settings: ISettings,
/**
* Error-first callback invoked when the storage is ready to be used. An error means that the storage failed to connect and shouldn't be used.
* 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 All @@ -518,3 +520,21 @@ export type IStorageAsyncFactory = SplitIO.StorageAsyncFactory & {
readonly type: SplitIO.StorageType,
(params: IStorageFactoryParams): IStorageAsync
}

export type RolloutPlan = {
/**
* Feature flags and rule-based segments.
*/
splitChanges: ISplitChangesResponse;
/**
* Optional map of matching keys to their memberships.
*/
memberships?: {
[matchingKey: string]: IMembershipsResponse;
};
/**
* Optional list of standard segments.
* This property is ignored if `memberships` is provided.
*/
segmentChanges?: ISegmentChangesResponse[];
};
Loading