@splitsoftware/splitio-commons 2.0.0-rc.0 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +5 -1
- package/cjs/evaluator/Engine.js +1 -1
- package/cjs/evaluator/index.js +1 -1
- package/cjs/readiness/readinessManager.js +13 -2
- package/cjs/sdkClient/sdkClientMethodCS.js +0 -1
- package/cjs/sdkFactory/index.js +29 -9
- package/cjs/storages/{AbstractSegmentsCacheSync.js → AbstractMySegmentsCacheSync.js} +15 -17
- package/cjs/storages/dataLoader.js +99 -37
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +5 -5
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +3 -2
- package/cjs/storages/inLocalStorage/index.js +1 -1
- package/cjs/storages/inMemory/InMemoryStorageCS.js +18 -6
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +5 -5
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +13 -27
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -1
- package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +2 -1
- package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -1
- package/cjs/storages/inRedis/RedisAdapter.js +2 -1
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +13 -19
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +2 -1
- package/cjs/storages/pluggable/SegmentsCachePluggable.js +11 -32
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +2 -1
- package/cjs/storages/pluggable/inMemoryWrapper.js +2 -1
- package/cjs/sync/offline/syncManagerOffline.js +18 -11
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +12 -28
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +2 -1
- package/cjs/sync/syncManagerOnline.js +20 -21
- package/cjs/trackers/eventTracker.js +12 -10
- package/cjs/trackers/impressionsTracker.js +16 -14
- package/cjs/trackers/uniqueKeysTracker.js +5 -3
- package/cjs/utils/lang/sets.js +12 -2
- package/esm/evaluator/Engine.js +1 -1
- package/esm/evaluator/index.js +2 -2
- package/esm/readiness/readinessManager.js +13 -2
- package/esm/sdkClient/sdkClientMethodCS.js +0 -1
- package/esm/sdkFactory/index.js +30 -10
- package/esm/storages/{AbstractSegmentsCacheSync.js → AbstractMySegmentsCacheSync.js} +14 -16
- package/esm/storages/dataLoader.js +96 -35
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +5 -5
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +3 -2
- package/esm/storages/inLocalStorage/index.js +1 -1
- package/esm/storages/inMemory/InMemoryStorageCS.js +18 -6
- package/esm/storages/inMemory/MySegmentsCacheInMemory.js +5 -5
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +13 -27
- package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -1
- package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +2 -1
- package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -1
- package/esm/storages/inRedis/RedisAdapter.js +2 -1
- package/esm/storages/inRedis/SegmentsCacheInRedis.js +13 -19
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +2 -1
- package/esm/storages/pluggable/SegmentsCachePluggable.js +11 -32
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +2 -1
- package/esm/storages/pluggable/inMemoryWrapper.js +2 -1
- package/esm/sync/offline/syncManagerOffline.js +18 -11
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +12 -28
- package/esm/sync/polling/updaters/splitChangesUpdater.js +2 -1
- package/esm/sync/syncManagerOnline.js +20 -21
- package/esm/trackers/eventTracker.js +12 -10
- package/esm/trackers/impressionsTracker.js +16 -14
- package/esm/trackers/uniqueKeysTracker.js +5 -3
- package/esm/utils/lang/sets.js +10 -1
- package/package.json +1 -1
- package/src/evaluator/Engine.ts +1 -1
- package/src/evaluator/index.ts +2 -2
- package/src/readiness/readinessManager.ts +12 -3
- package/src/readiness/types.ts +3 -0
- package/src/sdkClient/sdkClientMethodCS.ts +0 -2
- package/src/sdkFactory/index.ts +34 -12
- package/src/sdkFactory/types.ts +2 -0
- package/src/storages/{AbstractSegmentsCacheSync.ts → AbstractMySegmentsCacheSync.ts} +13 -28
- package/src/storages/dataLoader.ts +97 -38
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +5 -5
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +3 -2
- package/src/storages/inLocalStorage/index.ts +1 -1
- package/src/storages/inMemory/InMemoryStorageCS.ts +21 -6
- package/src/storages/inMemory/MySegmentsCacheInMemory.ts +5 -5
- package/src/storages/inMemory/SegmentsCacheInMemory.ts +12 -26
- package/src/storages/inMemory/SplitsCacheInMemory.ts +0 -1
- package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +2 -1
- package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +2 -1
- package/src/storages/inRedis/RedisAdapter.ts +2 -1
- package/src/storages/inRedis/SegmentsCacheInRedis.ts +13 -22
- package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +2 -1
- package/src/storages/pluggable/SegmentsCachePluggable.ts +11 -35
- package/src/storages/pluggable/UniqueKeysCachePluggable.ts +2 -1
- package/src/storages/pluggable/inMemoryWrapper.ts +2 -1
- package/src/storages/types.ts +7 -11
- package/src/sync/offline/syncManagerOffline.ts +21 -13
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +13 -29
- package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -1
- package/src/sync/syncManagerOnline.ts +17 -17
- package/src/sync/types.ts +1 -1
- package/src/trackers/eventTracker.ts +11 -8
- package/src/trackers/impressionsTracker.ts +13 -10
- package/src/trackers/types.ts +1 -0
- package/src/trackers/uniqueKeysTracker.ts +6 -4
- package/src/types.ts +14 -13
- package/src/utils/lang/sets.ts +11 -1
- package/types/readiness/types.d.ts +3 -0
- package/types/sdkFactory/types.d.ts +1 -0
- package/types/storages/dataLoader.d.ts +17 -6
- package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +5 -5
- package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +5 -5
- package/types/storages/inMemory/SegmentsCacheInMemory.d.ts +5 -7
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +0 -1
- package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +6 -3
- package/types/storages/pluggable/SegmentsCachePluggable.d.ts +4 -16
- package/types/storages/types.d.ts +7 -10
- package/types/sync/types.d.ts +1 -1
- package/types/trackers/eventTracker.d.ts +1 -1
- package/types/trackers/impressionsTracker.d.ts +1 -1
- package/types/trackers/types.d.ts +1 -0
- package/types/types.d.ts +13 -13
- package/types/utils/lang/sets.d.ts +1 -0
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ISegmentsCacheSync } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
* Default ISplitsCacheSync implementation that stores
|
|
4
|
-
* Supported by all JS runtimes.
|
|
3
|
+
* Default ISplitsCacheSync implementation for server-side that stores segments definitions in memory.
|
|
5
4
|
*/
|
|
6
|
-
export declare class SegmentsCacheInMemory
|
|
5
|
+
export declare class SegmentsCacheInMemory implements ISegmentsCacheSync {
|
|
7
6
|
private segmentCache;
|
|
8
7
|
private segmentChangeNumber;
|
|
9
|
-
|
|
10
|
-
removeFromSegment(name: string, segmentKeys: string[]): boolean;
|
|
8
|
+
update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): boolean;
|
|
11
9
|
isInSegment(name: string, key: string): boolean;
|
|
12
10
|
clear(): void;
|
|
13
11
|
private _registerSegment;
|
|
14
12
|
registerSegments(names: string[]): boolean;
|
|
15
13
|
getRegisteredSegments(): string[];
|
|
16
14
|
getKeysCount(): number;
|
|
17
|
-
setChangeNumber(name: string, changeNumber: number): boolean;
|
|
18
15
|
getChangeNumber(name: string): number;
|
|
16
|
+
resetSegments(): boolean;
|
|
19
17
|
}
|
|
@@ -2,7 +2,6 @@ import { ISplit, ISplitFiltersValidation } from '../../dtos/types';
|
|
|
2
2
|
import { AbstractSplitsCacheSync } from '../AbstractSplitsCacheSync';
|
|
3
3
|
/**
|
|
4
4
|
* Default ISplitsCacheSync implementation that stores split definitions in memory.
|
|
5
|
-
* Supported by all JS runtimes.
|
|
6
5
|
*/
|
|
7
6
|
export declare class SplitsCacheInMemory extends AbstractSplitsCacheSync {
|
|
8
7
|
private flagSetsFilter;
|
|
@@ -7,10 +7,13 @@ export declare class SegmentsCacheInRedis implements ISegmentsCacheAsync {
|
|
|
7
7
|
private readonly redis;
|
|
8
8
|
private readonly keys;
|
|
9
9
|
constructor(log: ILogger, keys: KeyBuilderSS, redis: RedisAdapter);
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Update the given segment `name` with the lists of `addedKeys`, `removedKeys` and `changeNumber`.
|
|
12
|
+
* The returned promise is resolved if the operation success, with `true` if the segment was updated (i.e., some key was added or removed),
|
|
13
|
+
* or rejected if it fails (e.g., Redis operation fails).
|
|
14
|
+
*/
|
|
15
|
+
update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): Promise<boolean>;
|
|
12
16
|
isInSegment(name: string, key: string): Promise<boolean>;
|
|
13
|
-
setChangeNumber(name: string, changeNumber: number): Promise<boolean>;
|
|
14
17
|
getChangeNumber(name: string): Promise<number>;
|
|
15
18
|
registerSegments(segments: string[]): Promise<boolean>;
|
|
16
19
|
getRegisteredSegments(): Promise<string[]>;
|
|
@@ -10,28 +10,16 @@ export declare class SegmentsCachePluggable implements ISegmentsCacheAsync {
|
|
|
10
10
|
private readonly wrapper;
|
|
11
11
|
constructor(log: ILogger, keys: KeyBuilderSS, wrapper: IPluggableStorageWrapper);
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* The returned promise is resolved
|
|
15
|
-
* or rejected if wrapper operation fails.
|
|
16
|
-
*/
|
|
17
|
-
addToSegment(name: string, segmentKeys: string[]): Promise<boolean | void>;
|
|
18
|
-
/**
|
|
19
|
-
* Remove a list of `segmentKeys` from the given segment `name`.
|
|
20
|
-
* The returned promise is resolved when the operation success
|
|
21
|
-
* or rejected if wrapper operation fails.
|
|
13
|
+
* Update the given segment `name` with the lists of `addedKeys`, `removedKeys` and `changeNumber`.
|
|
14
|
+
* The returned promise is resolved if the operation success, with `true` if the segment was updated (i.e., some key was added or removed),
|
|
15
|
+
* or rejected if it fails (e.g., wrapper operation fails).
|
|
22
16
|
*/
|
|
23
|
-
|
|
17
|
+
update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): Promise<boolean>;
|
|
24
18
|
/**
|
|
25
19
|
* Returns a promise that resolves with a boolean value indicating if `key` is part of `name` segment.
|
|
26
20
|
* Promise can be rejected if wrapper operation fails.
|
|
27
21
|
*/
|
|
28
22
|
isInSegment(name: string, key: string): Promise<boolean>;
|
|
29
|
-
/**
|
|
30
|
-
* Set till number for the given segment `name`.
|
|
31
|
-
* The returned promise is resolved when the operation success,
|
|
32
|
-
* or rejected if it fails (e.g., wrapper operation fails).
|
|
33
|
-
*/
|
|
34
|
-
setChangeNumber(name: string, changeNumber: number): Promise<boolean | void>;
|
|
35
23
|
/**
|
|
36
24
|
* Get till number or -1 if it's not defined.
|
|
37
25
|
* The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
|
|
@@ -229,35 +229,29 @@ export interface ISplitsCacheAsync extends ISplitsCacheBase {
|
|
|
229
229
|
}
|
|
230
230
|
/** Segments cache */
|
|
231
231
|
export interface ISegmentsCacheBase {
|
|
232
|
-
addToSegment(name: string, segmentKeys: string[]): MaybeThenable<boolean | void>;
|
|
233
|
-
removeFromSegment(name: string, segmentKeys: string[]): MaybeThenable<boolean | void>;
|
|
234
232
|
isInSegment(name: string, key?: string): MaybeThenable<boolean>;
|
|
235
233
|
registerSegments(names: string[]): MaybeThenable<boolean | void>;
|
|
236
234
|
getRegisteredSegments(): MaybeThenable<string[]>;
|
|
237
|
-
setChangeNumber(name: string, changeNumber: number): MaybeThenable<boolean | void>;
|
|
238
235
|
getChangeNumber(name: string): MaybeThenable<number>;
|
|
236
|
+
update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): MaybeThenable<boolean>;
|
|
239
237
|
clear(): MaybeThenable<boolean | void>;
|
|
240
238
|
}
|
|
241
239
|
export interface ISegmentsCacheSync extends ISegmentsCacheBase {
|
|
242
|
-
addToSegment(name: string, segmentKeys?: string[]): boolean;
|
|
243
|
-
removeFromSegment(name: string, segmentKeys?: string[]): boolean;
|
|
244
240
|
isInSegment(name: string, key?: string): boolean;
|
|
245
241
|
registerSegments(names: string[]): boolean;
|
|
246
242
|
getRegisteredSegments(): string[];
|
|
247
243
|
getKeysCount(): number;
|
|
248
|
-
setChangeNumber(name: string, changeNumber: number): boolean | void;
|
|
249
244
|
getChangeNumber(name?: string): number;
|
|
245
|
+
update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): boolean;
|
|
250
246
|
resetSegments(segmentsData: MySegmentsData | IMySegmentsResponse): boolean;
|
|
251
247
|
clear(): void;
|
|
252
248
|
}
|
|
253
249
|
export interface ISegmentsCacheAsync extends ISegmentsCacheBase {
|
|
254
|
-
addToSegment(name: string, segmentKeys: string[]): Promise<boolean | void>;
|
|
255
|
-
removeFromSegment(name: string, segmentKeys: string[]): Promise<boolean | void>;
|
|
256
250
|
isInSegment(name: string, key: string): Promise<boolean>;
|
|
257
251
|
registerSegments(names: string[]): Promise<boolean | void>;
|
|
258
252
|
getRegisteredSegments(): Promise<string[]>;
|
|
259
|
-
setChangeNumber(name: string, changeNumber: number): Promise<boolean | void>;
|
|
260
253
|
getChangeNumber(name: string): Promise<number>;
|
|
254
|
+
update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): Promise<boolean>;
|
|
261
255
|
clear(): Promise<boolean | void>;
|
|
262
256
|
}
|
|
263
257
|
/** Recorder storages (impressions, events and telemetry) */
|
|
@@ -393,7 +387,6 @@ export interface IStorageSync extends IStorageBase<ISplitsCacheSync, ISegmentsCa
|
|
|
393
387
|
export interface IStorageAsync extends IStorageBase<ISplitsCacheAsync, ISegmentsCacheAsync, IImpressionsCacheAsync | IImpressionsCacheSync, IImpressionCountsCacheBase, IEventsCacheAsync | IEventsCacheSync, ITelemetryCacheAsync | ITelemetryCacheSync, IUniqueKeysCacheBase> {
|
|
394
388
|
}
|
|
395
389
|
/** StorageFactory */
|
|
396
|
-
export declare type DataLoader = (storage: IStorageSync, matchingKey: string) => void;
|
|
397
390
|
export interface IStorageFactoryParams {
|
|
398
391
|
settings: ISettings;
|
|
399
392
|
/**
|
|
@@ -401,6 +394,10 @@ export interface IStorageFactoryParams {
|
|
|
401
394
|
* It is meant for emitting SDK_READY event in consumer mode, and waiting before using the storage in the synchronizer.
|
|
402
395
|
*/
|
|
403
396
|
onReadyCb: (error?: any) => void;
|
|
397
|
+
/**
|
|
398
|
+
* It is meant for emitting SDK_READY_FROM_CACHE event in standalone mode with preloaded data
|
|
399
|
+
*/
|
|
400
|
+
onReadyFromCacheCb: () => void;
|
|
404
401
|
}
|
|
405
402
|
export declare type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'PLUGGABLE';
|
|
406
403
|
export declare type IStorageSyncFactory = {
|
package/types/sync/types.d.ts
CHANGED
|
@@ -39,5 +39,5 @@ export interface ISyncManager extends ITask {
|
|
|
39
39
|
submitterManager?: ISubmitterManager;
|
|
40
40
|
}
|
|
41
41
|
export interface ISyncManagerCS extends ISyncManager {
|
|
42
|
-
shared(matchingKey: string, readinessManager: IReadinessManager, storage: IStorageSync): ISyncManager | undefined;
|
|
42
|
+
shared(matchingKey: string, readinessManager: IReadinessManager, storage: IStorageSync): Pick<ISyncManager, 'stop' | 'flush'> | undefined;
|
|
43
43
|
}
|
|
@@ -7,4 +7,4 @@ import { ISettings } from '../types';
|
|
|
7
7
|
* @param eventsCache cache to save events
|
|
8
8
|
* @param integrationsManager optional event handler used for integrations
|
|
9
9
|
*/
|
|
10
|
-
export declare function eventTrackerFactory(settings: ISettings, eventsCache: IEventsCacheBase, integrationsManager?: IEventsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IEventTracker;
|
|
10
|
+
export declare function eventTrackerFactory(settings: ISettings, eventsCache: IEventsCacheBase, whenInit: (cb: () => void) => void, integrationsManager?: IEventsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IEventTracker;
|
|
@@ -10,4 +10,4 @@ import { ISettings } from '../types';
|
|
|
10
10
|
* @param integrationsManager optional integrations manager
|
|
11
11
|
* @param strategy strategy for impressions tracking.
|
|
12
12
|
*/
|
|
13
|
-
export declare function impressionsTrackerFactory(settings: ISettings, impressionsCache: IImpressionsCacheBase, strategy: IStrategy, integrationsManager?: IImpressionsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IImpressionsTracker;
|
|
13
|
+
export declare function impressionsTrackerFactory(settings: ISettings, impressionsCache: IImpressionsCacheBase, strategy: IStrategy, whenInit: (cb: () => void) => void, integrationsManager?: IImpressionsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IImpressionsTracker;
|
package/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ISplitFiltersValidation } from './dtos/types';
|
|
1
|
+
import { IMembershipsResponse, ISplit, ISplitFiltersValidation } from './dtos/types';
|
|
2
2
|
import { IIntegration, IIntegrationFactoryParams } from './integrations/types';
|
|
3
3
|
import { ILogger } from './logger/types';
|
|
4
4
|
import { ISdkFactoryContext } from './sdkFactory/types';
|
|
@@ -91,6 +91,7 @@ export interface ISettings {
|
|
|
91
91
|
eventsFirstPushWindow: number;
|
|
92
92
|
};
|
|
93
93
|
readonly storage: IStorageSyncFactory | IStorageAsyncFactory;
|
|
94
|
+
readonly preloadedData?: SplitIO.PreloadedData;
|
|
94
95
|
readonly integrations: Array<{
|
|
95
96
|
readonly type: string;
|
|
96
97
|
(params: IIntegrationFactoryParams): IIntegration | void;
|
|
@@ -769,31 +770,30 @@ export declare namespace SplitIO {
|
|
|
769
770
|
* If this value is older than 10 days ago (expiration time policy), the data is not used to update the storage content.
|
|
770
771
|
* @TODO configurable expiration time policy?
|
|
771
772
|
*/
|
|
772
|
-
lastUpdated: number;
|
|
773
773
|
/**
|
|
774
774
|
* Change number of the preloaded data.
|
|
775
775
|
* If this value is older than the current changeNumber at the storage, the data is not used to update the storage content.
|
|
776
776
|
*/
|
|
777
777
|
since: number;
|
|
778
778
|
/**
|
|
779
|
-
*
|
|
779
|
+
* List of feature flag definitions.
|
|
780
|
+
* @TODO rename to flags
|
|
780
781
|
*/
|
|
781
|
-
splitsData:
|
|
782
|
-
[splitName: string]: string;
|
|
783
|
-
};
|
|
782
|
+
splitsData: ISplit[];
|
|
784
783
|
/**
|
|
785
|
-
* Optional map of user keys to their
|
|
786
|
-
* @TODO
|
|
784
|
+
* Optional map of user keys to their memberships.
|
|
785
|
+
* @TODO rename to memberships
|
|
787
786
|
*/
|
|
788
|
-
|
|
789
|
-
[key: string]:
|
|
787
|
+
membershipsData?: {
|
|
788
|
+
[key: string]: IMembershipsResponse;
|
|
790
789
|
};
|
|
791
790
|
/**
|
|
792
|
-
* Optional map of segments to their
|
|
793
|
-
* This property is ignored if `
|
|
791
|
+
* Optional map of segments to their list of keys.
|
|
792
|
+
* This property is ignored if `membershipsData` was provided.
|
|
793
|
+
* @TODO rename to segments
|
|
794
794
|
*/
|
|
795
795
|
segmentsData?: {
|
|
796
|
-
[segmentName: string]: string;
|
|
796
|
+
[segmentName: string]: string[];
|
|
797
797
|
};
|
|
798
798
|
}
|
|
799
799
|
/**
|