@splitsoftware/splitio-commons 3.1.1-rc.0 → 3.1.1-rc.10
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 +10 -1
- package/cjs/evaluator/condition/index.js +1 -1
- package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +8 -5
- package/cjs/evaluator/index.js +69 -81
- package/cjs/listeners/browser.js +1 -2
- package/cjs/listeners/node.js +4 -4
- package/cjs/logger/constants.js +20 -15
- package/cjs/logger/messages/debug.js +6 -5
- package/cjs/logger/messages/error.js +3 -3
- package/cjs/logger/messages/info.js +4 -3
- package/cjs/logger/messages/warn.js +7 -6
- package/cjs/presets/serverSide.js +2 -2
- package/cjs/readiness/constants.js +4 -5
- package/cjs/readiness/readinessManager.js +23 -23
- package/cjs/readiness/sdkReadinessManager.js +17 -1
- package/cjs/sdkClient/client.js +34 -9
- package/cjs/sdkClient/clientInputValidation.js +17 -6
- package/cjs/sdkClient/sdkClient.js +60 -3
- package/cjs/sdkFactory/index.js +15 -11
- package/cjs/sdkManager/index.js +5 -5
- package/cjs/services/decorateHeaders.js +1 -2
- package/cjs/services/splitApi.js +1 -14
- package/cjs/services/splitHttpClient.js +5 -3
- package/cjs/storages/AbstractSplitsCacheAsync.js +51 -0
- package/cjs/storages/AbstractSplitsCacheSync.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/MySegmentsCacheInLocal.js +2 -1
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +194 -0
- package/cjs/storages/inLocalStorage/index.js +6 -6
- package/cjs/storages/inLocalStorage/validateCache.js +3 -3
- 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/SplitsCacheInMemory.js +121 -0
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RedisAdapter.js +8 -5
- package/cjs/storages/inRedis/{DefinitionsCacheInRedis.js → SplitsCacheInRedis.js} +77 -77
- package/cjs/storages/inRedis/index.js +2 -2
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +212 -0
- package/cjs/storages/pluggable/index.js +2 -2
- package/cjs/storages/setRolloutPlan.js +4 -4
- package/cjs/storages/utils.js +0 -1
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +15 -24
- package/cjs/sync/polling/pollingManagerCS.js +20 -20
- package/cjs/sync/polling/pollingManagerSS.js +15 -15
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +3 -2
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +13 -0
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
- package/cjs/sync/polling/updaters/{definitionChangesUpdater.js → splitChangesUpdater.js} +68 -65
- package/cjs/sync/streaming/AuthClient/index.js +1 -1
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +1 -1
- package/cjs/sync/streaming/UpdateWorkers/{DefinitionsUpdateWorker.js → SplitsUpdateWorker.js} +19 -16
- package/cjs/sync/streaming/constants.js +3 -3
- package/cjs/sync/streaming/parseUtils.js +11 -11
- package/cjs/sync/streaming/pushManager.js +16 -16
- package/cjs/sync/submitters/eventsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionsSubmitter.js +4 -5
- package/cjs/sync/submitters/telemetrySubmitter.js +4 -3
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/cjs/sync/syncManagerOnline.js +7 -12
- package/cjs/utils/Backoff.js +0 -20
- package/cjs/utils/inputValidation/index.js +7 -7
- package/cjs/utils/inputValidation/isOperational.js +4 -4
- package/cjs/utils/inputValidation/{definition.js → split.js} +10 -10
- package/cjs/utils/inputValidation/{definitionExistence.js → splitExistence.js} +6 -6
- package/cjs/utils/inputValidation/splits.js +25 -0
- package/cjs/utils/labels/index.js +3 -3
- package/cjs/utils/settingsValidation/index.js +0 -2
- package/cjs/utils/settingsValidation/splitFilters.js +3 -3
- package/cjs/utils/settingsValidation/url.js +2 -6
- package/esm/evaluator/condition/index.js +1 -1
- package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +8 -5
- package/esm/evaluator/index.js +69 -80
- package/esm/listeners/browser.js +1 -2
- package/esm/listeners/node.js +4 -4
- package/esm/logger/constants.js +17 -12
- package/esm/logger/messages/debug.js +6 -5
- package/esm/logger/messages/error.js +3 -3
- package/esm/logger/messages/info.js +4 -3
- package/esm/logger/messages/warn.js +7 -6
- package/esm/presets/serverSide.js +2 -2
- package/esm/readiness/constants.js +3 -4
- package/esm/readiness/readinessManager.js +24 -24
- package/esm/readiness/sdkReadinessManager.js +18 -2
- package/esm/sdkClient/client.js +35 -9
- package/esm/sdkClient/clientInputValidation.js +19 -8
- package/esm/sdkClient/sdkClient.js +60 -3
- package/esm/sdkFactory/index.js +16 -12
- package/esm/sdkManager/index.js +6 -6
- package/esm/services/decorateHeaders.js +1 -2
- package/esm/services/splitApi.js +1 -14
- package/esm/services/splitHttpClient.js +5 -3
- package/esm/storages/AbstractSplitsCacheAsync.js +48 -0
- package/esm/storages/AbstractSplitsCacheSync.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/MySegmentsCacheInLocal.js +2 -1
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +191 -0
- package/esm/storages/inLocalStorage/index.js +6 -6
- package/esm/storages/inLocalStorage/validateCache.js +3 -3
- 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/SplitsCacheInMemory.js +118 -0
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/RedisAdapter.js +8 -5
- package/esm/storages/inRedis/{DefinitionsCacheInRedis.js → SplitsCacheInRedis.js} +76 -76
- package/esm/storages/inRedis/index.js +2 -2
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/esm/storages/pluggable/SplitsCachePluggable.js +209 -0
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/storages/setRolloutPlan.js +4 -4
- package/esm/storages/utils.js +0 -1
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +16 -25
- package/esm/sync/polling/pollingManagerCS.js +17 -17
- package/esm/sync/polling/pollingManagerSS.js +15 -15
- package/esm/sync/polling/syncTasks/segmentsSyncTask.js +3 -2
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +9 -0
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
- package/esm/sync/polling/updaters/{definitionChangesUpdater.js → splitChangesUpdater.js} +68 -65
- package/esm/sync/streaming/AuthClient/index.js +1 -1
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
- package/esm/sync/streaming/SSEHandler/index.js +2 -2
- package/esm/sync/streaming/UpdateWorkers/{DefinitionsUpdateWorker.js → SplitsUpdateWorker.js} +18 -15
- package/esm/sync/streaming/constants.js +2 -2
- package/esm/sync/streaming/parseUtils.js +9 -9
- package/esm/sync/streaming/pushManager.js +18 -18
- package/esm/sync/submitters/eventsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionsSubmitter.js +4 -5
- package/esm/sync/submitters/telemetrySubmitter.js +4 -3
- package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/esm/sync/syncManagerOnline.js +6 -11
- package/esm/utils/Backoff.js +0 -20
- package/esm/utils/inputValidation/index.js +3 -3
- package/esm/utils/inputValidation/isOperational.js +4 -4
- package/esm/utils/inputValidation/{definition.js → split.js} +8 -8
- package/esm/utils/inputValidation/splitExistence.js +15 -0
- package/esm/utils/inputValidation/splits.js +21 -0
- package/esm/utils/labels/index.js +2 -2
- package/esm/utils/settingsValidation/index.js +0 -2
- package/esm/utils/settingsValidation/splitFilters.js +3 -3
- package/esm/utils/settingsValidation/url.js +2 -6
- package/package.json +6 -7
- package/src/dtos/types.ts +1 -1
- package/src/evaluator/Engine.ts +3 -3
- package/src/evaluator/condition/index.ts +2 -2
- package/src/evaluator/index.ts +27 -35
- package/src/evaluator/types.ts +2 -6
- package/src/presets/serverSide.ts +3 -3
- package/src/sdkClient/client.ts +22 -24
- package/src/sdkClient/sdkLifecycle.ts +3 -0
- package/src/services/authProvider.ts +41 -19
- package/src/services/secureSplitHttpClient.ts +10 -18
- package/src/services/serviceApi.ts +27 -24
- package/src/services/splitApi.ts +10 -9
- package/src/services/types.ts +5 -4
- package/src/storages/inRedis/RedisAdapter.ts +8 -5
- package/src/sync/polling/pollingManagerCS.ts +80 -78
- package/src/sync/polling/pollingManagerSS.ts +49 -45
- package/src/sync/polling/updaters/definitionChangesUpdater.ts +3 -3
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
- package/src/sync/streaming/AuthClient/index.ts +14 -15
- package/src/sync/streaming/AuthClient/types.ts +9 -13
- package/src/sync/streaming/SSEClient/index.ts +2 -2
- package/src/sync/streaming/SSEClient/types.ts +2 -2
- package/src/sync/streaming/SSEHandler/index.ts +2 -1
- package/src/sync/streaming/SSEHandler/types.ts +2 -2
- package/src/sync/streaming/constants.ts +1 -0
- package/src/sync/streaming/pushManager.ts +32 -42
- package/src/sync/streaming/types.ts +3 -2
- package/src/sync/submitters/impressionsSubmitter.ts +3 -3
- package/src/sync/submitters/types.ts +2 -2
- package/src/sync/syncManagerOnline.ts +2 -8
- package/src/utils/Backoff.ts +16 -4
- package/types/splitio.d.ts +5 -4
- package/cjs/platform/browser.js +0 -15
- package/cjs/platform/getEventSource/browser.js +0 -8
- package/cjs/platform/getEventSource/eventsource.js +0 -480
- package/cjs/platform/getEventSource/node.js +0 -26
- package/cjs/platform/getFetch/browser.js +0 -9
- package/cjs/platform/getFetch/node.js +0 -27
- package/cjs/platform/getOptions/node.js +0 -25
- package/cjs/platform/node.js +0 -17
- package/cjs/sdkClient/sdkLifecycle.js +0 -72
- package/cjs/sdkClient/trackMethod.js +0 -56
- package/cjs/services/authProvider.js +0 -67
- package/cjs/services/secureSplitHttpClient.js +0 -39
- package/cjs/services/serviceApi.js +0 -145
- package/cjs/storages/AbstractDefinitionsCacheAsync.js +0 -51
- package/cjs/storages/AbstractDefinitionsCacheSync.js +0 -76
- package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +0 -194
- package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +0 -121
- package/cjs/storages/pluggable/DefinitionsCachePluggable.js +0 -212
- package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +0 -13
- package/cjs/utils/EventEmitter.js +0 -391
- package/cjs/utils/filter/bloomFilter.js +0 -37
- package/cjs/utils/inputValidation/definitions.js +0 -25
- package/cjs/utils/inputValidation/target.js +0 -22
- package/esm/platform/browser.js +0 -12
- package/esm/platform/getEventSource/browser.js +0 -4
- package/esm/platform/getEventSource/eventsource.js +0 -480
- package/esm/platform/getEventSource/node.js +0 -20
- package/esm/platform/getFetch/browser.js +0 -5
- package/esm/platform/getFetch/node.js +0 -22
- package/esm/platform/getOptions/node.js +0 -20
- package/esm/platform/node.js +0 -14
- package/esm/sdkClient/sdkLifecycle.js +0 -68
- package/esm/sdkClient/trackMethod.js +0 -52
- package/esm/services/authProvider.js +0 -63
- package/esm/services/secureSplitHttpClient.js +0 -35
- package/esm/services/serviceApi.js +0 -141
- package/esm/storages/AbstractDefinitionsCacheAsync.js +0 -48
- package/esm/storages/AbstractDefinitionsCacheSync.js +0 -71
- package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +0 -191
- package/esm/storages/inMemory/DefinitionsCacheInMemory.js +0 -118
- package/esm/storages/pluggable/DefinitionsCachePluggable.js +0 -209
- package/esm/sync/polling/syncTasks/definitionsSyncTask.js +0 -9
- package/esm/utils/EventEmitter.js +0 -387
- package/esm/utils/filter/bloomFilter.js +0 -33
- package/esm/utils/inputValidation/definitionExistence.js +0 -15
- package/esm/utils/inputValidation/definitions.js +0 -21
- package/esm/utils/inputValidation/target.js +0 -18
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { AbstractSplitsCacheSync, usesSegments } from '../AbstractSplitsCacheSync';
|
|
3
|
+
import { isFiniteNumber, toNumber, isNaNNumber } from '../../utils/lang';
|
|
4
|
+
import { LOG_PREFIX } from './constants';
|
|
5
|
+
import { setToArray } from '../../utils/lang/sets';
|
|
6
|
+
var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
7
|
+
__extends(SplitsCacheInLocal, _super);
|
|
8
|
+
function SplitsCacheInLocal(settings, keys, storage) {
|
|
9
|
+
var _this = _super.call(this) || this;
|
|
10
|
+
_this.keys = keys;
|
|
11
|
+
_this.log = settings.log;
|
|
12
|
+
_this.flagSetsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
|
|
13
|
+
_this.storage = storage;
|
|
14
|
+
return _this;
|
|
15
|
+
}
|
|
16
|
+
SplitsCacheInLocal.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
|
+
SplitsCacheInLocal.prototype._decrementCounts = function (split) {
|
|
24
|
+
try {
|
|
25
|
+
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
26
|
+
this._decrementCount(ttKey);
|
|
27
|
+
if (usesSegments(split)) {
|
|
28
|
+
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
29
|
+
this._decrementCount(segmentsCountKey);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
this.log.error(LOG_PREFIX + e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
SplitsCacheInLocal.prototype._incrementCounts = function (split) {
|
|
37
|
+
try {
|
|
38
|
+
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
39
|
+
this.storage.setItem(ttKey, (toNumber(this.storage.getItem(ttKey)) + 1) + '');
|
|
40
|
+
if (usesSegments(split)) {
|
|
41
|
+
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
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 splits cache 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
|
+
SplitsCacheInLocal.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.isSplitsCacheKey(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
|
+
SplitsCacheInLocal.prototype.addSplit = function (split) {
|
|
70
|
+
var name = split.name;
|
|
71
|
+
var splitKey = this.keys.buildSplitKey(name);
|
|
72
|
+
var splitFromStorage = this.storage.getItem(splitKey);
|
|
73
|
+
var previousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : null;
|
|
74
|
+
if (previousSplit) {
|
|
75
|
+
this._decrementCounts(previousSplit);
|
|
76
|
+
this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
77
|
+
}
|
|
78
|
+
this.storage.setItem(splitKey, JSON.stringify(split));
|
|
79
|
+
this._incrementCounts(split);
|
|
80
|
+
this.addToFlagSets(split);
|
|
81
|
+
return true;
|
|
82
|
+
};
|
|
83
|
+
SplitsCacheInLocal.prototype.removeSplit = function (name) {
|
|
84
|
+
var split = this.getSplit(name);
|
|
85
|
+
if (!split)
|
|
86
|
+
return false;
|
|
87
|
+
this.storage.removeItem(this.keys.buildSplitKey(name));
|
|
88
|
+
this._decrementCounts(split);
|
|
89
|
+
this.removeFromFlagSets(split.name, split.sets);
|
|
90
|
+
return true;
|
|
91
|
+
};
|
|
92
|
+
SplitsCacheInLocal.prototype.getSplit = function (name) {
|
|
93
|
+
var item = this.storage.getItem(this.keys.buildSplitKey(name));
|
|
94
|
+
return item && JSON.parse(item);
|
|
95
|
+
};
|
|
96
|
+
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
97
|
+
try {
|
|
98
|
+
this.storage.setItem(this.keys.buildSplitsTillKey(), 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
|
+
SplitsCacheInLocal.prototype.getChangeNumber = function () {
|
|
110
|
+
var n = -1;
|
|
111
|
+
var value = this.storage.getItem(this.keys.buildSplitsTillKey());
|
|
112
|
+
if (value !== null) {
|
|
113
|
+
value = parseInt(value, 10);
|
|
114
|
+
return isNaNNumber(value) ? n : value;
|
|
115
|
+
}
|
|
116
|
+
return n;
|
|
117
|
+
};
|
|
118
|
+
SplitsCacheInLocal.prototype.getSplitNames = 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.isSplitKey(key))
|
|
125
|
+
accum.push(this.keys.extractKey(key));
|
|
126
|
+
cur++;
|
|
127
|
+
}
|
|
128
|
+
return accum;
|
|
129
|
+
};
|
|
130
|
+
SplitsCacheInLocal.prototype.trafficTypeExists = function (trafficType) {
|
|
131
|
+
var ttCount = toNumber(this.storage.getItem(this.keys.buildTrafficTypeKey(trafficType)));
|
|
132
|
+
return isFiniteNumber(ttCount) && ttCount > 0;
|
|
133
|
+
};
|
|
134
|
+
SplitsCacheInLocal.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.buildSplitsWithSegmentCountKey());
|
|
139
|
+
var splitsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
|
|
140
|
+
return isFiniteNumber(splitsWithSegmentsCount) ?
|
|
141
|
+
splitsWithSegmentsCount > 0 :
|
|
142
|
+
true;
|
|
143
|
+
};
|
|
144
|
+
SplitsCacheInLocal.prototype.getNamesByFlagSets = function (flagSets) {
|
|
145
|
+
var _this = this;
|
|
146
|
+
return flagSets.map(function (flagSet) {
|
|
147
|
+
var flagSetKey = _this.keys.buildFlagSetKey(flagSet);
|
|
148
|
+
var flagSetFromStorage = _this.storage.getItem(flagSetKey);
|
|
149
|
+
return new Set(flagSetFromStorage ? JSON.parse(flagSetFromStorage) : []);
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
SplitsCacheInLocal.prototype.addToFlagSets = function (featureFlag) {
|
|
153
|
+
var _this = this;
|
|
154
|
+
if (!featureFlag.sets)
|
|
155
|
+
return;
|
|
156
|
+
featureFlag.sets.forEach(function (featureFlagSet) {
|
|
157
|
+
if (_this.flagSetsFilter.length > 0 && !_this.flagSetsFilter.some(function (filterFlagSet) { return filterFlagSet === featureFlagSet; }))
|
|
158
|
+
return;
|
|
159
|
+
var flagSetKey = _this.keys.buildFlagSetKey(featureFlagSet);
|
|
160
|
+
var flagSetFromStorage = _this.storage.getItem(flagSetKey);
|
|
161
|
+
var flagSetCache = new Set(flagSetFromStorage ? JSON.parse(flagSetFromStorage) : []);
|
|
162
|
+
if (flagSetCache.has(featureFlag.name))
|
|
163
|
+
return;
|
|
164
|
+
flagSetCache.add(featureFlag.name);
|
|
165
|
+
_this.storage.setItem(flagSetKey, JSON.stringify(setToArray(flagSetCache)));
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
SplitsCacheInLocal.prototype.removeFromFlagSets = function (featureFlagName, flagSets) {
|
|
169
|
+
var _this = this;
|
|
170
|
+
if (!flagSets)
|
|
171
|
+
return;
|
|
172
|
+
flagSets.forEach(function (flagSet) {
|
|
173
|
+
_this.removeNames(flagSet, featureFlagName);
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
SplitsCacheInLocal.prototype.removeNames = function (flagSetName, featureFlagName) {
|
|
177
|
+
var flagSetKey = this.keys.buildFlagSetKey(flagSetName);
|
|
178
|
+
var flagSetFromStorage = this.storage.getItem(flagSetKey);
|
|
179
|
+
if (!flagSetFromStorage)
|
|
180
|
+
return;
|
|
181
|
+
var flagSetCache = new Set(JSON.parse(flagSetFromStorage));
|
|
182
|
+
flagSetCache.delete(featureFlagName);
|
|
183
|
+
if (flagSetCache.size === 0) {
|
|
184
|
+
this.storage.removeItem(flagSetKey);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
this.storage.setItem(flagSetKey, JSON.stringify(setToArray(flagSetCache)));
|
|
188
|
+
};
|
|
189
|
+
return SplitsCacheInLocal;
|
|
190
|
+
}(AbstractSplitsCacheSync));
|
|
191
|
+
export { SplitsCacheInLocal };
|
|
@@ -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 { SplitsCacheInLocal } from './SplitsCacheInLocal';
|
|
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 splits = new SplitsCacheInLocal(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
|
+
splits: splits,
|
|
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(splits, 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, splits, 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
|
+
splits: this.splits,
|
|
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, splits, 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 = splits.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
|
+
splits.clear();
|
|
67
67
|
rbSegments.clear();
|
|
68
68
|
segments.clear();
|
|
69
69
|
largeSegments.clear();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SplitsCacheInMemory } from './SplitsCacheInMemory';
|
|
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 splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
18
18
|
var rbSegments = new RBSegmentsCacheInMemory();
|
|
19
19
|
var segments = new SegmentsCacheInMemory();
|
|
20
20
|
var storage = {
|
|
21
|
-
|
|
21
|
+
splits: splits,
|
|
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(splits, segments) : undefined,
|
|
28
28
|
uniqueKeys: new UniqueKeysCacheInMemory(),
|
|
29
29
|
destroy: function () { }
|
|
30
30
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SplitsCacheInMemory } from './SplitsCacheInMemory';
|
|
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 splits = new SplitsCacheInMemory(__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
|
+
splits: splits,
|
|
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(splits, 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
|
+
splits: this.splits,
|
|
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 '../AbstractSplitsCacheSync';
|
|
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); }).some(function (result) { return result; }) || updated;
|
|
17
|
+
updated = toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).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 ISplitsCacheSync implementation for server-side that stores segments definitions in memory.
|
|
4
4
|
*/
|
|
5
5
|
var SegmentsCacheInMemory = /** @class */ (function () {
|
|
6
6
|
function SegmentsCacheInMemory() {
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { AbstractSplitsCacheSync, usesSegments } from '../AbstractSplitsCacheSync';
|
|
3
|
+
import { isFiniteNumber } from '../../utils/lang';
|
|
4
|
+
/**
|
|
5
|
+
* Default ISplitsCacheSync implementation that stores split definitions in memory.
|
|
6
|
+
*/
|
|
7
|
+
var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
8
|
+
__extends(SplitsCacheInMemory, _super);
|
|
9
|
+
function SplitsCacheInMemory(splitFiltersValidation) {
|
|
10
|
+
var _this = _super.call(this) || this;
|
|
11
|
+
_this.splitsCache = {};
|
|
12
|
+
_this.ttCache = {};
|
|
13
|
+
_this.changeNumber = -1;
|
|
14
|
+
_this.segmentsCount = 0;
|
|
15
|
+
_this.flagSetsCache = {};
|
|
16
|
+
_this.flagSetsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
17
|
+
return _this;
|
|
18
|
+
}
|
|
19
|
+
SplitsCacheInMemory.prototype.clear = function () {
|
|
20
|
+
this.splitsCache = {};
|
|
21
|
+
this.ttCache = {};
|
|
22
|
+
this.changeNumber = -1;
|
|
23
|
+
this.segmentsCount = 0;
|
|
24
|
+
this.flagSetsCache = {};
|
|
25
|
+
};
|
|
26
|
+
SplitsCacheInMemory.prototype.addSplit = function (split) {
|
|
27
|
+
var name = split.name;
|
|
28
|
+
var previousSplit = this.getSplit(name);
|
|
29
|
+
if (previousSplit) { // We had this Split already
|
|
30
|
+
var previousTtName = previousSplit.trafficTypeName;
|
|
31
|
+
this.ttCache[previousTtName]--;
|
|
32
|
+
if (!this.ttCache[previousTtName])
|
|
33
|
+
delete this.ttCache[previousTtName];
|
|
34
|
+
this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
35
|
+
// Subtract from segments count for the previous version of this Split
|
|
36
|
+
if (usesSegments(previousSplit))
|
|
37
|
+
this.segmentsCount--;
|
|
38
|
+
}
|
|
39
|
+
// Store the Split.
|
|
40
|
+
this.splitsCache[name] = split;
|
|
41
|
+
// Update TT cache
|
|
42
|
+
var ttName = split.trafficTypeName;
|
|
43
|
+
this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
|
|
44
|
+
this.addToFlagSets(split);
|
|
45
|
+
// Add to segments count for the new version of the Split
|
|
46
|
+
if (usesSegments(split))
|
|
47
|
+
this.segmentsCount++;
|
|
48
|
+
return true;
|
|
49
|
+
};
|
|
50
|
+
SplitsCacheInMemory.prototype.removeSplit = function (name) {
|
|
51
|
+
var split = this.getSplit(name);
|
|
52
|
+
if (!split)
|
|
53
|
+
return false;
|
|
54
|
+
// Delete the Split
|
|
55
|
+
delete this.splitsCache[name];
|
|
56
|
+
var ttName = split.trafficTypeName;
|
|
57
|
+
this.ttCache[ttName]--; // Update tt cache
|
|
58
|
+
if (!this.ttCache[ttName])
|
|
59
|
+
delete this.ttCache[ttName];
|
|
60
|
+
this.removeFromFlagSets(split.name, split.sets);
|
|
61
|
+
// Update the segments count.
|
|
62
|
+
if (usesSegments(split))
|
|
63
|
+
this.segmentsCount--;
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
SplitsCacheInMemory.prototype.getSplit = function (name) {
|
|
67
|
+
return this.splitsCache[name] || null;
|
|
68
|
+
};
|
|
69
|
+
SplitsCacheInMemory.prototype.setChangeNumber = function (changeNumber) {
|
|
70
|
+
this.changeNumber = changeNumber;
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
SplitsCacheInMemory.prototype.getChangeNumber = function () {
|
|
74
|
+
return this.changeNumber;
|
|
75
|
+
};
|
|
76
|
+
SplitsCacheInMemory.prototype.getSplitNames = function () {
|
|
77
|
+
return Object.keys(this.splitsCache);
|
|
78
|
+
};
|
|
79
|
+
SplitsCacheInMemory.prototype.trafficTypeExists = function (trafficType) {
|
|
80
|
+
return isFiniteNumber(this.ttCache[trafficType]) && this.ttCache[trafficType] > 0;
|
|
81
|
+
};
|
|
82
|
+
SplitsCacheInMemory.prototype.usesSegments = function () {
|
|
83
|
+
return this.getChangeNumber() === -1 || this.segmentsCount > 0;
|
|
84
|
+
};
|
|
85
|
+
SplitsCacheInMemory.prototype.getNamesByFlagSets = function (flagSets) {
|
|
86
|
+
var _this = this;
|
|
87
|
+
return flagSets.map(function (flagSet) { return _this.flagSetsCache[flagSet] || new Set(); });
|
|
88
|
+
};
|
|
89
|
+
SplitsCacheInMemory.prototype.addToFlagSets = function (featureFlag) {
|
|
90
|
+
var _this = this;
|
|
91
|
+
if (!featureFlag.sets)
|
|
92
|
+
return;
|
|
93
|
+
featureFlag.sets.forEach(function (featureFlagSet) {
|
|
94
|
+
if (_this.flagSetsFilter.length > 0 && !_this.flagSetsFilter.some(function (filterFlagSet) { return filterFlagSet === featureFlagSet; }))
|
|
95
|
+
return;
|
|
96
|
+
if (!_this.flagSetsCache[featureFlagSet])
|
|
97
|
+
_this.flagSetsCache[featureFlagSet] = new Set([]);
|
|
98
|
+
_this.flagSetsCache[featureFlagSet].add(featureFlag.name);
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
SplitsCacheInMemory.prototype.removeFromFlagSets = function (featureFlagName, flagSets) {
|
|
102
|
+
var _this = this;
|
|
103
|
+
if (!flagSets)
|
|
104
|
+
return;
|
|
105
|
+
flagSets.forEach(function (flagSet) {
|
|
106
|
+
_this.removeNames(flagSet, featureFlagName);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
SplitsCacheInMemory.prototype.removeNames = function (flagSetName, featureFlagName) {
|
|
110
|
+
if (!this.flagSetsCache[flagSetName])
|
|
111
|
+
return;
|
|
112
|
+
this.flagSetsCache[flagSetName].delete(featureFlagName);
|
|
113
|
+
if (this.flagSetsCache[flagSetName].size === 0)
|
|
114
|
+
delete this.flagSetsCache[flagSetName];
|
|
115
|
+
};
|
|
116
|
+
return SplitsCacheInMemory;
|
|
117
|
+
}(AbstractSplitsCacheSync));
|
|
118
|
+
export { SplitsCacheInMemory };
|
|
@@ -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
|
|
18
|
+
var settings = _a.settings;
|
|
19
|
+
return 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(splits, segments, largeSegments) {
|
|
23
|
+
this.splits = splits;
|
|
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.splits && this.splits.getSplitNames().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,
|
|
@@ -31,7 +31,7 @@ var RBSegmentsCacheInRedis = /** @class */ (function () {
|
|
|
31
31
|
return _this.redis.set(key, stringifiedNewRBSegment).then(function () { return true; });
|
|
32
32
|
})),
|
|
33
33
|
Promise.all(toRemove.map(function (toRemove) {
|
|
34
|
-
var key = _this.keys.buildRBSegmentKey(toRemove);
|
|
34
|
+
var key = _this.keys.buildRBSegmentKey(toRemove.name);
|
|
35
35
|
return _this.redis.del(key).then(function (status) { return status === 1; });
|
|
36
36
|
}))
|
|
37
37
|
]).then(function (_a) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __spreadArray } from "tslib";
|
|
2
2
|
// Dynamically require ioredis to prevent strict TypeScript binding
|
|
3
|
-
// and handle module export differences between v4 and
|
|
3
|
+
// and handle module export differences between v4 and later major versions.
|
|
4
4
|
var RedisConstructor;
|
|
5
5
|
try {
|
|
6
6
|
var ioredisLib = require('ioredis');
|
|
@@ -8,7 +8,7 @@ try {
|
|
|
8
8
|
}
|
|
9
9
|
catch (e) {
|
|
10
10
|
// If we reach here, the peer dependency is missing
|
|
11
|
-
throw new Error('ioredis is missing. Please install ioredis v4 or
|
|
11
|
+
throw new Error('ioredis is missing. Please install ioredis v4, v5 or v6.');
|
|
12
12
|
}
|
|
13
13
|
import { merge, isString } from '../../utils/lang';
|
|
14
14
|
import { thenable } from '../../utils/promise/thenable';
|
|
@@ -28,13 +28,16 @@ var DEFAULT_LIBRARY_OPTIONS = {
|
|
|
28
28
|
enableOfflineQueue: false,
|
|
29
29
|
connectTimeout: DEFAULT_OPTIONS.connectionTimeout,
|
|
30
30
|
lazyConnect: false,
|
|
31
|
-
// CRITICAL: v5
|
|
32
|
-
// v4 defaulted to 5000. We explicitly set it here to ensure v5
|
|
31
|
+
// CRITICAL: v5 and v6 default this to 0 (disabled), which breaks dynamic clusters.
|
|
32
|
+
// v4 defaulted to 5000. We explicitly set it here to ensure v5 and v6 work like v4.
|
|
33
33
|
slotsRefreshInterval: 5000,
|
|
34
|
+
// v6 defaults to RESP3 (`protocol: 3`). The SDK doesn't use any RESP3 feature,
|
|
35
|
+
// so we stick to RESP2 to keep the v4 and v5 behavior. Ignored by v4 and v5.
|
|
36
|
+
protocol: 2,
|
|
34
37
|
};
|
|
35
38
|
/**
|
|
36
39
|
* Redis adapter on top of the library of choice (written with ioredis) for some extra control.
|
|
37
|
-
* Refactored to use Composition instead of Inheritance to support
|
|
40
|
+
* Refactored to use Composition instead of Inheritance to support v4, v5 and v6.
|
|
38
41
|
*/
|
|
39
42
|
var RedisAdapter = /** @class */ (function () {
|
|
40
43
|
function RedisAdapter(log, storageSettings) {
|