@splitsoftware/splitio-commons 1.6.2-rc.0 → 1.6.2-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 +4 -0
- package/cjs/consent/sdkUserConsent.js +2 -2
- package/cjs/evaluator/index.js +15 -16
- package/cjs/integrations/ga/GaToSplit.js +8 -5
- package/cjs/listeners/browser.js +2 -1
- package/cjs/logger/constants.js +2 -1
- package/cjs/sdkClient/client.js +19 -7
- package/cjs/sdkClient/sdkClient.js +3 -1
- package/cjs/sdkFactory/index.js +24 -7
- package/cjs/sdkManager/index.js +3 -11
- package/cjs/services/splitApi.js +24 -4
- package/cjs/storages/AbstractSplitsCacheAsync.js +8 -10
- package/cjs/storages/AbstractSplitsCacheSync.js +8 -10
- package/cjs/storages/KeyBuilderSS.js +54 -9
- package/cjs/storages/dataLoader.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +5 -7
- package/cjs/storages/inLocalStorage/index.js +5 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +6 -2
- package/cjs/storages/inMemory/InMemoryStorageCS.js +6 -2
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +10 -5
- package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +73 -0
- package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +78 -0
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +50 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +59 -0
- package/cjs/storages/inRedis/constants.js +4 -1
- package/cjs/storages/inRedis/index.js +17 -2
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +43 -0
- package/cjs/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +50 -0
- package/cjs/storages/pluggable/index.js +42 -17
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/cjs/sync/submitters/submitterManager.js +3 -0
- package/cjs/sync/submitters/telemetrySubmitter.js +8 -4
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +27 -0
- package/cjs/trackers/impressionsTracker.js +22 -41
- package/cjs/trackers/strategy/strategyDebug.js +25 -0
- package/cjs/trackers/strategy/strategyNone.js +29 -0
- package/cjs/trackers/strategy/strategyOptimized.js +35 -0
- package/cjs/trackers/telemetryTracker.js +6 -0
- package/cjs/trackers/uniqueKeysTracker.js +38 -0
- package/cjs/utils/constants/index.js +4 -2
- package/cjs/utils/lang/maps.js +15 -7
- package/cjs/utils/redis/RedisMock.js +31 -0
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/evaluator/index.js +15 -16
- package/esm/integrations/ga/GaToSplit.js +8 -5
- package/esm/listeners/browser.js +3 -2
- package/esm/logger/constants.js +1 -0
- package/esm/sdkClient/client.js +19 -7
- package/esm/sdkClient/sdkClient.js +3 -1
- package/esm/sdkFactory/index.js +24 -7
- package/esm/sdkManager/index.js +3 -11
- package/esm/services/splitApi.js +24 -4
- package/esm/storages/AbstractSplitsCacheAsync.js +8 -10
- package/esm/storages/AbstractSplitsCacheSync.js +8 -10
- package/esm/storages/KeyBuilderSS.js +50 -8
- package/esm/storages/dataLoader.js +1 -1
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -7
- package/esm/storages/inLocalStorage/index.js +6 -2
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/esm/storages/inMemory/InMemoryStorage.js +8 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +7 -3
- package/esm/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +9 -5
- package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +70 -0
- package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +75 -0
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +47 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +56 -0
- package/esm/storages/inRedis/constants.js +3 -0
- package/esm/storages/inRedis/index.js +18 -3
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +40 -0
- package/esm/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/esm/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +47 -0
- package/esm/storages/pluggable/index.js +43 -18
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/esm/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/esm/sync/submitters/submitterManager.js +3 -0
- package/esm/sync/submitters/telemetrySubmitter.js +9 -5
- package/esm/sync/submitters/uniqueKeysSubmitter.js +23 -0
- package/esm/trackers/impressionsTracker.js +22 -41
- package/esm/trackers/strategy/strategyDebug.js +21 -0
- package/esm/trackers/strategy/strategyNone.js +25 -0
- package/esm/trackers/strategy/strategyOptimized.js +31 -0
- package/esm/trackers/telemetryTracker.js +6 -0
- package/esm/trackers/uniqueKeysTracker.js +34 -0
- package/esm/utils/constants/index.js +2 -0
- package/esm/utils/lang/maps.js +15 -7
- package/esm/utils/redis/RedisMock.js +28 -0
- package/esm/utils/settingsValidation/impressionsMode.js +3 -3
- package/package.json +1 -2
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/evaluator/index.ts +14 -15
- package/src/integrations/ga/GaToSplit.ts +9 -5
- package/src/integrations/types.ts +2 -1
- package/src/listeners/browser.ts +3 -2
- package/src/logger/constants.ts +1 -0
- package/src/sdkClient/client.ts +21 -8
- package/src/sdkClient/sdkClient.ts +3 -1
- package/src/sdkFactory/index.ts +28 -8
- package/src/sdkFactory/types.ts +7 -4
- package/src/sdkManager/index.ts +3 -12
- package/src/services/splitApi.ts +26 -4
- package/src/services/types.ts +8 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +13 -15
- package/src/storages/AbstractSplitsCacheSync.ts +15 -17
- package/src/storages/KeyBuilderSS.ts +61 -9
- package/src/storages/dataLoader.ts +1 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +8 -11
- package/src/storages/inLocalStorage/index.ts +5 -2
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +16 -1
- package/src/storages/inMemory/InMemoryStorage.ts +7 -4
- package/src/storages/inMemory/InMemoryStorageCS.ts +6 -3
- package/src/storages/inMemory/SplitsCacheInMemory.ts +10 -14
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +10 -6
- package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +82 -0
- package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +88 -0
- package/src/storages/inRedis/EventsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +53 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +21 -17
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +122 -2
- package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +65 -0
- package/src/storages/inRedis/constants.ts +3 -0
- package/src/storages/inRedis/index.ts +15 -5
- package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +47 -0
- package/src/storages/pluggable/SplitsCachePluggable.ts +20 -17
- package/src/storages/pluggable/TelemetryCachePluggable.ts +147 -2
- package/src/storages/pluggable/UniqueKeysCachePluggable.ts +56 -0
- package/src/storages/pluggable/index.ts +44 -19
- package/src/storages/types.ts +50 -29
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
- package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -2
- package/src/sync/submitters/submitterManager.ts +2 -0
- package/src/sync/submitters/telemetrySubmitter.ts +15 -8
- package/src/sync/submitters/types.ts +38 -7
- package/src/sync/submitters/uniqueKeysSubmitter.ts +36 -0
- package/src/trackers/impressionsTracker.ts +27 -48
- package/src/trackers/strategy/strategyDebug.ts +28 -0
- package/src/trackers/strategy/strategyNone.ts +34 -0
- package/src/trackers/strategy/strategyOptimized.ts +42 -0
- package/src/trackers/telemetryTracker.ts +7 -2
- package/src/trackers/types.ts +32 -0
- package/src/trackers/uniqueKeysTracker.ts +48 -0
- package/src/types.ts +1 -1
- package/src/utils/constants/index.ts +2 -0
- package/src/utils/lang/maps.ts +20 -8
- package/src/utils/redis/RedisMock.ts +33 -0
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +1 -0
- package/types/integrations/types.d.ts +2 -1
- package/types/logger/browser/{debugLogger.d.ts → DebugLogger.d.ts} +0 -0
- package/types/logger/browser/{errorLogger.d.ts → ErrorLogger.d.ts} +0 -0
- package/types/logger/browser/{infoLogger.d.ts → InfoLogger.d.ts} +0 -0
- package/types/logger/browser/{warnLogger.d.ts → WarnLogger.d.ts} +0 -0
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkFactory/types.d.ts +4 -2
- package/types/services/types.d.ts +6 -2
- package/types/storages/AbstractSplitsCacheAsync.d.ts +7 -6
- package/types/storages/AbstractSplitsCacheSync.d.ts +6 -6
- package/types/storages/KeyBuilderSS.d.ts +9 -2
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +3 -4
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +5 -1
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +3 -2
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -3
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +35 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +37 -0
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +14 -0
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +6 -5
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +16 -1
- package/types/storages/inRedis/constants.d.ts +3 -0
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +15 -0
- package/types/storages/pluggable/ImpressionCountsCachePluggable.d.ts +14 -0
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +6 -5
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +17 -1
- package/types/storages/pluggable/UniqueKeysCachePluggable.d.ts +14 -0
- package/types/storages/types.d.ts +38 -25
- package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
- package/types/sync/submitters/telemetrySubmitter.d.ts +1 -1
- package/types/sync/submitters/types.d.ts +30 -7
- package/types/sync/submitters/uniqueKeysSubmitter.d.ts +0 -8
- package/types/trackers/impressionsTracker.d.ts +4 -6
- package/types/trackers/types.d.ts +27 -0
- package/types/trackers/uniqueKeysTracker.d.ts +3 -3
- package/types/types.d.ts +1 -1
- package/types/utils/constants/index.d.ts +2 -0
- package/types/utils/lang/maps.d.ts +6 -2
- package/types/utils/redis/RedisMock.d.ts +4 -0
- package/src/splitio.d.ts +0 -1602
- package/types/integrations/ga/GaToSplitPlugin.d.ts +0 -3
- package/types/integrations/ga/SplitToGaPlugin.d.ts +0 -4
- package/types/integrations/ga/autoRequire.d.ts +0 -4
- package/types/logger/codes.d.ts +0 -2
- package/types/logger/codesConstants.d.ts +0 -117
- package/types/logger/codesConstantsBrowser.d.ts +0 -2
- package/types/logger/codesConstantsNode.d.ts +0 -14
- package/types/logger/codesDebug.d.ts +0 -1
- package/types/logger/codesDebugBrowser.d.ts +0 -1
- package/types/logger/codesDebugNode.d.ts +0 -1
- package/types/logger/codesError.d.ts +0 -1
- package/types/logger/codesErrorNode.d.ts +0 -1
- package/types/logger/codesInfo.d.ts +0 -1
- package/types/logger/codesWarn.d.ts +0 -1
- package/types/logger/codesWarnNode.d.ts +0 -1
- package/types/logger/debugLogger.d.ts +0 -2
- package/types/logger/errorLogger.d.ts +0 -2
- package/types/logger/infoLogger.d.ts +0 -2
- package/types/logger/messages/debugBrowser.d.ts +0 -1
- package/types/logger/messages/debugNode.d.ts +0 -1
- package/types/logger/messages/errorNode.d.ts +0 -1
- package/types/logger/messages/warnNode.d.ts +0 -1
- package/types/logger/noopLogger.d.ts +0 -2
- package/types/logger/warnLogger.d.ts +0 -2
- package/types/sdkClient/types.d.ts +0 -18
- package/types/sdkFactory/userConsentProps.d.ts +0 -6
- package/types/sdkManager/sdkManagerMethod.d.ts +0 -6
- package/types/storages/getRegisteredSegments.d.ts +0 -10
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/index.d.ts +0 -10
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
- package/types/storages/parseSegments.d.ts +0 -6
- package/types/sync/offline/LocalhostFromFile.d.ts +0 -2
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +0 -2
- package/types/sync/polling/syncTasks/splitsSyncTask.copy.d.ts +0 -35
- package/types/sync/polling/syncTasks/splitsSyncTask.morelikeoriginal.d.ts +0 -35
- package/types/sync/streaming/AuthClient/indexV1.d.ts +0 -12
- package/types/sync/streaming/AuthClient/indexV2.d.ts +0 -8
- package/types/sync/streaming/pushManagerCS.d.ts +0 -1
- package/types/sync/streaming/pushManagerNoUsers.d.ts +0 -13
- package/types/sync/streaming/pushManagerSS.d.ts +0 -1
- package/types/sync/submitters/eventsSyncTask.d.ts +0 -8
- package/types/sync/submitters/impressionCountsSyncTask.d.ts +0 -13
- package/types/sync/submitters/impressionsSyncTask.d.ts +0 -14
- package/types/sync/submitters/metricsSyncTask.d.ts +0 -12
- package/types/sync/submitters/submitterSyncTask.d.ts +0 -10
- package/types/sync/submitters/telemetrySyncTask.d.ts +0 -0
- package/types/sync/syncManagerFromFile.d.ts +0 -2
- package/types/sync/syncManagerFromObject.d.ts +0 -2
- package/types/sync/syncManagerOffline.d.ts +0 -9
- package/types/sync/syncTaskComposite.d.ts +0 -5
- package/types/trackers/telemetryRecorder.d.ts +0 -0
- package/types/utils/EventEmitter.d.ts +0 -4
- package/types/utils/consent.d.ts +0 -2
- package/types/utils/lang/errors.d.ts +0 -10
- package/types/utils/murmur3/commons.d.ts +0 -12
- package/types/utils/settingsValidation/buildMetadata.d.ts +0 -3
- package/types/utils/settingsValidation/localhost/index.d.ts +0 -9
- package/types/utils/settingsValidation/logger.d.ts +0 -11
- package/types/utils/settingsValidation/runtime/browser.d.ts +0 -2
- package/types/utils/settingsValidation/runtime/node.d.ts +0 -2
- package/types/utils/settingsValidation/userConsent.d.ts +0 -5
- package/types/utils/timeTracker/index.d.ts +0 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { setToArray, _Set } from '../../utils/lang/sets';
|
|
2
|
+
import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
|
|
3
|
+
var UniqueKeysCacheInMemoryCS = /** @class */ (function () {
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param impressionsQueueSize number of queued impressions to call onFullQueueCb.
|
|
7
|
+
* Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
|
|
8
|
+
*/
|
|
9
|
+
function UniqueKeysCacheInMemoryCS(uniqueKeysQueueSize) {
|
|
10
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = DEFAULT_CACHE_SIZE; }
|
|
11
|
+
this.uniqueTrackerSize = 0;
|
|
12
|
+
this.maxStorage = uniqueKeysQueueSize;
|
|
13
|
+
this.uniqueKeysTracker = {};
|
|
14
|
+
}
|
|
15
|
+
UniqueKeysCacheInMemoryCS.prototype.setOnFullQueueCb = function (cb) {
|
|
16
|
+
this.onFullQueue = cb;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Store unique keys in sequential order
|
|
20
|
+
* key: string = key.
|
|
21
|
+
* value: HashSet<string> = set of split names.
|
|
22
|
+
*/
|
|
23
|
+
UniqueKeysCacheInMemoryCS.prototype.track = function (key, featureName) {
|
|
24
|
+
if (!this.uniqueKeysTracker[key])
|
|
25
|
+
this.uniqueKeysTracker[key] = new _Set();
|
|
26
|
+
var tracker = this.uniqueKeysTracker[key];
|
|
27
|
+
if (!tracker.has(featureName)) {
|
|
28
|
+
tracker.add(featureName);
|
|
29
|
+
this.uniqueTrackerSize++;
|
|
30
|
+
}
|
|
31
|
+
if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
|
|
32
|
+
this.uniqueTrackerSize = 0;
|
|
33
|
+
this.onFullQueue();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Clear the data stored on the cache.
|
|
38
|
+
*/
|
|
39
|
+
UniqueKeysCacheInMemoryCS.prototype.clear = function () {
|
|
40
|
+
this.uniqueKeysTracker = {};
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Pop the collected data, used as payload for posting.
|
|
44
|
+
*/
|
|
45
|
+
UniqueKeysCacheInMemoryCS.prototype.pop = function () {
|
|
46
|
+
var data = this.uniqueKeysTracker;
|
|
47
|
+
this.uniqueKeysTracker = {};
|
|
48
|
+
return this.fromUniqueKeysCollector(data);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Check if the cache is empty.
|
|
52
|
+
*/
|
|
53
|
+
UniqueKeysCacheInMemoryCS.prototype.isEmpty = function () {
|
|
54
|
+
return Object.keys(this.uniqueKeysTracker).length === 0;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Converts `uniqueKeys` data from cache into request payload.
|
|
58
|
+
*/
|
|
59
|
+
UniqueKeysCacheInMemoryCS.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
|
|
60
|
+
var payload = [];
|
|
61
|
+
var featureKeys = Object.keys(uniqueKeys);
|
|
62
|
+
for (var k = 0; k < featureKeys.length; k++) {
|
|
63
|
+
var featureKey = featureKeys[k];
|
|
64
|
+
var featureNames = setToArray(uniqueKeys[featureKey]);
|
|
65
|
+
var uniqueKeysPayload = {
|
|
66
|
+
k: featureKey,
|
|
67
|
+
fs: featureNames
|
|
68
|
+
};
|
|
69
|
+
payload.push(uniqueKeysPayload);
|
|
70
|
+
}
|
|
71
|
+
return { keys: payload };
|
|
72
|
+
};
|
|
73
|
+
return UniqueKeysCacheInMemoryCS;
|
|
74
|
+
}());
|
|
75
|
+
export { UniqueKeysCacheInMemoryCS };
|
|
@@ -39,7 +39,7 @@ var EventsCacheInRedis = /** @class */ (function () {
|
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
41
|
* Pop the given number of events from the storage.
|
|
42
|
-
* The returned promise rejects if the
|
|
42
|
+
* The returned promise rejects if the redis operation fails.
|
|
43
43
|
*
|
|
44
44
|
* NOTE: this method doesn't take into account MAX_EVENT_SIZE or MAX_QUEUE_BYTE_SIZE limits.
|
|
45
45
|
* It is the submitter responsability to handle that.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
|
|
3
|
+
import { LOG_PREFIX, REFRESH_RATE, TTL_REFRESH } from './constants';
|
|
4
|
+
var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
|
|
5
|
+
__extends(ImpressionCountsCacheInRedis, _super);
|
|
6
|
+
function ImpressionCountsCacheInRedis(log, key, redis, impressionCountsCacheSize, refreshRate) {
|
|
7
|
+
if (refreshRate === void 0) { refreshRate = REFRESH_RATE; }
|
|
8
|
+
var _this = _super.call(this, impressionCountsCacheSize) || this;
|
|
9
|
+
_this.log = log;
|
|
10
|
+
_this.key = key;
|
|
11
|
+
_this.redis = redis;
|
|
12
|
+
_this.refreshRate = refreshRate;
|
|
13
|
+
_this.onFullQueue = function () { _this.postImpressionCountsInRedis(); };
|
|
14
|
+
return _this;
|
|
15
|
+
}
|
|
16
|
+
ImpressionCountsCacheInRedis.prototype.postImpressionCountsInRedis = function () {
|
|
17
|
+
var _this = this;
|
|
18
|
+
var counts = this.pop();
|
|
19
|
+
var keys = Object.keys(counts);
|
|
20
|
+
if (!keys.length)
|
|
21
|
+
return Promise.resolve(false);
|
|
22
|
+
var pipeline = this.redis.pipeline();
|
|
23
|
+
keys.forEach(function (key) {
|
|
24
|
+
pipeline.hincrby(_this.key, key, counts[key]);
|
|
25
|
+
});
|
|
26
|
+
return pipeline.exec()
|
|
27
|
+
.then(function (data) {
|
|
28
|
+
// If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
|
|
29
|
+
if (data.length && data.length === keys.length) {
|
|
30
|
+
return _this.redis.expire(_this.key, TTL_REFRESH);
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
.catch(function (err) {
|
|
34
|
+
_this.log.error(LOG_PREFIX + "Error in impression counts pipeline: " + err + ".");
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
ImpressionCountsCacheInRedis.prototype.start = function () {
|
|
39
|
+
this.intervalId = setInterval(this.postImpressionCountsInRedis.bind(this), this.refreshRate);
|
|
40
|
+
};
|
|
41
|
+
ImpressionCountsCacheInRedis.prototype.stop = function () {
|
|
42
|
+
clearInterval(this.intervalId);
|
|
43
|
+
return this.postImpressionCountsInRedis();
|
|
44
|
+
};
|
|
45
|
+
return ImpressionCountsCacheInRedis;
|
|
46
|
+
}(ImpressionCountsCacheInMemory));
|
|
47
|
+
export { ImpressionCountsCacheInRedis };
|
|
@@ -59,17 +59,17 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
59
59
|
var splitKey = this.keys.buildSplitKey(name);
|
|
60
60
|
return this.redis.get(splitKey).then(function (splitFromStorage) {
|
|
61
61
|
// handling parsing errors
|
|
62
|
-
var parsedPreviousSplit,
|
|
62
|
+
var parsedPreviousSplit, newStringifiedSplit;
|
|
63
63
|
try {
|
|
64
64
|
parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
|
|
65
|
-
|
|
65
|
+
newStringifiedSplit = JSON.stringify(split);
|
|
66
66
|
}
|
|
67
67
|
catch (e) {
|
|
68
68
|
throw new Error('Error parsing split definition: ' + e);
|
|
69
69
|
}
|
|
70
70
|
return Promise.all([
|
|
71
|
-
_this.redis.set(splitKey,
|
|
72
|
-
_this._incrementCounts(
|
|
71
|
+
_this.redis.set(splitKey, newStringifiedSplit),
|
|
72
|
+
_this._incrementCounts(split),
|
|
73
73
|
// If it's an update, we decrement the traffic type of the existing split,
|
|
74
74
|
parsedPreviousSplit && _this._decrementCounts(parsedPreviousSplit)
|
|
75
75
|
]);
|
|
@@ -96,8 +96,7 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
96
96
|
var _this = this;
|
|
97
97
|
return this.getSplit(name).then(function (split) {
|
|
98
98
|
if (split) {
|
|
99
|
-
|
|
100
|
-
_this._decrementCounts(parsedSplit);
|
|
99
|
+
_this._decrementCounts(split);
|
|
101
100
|
}
|
|
102
101
|
return _this.redis.del(_this.keys.buildSplitKey(name));
|
|
103
102
|
});
|
|
@@ -120,7 +119,8 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
120
119
|
this.log.error(LOG_PREFIX + this.redisError);
|
|
121
120
|
return Promise.reject(this.redisError);
|
|
122
121
|
}
|
|
123
|
-
return this.redis.get(this.keys.buildSplitKey(name))
|
|
122
|
+
return this.redis.get(this.keys.buildSplitKey(name))
|
|
123
|
+
.then(function (maybeSplit) { return maybeSplit && JSON.parse(maybeSplit); });
|
|
124
124
|
};
|
|
125
125
|
/**
|
|
126
126
|
* Set till number.
|
|
@@ -155,7 +155,12 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
155
155
|
*/
|
|
156
156
|
SplitsCacheInRedis.prototype.getAll = function () {
|
|
157
157
|
var _this = this;
|
|
158
|
-
return this.redis.keys(this.keys.searchPatternForSplitKeys())
|
|
158
|
+
return this.redis.keys(this.keys.searchPatternForSplitKeys())
|
|
159
|
+
.then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
|
|
160
|
+
.then(processPipelineAnswer)
|
|
161
|
+
.then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
|
|
162
|
+
return JSON.parse(splitDefinition);
|
|
163
|
+
}); });
|
|
159
164
|
};
|
|
160
165
|
/**
|
|
161
166
|
* Get list of split names.
|
|
@@ -215,7 +220,8 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
215
220
|
var keys = names.map(function (name) { return _this.keys.buildSplitKey(name); });
|
|
216
221
|
return (_a = this.redis).mget.apply(_a, keys).then(function (splitDefinitions) {
|
|
217
222
|
names.forEach(function (name, idx) {
|
|
218
|
-
|
|
223
|
+
var split = splitDefinitions[idx];
|
|
224
|
+
splits[name] = split && JSON.parse(split);
|
|
219
225
|
});
|
|
220
226
|
return Promise.resolve(splits);
|
|
221
227
|
})
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { parseExceptionField, parseLatencyField, parseMetadata } from '../KeyBuilderSS';
|
|
1
2
|
import { findLatencyIndex } from '../findLatencyIndex';
|
|
2
3
|
import { getTelemetryConfigStats } from '../../sync/submitters/telemetrySubmitter';
|
|
3
4
|
import { CONSUMER_MODE, STORAGE_REDIS } from '../../utils/constants';
|
|
5
|
+
import { isNaNNumber, isString } from '../../utils/lang';
|
|
6
|
+
import { _Map } from '../../utils/lang/maps';
|
|
7
|
+
import { MAX_LATENCY_BUCKET_COUNT, newBuckets } from '../inMemory/TelemetryCacheInMemory';
|
|
4
8
|
var TelemetryCacheInRedis = /** @class */ (function () {
|
|
5
9
|
/**
|
|
6
10
|
* Create a Telemetry cache that uses Redis as storage.
|
|
@@ -28,6 +32,102 @@ var TelemetryCacheInRedis = /** @class */ (function () {
|
|
|
28
32
|
var value = JSON.stringify(getTelemetryConfigStats(CONSUMER_MODE, STORAGE_REDIS));
|
|
29
33
|
return this.redis.hset(key, field, value).catch(function () { });
|
|
30
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Pop telemetry latencies.
|
|
37
|
+
* The returned promise rejects if redis operations fail.
|
|
38
|
+
*/
|
|
39
|
+
TelemetryCacheInRedis.prototype.popLatencies = function () {
|
|
40
|
+
var _this = this;
|
|
41
|
+
return this.redis.hgetall(this.keys.latencyPrefix).then(function (latencies) {
|
|
42
|
+
var result = new _Map();
|
|
43
|
+
Object.keys(latencies).forEach(function (field) {
|
|
44
|
+
var parsedField = parseLatencyField(field);
|
|
45
|
+
if (isString(parsedField)) {
|
|
46
|
+
_this.log.error("Ignoring invalid latency field: " + field + ": " + parsedField);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var count = parseInt(latencies[field]);
|
|
50
|
+
if (isNaNNumber(count)) {
|
|
51
|
+
_this.log.error("Ignoring latency with invalid count: " + latencies[field]);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
var metadata = parsedField[0], method = parsedField[1], bucket = parsedField[2];
|
|
55
|
+
if (bucket >= MAX_LATENCY_BUCKET_COUNT) {
|
|
56
|
+
_this.log.error("Ignoring latency with invalid bucket: " + bucket);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!result.has(metadata))
|
|
60
|
+
result.set(metadata, {
|
|
61
|
+
t: newBuckets(),
|
|
62
|
+
ts: newBuckets(),
|
|
63
|
+
tc: newBuckets(),
|
|
64
|
+
tcs: newBuckets(),
|
|
65
|
+
tr: newBuckets(),
|
|
66
|
+
});
|
|
67
|
+
result.get(metadata)[method][bucket] = count;
|
|
68
|
+
});
|
|
69
|
+
return _this.redis.del(_this.keys.latencyPrefix).then(function () { return result; });
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Pop telemetry exceptions.
|
|
74
|
+
* The returned promise rejects if redis operations fail.
|
|
75
|
+
*/
|
|
76
|
+
TelemetryCacheInRedis.prototype.popExceptions = function () {
|
|
77
|
+
var _this = this;
|
|
78
|
+
return this.redis.hgetall(this.keys.exceptionPrefix).then(function (exceptions) {
|
|
79
|
+
var result = new _Map();
|
|
80
|
+
Object.keys(exceptions).forEach(function (field) {
|
|
81
|
+
var parsedField = parseExceptionField(field);
|
|
82
|
+
if (isString(parsedField)) {
|
|
83
|
+
_this.log.error("Ignoring invalid exception field: " + field + ": " + parsedField);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
var count = parseInt(exceptions[field]);
|
|
87
|
+
if (isNaNNumber(count)) {
|
|
88
|
+
_this.log.error("Ignoring exception with invalid count: " + exceptions[field]);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
var metadata = parsedField[0], method = parsedField[1];
|
|
92
|
+
if (!result.has(metadata))
|
|
93
|
+
result.set(metadata, {
|
|
94
|
+
t: 0,
|
|
95
|
+
ts: 0,
|
|
96
|
+
tc: 0,
|
|
97
|
+
tcs: 0,
|
|
98
|
+
tr: 0,
|
|
99
|
+
});
|
|
100
|
+
result.get(metadata)[method] = count;
|
|
101
|
+
});
|
|
102
|
+
return _this.redis.del(_this.keys.exceptionPrefix).then(function () { return result; });
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Pop telemetry configs.
|
|
107
|
+
* The returned promise rejects if redis operations fail.
|
|
108
|
+
*/
|
|
109
|
+
TelemetryCacheInRedis.prototype.popConfigs = function () {
|
|
110
|
+
var _this = this;
|
|
111
|
+
return this.redis.hgetall(this.keys.initPrefix).then(function (configs) {
|
|
112
|
+
var result = new _Map();
|
|
113
|
+
Object.keys(configs).forEach(function (field) {
|
|
114
|
+
var parsedField = parseMetadata(field);
|
|
115
|
+
if (isString(parsedField)) {
|
|
116
|
+
_this.log.error("Ignoring invalid config field: " + field + ": " + parsedField);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
var metadata = parsedField[0];
|
|
120
|
+
try {
|
|
121
|
+
var config = JSON.parse(configs[field]);
|
|
122
|
+
result.set(metadata, config);
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
_this.log.error("Ignoring invalid config: " + configs[field]);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return _this.redis.del(_this.keys.initPrefix).then(function () { return result; });
|
|
129
|
+
});
|
|
130
|
+
};
|
|
31
131
|
return TelemetryCacheInRedis;
|
|
32
132
|
}());
|
|
33
133
|
export { TelemetryCacheInRedis };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { UniqueKeysCacheInMemory } from '../inMemory/UniqueKeysCacheInMemory';
|
|
3
|
+
import { setToArray } from '../../utils/lang/sets';
|
|
4
|
+
import { DEFAULT_CACHE_SIZE, REFRESH_RATE, TTL_REFRESH } from './constants';
|
|
5
|
+
import { LOG_PREFIX } from './constants';
|
|
6
|
+
var UniqueKeysCacheInRedis = /** @class */ (function (_super) {
|
|
7
|
+
__extends(UniqueKeysCacheInRedis, _super);
|
|
8
|
+
function UniqueKeysCacheInRedis(log, key, redis, uniqueKeysQueueSize, refreshRate) {
|
|
9
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = DEFAULT_CACHE_SIZE; }
|
|
10
|
+
if (refreshRate === void 0) { refreshRate = REFRESH_RATE; }
|
|
11
|
+
var _this = _super.call(this, uniqueKeysQueueSize) || this;
|
|
12
|
+
_this.log = log;
|
|
13
|
+
_this.key = key;
|
|
14
|
+
_this.redis = redis;
|
|
15
|
+
_this.refreshRate = refreshRate;
|
|
16
|
+
_this.onFullQueue = function () { _this.postUniqueKeysInRedis(); };
|
|
17
|
+
return _this;
|
|
18
|
+
}
|
|
19
|
+
UniqueKeysCacheInRedis.prototype.postUniqueKeysInRedis = function () {
|
|
20
|
+
var _this = this;
|
|
21
|
+
var featureNames = Object.keys(this.uniqueKeysTracker);
|
|
22
|
+
if (!featureNames.length)
|
|
23
|
+
return Promise.resolve(false);
|
|
24
|
+
var pipeline = this.redis.pipeline();
|
|
25
|
+
for (var i = 0; i < featureNames.length; i++) {
|
|
26
|
+
var featureName = featureNames[i];
|
|
27
|
+
var featureKeys = setToArray(this.uniqueKeysTracker[featureName]);
|
|
28
|
+
var uniqueKeysPayload = {
|
|
29
|
+
f: featureName,
|
|
30
|
+
ks: featureKeys
|
|
31
|
+
};
|
|
32
|
+
pipeline.rpush(this.key, JSON.stringify(uniqueKeysPayload));
|
|
33
|
+
}
|
|
34
|
+
this.clear();
|
|
35
|
+
return pipeline.exec()
|
|
36
|
+
.then(function (data) {
|
|
37
|
+
// If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
|
|
38
|
+
if (data.length && data.length === featureNames.length) {
|
|
39
|
+
return _this.redis.expire(_this.key, TTL_REFRESH);
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
.catch(function (err) {
|
|
43
|
+
_this.log.error(LOG_PREFIX + "Error in uniqueKeys pipeline: " + err + ".");
|
|
44
|
+
return false;
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
UniqueKeysCacheInRedis.prototype.start = function () {
|
|
48
|
+
this.intervalId = setInterval(this.postUniqueKeysInRedis.bind(this), this.refreshRate);
|
|
49
|
+
};
|
|
50
|
+
UniqueKeysCacheInRedis.prototype.stop = function () {
|
|
51
|
+
clearInterval(this.intervalId);
|
|
52
|
+
return this.postUniqueKeysInRedis();
|
|
53
|
+
};
|
|
54
|
+
return UniqueKeysCacheInRedis;
|
|
55
|
+
}(UniqueKeysCacheInMemory));
|
|
56
|
+
export { UniqueKeysCacheInRedis };
|
|
@@ -5,8 +5,10 @@ import { SplitsCacheInRedis } from './SplitsCacheInRedis';
|
|
|
5
5
|
import { SegmentsCacheInRedis } from './SegmentsCacheInRedis';
|
|
6
6
|
import { ImpressionsCacheInRedis } from './ImpressionsCacheInRedis';
|
|
7
7
|
import { EventsCacheInRedis } from './EventsCacheInRedis';
|
|
8
|
-
import { STORAGE_REDIS } from '../../utils/constants';
|
|
8
|
+
import { DEBUG, NONE, STORAGE_REDIS } from '../../utils/constants';
|
|
9
9
|
import { TelemetryCacheInRedis } from './TelemetryCacheInRedis';
|
|
10
|
+
import { UniqueKeysCacheInRedis } from './UniqueKeysCacheInRedis';
|
|
11
|
+
import { ImpressionCountsCacheInRedis } from './ImpressionCountsCacheInRedis';
|
|
10
12
|
/**
|
|
11
13
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
12
14
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
@@ -15,13 +17,19 @@ export function InRedisStorage(options) {
|
|
|
15
17
|
if (options === void 0) { options = {}; }
|
|
16
18
|
var prefix = validatePrefix(options.prefix);
|
|
17
19
|
function InRedisStorageFactory(_a) {
|
|
18
|
-
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb;
|
|
20
|
+
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb, impressionsMode = _a.impressionsMode;
|
|
19
21
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
20
22
|
var redisClient = new RedisAdapter(log, options.options || {});
|
|
21
23
|
var telemetry = new TelemetryCacheInRedis(log, keys, redisClient);
|
|
24
|
+
var impressionCountsCache = impressionsMode !== DEBUG ? new ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient) : undefined;
|
|
25
|
+
var uniqueKeysCache = impressionsMode === NONE ? new UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient) : undefined;
|
|
22
26
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
23
27
|
redisClient.on('connect', function () {
|
|
24
28
|
onReadyCb();
|
|
29
|
+
if (impressionCountsCache)
|
|
30
|
+
impressionCountsCache.start();
|
|
31
|
+
if (uniqueKeysCache)
|
|
32
|
+
uniqueKeysCache.start();
|
|
25
33
|
// Synchronize config
|
|
26
34
|
telemetry.recordConfig();
|
|
27
35
|
});
|
|
@@ -29,12 +37,19 @@ export function InRedisStorage(options) {
|
|
|
29
37
|
splits: new SplitsCacheInRedis(log, keys, redisClient),
|
|
30
38
|
segments: new SegmentsCacheInRedis(log, keys, redisClient),
|
|
31
39
|
impressions: new ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
40
|
+
impressionCounts: impressionCountsCache,
|
|
32
41
|
events: new EventsCacheInRedis(log, keys.buildEventsKey(), redisClient, metadata),
|
|
33
42
|
telemetry: telemetry,
|
|
43
|
+
uniqueKeys: uniqueKeysCache,
|
|
34
44
|
// When using REDIS we should:
|
|
35
45
|
// 1- Disconnect from the storage
|
|
36
46
|
destroy: function () {
|
|
37
|
-
|
|
47
|
+
var promises = [];
|
|
48
|
+
if (impressionCountsCache)
|
|
49
|
+
promises.push(impressionCountsCache.stop());
|
|
50
|
+
if (uniqueKeysCache)
|
|
51
|
+
promises.push(uniqueKeysCache.stop());
|
|
52
|
+
return Promise.all(promises).then(function () { redisClient.disconnect(); });
|
|
38
53
|
// @TODO check that caches works as expected when redisClient is disconnected
|
|
39
54
|
}
|
|
40
55
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
|
|
3
|
+
import { REFRESH_RATE } from '../inRedis/constants';
|
|
4
|
+
import { LOG_PREFIX } from './constants';
|
|
5
|
+
var ImpressionCountsCachePluggable = /** @class */ (function (_super) {
|
|
6
|
+
__extends(ImpressionCountsCachePluggable, _super);
|
|
7
|
+
function ImpressionCountsCachePluggable(log, key, wrapper, impressionCountsCacheSize, refreshRate) {
|
|
8
|
+
if (refreshRate === void 0) { refreshRate = REFRESH_RATE; }
|
|
9
|
+
var _this = _super.call(this, impressionCountsCacheSize) || this;
|
|
10
|
+
_this.log = log;
|
|
11
|
+
_this.key = key;
|
|
12
|
+
_this.wrapper = wrapper;
|
|
13
|
+
_this.refreshRate = refreshRate;
|
|
14
|
+
_this.onFullQueue = function () { _this.storeImpressionCounts(); };
|
|
15
|
+
return _this;
|
|
16
|
+
}
|
|
17
|
+
ImpressionCountsCachePluggable.prototype.storeImpressionCounts = function () {
|
|
18
|
+
var _this = this;
|
|
19
|
+
var counts = this.pop();
|
|
20
|
+
var keys = Object.keys(counts);
|
|
21
|
+
if (!keys.length)
|
|
22
|
+
return Promise.resolve(false);
|
|
23
|
+
var pipeline = keys.reduce(function (pipeline, key) {
|
|
24
|
+
return pipeline.then(function () { return _this.wrapper.incr(_this.key + "::" + key, counts[key]); });
|
|
25
|
+
}, Promise.resolve());
|
|
26
|
+
return pipeline.catch(function (err) {
|
|
27
|
+
_this.log.error(LOG_PREFIX + "Error in impression counts pipeline: " + err + ".");
|
|
28
|
+
return false;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
ImpressionCountsCachePluggable.prototype.start = function () {
|
|
32
|
+
this.intervalId = setInterval(this.storeImpressionCounts.bind(this), this.refreshRate);
|
|
33
|
+
};
|
|
34
|
+
ImpressionCountsCachePluggable.prototype.stop = function () {
|
|
35
|
+
clearInterval(this.intervalId);
|
|
36
|
+
return this.storeImpressionCounts();
|
|
37
|
+
};
|
|
38
|
+
return ImpressionCountsCachePluggable;
|
|
39
|
+
}(ImpressionCountsCacheInMemory));
|
|
40
|
+
export { ImpressionCountsCachePluggable };
|
|
@@ -46,17 +46,17 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
46
46
|
var splitKey = this.keys.buildSplitKey(name);
|
|
47
47
|
return this.wrapper.get(splitKey).then(function (splitFromStorage) {
|
|
48
48
|
// handling parsing error
|
|
49
|
-
var parsedPreviousSplit,
|
|
49
|
+
var parsedPreviousSplit, stringifiedNewSplit;
|
|
50
50
|
try {
|
|
51
51
|
parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
|
|
52
|
-
|
|
52
|
+
stringifiedNewSplit = JSON.stringify(split);
|
|
53
53
|
}
|
|
54
54
|
catch (e) {
|
|
55
55
|
throw new Error('Error parsing split definition: ' + e);
|
|
56
56
|
}
|
|
57
57
|
return Promise.all([
|
|
58
|
-
_this.wrapper.set(splitKey,
|
|
59
|
-
_this._incrementCounts(
|
|
58
|
+
_this.wrapper.set(splitKey, stringifiedNewSplit),
|
|
59
|
+
_this._incrementCounts(split),
|
|
60
60
|
// If it's an update, we decrement the traffic type and segment count of the existing split,
|
|
61
61
|
parsedPreviousSplit && _this._decrementCounts(parsedPreviousSplit)
|
|
62
62
|
]);
|
|
@@ -80,8 +80,7 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
80
80
|
var _this = this;
|
|
81
81
|
return this.getSplit(name).then(function (split) {
|
|
82
82
|
if (split) {
|
|
83
|
-
|
|
84
|
-
_this._decrementCounts(parsedSplit);
|
|
83
|
+
_this._decrementCounts(split);
|
|
85
84
|
}
|
|
86
85
|
return _this.wrapper.del(_this.keys.buildSplitKey(name));
|
|
87
86
|
});
|
|
@@ -101,7 +100,8 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
101
100
|
* or rejected if wrapper operation fails.
|
|
102
101
|
*/
|
|
103
102
|
SplitsCachePluggable.prototype.getSplit = function (name) {
|
|
104
|
-
return this.wrapper.get(this.keys.buildSplitKey(name))
|
|
103
|
+
return this.wrapper.get(this.keys.buildSplitKey(name))
|
|
104
|
+
.then(function (maybeSplit) { return maybeSplit && JSON.parse(maybeSplit); });
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
107
107
|
* Get list of splits.
|
|
@@ -114,7 +114,8 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
114
114
|
return this.wrapper.getMany(keys).then(function (splitDefinitions) {
|
|
115
115
|
var splits = {};
|
|
116
116
|
names.forEach(function (name, idx) {
|
|
117
|
-
|
|
117
|
+
var split = splitDefinitions[idx];
|
|
118
|
+
splits[name] = split && JSON.parse(split);
|
|
118
119
|
});
|
|
119
120
|
return Promise.resolve(splits);
|
|
120
121
|
});
|
|
@@ -126,7 +127,11 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
126
127
|
*/
|
|
127
128
|
SplitsCachePluggable.prototype.getAll = function () {
|
|
128
129
|
var _this = this;
|
|
129
|
-
return this.wrapper.getKeysByPrefix(this.keys.buildSplitKeyPrefix())
|
|
130
|
+
return this.wrapper.getKeysByPrefix(this.keys.buildSplitKeyPrefix())
|
|
131
|
+
.then(function (listOfKeys) { return _this.wrapper.getMany(listOfKeys); })
|
|
132
|
+
.then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
|
|
133
|
+
return JSON.parse(splitDefinition);
|
|
134
|
+
}); });
|
|
130
135
|
};
|
|
131
136
|
/**
|
|
132
137
|
* Get list of split names.
|