@splitsoftware/splitio-commons 2.1.0-rc.2 → 2.1.1-rc.0
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 +2 -7
- package/README.md +1 -0
- package/cjs/evaluator/combiners/and.js +2 -6
- package/cjs/evaluator/combiners/ifelseif.js +6 -6
- package/cjs/evaluator/condition/index.js +6 -5
- package/cjs/evaluator/index.js +7 -7
- package/cjs/evaluator/matchers/index.js +3 -1
- package/cjs/evaluator/matchers/matcherTypes.js +1 -0
- package/cjs/evaluator/matchers/rbsegment.js +43 -0
- package/cjs/evaluator/matchersTransform/index.js +4 -0
- package/cjs/evaluator/parser/index.js +2 -2
- package/cjs/evaluator/value/sanitize.js +1 -0
- package/cjs/logger/constants.js +5 -6
- package/cjs/logger/messages/debug.js +3 -4
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/readiness/readinessManager.js +0 -6
- package/cjs/services/splitApi.js +2 -2
- package/cjs/storages/AbstractSplitsCacheAsync.js +19 -1
- package/cjs/storages/AbstractSplitsCacheSync.js +17 -9
- package/cjs/storages/KeyBuilder.js +8 -15
- package/cjs/storages/KeyBuilderCS.js +11 -5
- package/cjs/storages/KeyBuilderSS.js +3 -0
- package/cjs/storages/dataLoader.js +3 -5
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +117 -0
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +69 -15
- package/cjs/storages/inLocalStorage/index.js +7 -5
- package/cjs/storages/inMemory/InMemoryStorage.js +3 -0
- package/cjs/storages/inMemory/InMemoryStorageCS.js +4 -0
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +61 -0
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +24 -31
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +64 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +4 -21
- package/cjs/storages/inRedis/constants.js +1 -1
- package/cjs/storages/inRedis/index.js +2 -0
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +64 -0
- package/cjs/storages/pluggable/SplitsCachePluggable.js +2 -19
- package/cjs/storages/pluggable/index.js +3 -2
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +14 -16
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/cjs/sync/polling/pollingManagerCS.js +7 -7
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +62 -51
- package/cjs/sync/streaming/SSEHandler/index.js +1 -0
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +106 -77
- package/cjs/sync/streaming/constants.js +2 -1
- package/cjs/sync/streaming/pushManager.js +3 -16
- package/cjs/sync/syncManagerOnline.js +5 -10
- package/cjs/trackers/uniqueKeysTracker.js +1 -1
- package/cjs/utils/constants/browser.js +5 -0
- package/cjs/utils/constants/index.js +3 -2
- package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
- package/esm/evaluator/combiners/and.js +2 -6
- package/esm/evaluator/combiners/ifelseif.js +7 -7
- package/esm/evaluator/condition/index.js +6 -5
- package/esm/evaluator/index.js +7 -7
- package/esm/evaluator/matchers/index.js +3 -1
- package/esm/evaluator/matchers/matcherTypes.js +1 -0
- package/esm/evaluator/matchers/rbsegment.js +39 -0
- package/esm/evaluator/matchersTransform/index.js +4 -0
- package/esm/evaluator/parser/index.js +2 -2
- package/esm/evaluator/value/sanitize.js +1 -0
- package/esm/logger/constants.js +2 -3
- package/esm/logger/messages/debug.js +3 -4
- package/esm/logger/messages/warn.js +1 -1
- package/esm/readiness/readinessManager.js +0 -6
- package/esm/services/splitApi.js +2 -2
- package/esm/storages/AbstractSplitsCacheAsync.js +19 -1
- package/esm/storages/AbstractSplitsCacheSync.js +17 -9
- package/esm/storages/KeyBuilder.js +8 -15
- package/esm/storages/KeyBuilderCS.js +11 -5
- package/esm/storages/KeyBuilderSS.js +3 -0
- package/esm/storages/dataLoader.js +2 -4
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +114 -0
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +69 -15
- package/esm/storages/inLocalStorage/index.js +7 -5
- package/esm/storages/inMemory/InMemoryStorage.js +3 -0
- package/esm/storages/inMemory/InMemoryStorageCS.js +4 -0
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +58 -0
- package/esm/storages/inMemory/SplitsCacheInMemory.js +24 -31
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +61 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +4 -21
- package/esm/storages/inRedis/constants.js +1 -1
- package/esm/storages/inRedis/index.js +2 -0
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +61 -0
- package/esm/storages/pluggable/SplitsCachePluggable.js +2 -19
- package/esm/storages/pluggable/index.js +3 -2
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +14 -16
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/esm/sync/polling/pollingManagerCS.js +7 -7
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/esm/sync/polling/updaters/splitChangesUpdater.js +63 -52
- package/esm/sync/streaming/SSEHandler/index.js +2 -1
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +102 -73
- package/esm/sync/streaming/constants.js +1 -0
- package/esm/sync/streaming/pushManager.js +6 -19
- package/esm/sync/syncManagerOnline.js +5 -10
- package/esm/trackers/uniqueKeysTracker.js +1 -1
- package/esm/utils/constants/browser.js +2 -0
- package/esm/utils/constants/index.js +2 -1
- package/esm/utils/settingsValidation/storage/storageCS.js +1 -1
- package/package.json +1 -1
- package/src/dtos/types.ts +32 -8
- package/src/evaluator/Engine.ts +1 -1
- package/src/evaluator/combiners/and.ts +5 -4
- package/src/evaluator/combiners/ifelseif.ts +7 -9
- package/src/evaluator/condition/engineUtils.ts +1 -1
- package/src/evaluator/condition/index.ts +12 -12
- package/src/evaluator/index.ts +7 -7
- package/src/evaluator/matchers/index.ts +3 -1
- package/src/evaluator/matchers/matcherTypes.ts +1 -0
- package/src/evaluator/matchers/rbsegment.ts +61 -0
- package/src/evaluator/matchersTransform/index.ts +3 -0
- package/src/evaluator/parser/index.ts +3 -3
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +5 -4
- package/src/logger/constants.ts +2 -3
- package/src/logger/messages/debug.ts +3 -4
- package/src/logger/messages/warn.ts +1 -1
- package/src/readiness/readinessManager.ts +0 -5
- package/src/sdkManager/index.ts +1 -1
- package/src/services/splitApi.ts +2 -2
- package/src/services/types.ts +1 -1
- package/src/storages/AbstractSplitsCacheAsync.ts +23 -5
- package/src/storages/AbstractSplitsCacheSync.ts +22 -15
- package/src/storages/KeyBuilder.ts +9 -17
- package/src/storages/KeyBuilderCS.ts +13 -6
- package/src/storages/KeyBuilderSS.ts +4 -0
- package/src/storages/dataLoader.ts +2 -5
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +136 -0
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +80 -16
- package/src/storages/inLocalStorage/index.ts +12 -8
- package/src/storages/inMemory/InMemoryStorage.ts +3 -0
- package/src/storages/inMemory/InMemoryStorageCS.ts +4 -0
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +68 -0
- package/src/storages/inMemory/SplitsCacheInMemory.ts +22 -27
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +79 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +4 -21
- package/src/storages/inRedis/constants.ts +1 -1
- package/src/storages/inRedis/index.ts +2 -0
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +76 -0
- package/src/storages/pluggable/SplitsCachePluggable.ts +2 -19
- package/src/storages/pluggable/index.ts +3 -2
- package/src/storages/types.ts +47 -18
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +19 -21
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +2 -1
- package/src/sync/polling/fetchers/types.ts +1 -0
- package/src/sync/polling/pollingManagerCS.ts +7 -7
- package/src/sync/polling/syncTasks/splitsSyncTask.ts +1 -2
- package/src/sync/polling/types.ts +2 -2
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -2
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
- package/src/sync/polling/updaters/splitChangesUpdater.ts +74 -63
- package/src/sync/streaming/SSEHandler/index.ts +2 -1
- package/src/sync/streaming/SSEHandler/types.ts +2 -2
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +98 -68
- package/src/sync/streaming/constants.ts +1 -0
- package/src/sync/streaming/parseUtils.ts +2 -2
- package/src/sync/streaming/pushManager.ts +6 -18
- package/src/sync/streaming/types.ts +3 -2
- package/src/sync/syncManagerOnline.ts +5 -11
- package/src/trackers/uniqueKeysTracker.ts +1 -1
- package/src/utils/constants/browser.ts +2 -0
- package/src/utils/constants/index.ts +2 -1
- package/src/utils/lang/index.ts +2 -2
- package/src/utils/settingsValidation/storage/storageCS.ts +1 -1
- package/types/splitio.d.ts +1 -25
- package/cjs/storages/inLocalStorage/validateCache.js +0 -79
- package/esm/storages/inLocalStorage/validateCache.js +0 -75
- package/src/storages/inLocalStorage/validateCache.ts +0 -91
|
@@ -31,7 +31,7 @@ export var codesWarn = codesError.concat([
|
|
|
31
31
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS + ': feature flag filter configuration must be a non-empty array of filter objects.'],
|
|
32
32
|
[c.WARN_SDK_KEY, c.LOG_PREFIX_SETTINGS + ': You already have %s. We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application'],
|
|
33
33
|
[c.STREAMING_PARSING_MEMBERSHIPS_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching Memberships due to an error processing %s notification: %s'],
|
|
34
|
-
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing
|
|
34
|
+
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing %s notification: %s'],
|
|
35
35
|
[c.WARN_INVALID_FLAGSET, '%s: you passed %s, flag set must adhere to the regular expressions %s. This means a flag set must start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. %s was discarded.'],
|
|
36
36
|
[c.WARN_LOWERCASE_FLAGSET, '%s: flag set %s should be all lowercase - converting string to lowercase.'],
|
|
37
37
|
[c.WARN_FLAGSET_WITHOUT_FLAGS, '%s: you passed %s flag set that does not contain cached feature flag names. Please double check what flag sets are in use in the Split user interface.'],
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
2
|
import { SDK_SPLITS_ARRIVED, SDK_SPLITS_CACHE_LOADED, SDK_SEGMENTS_ARRIVED, SDK_READY_TIMED_OUT, SDK_READY_FROM_CACHE, SDK_UPDATE, SDK_READY } from './constants';
|
|
3
|
-
import { STORAGE_LOCALSTORAGE } from '../utils/constants';
|
|
4
3
|
function splitsEventEmitterFactory(EventEmitter) {
|
|
5
4
|
var splitsEventEmitter = objectAssign(new EventEmitter(), {
|
|
6
5
|
splitsArrived: false,
|
|
@@ -81,7 +80,6 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
|
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
function checkIsReadyOrUpdate(diff) {
|
|
84
|
-
var _a;
|
|
85
83
|
if (isDestroyed)
|
|
86
84
|
return;
|
|
87
85
|
if (isReady) {
|
|
@@ -100,10 +98,6 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
|
|
|
100
98
|
isReady = true;
|
|
101
99
|
try {
|
|
102
100
|
syncLastUpdate();
|
|
103
|
-
if (!isReadyFromCache && ((_a = settings.storage) === null || _a === void 0 ? void 0 : _a.type) === STORAGE_LOCALSTORAGE) {
|
|
104
|
-
isReadyFromCache = true;
|
|
105
|
-
gate.emit(SDK_READY_FROM_CACHE);
|
|
106
|
-
}
|
|
107
101
|
gate.emit(SDK_READY);
|
|
108
102
|
}
|
|
109
103
|
catch (e) {
|
package/esm/services/splitApi.js
CHANGED
|
@@ -38,8 +38,8 @@ export function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
38
38
|
}
|
|
39
39
|
return splitHttpClient(url, undefined, telemetryTracker.trackHttp(TOKEN));
|
|
40
40
|
},
|
|
41
|
-
fetchSplitChanges: function (since, noCache, till) {
|
|
42
|
-
var url = urls.sdk + "/splitChanges?s=" + flagSpecVersion + "&since=" + since + (filterQueryString || '') + (till ? '&till=' + till : '');
|
|
41
|
+
fetchSplitChanges: function (since, noCache, till, rbSince) {
|
|
42
|
+
var url = urls.sdk + "/splitChanges?s=" + flagSpecVersion + "&since=" + since + (rbSince ? '&rbSince=' + rbSince : '') + (filterQueryString || '') + (till ? '&till=' + till : '');
|
|
43
43
|
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(SPLITS))
|
|
44
44
|
.catch(function (err) {
|
|
45
45
|
if (err.statusCode === 414)
|
|
@@ -6,11 +6,29 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
6
6
|
var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
7
7
|
function AbstractSplitsCacheAsync() {
|
|
8
8
|
}
|
|
9
|
+
AbstractSplitsCacheAsync.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
10
|
+
var _this = this;
|
|
11
|
+
return Promise.all([
|
|
12
|
+
this.setChangeNumber(changeNumber),
|
|
13
|
+
Promise.all(toAdd.map(function (addedFF) { return _this.addSplit(addedFF); })),
|
|
14
|
+
Promise.all(toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }))
|
|
15
|
+
]).then(function (_a) {
|
|
16
|
+
var added = _a[1], removed = _a[2];
|
|
17
|
+
return added.some(function (result) { return result; }) || removed.some(function (result) { return result; });
|
|
18
|
+
});
|
|
19
|
+
};
|
|
9
20
|
// @TODO revisit segment-related methods ('usesSegments', 'getRegisteredSegments', 'registerSegments')
|
|
10
21
|
// noop, just keeping the interface. This is used by standalone client-side API only, and so only implemented by InMemory and InLocalStorage.
|
|
11
22
|
AbstractSplitsCacheAsync.prototype.usesSegments = function () {
|
|
12
23
|
return Promise.resolve(true);
|
|
13
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Check if the splits information is already stored in cache.
|
|
27
|
+
* Noop, just keeping the interface. This is used by client-side implementations only.
|
|
28
|
+
*/
|
|
29
|
+
AbstractSplitsCacheAsync.prototype.checkCache = function () {
|
|
30
|
+
return Promise.resolve(false);
|
|
31
|
+
};
|
|
14
32
|
/**
|
|
15
33
|
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
16
34
|
* Used for SPLIT_KILL push notifications.
|
|
@@ -27,7 +45,7 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
|
27
45
|
newSplit.killed = true;
|
|
28
46
|
newSplit.defaultTreatment = defaultTreatment;
|
|
29
47
|
newSplit.changeNumber = changeNumber;
|
|
30
|
-
return _this.addSplit(
|
|
48
|
+
return _this.addSplit(newSplit);
|
|
31
49
|
}
|
|
32
50
|
return false;
|
|
33
51
|
}).catch(function () { return false; });
|
|
@@ -7,13 +7,11 @@ import { IN_SEGMENT, IN_LARGE_SEGMENT } from '../utils/constants';
|
|
|
7
7
|
var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
8
8
|
function AbstractSplitsCacheSync() {
|
|
9
9
|
}
|
|
10
|
-
AbstractSplitsCacheSync.prototype.
|
|
10
|
+
AbstractSplitsCacheSync.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
11
11
|
var _this = this;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _this = this;
|
|
16
|
-
return names.map(function (name) { return _this.removeSplit(name); });
|
|
12
|
+
this.setChangeNumber(changeNumber);
|
|
13
|
+
var updated = toAdd.map(function (addedFF) { return _this.addSplit(addedFF); }).some(function (result) { return result; });
|
|
14
|
+
return toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }).some(function (result) { return result; }) || updated;
|
|
17
15
|
};
|
|
18
16
|
AbstractSplitsCacheSync.prototype.getSplits = function (names) {
|
|
19
17
|
var _this = this;
|
|
@@ -27,6 +25,13 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
27
25
|
var _this = this;
|
|
28
26
|
return this.getSplitNames().map(function (key) { return _this.getSplit(key); });
|
|
29
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Check if the splits information is already stored in cache. This data can be preloaded.
|
|
30
|
+
* It is used as condition to emit SDK_SPLITS_CACHE_LOADED, and then SDK_READY_FROM_CACHE.
|
|
31
|
+
*/
|
|
32
|
+
AbstractSplitsCacheSync.prototype.checkCache = function () {
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
30
35
|
/**
|
|
31
36
|
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
32
37
|
* Used for SPLIT_KILL push notifications.
|
|
@@ -41,7 +46,7 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
41
46
|
newSplit.killed = true;
|
|
42
47
|
newSplit.defaultTreatment = defaultTreatment;
|
|
43
48
|
newSplit.changeNumber = changeNumber;
|
|
44
|
-
return this.addSplit(
|
|
49
|
+
return this.addSplit(newSplit);
|
|
45
50
|
}
|
|
46
51
|
return false;
|
|
47
52
|
};
|
|
@@ -52,8 +57,8 @@ export { AbstractSplitsCacheSync };
|
|
|
52
57
|
* Given a parsed split, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).
|
|
53
58
|
* This util is intended to simplify the implementation of `splitsCache::usesSegments` method
|
|
54
59
|
*/
|
|
55
|
-
export function usesSegments(
|
|
56
|
-
var conditions =
|
|
60
|
+
export function usesSegments(ruleEntity) {
|
|
61
|
+
var conditions = ruleEntity.conditions || [];
|
|
57
62
|
for (var i = 0; i < conditions.length; i++) {
|
|
58
63
|
var matchers = conditions[i].matcherGroup.matchers;
|
|
59
64
|
for (var j = 0; j < matchers.length; j++) {
|
|
@@ -62,5 +67,8 @@ export function usesSegments(split) {
|
|
|
62
67
|
return true;
|
|
63
68
|
}
|
|
64
69
|
}
|
|
70
|
+
var excluded = ruleEntity.excluded;
|
|
71
|
+
if (excluded && excluded.segments && excluded.segments.length > 0)
|
|
72
|
+
return true;
|
|
65
73
|
return false;
|
|
66
74
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { startsWith } from '../utils/lang';
|
|
2
1
|
import { hash } from '../utils/murmur3/murmur3';
|
|
3
2
|
var everythingAtTheEnd = /[^.]+$/;
|
|
4
3
|
var DEFAULT_PREFIX = 'SPLITIO';
|
|
@@ -22,19 +21,17 @@ var KeyBuilder = /** @class */ (function () {
|
|
|
22
21
|
KeyBuilder.prototype.buildSplitsTillKey = function () {
|
|
23
22
|
return this.prefix + ".splits.till";
|
|
24
23
|
};
|
|
25
|
-
// NOT USED
|
|
26
|
-
// buildSplitsReady() {
|
|
27
|
-
// return `${this.prefix}.splits.ready`;
|
|
28
|
-
// }
|
|
29
|
-
KeyBuilder.prototype.isSplitKey = function (key) {
|
|
30
|
-
return startsWith(key, this.prefix + ".split.");
|
|
31
|
-
};
|
|
32
24
|
KeyBuilder.prototype.buildSplitKeyPrefix = function () {
|
|
33
25
|
return this.prefix + ".split.";
|
|
34
26
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
KeyBuilder.prototype.buildRBSegmentKey = function (rbsegmentName) {
|
|
28
|
+
return this.prefix + ".rbsegment." + rbsegmentName;
|
|
29
|
+
};
|
|
30
|
+
KeyBuilder.prototype.buildRBSegmentsTillKey = function () {
|
|
31
|
+
return this.prefix + ".rbsegments.till";
|
|
32
|
+
};
|
|
33
|
+
KeyBuilder.prototype.buildRBSegmentKeyPrefix = function () {
|
|
34
|
+
return this.prefix + ".rbsegment.";
|
|
38
35
|
};
|
|
39
36
|
KeyBuilder.prototype.buildSegmentNameKey = function (segmentName) {
|
|
40
37
|
return this.prefix + ".segment." + segmentName;
|
|
@@ -42,10 +39,6 @@ var KeyBuilder = /** @class */ (function () {
|
|
|
42
39
|
KeyBuilder.prototype.buildSegmentTillKey = function (segmentName) {
|
|
43
40
|
return this.prefix + ".segment." + segmentName + ".till";
|
|
44
41
|
};
|
|
45
|
-
// NOT USED
|
|
46
|
-
// buildSegmentsReady() {
|
|
47
|
-
// return `${this.prefix}.segments.ready`;
|
|
48
|
-
// }
|
|
49
42
|
KeyBuilder.prototype.extractKey = function (builtKey) {
|
|
50
43
|
var s = builtKey.match(everythingAtTheEnd);
|
|
51
44
|
if (s && s.length) {
|
|
@@ -6,7 +6,7 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
6
6
|
function KeyBuilderCS(prefix, matchingKey) {
|
|
7
7
|
var _this = _super.call(this, prefix) || this;
|
|
8
8
|
_this.matchingKey = matchingKey;
|
|
9
|
-
_this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.(splits?|trafficType|flagSet)\\.");
|
|
9
|
+
_this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.(splits?|trafficType|flagSet|rbsegment)\\.");
|
|
10
10
|
return _this;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -18,7 +18,7 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
18
18
|
KeyBuilderCS.prototype.extractSegmentName = function (builtSegmentKeyName) {
|
|
19
19
|
var prefix = this.prefix + "." + this.matchingKey + ".segment.";
|
|
20
20
|
if (startsWith(builtSegmentKeyName, prefix))
|
|
21
|
-
return builtSegmentKeyName.
|
|
21
|
+
return builtSegmentKeyName.slice(prefix.length);
|
|
22
22
|
};
|
|
23
23
|
KeyBuilderCS.prototype.buildLastUpdatedKey = function () {
|
|
24
24
|
return this.prefix + ".splits.lastUpdated";
|
|
@@ -29,8 +29,14 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
29
29
|
KeyBuilderCS.prototype.buildTillKey = function () {
|
|
30
30
|
return this.prefix + "." + this.matchingKey + ".segments.till";
|
|
31
31
|
};
|
|
32
|
-
KeyBuilderCS.prototype.
|
|
33
|
-
return this.prefix + ".
|
|
32
|
+
KeyBuilderCS.prototype.isSplitKey = function (key) {
|
|
33
|
+
return startsWith(key, this.prefix + ".split.");
|
|
34
|
+
};
|
|
35
|
+
KeyBuilderCS.prototype.isRBSegmentKey = function (key) {
|
|
36
|
+
return startsWith(key, this.prefix + ".rbsegment.");
|
|
37
|
+
};
|
|
38
|
+
KeyBuilderCS.prototype.buildSplitsWithSegmentCountKey = function () {
|
|
39
|
+
return this.prefix + ".splits.usingSegments";
|
|
34
40
|
};
|
|
35
41
|
return KeyBuilderCS;
|
|
36
42
|
}(KeyBuilder));
|
|
@@ -43,7 +49,7 @@ export function myLargeSegmentsKeyBuilder(prefix, matchingKey) {
|
|
|
43
49
|
extractSegmentName: function (builtSegmentKeyName) {
|
|
44
50
|
var p = prefix + "." + matchingKey + ".largeSegment.";
|
|
45
51
|
if (startsWith(builtSegmentKeyName, p))
|
|
46
|
-
return builtSegmentKeyName.
|
|
52
|
+
return builtSegmentKeyName.slice(p.length);
|
|
47
53
|
},
|
|
48
54
|
buildTillKey: function () {
|
|
49
55
|
return prefix + "." + matchingKey + ".largeSegments.till";
|
|
@@ -39,6 +39,9 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
39
39
|
KeyBuilderSS.prototype.searchPatternForSplitKeys = function () {
|
|
40
40
|
return this.buildSplitKeyPrefix() + "*";
|
|
41
41
|
};
|
|
42
|
+
KeyBuilderSS.prototype.searchPatternForRBSegmentKeys = function () {
|
|
43
|
+
return this.buildRBSegmentKeyPrefix() + "*";
|
|
44
|
+
};
|
|
42
45
|
/* Telemetry keys */
|
|
43
46
|
KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
|
|
44
47
|
return this.latencyPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method] + "/" + bucket;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var DEFAULT_CACHE_EXPIRATION_IN_MILLIS = 864000000; // 10 days
|
|
1
|
+
import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../utils/constants/browser';
|
|
3
2
|
/**
|
|
4
3
|
* Factory of client-side storage loader
|
|
5
4
|
*
|
|
@@ -30,9 +29,8 @@ export function dataLoaderFactory(preloadedData) {
|
|
|
30
29
|
return;
|
|
31
30
|
// cleaning up the localStorage data, since some cached splits might need be part of the preloaded data
|
|
32
31
|
storage.splits.clear();
|
|
33
|
-
storage.splits.setChangeNumber(since);
|
|
34
32
|
// splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
|
|
35
|
-
storage.splits.
|
|
33
|
+
storage.splits.update(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }), [], since);
|
|
36
34
|
// add mySegments data
|
|
37
35
|
var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userId];
|
|
38
36
|
if (!mySegmentsData) {
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { isFiniteNumber, isNaNNumber, toNumber } from '../../utils/lang';
|
|
2
|
+
import { setToArray } from '../../utils/lang/sets';
|
|
3
|
+
import { usesSegments } from '../AbstractSplitsCacheSync';
|
|
4
|
+
import { LOG_PREFIX } from './constants';
|
|
5
|
+
var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
6
|
+
function RBSegmentsCacheInLocal(settings, keys) {
|
|
7
|
+
this.keys = keys;
|
|
8
|
+
this.log = settings.log;
|
|
9
|
+
}
|
|
10
|
+
RBSegmentsCacheInLocal.prototype.clear = function () {
|
|
11
|
+
var _this = this;
|
|
12
|
+
this.getNames().forEach(function (name) { return _this.remove(name); });
|
|
13
|
+
localStorage.removeItem(this.keys.buildRBSegmentsTillKey());
|
|
14
|
+
};
|
|
15
|
+
RBSegmentsCacheInLocal.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
16
|
+
var _this = this;
|
|
17
|
+
this.setChangeNumber(changeNumber);
|
|
18
|
+
var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
|
|
19
|
+
return toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
|
|
20
|
+
};
|
|
21
|
+
RBSegmentsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
22
|
+
try {
|
|
23
|
+
localStorage.setItem(this.keys.buildRBSegmentsTillKey(), changeNumber + '');
|
|
24
|
+
localStorage.setItem(this.keys.buildLastUpdatedKey(), Date.now() + '');
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
this.log.error(LOG_PREFIX + e);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
RBSegmentsCacheInLocal.prototype.updateSegmentCount = function (diff) {
|
|
31
|
+
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
32
|
+
var count = toNumber(localStorage.getItem(segmentsCountKey)) + diff;
|
|
33
|
+
// @ts-expect-error
|
|
34
|
+
if (count > 0)
|
|
35
|
+
localStorage.setItem(segmentsCountKey, count);
|
|
36
|
+
else
|
|
37
|
+
localStorage.removeItem(segmentsCountKey);
|
|
38
|
+
};
|
|
39
|
+
RBSegmentsCacheInLocal.prototype.add = function (rbSegment) {
|
|
40
|
+
try {
|
|
41
|
+
var name_1 = rbSegment.name;
|
|
42
|
+
var rbSegmentKey = this.keys.buildRBSegmentKey(name_1);
|
|
43
|
+
var rbSegmentFromLocalStorage = localStorage.getItem(rbSegmentKey);
|
|
44
|
+
var previous = rbSegmentFromLocalStorage ? JSON.parse(rbSegmentFromLocalStorage) : null;
|
|
45
|
+
localStorage.setItem(rbSegmentKey, JSON.stringify(rbSegment));
|
|
46
|
+
var usesSegmentsDiff = 0;
|
|
47
|
+
if (previous && usesSegments(previous))
|
|
48
|
+
usesSegmentsDiff--;
|
|
49
|
+
if (usesSegments(rbSegment))
|
|
50
|
+
usesSegmentsDiff++;
|
|
51
|
+
if (usesSegmentsDiff !== 0)
|
|
52
|
+
this.updateSegmentCount(usesSegmentsDiff);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
this.log.error(LOG_PREFIX + e);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
RBSegmentsCacheInLocal.prototype.remove = function (name) {
|
|
61
|
+
try {
|
|
62
|
+
var rbSegment = this.get(name);
|
|
63
|
+
if (!rbSegment)
|
|
64
|
+
return false;
|
|
65
|
+
localStorage.removeItem(this.keys.buildRBSegmentKey(name));
|
|
66
|
+
if (usesSegments(rbSegment))
|
|
67
|
+
this.updateSegmentCount(-1);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
this.log.error(LOG_PREFIX + e);
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
RBSegmentsCacheInLocal.prototype.getNames = function () {
|
|
76
|
+
var len = localStorage.length;
|
|
77
|
+
var accum = [];
|
|
78
|
+
var cur = 0;
|
|
79
|
+
while (cur < len) {
|
|
80
|
+
var key = localStorage.key(cur);
|
|
81
|
+
if (key != null && this.keys.isRBSegmentKey(key))
|
|
82
|
+
accum.push(this.keys.extractKey(key));
|
|
83
|
+
cur++;
|
|
84
|
+
}
|
|
85
|
+
return accum;
|
|
86
|
+
};
|
|
87
|
+
RBSegmentsCacheInLocal.prototype.get = function (name) {
|
|
88
|
+
var item = localStorage.getItem(this.keys.buildRBSegmentKey(name));
|
|
89
|
+
return item && JSON.parse(item);
|
|
90
|
+
};
|
|
91
|
+
RBSegmentsCacheInLocal.prototype.contains = function (names) {
|
|
92
|
+
var namesArray = setToArray(names);
|
|
93
|
+
var namesInStorage = this.getNames();
|
|
94
|
+
return namesArray.every(function (name) { return namesInStorage.indexOf(name) !== -1; });
|
|
95
|
+
};
|
|
96
|
+
RBSegmentsCacheInLocal.prototype.getChangeNumber = function () {
|
|
97
|
+
var n = -1;
|
|
98
|
+
var value = localStorage.getItem(this.keys.buildRBSegmentsTillKey());
|
|
99
|
+
if (value !== null) {
|
|
100
|
+
value = parseInt(value, 10);
|
|
101
|
+
return isNaNNumber(value) ? n : value;
|
|
102
|
+
}
|
|
103
|
+
return n;
|
|
104
|
+
};
|
|
105
|
+
RBSegmentsCacheInLocal.prototype.usesSegments = function () {
|
|
106
|
+
var storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
107
|
+
var splitsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
|
|
108
|
+
return isFiniteNumber(splitsWithSegmentsCount) ?
|
|
109
|
+
splitsWithSegmentsCount > 0 :
|
|
110
|
+
true;
|
|
111
|
+
};
|
|
112
|
+
return RBSegmentsCacheInLocal;
|
|
113
|
+
}());
|
|
114
|
+
export { RBSegmentsCacheInLocal };
|
|
@@ -2,17 +2,21 @@ import { __extends } from "tslib";
|
|
|
2
2
|
import { AbstractSplitsCacheSync, usesSegments } from '../AbstractSplitsCacheSync';
|
|
3
3
|
import { isFiniteNumber, toNumber, isNaNNumber } from '../../utils/lang';
|
|
4
4
|
import { LOG_PREFIX } from './constants';
|
|
5
|
+
import { getStorageHash } from '../KeyBuilder';
|
|
5
6
|
import { setToArray } from '../../utils/lang/sets';
|
|
6
7
|
/**
|
|
7
8
|
* ISplitsCacheSync implementation that stores split definitions in browser LocalStorage.
|
|
8
9
|
*/
|
|
9
10
|
var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
10
11
|
__extends(SplitsCacheInLocal, _super);
|
|
11
|
-
function SplitsCacheInLocal(settings, keys) {
|
|
12
|
+
function SplitsCacheInLocal(settings, keys, expirationTimestamp) {
|
|
12
13
|
var _this = _super.call(this) || this;
|
|
13
14
|
_this.keys = keys;
|
|
14
15
|
_this.log = settings.log;
|
|
16
|
+
_this.storageHash = getStorageHash(settings);
|
|
15
17
|
_this.flagSetsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
|
|
18
|
+
_this._checkExpiration(expirationTimestamp);
|
|
19
|
+
_this._checkFilterQuery();
|
|
16
20
|
return _this;
|
|
17
21
|
}
|
|
18
22
|
SplitsCacheInLocal.prototype._decrementCount = function (key) {
|
|
@@ -40,15 +44,13 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
40
44
|
};
|
|
41
45
|
SplitsCacheInLocal.prototype._incrementCounts = function (split) {
|
|
42
46
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
48
|
+
// @ts-expect-error
|
|
49
|
+
localStorage.setItem(ttKey, toNumber(localStorage.getItem(ttKey)) + 1);
|
|
50
|
+
if (usesSegments(split)) {
|
|
51
|
+
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
45
52
|
// @ts-expect-error
|
|
46
|
-
localStorage.setItem(
|
|
47
|
-
if (usesSegments(split)) {
|
|
48
|
-
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
49
|
-
// @ts-expect-error
|
|
50
|
-
localStorage.setItem(segmentsCountKey, toNumber(localStorage.getItem(segmentsCountKey)) + 1);
|
|
51
|
-
}
|
|
53
|
+
localStorage.setItem(segmentsCountKey, toNumber(localStorage.getItem(segmentsCountKey)) + 1);
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
catch (e) {
|
|
@@ -60,6 +62,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
60
62
|
* We cannot simply call `localStorage.clear()` since that implies removing user items from the storage.
|
|
61
63
|
*/
|
|
62
64
|
SplitsCacheInLocal.prototype.clear = function () {
|
|
65
|
+
this.log.info(LOG_PREFIX + 'Flushing Splits data from localStorage');
|
|
63
66
|
// collect item keys
|
|
64
67
|
var len = localStorage.length;
|
|
65
68
|
var accum = [];
|
|
@@ -74,9 +77,10 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
74
77
|
});
|
|
75
78
|
this.hasSync = false;
|
|
76
79
|
};
|
|
77
|
-
SplitsCacheInLocal.prototype.addSplit = function (
|
|
80
|
+
SplitsCacheInLocal.prototype.addSplit = function (split) {
|
|
78
81
|
try {
|
|
79
|
-
var
|
|
82
|
+
var name_1 = split.name;
|
|
83
|
+
var splitKey = this.keys.buildSplitKey(name_1);
|
|
80
84
|
var splitFromLocalStorage = localStorage.getItem(splitKey);
|
|
81
85
|
var previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
|
|
82
86
|
localStorage.setItem(splitKey, JSON.stringify(split));
|
|
@@ -95,6 +99,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
95
99
|
SplitsCacheInLocal.prototype.removeSplit = function (name) {
|
|
96
100
|
try {
|
|
97
101
|
var split = this.getSplit(name);
|
|
102
|
+
if (!split)
|
|
103
|
+
return false;
|
|
98
104
|
localStorage.removeItem(this.keys.buildSplitKey(name));
|
|
99
105
|
this._decrementCounts(split);
|
|
100
106
|
if (split)
|
|
@@ -111,6 +117,18 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
111
117
|
return item && JSON.parse(item);
|
|
112
118
|
};
|
|
113
119
|
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
120
|
+
// when using a new split query, we must update it at the store
|
|
121
|
+
if (this.updateNewFilter) {
|
|
122
|
+
this.log.info(LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version was modified. Updating cache');
|
|
123
|
+
var storageHashKey = this.keys.buildHashKey();
|
|
124
|
+
try {
|
|
125
|
+
localStorage.setItem(storageHashKey, this.storageHash);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
this.log.error(LOG_PREFIX + e);
|
|
129
|
+
}
|
|
130
|
+
this.updateNewFilter = false;
|
|
131
|
+
}
|
|
114
132
|
try {
|
|
115
133
|
localStorage.setItem(this.keys.buildSplitsTillKey(), changeNumber + '');
|
|
116
134
|
// update "last updated" timestamp with current time
|
|
@@ -154,12 +172,48 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
154
172
|
return true;
|
|
155
173
|
var storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
156
174
|
var splitsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
|
|
157
|
-
|
|
158
|
-
|
|
175
|
+
return isFiniteNumber(splitsWithSegmentsCount) ?
|
|
176
|
+
splitsWithSegmentsCount > 0 :
|
|
177
|
+
true;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Check if the splits information is already stored in browser LocalStorage.
|
|
181
|
+
* In this function we could add more code to check if the data is valid.
|
|
182
|
+
* @override
|
|
183
|
+
*/
|
|
184
|
+
SplitsCacheInLocal.prototype.checkCache = function () {
|
|
185
|
+
return this.getChangeNumber() > -1;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Clean Splits cache if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
|
|
189
|
+
*
|
|
190
|
+
* @param expirationTimestamp - if the value is not a number, data will not be cleaned
|
|
191
|
+
*/
|
|
192
|
+
SplitsCacheInLocal.prototype._checkExpiration = function (expirationTimestamp) {
|
|
193
|
+
var value = localStorage.getItem(this.keys.buildLastUpdatedKey());
|
|
194
|
+
if (value !== null) {
|
|
195
|
+
value = parseInt(value, 10);
|
|
196
|
+
if (!isNaNNumber(value) && expirationTimestamp && value < expirationTimestamp)
|
|
197
|
+
this.clear();
|
|
159
198
|
}
|
|
160
|
-
|
|
161
|
-
|
|
199
|
+
};
|
|
200
|
+
// @TODO eventually remove `_checkFilterQuery`. Cache should be cleared at the storage level, reusing same logic than PluggableStorage
|
|
201
|
+
SplitsCacheInLocal.prototype._checkFilterQuery = function () {
|
|
202
|
+
var storageHashKey = this.keys.buildHashKey();
|
|
203
|
+
var storageHash = localStorage.getItem(storageHashKey);
|
|
204
|
+
if (storageHash !== this.storageHash) {
|
|
205
|
+
try {
|
|
206
|
+
// mark cache to update the new query filter on first successful splits fetch
|
|
207
|
+
this.updateNewFilter = true;
|
|
208
|
+
// if there is cache, clear it
|
|
209
|
+
if (this.checkCache())
|
|
210
|
+
this.clear();
|
|
211
|
+
}
|
|
212
|
+
catch (e) {
|
|
213
|
+
this.log.error(LOG_PREFIX + e);
|
|
214
|
+
}
|
|
162
215
|
}
|
|
216
|
+
// if the filter didn't change, nothing is done
|
|
163
217
|
};
|
|
164
218
|
SplitsCacheInLocal.prototype.getNamesByFlagSets = function (flagSets) {
|
|
165
219
|
var _this = this;
|
|
@@ -6,13 +6,14 @@ import { KeyBuilderCS, myLargeSegmentsKeyBuilder } from '../KeyBuilderCS';
|
|
|
6
6
|
import { isLocalStorageAvailable } from '../../utils/env/isLocalStorageAvailable';
|
|
7
7
|
import { SplitsCacheInLocal } from './SplitsCacheInLocal';
|
|
8
8
|
import { MySegmentsCacheInLocal } from './MySegmentsCacheInLocal';
|
|
9
|
+
import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../../utils/constants/browser';
|
|
9
10
|
import { InMemoryStorageCSFactory } from '../inMemory/InMemoryStorageCS';
|
|
10
11
|
import { LOG_PREFIX } from './constants';
|
|
11
12
|
import { STORAGE_LOCALSTORAGE } from '../../utils/constants';
|
|
12
13
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from '../inMemory/TelemetryCacheInMemory';
|
|
13
14
|
import { UniqueKeysCacheInMemoryCS } from '../inMemory/UniqueKeysCacheInMemoryCS';
|
|
14
15
|
import { getMatching } from '../../utils/key';
|
|
15
|
-
import {
|
|
16
|
+
import { RBSegmentsCacheInLocal } from './RBSegmentsCacheInLocal';
|
|
16
17
|
/**
|
|
17
18
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
18
19
|
*/
|
|
@@ -28,11 +29,14 @@ export function InLocalStorage(options) {
|
|
|
28
29
|
var settings = params.settings, _a = params.settings, log = _a.log, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize;
|
|
29
30
|
var matchingKey = getMatching(settings.core.key);
|
|
30
31
|
var keys = new KeyBuilderCS(prefix, matchingKey);
|
|
31
|
-
var
|
|
32
|
+
var expirationTimestamp = Date.now() - DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
33
|
+
var splits = new SplitsCacheInLocal(settings, keys, expirationTimestamp);
|
|
34
|
+
var rbSegments = new RBSegmentsCacheInLocal(settings, keys);
|
|
32
35
|
var segments = new MySegmentsCacheInLocal(log, keys);
|
|
33
36
|
var largeSegments = new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey));
|
|
34
37
|
return {
|
|
35
38
|
splits: splits,
|
|
39
|
+
rbSegments: rbSegments,
|
|
36
40
|
segments: segments,
|
|
37
41
|
largeSegments: largeSegments,
|
|
38
42
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
@@ -40,14 +44,12 @@ export function InLocalStorage(options) {
|
|
|
40
44
|
events: new EventsCacheInMemory(eventsQueueSize),
|
|
41
45
|
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(splits, segments) : undefined,
|
|
42
46
|
uniqueKeys: new UniqueKeysCacheInMemoryCS(),
|
|
43
|
-
validateCache: function () {
|
|
44
|
-
return validateCache(options, settings, keys, splits, segments, largeSegments);
|
|
45
|
-
},
|
|
46
47
|
destroy: function () { },
|
|
47
48
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are customer per key).
|
|
48
49
|
shared: function (matchingKey) {
|
|
49
50
|
return {
|
|
50
51
|
splits: this.splits,
|
|
52
|
+
rbSegments: this.rbSegments,
|
|
51
53
|
segments: new MySegmentsCacheInLocal(log, new KeyBuilderCS(prefix, matchingKey)),
|
|
52
54
|
largeSegments: new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey)),
|
|
53
55
|
impressions: this.impressions,
|
|
@@ -6,6 +6,7 @@ import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
|
6
6
|
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
8
|
import { UniqueKeysCacheInMemory } from './UniqueKeysCacheInMemory';
|
|
9
|
+
import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
|
|
9
10
|
/**
|
|
10
11
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
11
12
|
*
|
|
@@ -14,9 +15,11 @@ import { UniqueKeysCacheInMemory } from './UniqueKeysCacheInMemory';
|
|
|
14
15
|
export function InMemoryStorageFactory(params) {
|
|
15
16
|
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
16
17
|
var splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
18
|
+
var rbSegments = new RBSegmentsCacheInMemory();
|
|
17
19
|
var segments = new SegmentsCacheInMemory();
|
|
18
20
|
var storage = {
|
|
19
21
|
splits: splits,
|
|
22
|
+
rbSegments: rbSegments,
|
|
20
23
|
segments: segments,
|
|
21
24
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
22
25
|
impressionCounts: new ImpressionCountsCacheInMemory(),
|
|
@@ -6,6 +6,7 @@ import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
|
6
6
|
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
8
|
import { UniqueKeysCacheInMemoryCS } from './UniqueKeysCacheInMemoryCS';
|
|
9
|
+
import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
|
|
9
10
|
/**
|
|
10
11
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
11
12
|
*
|
|
@@ -14,10 +15,12 @@ import { UniqueKeysCacheInMemoryCS } from './UniqueKeysCacheInMemoryCS';
|
|
|
14
15
|
export function InMemoryStorageCSFactory(params) {
|
|
15
16
|
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
16
17
|
var splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
18
|
+
var rbSegments = new RBSegmentsCacheInMemory();
|
|
17
19
|
var segments = new MySegmentsCacheInMemory();
|
|
18
20
|
var largeSegments = new MySegmentsCacheInMemory();
|
|
19
21
|
var storage = {
|
|
20
22
|
splits: splits,
|
|
23
|
+
rbSegments: rbSegments,
|
|
21
24
|
segments: segments,
|
|
22
25
|
largeSegments: largeSegments,
|
|
23
26
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
@@ -30,6 +33,7 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
30
33
|
shared: function () {
|
|
31
34
|
return {
|
|
32
35
|
splits: this.splits,
|
|
36
|
+
rbSegments: this.rbSegments,
|
|
33
37
|
segments: new MySegmentsCacheInMemory(),
|
|
34
38
|
largeSegments: new MySegmentsCacheInMemory(),
|
|
35
39
|
impressions: this.impressions,
|