Skip to content

Commit f7dd0a1

Browse files
Rename new methods
1 parent b70d121 commit f7dd0a1

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
lines changed

CHANGES.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
2.5.0 (August XX, 2025)
2-
- Added `factory.getCache()` method for standalone server-side SDKs, which returns the rollout plan snapshot from the storage.
3-
- Added `preloadedData` configuration option for standalone client-side SDKs, which allows preloading the SDK storage with a snapshot of the rollout plan.
2+
- Added `factory.getRolloutPlan()` method for standalone server-side SDKs, which returns the rollout plan snapshot from the storage.
3+
- Added `initialRolloutPlan` configuration option for standalone client-side SDKs, which allows preloading the SDK storage with a snapshot of the rollout plan.
44

55
2.4.1 (June 3, 2025)
66
- Bugfix - Improved the Proxy fallback to flag spec version 1.2 to handle cases where the Proxy does not return an end-of-stream marker in 400 status code responses.

src/storages/__tests__/dataLoader.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { IRBSegment, ISplit } from '../../dtos/types';
66

77
import * as dataLoader from '../dataLoader';
88

9-
describe('setCache & getCache', () => {
10-
jest.spyOn(dataLoader, 'setCache');
9+
describe('setRolloutPlan & getRolloutPlan', () => {
10+
jest.spyOn(dataLoader, 'setRolloutPlan');
1111
const onReadyFromCacheCb = jest.fn();
1212
const onReadyCb = jest.fn();
1313

@@ -24,23 +24,23 @@ describe('setCache & getCache', () => {
2424
});
2525

2626
test('using preloaded data with memberships', () => {
27-
const preloadedData = dataLoader.getCache(loggerMock, serverStorage, [fullSettings.core.key as string, otherKey]);
27+
const rolloutPlanData = dataLoader.getRolloutPlan(loggerMock, serverStorage, [fullSettings.core.key as string, otherKey]);
2828

2929
// Load client-side storage with preloaded data
30-
const clientStorage = InMemoryStorageCSFactory({ settings: { ...fullSettings, preloadedData }, onReadyFromCacheCb, onReadyCb });
31-
expect(dataLoader.setCache).toBeCalledTimes(1);
30+
const clientStorage = InMemoryStorageCSFactory({ settings: { ...fullSettings, initialRolloutPlan: rolloutPlanData }, onReadyFromCacheCb, onReadyCb });
31+
expect(dataLoader.setRolloutPlan).toBeCalledTimes(1);
3232
expect(onReadyFromCacheCb).toBeCalledTimes(1);
3333

3434
// Shared client storage
3535
const sharedClientStorage = clientStorage.shared!(otherKey);
36-
expect(dataLoader.setCache).toBeCalledTimes(2);
36+
expect(dataLoader.setRolloutPlan).toBeCalledTimes(2);
3737

3838
expect(clientStorage.segments.getRegisteredSegments()).toEqual(['segment1']);
3939
expect(sharedClientStorage.segments.getRegisteredSegments()).toEqual(['segment1']);
4040

4141
// Get preloaded data from client-side storage
42-
expect(dataLoader.getCache(loggerMock, clientStorage, [fullSettings.core.key as string, otherKey])).toEqual(preloadedData);
43-
expect(preloadedData).toEqual({
42+
expect(dataLoader.getRolloutPlan(loggerMock, clientStorage, [fullSettings.core.key as string, otherKey])).toEqual(rolloutPlanData);
43+
expect(rolloutPlanData).toEqual({
4444
since: 123,
4545
flags: [{ name: 'split1' }],
4646
rbSince: 321,
@@ -54,20 +54,20 @@ describe('setCache & getCache', () => {
5454
});
5555

5656
test('using preloaded data with segments', () => {
57-
const preloadedData = dataLoader.getCache(loggerMock, serverStorage);
57+
const rolloutPlanData = dataLoader.getRolloutPlan(loggerMock, serverStorage);
5858

5959
// Load client-side storage with preloaded data
60-
const clientStorage = InMemoryStorageCSFactory({ settings: { ...fullSettings, preloadedData }, onReadyFromCacheCb, onReadyCb });
61-
expect(dataLoader.setCache).toBeCalledTimes(1);
60+
const clientStorage = InMemoryStorageCSFactory({ settings: { ...fullSettings, initialRolloutPlan: rolloutPlanData }, onReadyFromCacheCb, onReadyCb });
61+
expect(dataLoader.setRolloutPlan).toBeCalledTimes(1);
6262
expect(onReadyFromCacheCb).toBeCalledTimes(1);
6363

6464
// Shared client storage
6565
const sharedClientStorage = clientStorage.shared!(otherKey);
66-
expect(dataLoader.setCache).toBeCalledTimes(2);
66+
expect(dataLoader.setRolloutPlan).toBeCalledTimes(2);
6767
expect(clientStorage.segments.getRegisteredSegments()).toEqual(['segment1']);
6868
expect(sharedClientStorage.segments.getRegisteredSegments()).toEqual(['segment1']);
6969

70-
expect(preloadedData).toEqual({
70+
expect(rolloutPlanData).toEqual({
7171
since: 123,
7272
flags: [{ name: 'split1' }],
7373
rbSince: 321,

src/storages/dataLoader.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ import { IMembershipsResponse, IMySegmentsResponse, IRBSegment, ISplit } from '.
66
import { ILogger } from '../logger/types';
77

88
/**
9-
* Sets the given synchronous storage with the provided preloaded data snapshot.
9+
* Sets the given synchronous storage with the provided rollout plan snapshot.
1010
* If `matchingKey` is provided, the storage is handled as a client-side storage (segments and largeSegments are instances of MySegmentsCache).
1111
* Otherwise, the storage is handled as a server-side storage (segments is an instance of SegmentsCache).
1212
*/
13-
export function setCache(log: ILogger, preloadedData: SplitIO.PreloadedData, storage: { splits?: ISplitsCacheSync, rbSegments?: IRBSegmentsCacheSync, segments: ISegmentsCacheSync, largeSegments?: ISegmentsCacheSync }, matchingKey?: string) {
14-
// Do not load data if current preloadedData is empty
15-
if (Object.keys(preloadedData).length === 0) return;
13+
export function setRolloutPlan(log: ILogger, rolloutPlan: SplitIO.RolloutPlan, storage: { splits?: ISplitsCacheSync, rbSegments?: IRBSegmentsCacheSync, segments: ISegmentsCacheSync, largeSegments?: ISegmentsCacheSync }, matchingKey?: string) {
14+
// Do not load data if current rollout plan is empty
15+
if (Object.keys(rolloutPlan).length === 0) return;
1616

1717
const { splits, rbSegments, segments, largeSegments } = storage;
1818

19-
log.debug(`set cache${matchingKey ? ` for key ${matchingKey}` : ''}`);
19+
log.debug(`storage: set feature flags and segments${matchingKey ? ` for key ${matchingKey}` : ''}`);
2020

2121
if (splits) {
2222
splits.clear();
23-
splits.update(preloadedData.flags as ISplit[] || [], [], preloadedData.since || -1);
23+
splits.update(rolloutPlan.flags as ISplit[] || [], [], rolloutPlan.since || -1);
2424
}
2525

2626
if (rbSegments) {
2727
rbSegments.clear();
28-
rbSegments.update(preloadedData.rbSegments as IRBSegment[] || [], [], preloadedData.rbSince || -1);
28+
rbSegments.update(rolloutPlan.rbSegments as IRBSegment[] || [], [], rolloutPlan.rbSince || -1);
2929
}
3030

31-
const segmentsData = preloadedData.segments || {};
31+
const segmentsData = rolloutPlan.segments || {};
3232
if (matchingKey) { // add memberships data (client-side)
33-
let memberships = preloadedData.memberships && preloadedData.memberships[matchingKey];
33+
let memberships = rolloutPlan.memberships && rolloutPlan.memberships[matchingKey];
3434
if (!memberships && segmentsData) {
3535
memberships = {
3636
ms: {
@@ -55,13 +55,13 @@ export function setCache(log: ILogger, preloadedData: SplitIO.PreloadedData, sto
5555
}
5656

5757
/**
58-
* Gets the preloaded data snapshot from the given synchronous storage.
58+
* Gets the rollout plan snapshot from the given synchronous storage.
5959
* If `keys` are provided, the memberships for those keys is returned, to protect segments data.
6060
* Otherwise, the segments data is returned.
6161
*/
62-
export function getCache(log: ILogger, storage: IStorageSync, keys?: SplitIO.SplitKey[]): SplitIO.PreloadedData {
62+
export function getRolloutPlan(log: ILogger, storage: IStorageSync, keys?: SplitIO.SplitKey[]): SplitIO.RolloutPlan {
6363

64-
log.debug(`get cache${keys ? ` for keys ${keys}` : ''}`);
64+
log.debug(`storage: get feature flags and segments${keys ? ` for keys ${keys}` : ''}`);
6565

6666
return {
6767
since: storage.splits.getChangeNumber(),

src/storages/inLocalStorage/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export function InLocalStorage(options: SplitIO.InLocalStorageOptions = {}): ISt
2626

2727
function InLocalStorageCSFactory(params: IStorageFactoryParams): IStorageSync {
2828

29-
// Fallback to InMemoryStorage if LocalStorage API is not available
30-
if (!isLocalStorageAvailable()) {
31-
params.settings.log.warn(LOG_PREFIX + 'LocalStorage API is unavailable. Falling back to default MEMORY storage');
29+
// Fallback to InMemoryStorage if LocalStorage API is not available or preloaded data is provided
30+
if (!isLocalStorageAvailable() || params.settings.initialRolloutPlan) {
31+
params.settings.log.warn(LOG_PREFIX + 'LocalStorage API is unavailable or `initialRolloutPlan` is provided. Falling back to default MEMORY storage');
3232
return InMemoryStorageCSFactory(params);
3333
}
3434

src/storages/inMemory/InMemoryStorageCS.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
88
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
99
import { UniqueKeysCacheInMemoryCS } from './UniqueKeysCacheInMemoryCS';
1010
import { getMatching } from '../../utils/key';
11-
import { setCache } from '../dataLoader';
11+
import { setRolloutPlan } from '../dataLoader';
1212
import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
1313

1414
/**
@@ -17,7 +17,7 @@ import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
1717
* @param params - parameters required by EventsCacheSync
1818
*/
1919
export function InMemoryStorageCSFactory(params: IStorageFactoryParams): IStorageSync {
20-
const { settings: { log, scheduler: { impressionsQueueSize, eventsQueueSize }, sync: { __splitFiltersValidation }, preloadedData }, onReadyFromCacheCb } = params;
20+
const { settings: { log, scheduler: { impressionsQueueSize, eventsQueueSize }, sync: { __splitFiltersValidation }, initialRolloutPlan }, onReadyFromCacheCb } = params;
2121

2222
const storages: Record<string, IStorageSync> = {};
2323

@@ -45,8 +45,8 @@ export function InMemoryStorageCSFactory(params: IStorageFactoryParams): IStorag
4545
const segments = new MySegmentsCacheInMemory();
4646
const largeSegments = new MySegmentsCacheInMemory();
4747

48-
if (preloadedData) {
49-
setCache(log, preloadedData, { segments, largeSegments }, matchingKey);
48+
if (initialRolloutPlan) {
49+
setRolloutPlan(log, initialRolloutPlan, { segments, largeSegments }, matchingKey);
5050
}
5151

5252
storages[matchingKey] = {
@@ -81,8 +81,8 @@ export function InMemoryStorageCSFactory(params: IStorageFactoryParams): IStorag
8181
const matchingKey = getMatching(params.settings.core.key);
8282
storages[matchingKey] = storage;
8383

84-
if (preloadedData) {
85-
setCache(log, preloadedData, storage, matchingKey);
84+
if (initialRolloutPlan) {
85+
setRolloutPlan(log, initialRolloutPlan, storage, matchingKey);
8686
if (splits.getChangeNumber() > -1) onReadyFromCacheCb();
8787
}
8888

types/splitio.d.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ interface IClientSideSyncSharedSettings extends IClientSideSharedSettings, ISync
353353
/**
354354
* Data to initialize the SDK storage with. If provided and valid, the SDK will be ready from cache immediately.
355355
*/
356-
preloadedData?: SplitIO.PreloadedData;
356+
initialRolloutPlan?: SplitIO.RolloutPlan;
357357
/**
358358
* SDK Startup settings.
359359
*/
@@ -559,7 +559,7 @@ declare namespace SplitIO {
559559
eventsFirstPushWindow: number;
560560
};
561561
readonly storage: StorageSyncFactory | StorageAsyncFactory | StorageOptions;
562-
readonly preloadedData?: SplitIO.PreloadedData;
562+
readonly initialRolloutPlan?: SplitIO.RolloutPlan;
563563
readonly urls: {
564564
events: string;
565565
sdk: string;
@@ -1025,41 +1025,41 @@ declare namespace SplitIO {
10251025
type: NodeSyncStorage | NodeAsyncStorage | BrowserStorage;
10261026
prefix?: string;
10271027
options?: Object;
1028-
}
1028+
};
10291029
/**
1030-
* Defines the format of rollout plan data to preload the factory storage (cache).
1030+
* Defines the format of rollout plan data to preload the SDK cache.
10311031
*/
1032-
type PreloadedData = {
1032+
type RolloutPlan = {
10331033
/**
10341034
* Change number of feature flags.
10351035
*/
10361036
since: number;
10371037
/**
10381038
* List of feature flags.
10391039
*/
1040-
flags: Object[],
1040+
flags: Object[];
10411041
/**
10421042
* Change number of rule-based segments.
10431043
*/
1044-
rbSince?: number,
1044+
rbSince?: number;
10451045
/**
10461046
* List of rule-based segments.
10471047
*/
1048-
rbSegments?: Object[],
1048+
rbSegments?: Object[];
10491049
/**
10501050
* Optional map of user keys to their memberships.
10511051
*/
10521052
memberships?: {
1053-
[key: string]: Object
1054-
},
1053+
[key: string]: Object;
1054+
};
10551055
/**
10561056
* Optional map of segments to their list of keys.
10571057
* This property is ignored if `memberships` is provided.
10581058
*/
10591059
segments?: {
1060-
[segmentName: string]: string[]
1061-
},
1062-
}
1060+
[segmentName: string]: string[];
1061+
};
1062+
};
10631063
/**
10641064
* Impression listener interface. This is the interface that needs to be implemented
10651065
* by the element you provide to the SDK as impression listener.
@@ -1082,7 +1082,7 @@ declare namespace SplitIO {
10821082
type IntegrationFactory = {
10831083
readonly type: string;
10841084
(params: any): (Integration | void);
1085-
}
1085+
};
10861086
/**
10871087
* A pair of user key and it's trafficType, required for tracking valid Split events.
10881088
*/
@@ -1609,7 +1609,7 @@ declare namespace SplitIO {
16091609
* @param keys - Optional list of keys to generate the rollout plan snapshot with the memberships of the given keys, rather than the complete segments data.
16101610
* @returns The current snapshot of the SDK rollout plan.
16111611
*/
1612-
getCache(keys?: SplitKey[]): PreloadedData,
1612+
getRolloutPlan(keys?: SplitKey[]): RolloutPlan;
16131613
}
16141614
/**
16151615
* This represents the interface for the SDK instance for server-side with asynchronous storage.

0 commit comments

Comments
 (0)