@splitsoftware/splitio-commons 3.1.1-rc.10 → 3.1.1-rc.12
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 +3 -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/{sync/streaming/AuthClient/index.js → services/fetchAuth.js} +15 -16
- 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 +195 -0
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +12 -11
- package/cjs/storages/inLocalStorage/index.js +6 -6
- package/cjs/storages/inLocalStorage/validateCache.js +3 -3
- package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +122 -0
- package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +7 -6
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +79 -77
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +4 -2
- package/cjs/storages/inRedis/index.js +2 -2
- package/cjs/storages/pluggable/DefinitionsCachePluggable.js +214 -0
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +4 -2
- 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/definitionChangesUpdater.js +207 -0
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
- 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} +19 -20
- package/cjs/sync/streaming/constants.js +4 -3
- package/cjs/sync/streaming/parseUtils.js +14 -14
- package/cjs/sync/streaming/pushManager.js +22 -26
- 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/{sync/streaming/AuthClient/index.js → services/fetchAuth.js} +13 -13
- 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 +192 -0
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +9 -8
- package/esm/storages/inLocalStorage/index.js +6 -6
- package/esm/storages/inLocalStorage/validateCache.js +3 -3
- package/esm/storages/inMemory/DefinitionsCacheInMemory.js +119 -0
- package/esm/storages/inMemory/InMemoryStorage.js +4 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +4 -3
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/esm/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +78 -76
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +4 -2
- package/esm/storages/inRedis/index.js +2 -2
- package/esm/storages/pluggable/DefinitionsCachePluggable.js +211 -0
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +4 -2
- 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 +201 -0
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
- 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} +19 -20
- package/esm/sync/streaming/constants.js +3 -2
- package/esm/sync/streaming/parseUtils.js +11 -11
- package/esm/sync/streaming/pushManager.js +24 -28
- 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/src/dtos/types.ts +4 -4
- package/src/services/authProvider.ts +2 -2
- package/src/{sync/streaming/AuthClient/index.ts → services/fetchAuth.ts} +3 -4
- package/src/services/splitApi.ts +1 -1
- package/src/services/types.ts +21 -4
- package/src/storages/AbstractDefinitionsCacheAsync.ts +3 -3
- package/src/storages/AbstractDefinitionsCacheSync.ts +2 -2
- package/src/storages/inLocalStorage/DefinitionsCacheInLocal.ts +2 -2
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +3 -3
- package/src/storages/inMemory/DefinitionsCacheInMemory.ts +2 -2
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +2 -2
- package/src/storages/inRedis/DefinitionsCacheInRedis.ts +6 -4
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +7 -5
- package/src/storages/pluggable/DefinitionsCachePluggable.ts +4 -2
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +5 -3
- package/src/storages/types.ts +6 -6
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +5 -5
- package/src/sync/polling/types.ts +22 -1
- package/src/sync/polling/updaters/definitionChangesUpdater.ts +26 -20
- package/src/sync/streaming/SSEClient/index.ts +1 -1
- package/src/sync/streaming/SSEClient/types.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/DefinitionsUpdateWorker.ts +15 -11
- package/src/sync/streaming/UpdateWorkers/types.ts +6 -0
- package/src/sync/streaming/parseUtils.ts +3 -4
- package/src/sync/streaming/pushManager.ts +4 -3
- 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/sync/polling/updaters/splitChangesUpdater.js +0 -200
- package/cjs/sync/streaming/AuthClient/types.js +0 -2
- 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/sync/streaming/AuthClient/types.js +0 -1
- package/esm/utils/inputValidation/splitExistence.js +0 -15
- package/esm/utils/inputValidation/splits.js +0 -21
- package/src/sync/streaming/AuthClient/types.ts +0 -19
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __extends, __spreadArray } from "tslib";
|
|
2
2
|
import { isFiniteNumber, isNaNNumber } from '../../utils/lang';
|
|
3
3
|
import { LOG_PREFIX } from './constants';
|
|
4
|
-
import {
|
|
4
|
+
import { AbstractDefinitionsCacheAsync } from '../AbstractDefinitionsCacheAsync';
|
|
5
5
|
import { returnDifference } from '../../utils/lang/sets';
|
|
6
6
|
/**
|
|
7
7
|
* Discard errors for an answer of multiple operations.
|
|
@@ -14,17 +14,17 @@ function processPipelineAnswer(results) {
|
|
|
14
14
|
}, []) : [];
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* IDefinitionsCacheAsync implementation that stores definitions in Redis.
|
|
18
18
|
* Supported by Node.js
|
|
19
19
|
*/
|
|
20
|
-
var
|
|
21
|
-
__extends(
|
|
22
|
-
function
|
|
20
|
+
var DefinitionsCacheInRedis = /** @class */ (function (_super) {
|
|
21
|
+
__extends(DefinitionsCacheInRedis, _super);
|
|
22
|
+
function DefinitionsCacheInRedis(log, keys, redis, splitFiltersValidation) {
|
|
23
23
|
var _this = _super.call(this) || this;
|
|
24
24
|
_this.log = log;
|
|
25
25
|
_this.redis = redis;
|
|
26
26
|
_this.keys = keys;
|
|
27
|
-
_this.
|
|
27
|
+
_this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
28
28
|
// There is no need to listen for redis 'error' event, because in that case ioredis calls will be rejected and handled by redis storage adapters.
|
|
29
29
|
// But it is done just to avoid getting the ioredis message `Unhandled error event`.
|
|
30
30
|
_this.redis.on('error', function (e) {
|
|
@@ -35,104 +35,106 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
35
35
|
});
|
|
36
36
|
return _this;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
DefinitionsCacheInRedis.prototype._decrementCounts = function (definition) {
|
|
39
39
|
var _this = this;
|
|
40
|
-
var ttKey = this.keys.buildTrafficTypeKey(
|
|
40
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
41
41
|
return this.redis.decr(ttKey).then(function (count) {
|
|
42
42
|
if (count === 0)
|
|
43
43
|
return _this.redis.del(ttKey);
|
|
44
44
|
});
|
|
45
45
|
};
|
|
46
|
-
|
|
47
|
-
var ttKey = this.keys.buildTrafficTypeKey(
|
|
46
|
+
DefinitionsCacheInRedis.prototype._incrementCounts = function (definition) {
|
|
47
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
48
48
|
return this.redis.incr(ttKey);
|
|
49
49
|
};
|
|
50
|
-
|
|
50
|
+
DefinitionsCacheInRedis.prototype._updateSets = function (definitionName, setsOfRemovedDefinition, setsOfAddedDefinition) {
|
|
51
51
|
var _this = this;
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
if (this.
|
|
55
|
-
|
|
56
|
-
return _this.
|
|
52
|
+
var removeFromSets = returnDifference(setsOfRemovedDefinition, setsOfAddedDefinition);
|
|
53
|
+
var addToSets = returnDifference(setsOfAddedDefinition, setsOfRemovedDefinition);
|
|
54
|
+
if (this.setsFilter.length > 0) {
|
|
55
|
+
addToSets = addToSets.filter(function (set) {
|
|
56
|
+
return _this.setsFilter.some(function (filterSet) { return filterSet === set; });
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
var items = [
|
|
60
|
-
return Promise.all(__spreadArray(__spreadArray([],
|
|
59
|
+
var items = [definitionName];
|
|
60
|
+
return Promise.all(__spreadArray(__spreadArray([], removeFromSets.map(function (setName) { return _this.redis.srem(_this.keys.buildSetKey(setName), items); }), true), addToSets.map(function (setName) { return _this.redis.sadd(_this.keys.buildSetKey(setName), items); }), true));
|
|
61
61
|
};
|
|
62
62
|
/**
|
|
63
|
-
* Add a given
|
|
63
|
+
* Add a given definition.
|
|
64
64
|
* The returned promise is resolved when the operation success
|
|
65
65
|
* or rejected if it fails (e.g., redis operation fails)
|
|
66
66
|
*/
|
|
67
|
-
|
|
67
|
+
DefinitionsCacheInRedis.prototype.add = function (definition) {
|
|
68
68
|
var _this = this;
|
|
69
|
-
var name =
|
|
70
|
-
var
|
|
71
|
-
return this.redis.get(
|
|
69
|
+
var name = definition.name;
|
|
70
|
+
var definitionKey = this.keys.buildDefinitionKey(name);
|
|
71
|
+
return this.redis.get(definitionKey).then(function (definitionFromStorage) {
|
|
72
72
|
// handling parsing error
|
|
73
|
-
var
|
|
73
|
+
var parsedPreviousDefinition, stringifiedNewDefinition;
|
|
74
74
|
try {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
|
|
76
|
+
stringifiedNewDefinition = JSON.stringify(definition);
|
|
77
77
|
}
|
|
78
78
|
catch (e) {
|
|
79
79
|
throw new Error('Error parsing feature flag definition: ' + e);
|
|
80
80
|
}
|
|
81
|
-
return _this.redis.set(
|
|
81
|
+
return _this.redis.set(definitionKey, stringifiedNewDefinition).then(function () {
|
|
82
82
|
// avoid unnecessary increment/decrement operations
|
|
83
|
-
if (
|
|
83
|
+
if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName)
|
|
84
84
|
return;
|
|
85
85
|
// update traffic type counts
|
|
86
|
-
return _this._incrementCounts(
|
|
87
|
-
if (
|
|
88
|
-
return _this._decrementCounts(
|
|
86
|
+
return _this._incrementCounts(definition).then(function () {
|
|
87
|
+
if (parsedPreviousDefinition)
|
|
88
|
+
return _this._decrementCounts(parsedPreviousDefinition);
|
|
89
89
|
});
|
|
90
|
-
}).then(function () { return _this.
|
|
90
|
+
}).then(function () { return _this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets); });
|
|
91
91
|
}).then(function () { return true; });
|
|
92
92
|
};
|
|
93
93
|
/**
|
|
94
|
-
* Remove a given
|
|
95
|
-
* The returned promise is resolved when the operation success, with true or false indicating if the
|
|
94
|
+
* Remove a given definition.
|
|
95
|
+
* The returned promise is resolved when the operation success, with true or false indicating if the definition existed (and was removed) or not.
|
|
96
96
|
* or rejected if it fails (e.g., redis operation fails).
|
|
97
97
|
*/
|
|
98
|
-
|
|
98
|
+
DefinitionsCacheInRedis.prototype.remove = function (name) {
|
|
99
99
|
var _this = this;
|
|
100
|
-
return this.
|
|
101
|
-
if (
|
|
102
|
-
return _this._decrementCounts(
|
|
100
|
+
return this.get(name).then(function (definition) {
|
|
101
|
+
if (definition) {
|
|
102
|
+
return _this._decrementCounts(definition).then(function () { return _this._updateSets(name, definition.sets); });
|
|
103
103
|
}
|
|
104
104
|
}).then(function () {
|
|
105
|
-
return _this.redis.del(_this.keys.
|
|
105
|
+
return _this.redis.del(_this.keys.buildDefinitionKey(name)).then(function (status) { return status === 1; });
|
|
106
106
|
});
|
|
107
107
|
};
|
|
108
108
|
/**
|
|
109
|
-
* Get
|
|
109
|
+
* Get definition or null if it's not defined.
|
|
110
110
|
* Returned promise is rejected if redis operation fails.
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
DefinitionsCacheInRedis.prototype.get = function (name) {
|
|
113
113
|
if (this.redisError) {
|
|
114
114
|
this.log.error(LOG_PREFIX + this.redisError);
|
|
115
115
|
return Promise.reject(this.redisError);
|
|
116
116
|
}
|
|
117
|
-
return this.redis.get(this.keys.
|
|
118
|
-
.then(function (
|
|
117
|
+
return this.redis.get(this.keys.buildDefinitionKey(name))
|
|
118
|
+
.then(function (maybeDefinition) { return maybeDefinition && JSON.parse(maybeDefinition); });
|
|
119
119
|
};
|
|
120
120
|
/**
|
|
121
121
|
* Set till number.
|
|
122
122
|
* The returned promise is resolved when the operation success,
|
|
123
123
|
* or rejected if it fails.
|
|
124
124
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
DefinitionsCacheInRedis.prototype.setChangeNumber = function (changeNumber) {
|
|
126
|
+
if (changeNumber !== undefined) {
|
|
127
|
+
return this.redis.set(this.keys.buildDefinitionsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
|
|
128
|
+
}
|
|
127
129
|
};
|
|
128
130
|
/**
|
|
129
131
|
* Get till number or -1 if it's not defined.
|
|
130
132
|
* The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a redis operation fails.
|
|
131
133
|
* The promise will never be rejected.
|
|
132
134
|
*/
|
|
133
|
-
|
|
135
|
+
DefinitionsCacheInRedis.prototype.getChangeNumber = function () {
|
|
134
136
|
var _this = this;
|
|
135
|
-
return this.redis.get(this.keys.
|
|
137
|
+
return this.redis.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
|
|
136
138
|
var i = parseInt(value, 10);
|
|
137
139
|
return isNaNNumber(i) ? -1 : i;
|
|
138
140
|
}).catch(function (e) {
|
|
@@ -141,44 +143,44 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
141
143
|
});
|
|
142
144
|
};
|
|
143
145
|
/**
|
|
144
|
-
* Get list of all
|
|
145
|
-
* The returned promise is resolved with the list of
|
|
146
|
+
* Get list of all definitions.
|
|
147
|
+
* The returned promise is resolved with the list of definitions,
|
|
146
148
|
* or rejected if redis operation fails.
|
|
147
149
|
*/
|
|
148
150
|
// @TODO we need to benchmark which is the maximun number of commands we could pipeline without kill redis performance.
|
|
149
|
-
|
|
151
|
+
DefinitionsCacheInRedis.prototype.getAll = function () {
|
|
150
152
|
var _this = this;
|
|
151
|
-
return this.redis.keys(this.keys.
|
|
153
|
+
return this.redis.keys(this.keys.searchPatternForDefinitionKeys())
|
|
152
154
|
.then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
|
|
153
155
|
.then(processPipelineAnswer)
|
|
154
|
-
.then(function (
|
|
155
|
-
return JSON.parse(
|
|
156
|
+
.then(function (definitions) { return definitions.map(function (definition) {
|
|
157
|
+
return JSON.parse(definition);
|
|
156
158
|
}); });
|
|
157
159
|
};
|
|
158
160
|
/**
|
|
159
|
-
* Get list of
|
|
160
|
-
* The returned promise is resolved with the list of
|
|
161
|
+
* Get list of definition names.
|
|
162
|
+
* The returned promise is resolved with the list of names,
|
|
161
163
|
* or rejected if redis operation fails.
|
|
162
164
|
*/
|
|
163
|
-
|
|
165
|
+
DefinitionsCacheInRedis.prototype.getNames = function () {
|
|
164
166
|
var _this = this;
|
|
165
|
-
return this.redis.keys(this.keys.
|
|
167
|
+
return this.redis.keys(this.keys.searchPatternForDefinitionKeys()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
|
|
166
168
|
};
|
|
167
169
|
/**
|
|
168
|
-
* Get list of
|
|
169
|
-
* The returned promise is resolved with the list of
|
|
170
|
+
* Get list of definition names related to a given list of set names.
|
|
171
|
+
* The returned promise is resolved with the list of names per set,
|
|
170
172
|
* or rejected if the pipelined redis operation fails (e.g., timeout).
|
|
171
173
|
*/
|
|
172
|
-
|
|
174
|
+
DefinitionsCacheInRedis.prototype.getNamesBySets = function (sets) {
|
|
173
175
|
var _this = this;
|
|
174
|
-
return this.redis.pipeline(
|
|
176
|
+
return this.redis.pipeline(sets.map(function (set) { return ['smembers', _this.keys.buildSetKey(set)]; })).exec()
|
|
175
177
|
.then(function (results) { return results ? results.map(function (_a, index) {
|
|
176
178
|
var e = _a[0], value = _a[1];
|
|
177
179
|
if (e === null)
|
|
178
180
|
return value;
|
|
179
|
-
_this.log.error(LOG_PREFIX + "Could not read result from get members of
|
|
181
|
+
_this.log.error(LOG_PREFIX + "Could not read result from get members of set ".concat(sets[index], " due to an error: ").concat(e));
|
|
180
182
|
}) : []; })
|
|
181
|
-
.then(function (
|
|
183
|
+
.then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
|
|
182
184
|
};
|
|
183
185
|
/**
|
|
184
186
|
* Check traffic type existence.
|
|
@@ -186,7 +188,7 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
186
188
|
* In case of redis operation failure, the promise resolves with a true value, assuming that the TT might exist.
|
|
187
189
|
* It will never be rejected.
|
|
188
190
|
*/
|
|
189
|
-
|
|
191
|
+
DefinitionsCacheInRedis.prototype.trafficTypeExists = function (trafficType) {
|
|
190
192
|
var _this = this;
|
|
191
193
|
// If there is a number there should be > 0, otherwise the TT is considered as not existent.
|
|
192
194
|
return this.redis.get(this.keys.buildTrafficTypeKey(trafficType))
|
|
@@ -207,34 +209,34 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
207
209
|
});
|
|
208
210
|
};
|
|
209
211
|
// @TODO remove or implement. It is not being used.
|
|
210
|
-
|
|
212
|
+
DefinitionsCacheInRedis.prototype.clear = function () {
|
|
211
213
|
return Promise.resolve();
|
|
212
214
|
};
|
|
213
215
|
/**
|
|
214
|
-
* Fetches multiple
|
|
216
|
+
* Fetches multiple definitions.
|
|
215
217
|
* Returned promise is rejected if redis operation fails.
|
|
216
218
|
*/
|
|
217
|
-
|
|
219
|
+
DefinitionsCacheInRedis.prototype.getMany = function (names) {
|
|
218
220
|
var _a;
|
|
219
221
|
var _this = this;
|
|
220
222
|
if (this.redisError) {
|
|
221
223
|
this.log.error(LOG_PREFIX + this.redisError);
|
|
222
224
|
return Promise.reject(this.redisError);
|
|
223
225
|
}
|
|
224
|
-
var keys = names.map(function (name) { return _this.keys.
|
|
225
|
-
return (_a = this.redis).mget.apply(_a, keys).then(function (
|
|
226
|
-
var
|
|
226
|
+
var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
|
|
227
|
+
return (_a = this.redis).mget.apply(_a, keys).then(function (stringifiedDefinitions) {
|
|
228
|
+
var definitions = {};
|
|
227
229
|
names.forEach(function (name, idx) {
|
|
228
|
-
var
|
|
229
|
-
|
|
230
|
+
var definition = stringifiedDefinitions[idx];
|
|
231
|
+
definitions[name] = definition && JSON.parse(definition);
|
|
230
232
|
});
|
|
231
|
-
return Promise.resolve(
|
|
233
|
+
return Promise.resolve(definitions);
|
|
232
234
|
})
|
|
233
235
|
.catch(function (e) {
|
|
234
236
|
_this.log.error(LOG_PREFIX + "Could not grab feature flags due to an error: ".concat(e, "."));
|
|
235
237
|
return Promise.reject(e);
|
|
236
238
|
});
|
|
237
239
|
};
|
|
238
|
-
return
|
|
239
|
-
}(
|
|
240
|
-
export {
|
|
240
|
+
return DefinitionsCacheInRedis;
|
|
241
|
+
}(AbstractDefinitionsCacheAsync));
|
|
242
|
+
export { DefinitionsCacheInRedis };
|
|
@@ -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);
|
|
35
35
|
return _this.redis.del(key).then(function (status) { return status === 1; });
|
|
36
36
|
}))
|
|
37
37
|
]).then(function (_a) {
|
|
@@ -40,7 +40,9 @@ var RBSegmentsCacheInRedis = /** @class */ (function () {
|
|
|
40
40
|
});
|
|
41
41
|
};
|
|
42
42
|
RBSegmentsCacheInRedis.prototype.setChangeNumber = function (changeNumber) {
|
|
43
|
-
|
|
43
|
+
if (changeNumber !== undefined) {
|
|
44
|
+
return this.redis.set(this.keys.buildRBSegmentsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
|
|
45
|
+
}
|
|
44
46
|
};
|
|
45
47
|
RBSegmentsCacheInRedis.prototype.getChangeNumber = function () {
|
|
46
48
|
var _this = this;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { validatePrefix } from '../KeyBuilder';
|
|
2
2
|
import { KeyBuilderSS } from '../KeyBuilderSS';
|
|
3
|
-
import {
|
|
3
|
+
import { DefinitionsCacheInRedis } from './DefinitionsCacheInRedis';
|
|
4
4
|
import { SegmentsCacheInRedis } from './SegmentsCacheInRedis';
|
|
5
5
|
import { ImpressionsCacheInRedis } from './ImpressionsCacheInRedis';
|
|
6
6
|
import { EventsCacheInRedis } from './EventsCacheInRedis';
|
|
@@ -45,7 +45,7 @@ export function InRedisStorage(options) {
|
|
|
45
45
|
telemetry.recordConfig();
|
|
46
46
|
});
|
|
47
47
|
return {
|
|
48
|
-
|
|
48
|
+
definitions: new DefinitionsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
|
|
49
49
|
rbSegments: new RBSegmentsCacheInRedis(log, keys, redisClient),
|
|
50
50
|
segments: new SegmentsCacheInRedis(log, keys, redisClient),
|
|
51
51
|
impressions: new ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { __extends, __spreadArray } from "tslib";
|
|
2
|
+
import { isFiniteNumber, isNaNNumber } from '../../utils/lang';
|
|
3
|
+
import { LOG_PREFIX } from './constants';
|
|
4
|
+
import { AbstractDefinitionsCacheAsync } from '../AbstractDefinitionsCacheAsync';
|
|
5
|
+
import { returnDifference } from '../../utils/lang/sets';
|
|
6
|
+
/**
|
|
7
|
+
* IDefinitionsCacheAsync implementation for pluggable storages.
|
|
8
|
+
*/
|
|
9
|
+
var DefinitionsCachePluggable = /** @class */ (function (_super) {
|
|
10
|
+
__extends(DefinitionsCachePluggable, _super);
|
|
11
|
+
/**
|
|
12
|
+
* Create a DefinitionsCache that uses a storage wrapper.
|
|
13
|
+
* @param log - Logger instance.
|
|
14
|
+
* @param keys - Key builder.
|
|
15
|
+
* @param wrapper - Adapted wrapper storage.
|
|
16
|
+
*/
|
|
17
|
+
function DefinitionsCachePluggable(log, keys, wrapper, splitFiltersValidation) {
|
|
18
|
+
var _this = _super.call(this) || this;
|
|
19
|
+
_this.log = log;
|
|
20
|
+
_this.keys = keys;
|
|
21
|
+
_this.wrapper = wrapper;
|
|
22
|
+
_this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
23
|
+
return _this;
|
|
24
|
+
}
|
|
25
|
+
DefinitionsCachePluggable.prototype._decrementCounts = function (definition) {
|
|
26
|
+
var _this = this;
|
|
27
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
28
|
+
return this.wrapper.decr(ttKey).then(function (count) {
|
|
29
|
+
if (count === 0)
|
|
30
|
+
return _this.wrapper.del(ttKey);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
DefinitionsCachePluggable.prototype._incrementCounts = function (definition) {
|
|
34
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
35
|
+
return this.wrapper.incr(ttKey);
|
|
36
|
+
};
|
|
37
|
+
DefinitionsCachePluggable.prototype._updateSets = function (definitionName, setsOfRemovedDefinition, setsOfAddedDefinition) {
|
|
38
|
+
var _this = this;
|
|
39
|
+
var removeFromSets = returnDifference(setsOfRemovedDefinition, setsOfAddedDefinition);
|
|
40
|
+
var addToSets = returnDifference(setsOfAddedDefinition, setsOfRemovedDefinition);
|
|
41
|
+
if (this.setsFilter.length > 0) {
|
|
42
|
+
addToSets = addToSets.filter(function (set) {
|
|
43
|
+
return _this.setsFilter.some(function (filterSet) { return filterSet === set; });
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
var items = [definitionName];
|
|
47
|
+
return Promise.all(__spreadArray(__spreadArray([], removeFromSets.map(function (setName) { return _this.wrapper.removeItems(_this.keys.buildSetKey(setName), items); }), true), addToSets.map(function (setName) { return _this.wrapper.addItems(_this.keys.buildSetKey(setName), items); }), true));
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Add a given definition.
|
|
51
|
+
* The returned promise is resolved when the operation success
|
|
52
|
+
* or rejected if it fails (e.g., wrapper operation fails)
|
|
53
|
+
*/
|
|
54
|
+
DefinitionsCachePluggable.prototype.add = function (definition) {
|
|
55
|
+
var _this = this;
|
|
56
|
+
var name = definition.name;
|
|
57
|
+
var definitionKey = this.keys.buildDefinitionKey(name);
|
|
58
|
+
return this.wrapper.get(definitionKey).then(function (definitionFromStorage) {
|
|
59
|
+
// handling parsing error
|
|
60
|
+
var parsedPreviousDefinition, stringifiedNewDefinition;
|
|
61
|
+
try {
|
|
62
|
+
parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
|
|
63
|
+
stringifiedNewDefinition = JSON.stringify(definition);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
throw new Error('Error parsing feature flag definition: ' + e);
|
|
67
|
+
}
|
|
68
|
+
return _this.wrapper.set(definitionKey, stringifiedNewDefinition).then(function () {
|
|
69
|
+
// avoid unnecessary increment/decrement operations
|
|
70
|
+
if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName)
|
|
71
|
+
return;
|
|
72
|
+
// update traffic type counts
|
|
73
|
+
return _this._incrementCounts(definition).then(function () {
|
|
74
|
+
if (parsedPreviousDefinition)
|
|
75
|
+
return _this._decrementCounts(parsedPreviousDefinition);
|
|
76
|
+
});
|
|
77
|
+
}).then(function () { return _this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets); });
|
|
78
|
+
}).then(function () { return true; });
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Remove a given definition.
|
|
82
|
+
* The returned promise is resolved when the operation success, with a boolean indicating if the definition existed or not.
|
|
83
|
+
* or rejected if it fails (e.g., wrapper operation fails).
|
|
84
|
+
*/
|
|
85
|
+
DefinitionsCachePluggable.prototype.remove = function (name) {
|
|
86
|
+
var _this = this;
|
|
87
|
+
return this.get(name).then(function (definition) {
|
|
88
|
+
if (definition) {
|
|
89
|
+
return _this._decrementCounts(definition).then(function () { return _this._updateSets(name, definition.sets); });
|
|
90
|
+
}
|
|
91
|
+
}).then(function () {
|
|
92
|
+
return _this.wrapper.del(_this.keys.buildDefinitionKey(name));
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Get definition.
|
|
97
|
+
* The returned promise is resolved with the definition or null if it's not defined,
|
|
98
|
+
* or rejected if wrapper operation fails.
|
|
99
|
+
*/
|
|
100
|
+
DefinitionsCachePluggable.prototype.get = function (name) {
|
|
101
|
+
return this.wrapper.get(this.keys.buildDefinitionKey(name))
|
|
102
|
+
.then(function (maybeDefinition) { return maybeDefinition && JSON.parse(maybeDefinition); });
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Get list of definitions.
|
|
106
|
+
* The returned promise is resolved with a map of names to their definition or null if it's not defined,
|
|
107
|
+
* or rejected if wrapper operation fails.
|
|
108
|
+
*/
|
|
109
|
+
DefinitionsCachePluggable.prototype.getMany = function (names) {
|
|
110
|
+
var _this = this;
|
|
111
|
+
var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
|
|
112
|
+
return this.wrapper.getMany(keys).then(function (stringifiedDefinitions) {
|
|
113
|
+
var definitions = {};
|
|
114
|
+
names.forEach(function (name, idx) {
|
|
115
|
+
var definition = stringifiedDefinitions[idx];
|
|
116
|
+
definitions[name] = definition && JSON.parse(definition);
|
|
117
|
+
});
|
|
118
|
+
return Promise.resolve(definitions);
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Get list of all definitions.
|
|
123
|
+
* The returned promise is resolved with the list of definitions,
|
|
124
|
+
* or rejected if wrapper operation fails.
|
|
125
|
+
*/
|
|
126
|
+
DefinitionsCachePluggable.prototype.getAll = function () {
|
|
127
|
+
var _this = this;
|
|
128
|
+
return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix())
|
|
129
|
+
.then(function (listOfKeys) { return _this.wrapper.getMany(listOfKeys); })
|
|
130
|
+
.then(function (definitions) { return definitions.map(function (definition) {
|
|
131
|
+
return JSON.parse(definition);
|
|
132
|
+
}); });
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Get list of definition names.
|
|
136
|
+
* The returned promise is resolved with the list of names,
|
|
137
|
+
* or rejected if wrapper operation fails.
|
|
138
|
+
*/
|
|
139
|
+
DefinitionsCachePluggable.prototype.getNames = function () {
|
|
140
|
+
var _this = this;
|
|
141
|
+
return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Get list of definition names related to a given list of set names.
|
|
145
|
+
* The returned promise is resolved with the list of names per set.
|
|
146
|
+
* It never rejects (If there is a wrapper error for some set, an empty set is returned for it).
|
|
147
|
+
*/
|
|
148
|
+
DefinitionsCachePluggable.prototype.getNamesBySets = function (sets) {
|
|
149
|
+
var _this = this;
|
|
150
|
+
return Promise.all(sets.map(function (set) {
|
|
151
|
+
var setKey = _this.keys.buildSetKey(set);
|
|
152
|
+
return _this.wrapper.getItems(setKey).catch(function () { return []; });
|
|
153
|
+
})).then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Check traffic type existence.
|
|
157
|
+
* The returned promise is resolved with a boolean indicating whether the TT exist or not.
|
|
158
|
+
* In case of wrapper operation failures, the promise resolves with a true value, assuming that the TT might exist.
|
|
159
|
+
* It will never be rejected.
|
|
160
|
+
*/
|
|
161
|
+
DefinitionsCachePluggable.prototype.trafficTypeExists = function (trafficType) {
|
|
162
|
+
var _this = this;
|
|
163
|
+
// If there is a number there should be > 0, otherwise the TT is considered as not existent.
|
|
164
|
+
return this.wrapper.get(this.keys.buildTrafficTypeKey(trafficType))
|
|
165
|
+
.then(function (ttCount) {
|
|
166
|
+
if (ttCount === null)
|
|
167
|
+
return false; // if entry doesn't exist, means that TT doesn't exist
|
|
168
|
+
ttCount = parseInt(ttCount, 10);
|
|
169
|
+
if (!isFiniteNumber(ttCount) || ttCount < 0) {
|
|
170
|
+
_this.log.info(LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to data corruption of some sorts."));
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return ttCount > 0;
|
|
174
|
+
}).catch(function (e) {
|
|
175
|
+
_this.log.error(LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to an error: ").concat(e, "."));
|
|
176
|
+
// If there is an error, bypass the validation so the event can get tracked.
|
|
177
|
+
return true;
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Set till number.
|
|
182
|
+
* The returned promise is resolved when the operation success,
|
|
183
|
+
* or rejected if it fails (e.g., wrapper operation fails).
|
|
184
|
+
*/
|
|
185
|
+
DefinitionsCachePluggable.prototype.setChangeNumber = function (changeNumber) {
|
|
186
|
+
if (changeNumber !== undefined) {
|
|
187
|
+
return this.wrapper.set(this.keys.buildDefinitionsTillKey(), changeNumber + '');
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Get till number or -1 if it's not defined.
|
|
192
|
+
* The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
|
|
193
|
+
* The promise will never be rejected.
|
|
194
|
+
*/
|
|
195
|
+
DefinitionsCachePluggable.prototype.getChangeNumber = function () {
|
|
196
|
+
var _this = this;
|
|
197
|
+
return this.wrapper.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
|
|
198
|
+
var i = parseInt(value, 10);
|
|
199
|
+
return isNaNNumber(i) ? -1 : i;
|
|
200
|
+
}).catch(function (e) {
|
|
201
|
+
_this.log.error(LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
|
|
202
|
+
return -1;
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
// @TODO implement if required by DataLoader or producer mode
|
|
206
|
+
DefinitionsCachePluggable.prototype.clear = function () {
|
|
207
|
+
return Promise.resolve(true);
|
|
208
|
+
};
|
|
209
|
+
return DefinitionsCachePluggable;
|
|
210
|
+
}(AbstractDefinitionsCacheAsync));
|
|
211
|
+
export { DefinitionsCachePluggable };
|
|
@@ -31,7 +31,7 @@ var RBSegmentsCachePluggable = /** @class */ (function () {
|
|
|
31
31
|
return _this.wrapper.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);
|
|
35
35
|
return _this.wrapper.del(key);
|
|
36
36
|
}))
|
|
37
37
|
]).then(function (_a) {
|
|
@@ -40,7 +40,9 @@ var RBSegmentsCachePluggable = /** @class */ (function () {
|
|
|
40
40
|
});
|
|
41
41
|
};
|
|
42
42
|
RBSegmentsCachePluggable.prototype.setChangeNumber = function (changeNumber) {
|
|
43
|
-
|
|
43
|
+
if (changeNumber !== undefined) {
|
|
44
|
+
return this.wrapper.set(this.keys.buildRBSegmentsTillKey(), changeNumber + '');
|
|
45
|
+
}
|
|
44
46
|
};
|
|
45
47
|
RBSegmentsCachePluggable.prototype.getChangeNumber = function () {
|
|
46
48
|
var _this = this;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
2
|
import { KeyBuilderSS } from '../KeyBuilderSS';
|
|
3
|
-
import {
|
|
3
|
+
import { DefinitionsCachePluggable } from './DefinitionsCachePluggable';
|
|
4
4
|
import { SegmentsCachePluggable } from './SegmentsCachePluggable';
|
|
5
5
|
import { ImpressionsCachePluggable } from './ImpressionsCachePluggable';
|
|
6
6
|
import { EventsCachePluggable } from './EventsCachePluggable';
|
|
@@ -103,7 +103,7 @@ export function PluggableStorage(options) {
|
|
|
103
103
|
return e; // Propagate error for shared clients
|
|
104
104
|
});
|
|
105
105
|
return {
|
|
106
|
-
|
|
106
|
+
definitions: new DefinitionsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
|
|
107
107
|
rbSegments: new RBSegmentsCachePluggable(log, keys, wrapper),
|
|
108
108
|
segments: new SegmentsCachePluggable(log, keys, wrapper),
|
|
109
109
|
impressions: isPartialConsumer ? new ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
@@ -20,12 +20,12 @@ export function validateRolloutPlan(log, settings) {
|
|
|
20
20
|
* Otherwise, the storage is handled as a server-side storage (segments is an instance of SegmentsCache).
|
|
21
21
|
*/
|
|
22
22
|
export function setRolloutPlan(log, rolloutPlan, storage, matchingKey) {
|
|
23
|
-
var
|
|
23
|
+
var definitions = storage.definitions, rbSegments = storage.rbSegments, segments = storage.segments, largeSegments = storage.largeSegments;
|
|
24
24
|
var _a = rolloutPlan.splitChanges, ff = _a.ff, rbs = _a.rbs;
|
|
25
25
|
log.debug("storage: set feature flags and segments".concat(matchingKey ? " for key ".concat(matchingKey) : ''));
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (definitions && ff) {
|
|
27
|
+
definitions.clear();
|
|
28
|
+
definitions.update(ff.d || [], [], ff.t);
|
|
29
29
|
}
|
|
30
30
|
if (rbSegments && rbs) {
|
|
31
31
|
rbSegments.clear();
|
package/esm/storages/utils.js
CHANGED