Skip to content

Commit

Permalink
make method abstract and fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Zamora committed Sep 22, 2023
1 parent f906cb9 commit cd7030e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/storages/AbstractSplitsCacheAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class AbstractSplitsCacheAsync implements ISplitsCacheAsync {
abstract getChangeNumber(): Promise<number>
abstract getAll(): Promise<ISplit[]>
abstract getSplitNames(): Promise<string[]>
abstract getNamesByFlagSets(flagsets: string[]): Promise<ISet<string>>
abstract getNamesByFlagSets(flagSets: string[]): Promise<ISet<string>>
abstract trafficTypeExists(trafficType: string): Promise<boolean>
abstract clear(): Promise<boolean | void>

Expand Down
9 changes: 3 additions & 6 deletions src/storages/AbstractSplitsCacheSync.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ISplitsCacheSync } from './types';
import { ISplit } from '../dtos/types';
import { objectAssign } from '../utils/lang/objectAssign';
import { ISet, _Set } from '../utils/lang/sets';
import { ISet } from '../utils/lang/sets';

/**
* This class provides a skeletal implementation of the ISplitsCacheSync interface
Expand Down Expand Up @@ -78,11 +78,8 @@ export abstract class AbstractSplitsCacheSync implements ISplitsCacheSync {
}
return false;
}
/** NO-OP */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getNamesByFlagSets(flagsets: string[]): ISet<string> {
return new _Set([]);
}

abstract getNamesByFlagSets(flagSets: string[]): ISet<string>

}

Expand Down
14 changes: 7 additions & 7 deletions src/storages/inLocalStorage/SplitsCacheInLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
// if the filter didn't change, nothing is done
}

getNamesByFlagSets(flagsets: string[]): ISet<string>{
getNamesByFlagSets(flagSets: string[]): ISet<string>{
let toReturn: ISet<string> = new _Set([]);
flagsets.forEach(flagset => {
const flagsetKey = this.keys.buildFlagSetKey(flagset);
let flagsetFromLocalStorage = localStorage.getItem(flagsetKey);
flagSets.forEach(flagSet => {
const flagSetKey = this.keys.buildFlagSetKey(flagSet);
let flagSetFromLocalStorage = localStorage.getItem(flagSetKey);

if (flagsetFromLocalStorage) {
const flagsetCache = new _Set(JSON.parse(flagsetFromLocalStorage));
toReturn = returnSetsUnion(toReturn, flagsetCache);
if (flagSetFromLocalStorage) {
const flagSetCache = new _Set(JSON.parse(flagSetFromLocalStorage));
toReturn = returnSetsUnion(toReturn, flagSetCache);
}
});
return toReturn;
Expand Down
24 changes: 12 additions & 12 deletions src/storages/inMemory/SplitsCacheInMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import { ISet, _Set, returnSetsUnion } from '../../utils/lang/sets';
*/
export class SplitsCacheInMemory extends AbstractSplitsCacheSync {

private flagsetsFilter: string[];
private flagSetsFilter: string[];
private splitsCache: Record<string, ISplit> = {};
private ttCache: Record<string, number> = {};
private changeNumber: number = -1;
private splitsWithSegmentsCount: number = 0;
private flagsetsCache: Record<string, ISet<string>> = {};
private flagSetsCache: Record<string, ISet<string>> = {};

constructor(splitFiltersValidation: ISplitFiltersValidation = { queryString: null, groupedFilters: { bySet: [], byName: [], byPrefix: [] }, validFilters: [] }) {
super();
this.flagsetsFilter = splitFiltersValidation.groupedFilters.bySet;
this.flagSetsFilter = splitFiltersValidation.groupedFilters.bySet;
}

clear() {
Expand Down Expand Up @@ -105,10 +105,10 @@ export class SplitsCacheInMemory extends AbstractSplitsCacheSync {
return this.getChangeNumber() === -1 || this.splitsWithSegmentsCount > 0;
}

getNamesByFlagSets(flagsets: string[]): ISet<string>{
getNamesByFlagSets(flagSets: string[]): ISet<string>{
let toReturn: ISet<string> = new _Set([]);
flagsets.forEach(flagset => {
const featureFlagNames = this.flagsetsCache[flagset];
flagSets.forEach(flagSet => {
const featureFlagNames = this.flagSetsCache[flagSet];
if (featureFlagNames) {
toReturn = returnSetsUnion(toReturn, featureFlagNames);
}
Expand All @@ -121,11 +121,11 @@ export class SplitsCacheInMemory extends AbstractSplitsCacheSync {
if (!featureFlag.sets) return;
featureFlag.sets.forEach(featureFlagSet => {

if (this.flagsetsFilter.length > 0 && !this.flagsetsFilter.some(filterFlagSet => filterFlagSet === featureFlagSet)) return;
if (this.flagSetsFilter.length > 0 && !this.flagSetsFilter.some(filterFlagSet => filterFlagSet === featureFlagSet)) return;

if (!this.flagsetsCache[featureFlagSet]) this.flagsetsCache[featureFlagSet] = new _Set([]);
if (!this.flagSetsCache[featureFlagSet]) this.flagSetsCache[featureFlagSet] = new _Set([]);

this.flagsetsCache[featureFlagSet].add(featureFlag.name);
this.flagSetsCache[featureFlagSet].add(featureFlag.name);
});
}

Expand All @@ -137,9 +137,9 @@ export class SplitsCacheInMemory extends AbstractSplitsCacheSync {
}

private removeNames(flagsetName: string, featureFlagName: string) {
if (!this.flagsetsCache[flagsetName]) return;
this.flagsetsCache[flagsetName].delete(featureFlagName);
if (this.flagsetsCache[flagsetName].size === 0) delete this.flagsetsCache[flagsetName];
if (!this.flagSetsCache[flagsetName]) return;
this.flagSetsCache[flagsetName].delete(featureFlagName);
if (this.flagSetsCache[flagsetName].size === 0) delete this.flagSetsCache[flagsetName];
}

}
6 changes: 3 additions & 3 deletions src/storages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export interface ISplitsCacheBase {
// should never reject or throw an exception. Instead return false by default, to avoid emitting SDK_READY_FROM_CACHE.
checkCache(): MaybeThenable<boolean>,
killLocally(name: string, defaultTreatment: string, changeNumber: number): MaybeThenable<boolean>,
getNamesByFlagSets(flagsets: string[]): MaybeThenable<ISet<string>>
getNamesByFlagSets(flagSets: string[]): MaybeThenable<ISet<string>>
}

export interface ISplitsCacheSync extends ISplitsCacheBase {
Expand All @@ -227,7 +227,7 @@ export interface ISplitsCacheSync extends ISplitsCacheBase {
clear(): void,
checkCache(): boolean,
killLocally(name: string, defaultTreatment: string, changeNumber: number): boolean,
getNamesByFlagSets(flagsets: string[]): ISet<string>
getNamesByFlagSets(flagSets: string[]): ISet<string>
}

export interface ISplitsCacheAsync extends ISplitsCacheBase {
Expand All @@ -244,7 +244,7 @@ export interface ISplitsCacheAsync extends ISplitsCacheBase {
clear(): Promise<boolean | void>,
checkCache(): Promise<boolean>,
killLocally(name: string, defaultTreatment: string, changeNumber: number): Promise<boolean>,
getNamesByFlagSets(flagsets: string[]): Promise<ISet<string>>
getNamesByFlagSets(flagSets: string[]): Promise<ISet<string>>
}

/** Segments cache */
Expand Down

0 comments on commit cd7030e

Please sign in to comment.