@splitsoftware/splitio-commons 3.1.1-rc.10 → 3.1.1-rc.11
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 -0
- package/cjs/evaluator/condition/index.js +2 -2
- package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/cjs/evaluator/index.js +81 -71
- package/cjs/listeners/browser.js +2 -1
- package/cjs/listeners/node.js +4 -4
- package/cjs/logger/constants.js +15 -20
- package/cjs/logger/messages/debug.js +5 -6
- package/cjs/logger/messages/error.js +3 -3
- package/cjs/logger/messages/info.js +3 -4
- package/cjs/logger/messages/warn.js +6 -7
- package/cjs/platform/browser.js +15 -0
- package/cjs/platform/getEventSource/browser.js +8 -0
- package/cjs/platform/getEventSource/eventsource.js +480 -0
- package/cjs/platform/getEventSource/node.js +26 -0
- package/cjs/platform/getFetch/browser.js +9 -0
- package/cjs/platform/getFetch/node.js +27 -0
- package/cjs/platform/getOptions/node.js +25 -0
- package/cjs/platform/node.js +17 -0
- package/cjs/presets/serverSide.js +2 -2
- package/cjs/readiness/constants.js +5 -4
- package/cjs/readiness/readinessManager.js +23 -23
- package/cjs/readiness/sdkReadinessManager.js +1 -17
- package/cjs/sdkClient/client.js +24 -50
- package/cjs/sdkClient/clientInputValidation.js +6 -17
- package/cjs/sdkClient/sdkClient.js +3 -60
- package/cjs/sdkClient/sdkLifecycle.js +74 -0
- package/cjs/sdkClient/trackMethod.js +56 -0
- package/cjs/sdkFactory/index.js +11 -15
- package/cjs/sdkManager/index.js +5 -5
- package/cjs/services/authProvider.js +80 -0
- package/cjs/services/decorateHeaders.js +2 -1
- package/cjs/services/secureSplitHttpClient.js +36 -0
- package/cjs/services/serviceApi.js +147 -0
- package/cjs/services/splitApi.js +24 -10
- package/cjs/services/splitHttpClient.js +3 -5
- package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
- package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
- package/cjs/storages/KeyBuilder.js +6 -6
- package/cjs/storages/KeyBuilderCS.js +5 -5
- package/cjs/storages/KeyBuilderSS.js +2 -2
- package/cjs/storages/getRolloutPlan.js +3 -3
- package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +194 -0
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
- package/cjs/storages/inLocalStorage/index.js +6 -6
- package/cjs/storages/inLocalStorage/validateCache.js +3 -3
- package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +121 -0
- package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +5 -5
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +77 -77
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/index.js +2 -2
- package/cjs/storages/pluggable/DefinitionsCachePluggable.js +212 -0
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/index.js +2 -2
- package/cjs/storages/setRolloutPlan.js +4 -4
- package/cjs/storages/utils.js +1 -0
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +24 -15
- package/cjs/sync/polling/pollingManagerCS.js +86 -81
- package/cjs/sync/polling/pollingManagerSS.js +44 -36
- package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +13 -0
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +66 -69
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
- package/cjs/sync/streaming/AuthClient/index.js +13 -14
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +2 -1
- package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +16 -19
- package/cjs/sync/streaming/constants.js +4 -3
- package/cjs/sync/streaming/parseUtils.js +11 -11
- package/cjs/sync/streaming/pushManager.js +20 -25
- package/cjs/sync/submitters/eventsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionsSubmitter.js +5 -4
- package/cjs/sync/submitters/telemetrySubmitter.js +3 -4
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/cjs/sync/syncManagerOnline.js +5 -5
- package/cjs/utils/Backoff.js +35 -3
- package/cjs/utils/EventEmitter.js +391 -0
- package/cjs/utils/filter/bloomFilter.js +37 -0
- package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
- package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
- package/cjs/utils/inputValidation/definitions.js +25 -0
- package/cjs/utils/inputValidation/index.js +7 -7
- package/cjs/utils/inputValidation/isOperational.js +4 -4
- package/cjs/utils/inputValidation/target.js +22 -0
- package/cjs/utils/labels/index.js +3 -3
- package/cjs/utils/settingsValidation/index.js +2 -0
- package/cjs/utils/settingsValidation/splitFilters.js +3 -3
- package/cjs/utils/settingsValidation/url.js +6 -2
- package/esm/evaluator/condition/index.js +2 -2
- package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/esm/evaluator/index.js +80 -71
- package/esm/listeners/browser.js +2 -1
- package/esm/listeners/node.js +4 -4
- package/esm/logger/constants.js +12 -17
- package/esm/logger/messages/debug.js +5 -6
- package/esm/logger/messages/error.js +3 -3
- package/esm/logger/messages/info.js +3 -4
- package/esm/logger/messages/warn.js +6 -7
- package/esm/platform/browser.js +12 -0
- package/esm/platform/getEventSource/browser.js +4 -0
- package/esm/platform/getEventSource/eventsource.js +480 -0
- package/esm/platform/getEventSource/node.js +20 -0
- package/esm/platform/getFetch/browser.js +5 -0
- package/esm/platform/getFetch/node.js +22 -0
- package/esm/platform/getOptions/node.js +20 -0
- package/esm/platform/node.js +14 -0
- package/esm/presets/serverSide.js +2 -2
- package/esm/readiness/constants.js +4 -3
- package/esm/readiness/readinessManager.js +24 -24
- package/esm/readiness/sdkReadinessManager.js +2 -18
- package/esm/sdkClient/client.js +23 -50
- package/esm/sdkClient/clientInputValidation.js +8 -19
- package/esm/sdkClient/sdkClient.js +3 -60
- package/esm/sdkClient/sdkLifecycle.js +70 -0
- package/esm/sdkClient/trackMethod.js +52 -0
- package/esm/sdkFactory/index.js +12 -16
- package/esm/sdkManager/index.js +6 -6
- package/esm/services/authProvider.js +76 -0
- package/esm/services/decorateHeaders.js +2 -1
- package/esm/services/secureSplitHttpClient.js +32 -0
- package/esm/services/serviceApi.js +143 -0
- package/esm/services/splitApi.js +24 -10
- package/esm/services/splitHttpClient.js +3 -5
- package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
- package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
- package/esm/storages/KeyBuilder.js +6 -6
- package/esm/storages/KeyBuilderCS.js +5 -5
- package/esm/storages/KeyBuilderSS.js +2 -2
- package/esm/storages/getRolloutPlan.js +3 -3
- package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +191 -0
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
- package/esm/storages/inLocalStorage/index.js +6 -6
- package/esm/storages/inLocalStorage/validateCache.js +3 -3
- package/esm/storages/inMemory/DefinitionsCacheInMemory.js +118 -0
- package/esm/storages/inMemory/InMemoryStorage.js +4 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -2
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/esm/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +76 -76
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/index.js +2 -2
- package/esm/storages/pluggable/DefinitionsCachePluggable.js +209 -0
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/storages/setRolloutPlan.js +4 -4
- package/esm/storages/utils.js +1 -0
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +25 -16
- package/esm/sync/polling/pollingManagerCS.js +87 -82
- package/esm/sync/polling/pollingManagerSS.js +44 -36
- package/esm/sync/polling/syncTasks/definitionsSyncTask.js +9 -0
- package/esm/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
- package/esm/sync/polling/updaters/definitionChangesUpdater.js +191 -0
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
- package/esm/sync/streaming/AuthClient/index.js +11 -11
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
- package/esm/sync/streaming/SSEHandler/index.js +3 -2
- package/esm/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +15 -18
- package/esm/sync/streaming/constants.js +3 -2
- package/esm/sync/streaming/parseUtils.js +9 -9
- package/esm/sync/streaming/pushManager.js +22 -27
- package/esm/sync/submitters/eventsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionsSubmitter.js +5 -4
- package/esm/sync/submitters/telemetrySubmitter.js +3 -4
- package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/esm/sync/syncManagerOnline.js +4 -4
- package/esm/utils/Backoff.js +35 -3
- package/esm/utils/EventEmitter.js +387 -0
- package/esm/utils/filter/bloomFilter.js +33 -0
- package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
- package/esm/utils/inputValidation/definitionExistence.js +15 -0
- package/esm/utils/inputValidation/definitions.js +21 -0
- package/esm/utils/inputValidation/index.js +3 -3
- package/esm/utils/inputValidation/isOperational.js +4 -4
- package/esm/utils/inputValidation/target.js +18 -0
- package/esm/utils/labels/index.js +2 -2
- package/esm/utils/settingsValidation/index.js +2 -0
- package/esm/utils/settingsValidation/splitFilters.js +3 -3
- package/esm/utils/settingsValidation/url.js +6 -2
- package/package.json +1 -1
- package/cjs/storages/AbstractSplitsCacheAsync.js +0 -51
- package/cjs/storages/AbstractSplitsCacheSync.js +0 -76
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -194
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -121
- package/cjs/storages/pluggable/SplitsCachePluggable.js +0 -212
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
- package/cjs/utils/inputValidation/splits.js +0 -25
- package/esm/storages/AbstractSplitsCacheAsync.js +0 -48
- package/esm/storages/AbstractSplitsCacheSync.js +0 -71
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -191
- package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -118
- package/esm/storages/pluggable/SplitsCachePluggable.js +0 -209
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
- package/esm/sync/polling/updaters/splitChangesUpdater.js +0 -194
- package/esm/utils/inputValidation/splitExistence.js +0 -15
- package/esm/utils/inputValidation/splits.js +0 -21
|
@@ -36,8 +36,8 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
36
36
|
KeyBuilderSS.prototype.buildEventsKey = function () {
|
|
37
37
|
return "".concat(this.prefix, ".events");
|
|
38
38
|
};
|
|
39
|
-
KeyBuilderSS.prototype.
|
|
40
|
-
return "".concat(this.
|
|
39
|
+
KeyBuilderSS.prototype.searchPatternForDefinitionKeys = function () {
|
|
40
|
+
return "".concat(this.buildDefinitionKeyPrefix(), "*");
|
|
41
41
|
};
|
|
42
42
|
KeyBuilderSS.prototype.searchPatternForRBSegmentKeys = function () {
|
|
43
43
|
return "".concat(this.buildRBSegmentKeyPrefix(), "*");
|
|
@@ -6,14 +6,14 @@ import { getMatching } from '../utils/key';
|
|
|
6
6
|
export function getRolloutPlan(log, storage, options) {
|
|
7
7
|
if (options === void 0) { options = {}; }
|
|
8
8
|
var keys = options.keys, exposeSegments = options.exposeSegments;
|
|
9
|
-
var
|
|
9
|
+
var definitions = storage.definitions, segments = storage.segments, rbSegments = storage.rbSegments;
|
|
10
10
|
log.debug("storage: get feature flags".concat(keys ? ", and memberships for keys: ".concat(keys) : '').concat(exposeSegments ? ', and segments' : ''));
|
|
11
11
|
return {
|
|
12
12
|
splitChanges: {
|
|
13
13
|
ff: {
|
|
14
|
-
t:
|
|
14
|
+
t: definitions.getChangeNumber(),
|
|
15
15
|
s: -1,
|
|
16
|
-
d:
|
|
16
|
+
d: definitions.getAll(),
|
|
17
17
|
},
|
|
18
18
|
rbs: {
|
|
19
19
|
t: rbSegments.getChangeNumber(),
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { AbstractDefinitionsCacheSync, usesSegments } from '../AbstractDefinitionsCacheSync';
|
|
3
|
+
import { isFiniteNumber, toNumber, isNaNNumber } from '../../utils/lang';
|
|
4
|
+
import { LOG_PREFIX } from './constants';
|
|
5
|
+
import { setToArray } from '../../utils/lang/sets';
|
|
6
|
+
var DefinitionsCacheInLocal = /** @class */ (function (_super) {
|
|
7
|
+
__extends(DefinitionsCacheInLocal, _super);
|
|
8
|
+
function DefinitionsCacheInLocal(settings, keys, storage) {
|
|
9
|
+
var _this = _super.call(this) || this;
|
|
10
|
+
_this.keys = keys;
|
|
11
|
+
_this.log = settings.log;
|
|
12
|
+
_this.setsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
|
|
13
|
+
_this.storage = storage;
|
|
14
|
+
return _this;
|
|
15
|
+
}
|
|
16
|
+
DefinitionsCacheInLocal.prototype._decrementCount = function (key) {
|
|
17
|
+
var count = toNumber(this.storage.getItem(key)) - 1;
|
|
18
|
+
if (count > 0)
|
|
19
|
+
this.storage.setItem(key, count + '');
|
|
20
|
+
else
|
|
21
|
+
this.storage.removeItem(key);
|
|
22
|
+
};
|
|
23
|
+
DefinitionsCacheInLocal.prototype._decrementCounts = function (definition) {
|
|
24
|
+
try {
|
|
25
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
26
|
+
this._decrementCount(ttKey);
|
|
27
|
+
if (usesSegments(definition)) {
|
|
28
|
+
var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
|
|
29
|
+
this._decrementCount(segmentsCountKey);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
this.log.error(LOG_PREFIX + e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
DefinitionsCacheInLocal.prototype._incrementCounts = function (definition) {
|
|
37
|
+
try {
|
|
38
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
39
|
+
this.storage.setItem(ttKey, (toNumber(this.storage.getItem(ttKey)) + 1) + '');
|
|
40
|
+
if (usesSegments(definition)) {
|
|
41
|
+
var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
|
|
42
|
+
this.storage.setItem(segmentsCountKey, (toNumber(this.storage.getItem(segmentsCountKey)) + 1) + '');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
this.log.error(LOG_PREFIX + e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Removes all definitions related data from localStorage (splits, counters, changeNumber and lastUpdated).
|
|
51
|
+
* We cannot simply call `localStorage.clear()` since that implies removing user items from the storage.
|
|
52
|
+
*/
|
|
53
|
+
DefinitionsCacheInLocal.prototype.clear = function () {
|
|
54
|
+
var _this = this;
|
|
55
|
+
// collect item keys
|
|
56
|
+
var len = this.storage.length;
|
|
57
|
+
var accum = [];
|
|
58
|
+
for (var cur = 0; cur < len; cur++) {
|
|
59
|
+
var key = this.storage.key(cur);
|
|
60
|
+
if (key != null && this.keys.isDefinitionsCacheKey(key))
|
|
61
|
+
accum.push(key);
|
|
62
|
+
}
|
|
63
|
+
// remove items
|
|
64
|
+
accum.forEach(function (key) {
|
|
65
|
+
_this.storage.removeItem(key);
|
|
66
|
+
});
|
|
67
|
+
this.hasSync = false;
|
|
68
|
+
};
|
|
69
|
+
DefinitionsCacheInLocal.prototype.add = function (definition) {
|
|
70
|
+
var name = definition.name;
|
|
71
|
+
var definitionKey = this.keys.buildDefinitionKey(name);
|
|
72
|
+
var definitionFromStorage = this.storage.getItem(definitionKey);
|
|
73
|
+
var previousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : null;
|
|
74
|
+
if (previousDefinition) {
|
|
75
|
+
this._decrementCounts(previousDefinition);
|
|
76
|
+
this.removeFromSets(previousDefinition.name, previousDefinition.sets);
|
|
77
|
+
}
|
|
78
|
+
this.storage.setItem(definitionKey, JSON.stringify(definition));
|
|
79
|
+
this._incrementCounts(definition);
|
|
80
|
+
this.addToSets(definition);
|
|
81
|
+
return true;
|
|
82
|
+
};
|
|
83
|
+
DefinitionsCacheInLocal.prototype.remove = function (name) {
|
|
84
|
+
var definition = this.get(name);
|
|
85
|
+
if (!definition)
|
|
86
|
+
return false;
|
|
87
|
+
this.storage.removeItem(this.keys.buildDefinitionKey(name));
|
|
88
|
+
this._decrementCounts(definition);
|
|
89
|
+
this.removeFromSets(definition.name, definition.sets);
|
|
90
|
+
return true;
|
|
91
|
+
};
|
|
92
|
+
DefinitionsCacheInLocal.prototype.get = function (name) {
|
|
93
|
+
var item = this.storage.getItem(this.keys.buildDefinitionKey(name));
|
|
94
|
+
return item && JSON.parse(item);
|
|
95
|
+
};
|
|
96
|
+
DefinitionsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
97
|
+
try {
|
|
98
|
+
this.storage.setItem(this.keys.buildDefinitionsTillKey(), changeNumber + '');
|
|
99
|
+
// update "last updated" timestamp with current time
|
|
100
|
+
this.storage.setItem(this.keys.buildLastUpdatedKey(), Date.now() + '');
|
|
101
|
+
this.hasSync = true;
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
this.log.error(LOG_PREFIX + e);
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
DefinitionsCacheInLocal.prototype.getChangeNumber = function () {
|
|
110
|
+
var n = -1;
|
|
111
|
+
var value = this.storage.getItem(this.keys.buildDefinitionsTillKey());
|
|
112
|
+
if (value !== null) {
|
|
113
|
+
value = parseInt(value, 10);
|
|
114
|
+
return isNaNNumber(value) ? n : value;
|
|
115
|
+
}
|
|
116
|
+
return n;
|
|
117
|
+
};
|
|
118
|
+
DefinitionsCacheInLocal.prototype.getNames = function () {
|
|
119
|
+
var len = this.storage.length;
|
|
120
|
+
var accum = [];
|
|
121
|
+
var cur = 0;
|
|
122
|
+
while (cur < len) {
|
|
123
|
+
var key = this.storage.key(cur);
|
|
124
|
+
if (key != null && this.keys.isDefinitionKey(key))
|
|
125
|
+
accum.push(this.keys.extractKey(key));
|
|
126
|
+
cur++;
|
|
127
|
+
}
|
|
128
|
+
return accum;
|
|
129
|
+
};
|
|
130
|
+
DefinitionsCacheInLocal.prototype.trafficTypeExists = function (trafficType) {
|
|
131
|
+
var ttCount = toNumber(this.storage.getItem(this.keys.buildTrafficTypeKey(trafficType)));
|
|
132
|
+
return isFiniteNumber(ttCount) && ttCount > 0;
|
|
133
|
+
};
|
|
134
|
+
DefinitionsCacheInLocal.prototype.usesSegments = function () {
|
|
135
|
+
// If cache hasn't been synchronized with the cloud, assume we need them.
|
|
136
|
+
if (!this.hasSync)
|
|
137
|
+
return true;
|
|
138
|
+
var storedCount = this.storage.getItem(this.keys.buildDefinitionsWithSegmentCountKey());
|
|
139
|
+
var definitionsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
|
|
140
|
+
return isFiniteNumber(definitionsWithSegmentsCount) ?
|
|
141
|
+
definitionsWithSegmentsCount > 0 :
|
|
142
|
+
true;
|
|
143
|
+
};
|
|
144
|
+
DefinitionsCacheInLocal.prototype.getNamesBySets = function (sets) {
|
|
145
|
+
var _this = this;
|
|
146
|
+
return sets.map(function (set) {
|
|
147
|
+
var setKey = _this.keys.buildSetKey(set);
|
|
148
|
+
var setFromStorage = _this.storage.getItem(setKey);
|
|
149
|
+
return new Set(setFromStorage ? JSON.parse(setFromStorage) : []);
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
DefinitionsCacheInLocal.prototype.addToSets = function (definition) {
|
|
153
|
+
var _this = this;
|
|
154
|
+
if (!definition.sets)
|
|
155
|
+
return;
|
|
156
|
+
definition.sets.forEach(function (set) {
|
|
157
|
+
if (_this.setsFilter.length > 0 && !_this.setsFilter.some(function (filterSet) { return filterSet === set; }))
|
|
158
|
+
return;
|
|
159
|
+
var setKey = _this.keys.buildSetKey(set);
|
|
160
|
+
var setFromStorage = _this.storage.getItem(setKey);
|
|
161
|
+
var setCache = new Set(setFromStorage ? JSON.parse(setFromStorage) : []);
|
|
162
|
+
if (setCache.has(definition.name))
|
|
163
|
+
return;
|
|
164
|
+
setCache.add(definition.name);
|
|
165
|
+
_this.storage.setItem(setKey, JSON.stringify(setToArray(setCache)));
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
DefinitionsCacheInLocal.prototype.removeFromSets = function (definitionName, sets) {
|
|
169
|
+
var _this = this;
|
|
170
|
+
if (!sets)
|
|
171
|
+
return;
|
|
172
|
+
sets.forEach(function (set) {
|
|
173
|
+
_this.removeNames(set, definitionName);
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
DefinitionsCacheInLocal.prototype.removeNames = function (setName, definitionName) {
|
|
177
|
+
var setKey = this.keys.buildSetKey(setName);
|
|
178
|
+
var setFromStorage = this.storage.getItem(setKey);
|
|
179
|
+
if (!setFromStorage)
|
|
180
|
+
return;
|
|
181
|
+
var setCache = new Set(JSON.parse(setFromStorage));
|
|
182
|
+
setCache.delete(definitionName);
|
|
183
|
+
if (setCache.size === 0) {
|
|
184
|
+
this.storage.removeItem(setKey);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
this.storage.setItem(setKey, JSON.stringify(setToArray(setCache)));
|
|
188
|
+
};
|
|
189
|
+
return DefinitionsCacheInLocal;
|
|
190
|
+
}(AbstractDefinitionsCacheSync));
|
|
191
|
+
export { DefinitionsCacheInLocal };
|
|
@@ -4,9 +4,8 @@ import { AbstractMySegmentsCacheSync } from '../AbstractMySegmentsCacheSync';
|
|
|
4
4
|
import { DEFINED } from './constants';
|
|
5
5
|
var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
6
6
|
__extends(MySegmentsCacheInLocal, _super);
|
|
7
|
-
function MySegmentsCacheInLocal(
|
|
7
|
+
function MySegmentsCacheInLocal(_log, keys, storage) {
|
|
8
8
|
var _this = _super.call(this) || this;
|
|
9
|
-
_this.log = log;
|
|
10
9
|
_this.keys = keys;
|
|
11
10
|
_this.storage = storage;
|
|
12
11
|
return _this;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isFiniteNumber, isNaNNumber, toNumber } from '../../utils/lang';
|
|
2
2
|
import { setToArray } from '../../utils/lang/sets';
|
|
3
|
-
import { usesSegments } from '../
|
|
3
|
+
import { usesSegments } from '../AbstractDefinitionsCacheSync';
|
|
4
4
|
import { LOG_PREFIX } from './constants';
|
|
5
5
|
var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
6
6
|
function RBSegmentsCacheInLocal(settings, keys, storage) {
|
|
@@ -16,7 +16,7 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
|
16
16
|
RBSegmentsCacheInLocal.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
17
17
|
var _this = this;
|
|
18
18
|
var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
|
|
19
|
-
updated = toRemove.map(function (toRemove) { return _this.remove(toRemove
|
|
19
|
+
updated = toRemove.map(function (toRemove) { return _this.remove(toRemove); }).some(function (result) { return result; }) || updated;
|
|
20
20
|
this.setChangeNumber(changeNumber);
|
|
21
21
|
return updated;
|
|
22
22
|
};
|
|
@@ -30,7 +30,7 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
RBSegmentsCacheInLocal.prototype.updateSegmentCount = function (diff) {
|
|
33
|
-
var segmentsCountKey = this.keys.
|
|
33
|
+
var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
|
|
34
34
|
var count = toNumber(this.storage.getItem(segmentsCountKey)) + diff;
|
|
35
35
|
if (count > 0)
|
|
36
36
|
this.storage.setItem(segmentsCountKey, count + '');
|
|
@@ -96,10 +96,10 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
|
96
96
|
return n;
|
|
97
97
|
};
|
|
98
98
|
RBSegmentsCacheInLocal.prototype.usesSegments = function () {
|
|
99
|
-
var storedCount = this.storage.getItem(this.keys.
|
|
100
|
-
var
|
|
101
|
-
return isFiniteNumber(
|
|
102
|
-
|
|
99
|
+
var storedCount = this.storage.getItem(this.keys.buildDefinitionsWithSegmentCountKey());
|
|
100
|
+
var definitionsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
|
|
101
|
+
return isFiniteNumber(definitionsWithSegmentsCount) ?
|
|
102
|
+
definitionsWithSegmentsCount > 0 :
|
|
103
103
|
true;
|
|
104
104
|
};
|
|
105
105
|
return RBSegmentsCacheInLocal;
|
|
@@ -4,7 +4,7 @@ import { EventsCacheInMemory } from '../inMemory/EventsCacheInMemory';
|
|
|
4
4
|
import { validatePrefix } from '../KeyBuilder';
|
|
5
5
|
import { KeyBuilderCS, myLargeSegmentsKeyBuilder } from '../KeyBuilderCS';
|
|
6
6
|
import { isLocalStorageAvailable, isValidStorageWrapper, isWebStorage } from '../../utils/env/isLocalStorageAvailable';
|
|
7
|
-
import {
|
|
7
|
+
import { DefinitionsCacheInLocal } from './DefinitionsCacheInLocal';
|
|
8
8
|
import { RBSegmentsCacheInLocal } from './RBSegmentsCacheInLocal';
|
|
9
9
|
import { MySegmentsCacheInLocal } from './MySegmentsCacheInLocal';
|
|
10
10
|
import { InMemoryStorageCSFactory } from '../inMemory/InMemoryStorageCS';
|
|
@@ -41,24 +41,24 @@ export function InLocalStorage(options) {
|
|
|
41
41
|
return InMemoryStorageCSFactory(params);
|
|
42
42
|
var matchingKey = getMatching(settings.core.key);
|
|
43
43
|
var keys = new KeyBuilderCS(prefix, matchingKey);
|
|
44
|
-
var
|
|
44
|
+
var definitions = new DefinitionsCacheInLocal(settings, keys, storage);
|
|
45
45
|
var rbSegments = new RBSegmentsCacheInLocal(settings, keys, storage);
|
|
46
46
|
var segments = new MySegmentsCacheInLocal(log, keys, storage);
|
|
47
47
|
var largeSegments = new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey), storage);
|
|
48
48
|
var validateCachePromise;
|
|
49
49
|
return {
|
|
50
|
-
|
|
50
|
+
definitions: definitions,
|
|
51
51
|
rbSegments: rbSegments,
|
|
52
52
|
segments: segments,
|
|
53
53
|
largeSegments: largeSegments,
|
|
54
54
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
55
55
|
impressionCounts: new ImpressionCountsCacheInMemory(),
|
|
56
56
|
events: new EventsCacheInMemory(eventsQueueSize),
|
|
57
|
-
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(
|
|
57
|
+
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(definitions, segments) : undefined,
|
|
58
58
|
uniqueKeys: new UniqueKeysCacheInMemoryCS(),
|
|
59
59
|
validateCache: function () {
|
|
60
60
|
if (!validateCachePromise) {
|
|
61
|
-
validateCachePromise = validateCache(options, storage, settings, keys,
|
|
61
|
+
validateCachePromise = validateCache(options, storage, settings, keys, definitions, rbSegments, segments, largeSegments);
|
|
62
62
|
}
|
|
63
63
|
return validateCachePromise;
|
|
64
64
|
},
|
|
@@ -71,7 +71,7 @@ export function InLocalStorage(options) {
|
|
|
71
71
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are customer per key).
|
|
72
72
|
shared: function (matchingKey) {
|
|
73
73
|
return {
|
|
74
|
-
|
|
74
|
+
definitions: this.definitions,
|
|
75
75
|
rbSegments: this.rbSegments,
|
|
76
76
|
segments: new MySegmentsCacheInLocal(log, new KeyBuilderCS(prefix, matchingKey), storage),
|
|
77
77
|
largeSegments: new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey), storage),
|
|
@@ -54,16 +54,16 @@ function validateExpiration(options, storage, settings, keys, currentTimestamp,
|
|
|
54
54
|
*
|
|
55
55
|
* @returns Metadata object with `initialCacheLoad` (true if is fresh install, false if is ready from cache) and `lastUpdateTimestamp` (timestamp of last cache update or undefined)
|
|
56
56
|
*/
|
|
57
|
-
export function validateCache(options, storage, settings, keys,
|
|
57
|
+
export function validateCache(options, storage, settings, keys, definitions, rbSegments, segments, largeSegments) {
|
|
58
58
|
return Promise.resolve(storage.load && storage.load()).then(function () {
|
|
59
59
|
var currentTimestamp = Date.now();
|
|
60
|
-
var isThereCache =
|
|
60
|
+
var isThereCache = definitions.getChangeNumber() > -1;
|
|
61
61
|
// Get lastUpdateTimestamp from storage
|
|
62
62
|
var lastUpdatedTimestampStr = storage.getItem(keys.buildLastUpdatedKey());
|
|
63
63
|
var lastUpdatedTimestamp = lastUpdatedTimestampStr ? parseInt(lastUpdatedTimestampStr, 10) : undefined;
|
|
64
64
|
var lastUpdateTimestamp = (!isNaNNumber(lastUpdatedTimestamp) && lastUpdatedTimestamp !== undefined) ? lastUpdatedTimestamp : undefined;
|
|
65
65
|
if (validateExpiration(options, storage, settings, keys, currentTimestamp, isThereCache)) {
|
|
66
|
-
|
|
66
|
+
definitions.clear();
|
|
67
67
|
rbSegments.clear();
|
|
68
68
|
segments.clear();
|
|
69
69
|
largeSegments.clear();
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { AbstractDefinitionsCacheSync, usesSegments } from '../AbstractDefinitionsCacheSync';
|
|
3
|
+
import { isFiniteNumber } from '../../utils/lang';
|
|
4
|
+
/**
|
|
5
|
+
* Default IDefinitionsCacheSync implementation that stores split definitions in memory.
|
|
6
|
+
*/
|
|
7
|
+
var DefinitionsCacheInMemory = /** @class */ (function (_super) {
|
|
8
|
+
__extends(DefinitionsCacheInMemory, _super);
|
|
9
|
+
function DefinitionsCacheInMemory(splitFiltersValidation) {
|
|
10
|
+
var _this = _super.call(this) || this;
|
|
11
|
+
_this.definitionsCache = {};
|
|
12
|
+
_this.ttCache = {};
|
|
13
|
+
_this.changeNumber = -1;
|
|
14
|
+
_this.segmentsCount = 0;
|
|
15
|
+
_this.setsCache = {};
|
|
16
|
+
_this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
17
|
+
return _this;
|
|
18
|
+
}
|
|
19
|
+
DefinitionsCacheInMemory.prototype.clear = function () {
|
|
20
|
+
this.definitionsCache = {};
|
|
21
|
+
this.ttCache = {};
|
|
22
|
+
this.changeNumber = -1;
|
|
23
|
+
this.segmentsCount = 0;
|
|
24
|
+
this.setsCache = {};
|
|
25
|
+
};
|
|
26
|
+
DefinitionsCacheInMemory.prototype.add = function (definition) {
|
|
27
|
+
var name = definition.name;
|
|
28
|
+
var previousDefinition = this.get(name);
|
|
29
|
+
if (previousDefinition) { // We had this Split already
|
|
30
|
+
var previousTtName = previousDefinition.trafficTypeName;
|
|
31
|
+
this.ttCache[previousTtName]--;
|
|
32
|
+
if (!this.ttCache[previousTtName])
|
|
33
|
+
delete this.ttCache[previousTtName];
|
|
34
|
+
this.removeFromFlagSets(previousDefinition.name, previousDefinition.sets);
|
|
35
|
+
// Subtract from segments count for the previous version of this Split
|
|
36
|
+
if (usesSegments(previousDefinition))
|
|
37
|
+
this.segmentsCount--;
|
|
38
|
+
}
|
|
39
|
+
// Store the Split.
|
|
40
|
+
this.definitionsCache[name] = definition;
|
|
41
|
+
// Update TT cache
|
|
42
|
+
var ttName = definition.trafficTypeName;
|
|
43
|
+
this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
|
|
44
|
+
this.addToFlagSets(definition);
|
|
45
|
+
// Add to segments count for the new version of the Split
|
|
46
|
+
if (usesSegments(definition))
|
|
47
|
+
this.segmentsCount++;
|
|
48
|
+
return true;
|
|
49
|
+
};
|
|
50
|
+
DefinitionsCacheInMemory.prototype.remove = function (name) {
|
|
51
|
+
var definition = this.get(name);
|
|
52
|
+
if (!definition)
|
|
53
|
+
return false;
|
|
54
|
+
// Delete the Split
|
|
55
|
+
delete this.definitionsCache[name];
|
|
56
|
+
var ttName = definition.trafficTypeName;
|
|
57
|
+
this.ttCache[ttName]--; // Update tt cache
|
|
58
|
+
if (!this.ttCache[ttName])
|
|
59
|
+
delete this.ttCache[ttName];
|
|
60
|
+
this.removeFromFlagSets(definition.name, definition.sets);
|
|
61
|
+
// Update the segments count.
|
|
62
|
+
if (usesSegments(definition))
|
|
63
|
+
this.segmentsCount--;
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
DefinitionsCacheInMemory.prototype.get = function (name) {
|
|
67
|
+
return this.definitionsCache[name] || null;
|
|
68
|
+
};
|
|
69
|
+
DefinitionsCacheInMemory.prototype.setChangeNumber = function (changeNumber) {
|
|
70
|
+
this.changeNumber = changeNumber;
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
DefinitionsCacheInMemory.prototype.getChangeNumber = function () {
|
|
74
|
+
return this.changeNumber;
|
|
75
|
+
};
|
|
76
|
+
DefinitionsCacheInMemory.prototype.getNames = function () {
|
|
77
|
+
return Object.keys(this.definitionsCache);
|
|
78
|
+
};
|
|
79
|
+
DefinitionsCacheInMemory.prototype.trafficTypeExists = function (trafficType) {
|
|
80
|
+
return isFiniteNumber(this.ttCache[trafficType]) && this.ttCache[trafficType] > 0;
|
|
81
|
+
};
|
|
82
|
+
DefinitionsCacheInMemory.prototype.usesSegments = function () {
|
|
83
|
+
return this.getChangeNumber() === -1 || this.segmentsCount > 0;
|
|
84
|
+
};
|
|
85
|
+
DefinitionsCacheInMemory.prototype.getNamesBySets = function (sets) {
|
|
86
|
+
var _this = this;
|
|
87
|
+
return sets.map(function (set) { return _this.setsCache[set] || new Set(); });
|
|
88
|
+
};
|
|
89
|
+
DefinitionsCacheInMemory.prototype.addToFlagSets = function (featureFlag) {
|
|
90
|
+
var _this = this;
|
|
91
|
+
if (!featureFlag.sets)
|
|
92
|
+
return;
|
|
93
|
+
featureFlag.sets.forEach(function (featureFlagSet) {
|
|
94
|
+
if (_this.setsFilter.length > 0 && !_this.setsFilter.some(function (filterFlagSet) { return filterFlagSet === featureFlagSet; }))
|
|
95
|
+
return;
|
|
96
|
+
if (!_this.setsCache[featureFlagSet])
|
|
97
|
+
_this.setsCache[featureFlagSet] = new Set([]);
|
|
98
|
+
_this.setsCache[featureFlagSet].add(featureFlag.name);
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
DefinitionsCacheInMemory.prototype.removeFromFlagSets = function (featureFlagName, sets) {
|
|
102
|
+
var _this = this;
|
|
103
|
+
if (!sets)
|
|
104
|
+
return;
|
|
105
|
+
sets.forEach(function (set) {
|
|
106
|
+
_this.removeNames(set, featureFlagName);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
DefinitionsCacheInMemory.prototype.removeNames = function (setName, featureFlagName) {
|
|
110
|
+
if (!this.setsCache[setName])
|
|
111
|
+
return;
|
|
112
|
+
this.setsCache[setName].delete(featureFlagName);
|
|
113
|
+
if (this.setsCache[setName].size === 0)
|
|
114
|
+
delete this.setsCache[setName];
|
|
115
|
+
};
|
|
116
|
+
return DefinitionsCacheInMemory;
|
|
117
|
+
}(AbstractDefinitionsCacheSync));
|
|
118
|
+
export { DefinitionsCacheInMemory };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DefinitionsCacheInMemory } from './DefinitionsCacheInMemory';
|
|
2
2
|
import { SegmentsCacheInMemory } from './SegmentsCacheInMemory';
|
|
3
3
|
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
|
|
4
4
|
import { EventsCacheInMemory } from './EventsCacheInMemory';
|
|
@@ -14,17 +14,17 @@ import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
|
|
|
14
14
|
*/
|
|
15
15
|
export function InMemoryStorageFactory(params) {
|
|
16
16
|
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
17
|
-
var
|
|
17
|
+
var definitions = new DefinitionsCacheInMemory(__splitFiltersValidation);
|
|
18
18
|
var rbSegments = new RBSegmentsCacheInMemory();
|
|
19
19
|
var segments = new SegmentsCacheInMemory();
|
|
20
20
|
var storage = {
|
|
21
|
-
|
|
21
|
+
definitions: definitions,
|
|
22
22
|
rbSegments: rbSegments,
|
|
23
23
|
segments: segments,
|
|
24
24
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
25
25
|
impressionCounts: new ImpressionCountsCacheInMemory(),
|
|
26
26
|
events: new EventsCacheInMemory(eventsQueueSize),
|
|
27
|
-
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(
|
|
27
|
+
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(definitions, segments) : undefined,
|
|
28
28
|
uniqueKeys: new UniqueKeysCacheInMemory(),
|
|
29
29
|
destroy: function () { }
|
|
30
30
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DefinitionsCacheInMemory } from './DefinitionsCacheInMemory';
|
|
2
2
|
import { MySegmentsCacheInMemory } from './MySegmentsCacheInMemory';
|
|
3
3
|
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
|
|
4
4
|
import { EventsCacheInMemory } from './EventsCacheInMemory';
|
|
@@ -14,25 +14,25 @@ import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
|
|
|
14
14
|
*/
|
|
15
15
|
export function InMemoryStorageCSFactory(params) {
|
|
16
16
|
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
17
|
-
var
|
|
17
|
+
var definitions = new DefinitionsCacheInMemory(__splitFiltersValidation);
|
|
18
18
|
var rbSegments = new RBSegmentsCacheInMemory();
|
|
19
19
|
var segments = new MySegmentsCacheInMemory();
|
|
20
20
|
var largeSegments = new MySegmentsCacheInMemory();
|
|
21
21
|
var storage = {
|
|
22
|
-
|
|
22
|
+
definitions: definitions,
|
|
23
23
|
rbSegments: rbSegments,
|
|
24
24
|
segments: segments,
|
|
25
25
|
largeSegments: largeSegments,
|
|
26
26
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
27
27
|
impressionCounts: new ImpressionCountsCacheInMemory(),
|
|
28
28
|
events: new EventsCacheInMemory(eventsQueueSize),
|
|
29
|
-
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(
|
|
29
|
+
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(definitions, segments) : undefined,
|
|
30
30
|
uniqueKeys: new UniqueKeysCacheInMemoryCS(),
|
|
31
31
|
destroy: function () { },
|
|
32
32
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are unique per key)
|
|
33
33
|
shared: function () {
|
|
34
34
|
return {
|
|
35
|
-
|
|
35
|
+
definitions: this.definitions,
|
|
36
36
|
rbSegments: this.rbSegments,
|
|
37
37
|
segments: new MySegmentsCacheInMemory(),
|
|
38
38
|
largeSegments: new MySegmentsCacheInMemory(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setToArray } from '../../utils/lang/sets';
|
|
2
|
-
import { usesSegments } from '../
|
|
2
|
+
import { usesSegments } from '../AbstractDefinitionsCacheSync';
|
|
3
3
|
var RBSegmentsCacheInMemory = /** @class */ (function () {
|
|
4
4
|
function RBSegmentsCacheInMemory() {
|
|
5
5
|
this.cache = {};
|
|
@@ -14,7 +14,7 @@ var RBSegmentsCacheInMemory = /** @class */ (function () {
|
|
|
14
14
|
RBSegmentsCacheInMemory.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
15
15
|
var _this = this;
|
|
16
16
|
var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
|
|
17
|
-
updated = toRemove.map(function (toRemove) { return _this.remove(toRemove
|
|
17
|
+
updated = toRemove.map(function (toRemove) { return _this.remove(toRemove); }).some(function (result) { return result; }) || updated;
|
|
18
18
|
this.changeNumber = changeNumber;
|
|
19
19
|
return updated;
|
|
20
20
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isIntegerNumber } from '../../utils/lang';
|
|
2
2
|
/**
|
|
3
|
-
* Default
|
|
3
|
+
* Default IDefinitionsCacheSync implementation for server-side that stores segments definitions in memory.
|
|
4
4
|
*/
|
|
5
5
|
var SegmentsCacheInMemory = /** @class */ (function () {
|
|
6
6
|
function SegmentsCacheInMemory() {
|
|
@@ -15,12 +15,12 @@ var ACCEPTANCE_RANGE = 0.001;
|
|
|
15
15
|
* All factory instances track telemetry on server-side, and 0.1% on client-side.
|
|
16
16
|
*/
|
|
17
17
|
export function shouldRecordTelemetry(_a) {
|
|
18
|
-
var settings = _a.settings;
|
|
19
|
-
return settings.mode !== LOCALHOST_MODE && (checkIfServerSide(settings) || Math.random() <= ACCEPTANCE_RANGE);
|
|
18
|
+
var settings = _a.settings, disableTelemetry = _a.disableTelemetry;
|
|
19
|
+
return !disableTelemetry && settings.mode !== LOCALHOST_MODE && (checkIfServerSide(settings) || Math.random() <= ACCEPTANCE_RANGE);
|
|
20
20
|
}
|
|
21
21
|
var TelemetryCacheInMemory = /** @class */ (function () {
|
|
22
|
-
function TelemetryCacheInMemory(
|
|
23
|
-
this.
|
|
22
|
+
function TelemetryCacheInMemory(definitions, segments, largeSegments) {
|
|
23
|
+
this.definitions = definitions;
|
|
24
24
|
this.segments = segments;
|
|
25
25
|
this.largeSegments = largeSegments;
|
|
26
26
|
this.name = 'telemetry stats';
|
|
@@ -56,7 +56,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
56
56
|
iQ: this.getImpressionStats(QUEUED),
|
|
57
57
|
iDe: this.getImpressionStats(DEDUPED),
|
|
58
58
|
iDr: this.getImpressionStats(DROPPED),
|
|
59
|
-
spC: this.
|
|
59
|
+
spC: this.definitions && this.definitions.getNames().length,
|
|
60
60
|
seC: this.segments && this.segments.getRegisteredSegments().length,
|
|
61
61
|
skC: this.segments && this.segments.getKeysCount(),
|
|
62
62
|
lsC: this.largeSegments && this.largeSegments.getRegisteredSegments().length,
|