@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
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefinitionsCacheInMemory = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var AbstractDefinitionsCacheSync_1 = require("../AbstractDefinitionsCacheSync");
|
|
6
|
-
var lang_1 = require("../../utils/lang");
|
|
7
|
-
/**
|
|
8
|
-
* Default IDefinitionsCacheSync implementation that stores split definitions in memory.
|
|
9
|
-
*/
|
|
10
|
-
var DefinitionsCacheInMemory = /** @class */ (function (_super) {
|
|
11
|
-
tslib_1.__extends(DefinitionsCacheInMemory, _super);
|
|
12
|
-
function DefinitionsCacheInMemory(splitFiltersValidation) {
|
|
13
|
-
var _this = _super.call(this) || this;
|
|
14
|
-
_this.definitionsCache = {};
|
|
15
|
-
_this.ttCache = {};
|
|
16
|
-
_this.changeNumber = -1;
|
|
17
|
-
_this.segmentsCount = 0;
|
|
18
|
-
_this.setsCache = {};
|
|
19
|
-
_this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
20
|
-
return _this;
|
|
21
|
-
}
|
|
22
|
-
DefinitionsCacheInMemory.prototype.clear = function () {
|
|
23
|
-
this.definitionsCache = {};
|
|
24
|
-
this.ttCache = {};
|
|
25
|
-
this.changeNumber = -1;
|
|
26
|
-
this.segmentsCount = 0;
|
|
27
|
-
this.setsCache = {};
|
|
28
|
-
};
|
|
29
|
-
DefinitionsCacheInMemory.prototype.add = function (definition) {
|
|
30
|
-
var name = definition.name;
|
|
31
|
-
var previousDefinition = this.get(name);
|
|
32
|
-
if (previousDefinition) { // We had this Split already
|
|
33
|
-
var previousTtName = previousDefinition.trafficTypeName;
|
|
34
|
-
this.ttCache[previousTtName]--;
|
|
35
|
-
if (!this.ttCache[previousTtName])
|
|
36
|
-
delete this.ttCache[previousTtName];
|
|
37
|
-
this.removeFromFlagSets(previousDefinition.name, previousDefinition.sets);
|
|
38
|
-
// Subtract from segments count for the previous version of this Split
|
|
39
|
-
if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(previousDefinition))
|
|
40
|
-
this.segmentsCount--;
|
|
41
|
-
}
|
|
42
|
-
// Store the Split.
|
|
43
|
-
this.definitionsCache[name] = definition;
|
|
44
|
-
// Update TT cache
|
|
45
|
-
var ttName = definition.trafficTypeName;
|
|
46
|
-
this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
|
|
47
|
-
this.addToFlagSets(definition);
|
|
48
|
-
// Add to segments count for the new version of the Split
|
|
49
|
-
if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(definition))
|
|
50
|
-
this.segmentsCount++;
|
|
51
|
-
return true;
|
|
52
|
-
};
|
|
53
|
-
DefinitionsCacheInMemory.prototype.remove = function (name) {
|
|
54
|
-
var definition = this.get(name);
|
|
55
|
-
if (!definition)
|
|
56
|
-
return false;
|
|
57
|
-
// Delete the Split
|
|
58
|
-
delete this.definitionsCache[name];
|
|
59
|
-
var ttName = definition.trafficTypeName;
|
|
60
|
-
this.ttCache[ttName]--; // Update tt cache
|
|
61
|
-
if (!this.ttCache[ttName])
|
|
62
|
-
delete this.ttCache[ttName];
|
|
63
|
-
this.removeFromFlagSets(definition.name, definition.sets);
|
|
64
|
-
// Update the segments count.
|
|
65
|
-
if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(definition))
|
|
66
|
-
this.segmentsCount--;
|
|
67
|
-
return true;
|
|
68
|
-
};
|
|
69
|
-
DefinitionsCacheInMemory.prototype.get = function (name) {
|
|
70
|
-
return this.definitionsCache[name] || null;
|
|
71
|
-
};
|
|
72
|
-
DefinitionsCacheInMemory.prototype.setChangeNumber = function (changeNumber) {
|
|
73
|
-
this.changeNumber = changeNumber;
|
|
74
|
-
return true;
|
|
75
|
-
};
|
|
76
|
-
DefinitionsCacheInMemory.prototype.getChangeNumber = function () {
|
|
77
|
-
return this.changeNumber;
|
|
78
|
-
};
|
|
79
|
-
DefinitionsCacheInMemory.prototype.getNames = function () {
|
|
80
|
-
return Object.keys(this.definitionsCache);
|
|
81
|
-
};
|
|
82
|
-
DefinitionsCacheInMemory.prototype.trafficTypeExists = function (trafficType) {
|
|
83
|
-
return (0, lang_1.isFiniteNumber)(this.ttCache[trafficType]) && this.ttCache[trafficType] > 0;
|
|
84
|
-
};
|
|
85
|
-
DefinitionsCacheInMemory.prototype.usesSegments = function () {
|
|
86
|
-
return this.getChangeNumber() === -1 || this.segmentsCount > 0;
|
|
87
|
-
};
|
|
88
|
-
DefinitionsCacheInMemory.prototype.getNamesBySets = function (sets) {
|
|
89
|
-
var _this = this;
|
|
90
|
-
return sets.map(function (set) { return _this.setsCache[set] || new Set(); });
|
|
91
|
-
};
|
|
92
|
-
DefinitionsCacheInMemory.prototype.addToFlagSets = function (featureFlag) {
|
|
93
|
-
var _this = this;
|
|
94
|
-
if (!featureFlag.sets)
|
|
95
|
-
return;
|
|
96
|
-
featureFlag.sets.forEach(function (featureFlagSet) {
|
|
97
|
-
if (_this.setsFilter.length > 0 && !_this.setsFilter.some(function (filterFlagSet) { return filterFlagSet === featureFlagSet; }))
|
|
98
|
-
return;
|
|
99
|
-
if (!_this.setsCache[featureFlagSet])
|
|
100
|
-
_this.setsCache[featureFlagSet] = new Set([]);
|
|
101
|
-
_this.setsCache[featureFlagSet].add(featureFlag.name);
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
DefinitionsCacheInMemory.prototype.removeFromFlagSets = function (featureFlagName, sets) {
|
|
105
|
-
var _this = this;
|
|
106
|
-
if (!sets)
|
|
107
|
-
return;
|
|
108
|
-
sets.forEach(function (set) {
|
|
109
|
-
_this.removeNames(set, featureFlagName);
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
DefinitionsCacheInMemory.prototype.removeNames = function (setName, featureFlagName) {
|
|
113
|
-
if (!this.setsCache[setName])
|
|
114
|
-
return;
|
|
115
|
-
this.setsCache[setName].delete(featureFlagName);
|
|
116
|
-
if (this.setsCache[setName].size === 0)
|
|
117
|
-
delete this.setsCache[setName];
|
|
118
|
-
};
|
|
119
|
-
return DefinitionsCacheInMemory;
|
|
120
|
-
}(AbstractDefinitionsCacheSync_1.AbstractDefinitionsCacheSync));
|
|
121
|
-
exports.DefinitionsCacheInMemory = DefinitionsCacheInMemory;
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefinitionsCachePluggable = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var lang_1 = require("../../utils/lang");
|
|
6
|
-
var constants_1 = require("./constants");
|
|
7
|
-
var AbstractDefinitionsCacheAsync_1 = require("../AbstractDefinitionsCacheAsync");
|
|
8
|
-
var sets_1 = require("../../utils/lang/sets");
|
|
9
|
-
/**
|
|
10
|
-
* IDefinitionsCacheAsync implementation for pluggable storages.
|
|
11
|
-
*/
|
|
12
|
-
var DefinitionsCachePluggable = /** @class */ (function (_super) {
|
|
13
|
-
tslib_1.__extends(DefinitionsCachePluggable, _super);
|
|
14
|
-
/**
|
|
15
|
-
* Create a DefinitionsCache that uses a storage wrapper.
|
|
16
|
-
* @param log - Logger instance.
|
|
17
|
-
* @param keys - Key builder.
|
|
18
|
-
* @param wrapper - Adapted wrapper storage.
|
|
19
|
-
*/
|
|
20
|
-
function DefinitionsCachePluggable(log, keys, wrapper, splitFiltersValidation) {
|
|
21
|
-
var _this = _super.call(this) || this;
|
|
22
|
-
_this.log = log;
|
|
23
|
-
_this.keys = keys;
|
|
24
|
-
_this.wrapper = wrapper;
|
|
25
|
-
_this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
26
|
-
return _this;
|
|
27
|
-
}
|
|
28
|
-
DefinitionsCachePluggable.prototype._decrementCounts = function (definition) {
|
|
29
|
-
var _this = this;
|
|
30
|
-
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
31
|
-
return this.wrapper.decr(ttKey).then(function (count) {
|
|
32
|
-
if (count === 0)
|
|
33
|
-
return _this.wrapper.del(ttKey);
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
DefinitionsCachePluggable.prototype._incrementCounts = function (definition) {
|
|
37
|
-
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
38
|
-
return this.wrapper.incr(ttKey);
|
|
39
|
-
};
|
|
40
|
-
DefinitionsCachePluggable.prototype._updateSets = function (definitionName, setsOfRemovedDefinition, setsOfAddedDefinition) {
|
|
41
|
-
var _this = this;
|
|
42
|
-
var removeFromSets = (0, sets_1.returnDifference)(setsOfRemovedDefinition, setsOfAddedDefinition);
|
|
43
|
-
var addToSets = (0, sets_1.returnDifference)(setsOfAddedDefinition, setsOfRemovedDefinition);
|
|
44
|
-
if (this.setsFilter.length > 0) {
|
|
45
|
-
addToSets = addToSets.filter(function (set) {
|
|
46
|
-
return _this.setsFilter.some(function (filterSet) { return filterSet === set; });
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
var items = [definitionName];
|
|
50
|
-
return Promise.all(tslib_1.__spreadArray(tslib_1.__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));
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Add a given definition.
|
|
54
|
-
* The returned promise is resolved when the operation success
|
|
55
|
-
* or rejected if it fails (e.g., wrapper operation fails)
|
|
56
|
-
*/
|
|
57
|
-
DefinitionsCachePluggable.prototype.add = function (definition) {
|
|
58
|
-
var _this = this;
|
|
59
|
-
var name = definition.name;
|
|
60
|
-
var definitionKey = this.keys.buildDefinitionKey(name);
|
|
61
|
-
return this.wrapper.get(definitionKey).then(function (definitionFromStorage) {
|
|
62
|
-
// handling parsing error
|
|
63
|
-
var parsedPreviousDefinition, stringifiedNewDefinition;
|
|
64
|
-
try {
|
|
65
|
-
parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
|
|
66
|
-
stringifiedNewDefinition = JSON.stringify(definition);
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
throw new Error('Error parsing feature flag definition: ' + e);
|
|
70
|
-
}
|
|
71
|
-
return _this.wrapper.set(definitionKey, stringifiedNewDefinition).then(function () {
|
|
72
|
-
// avoid unnecessary increment/decrement operations
|
|
73
|
-
if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName)
|
|
74
|
-
return;
|
|
75
|
-
// update traffic type counts
|
|
76
|
-
return _this._incrementCounts(definition).then(function () {
|
|
77
|
-
if (parsedPreviousDefinition)
|
|
78
|
-
return _this._decrementCounts(parsedPreviousDefinition);
|
|
79
|
-
});
|
|
80
|
-
}).then(function () { return _this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets); });
|
|
81
|
-
}).then(function () { return true; });
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Remove a given definition.
|
|
85
|
-
* The returned promise is resolved when the operation success, with a boolean indicating if the definition existed or not.
|
|
86
|
-
* or rejected if it fails (e.g., wrapper operation fails).
|
|
87
|
-
*/
|
|
88
|
-
DefinitionsCachePluggable.prototype.remove = function (name) {
|
|
89
|
-
var _this = this;
|
|
90
|
-
return this.get(name).then(function (definition) {
|
|
91
|
-
if (definition) {
|
|
92
|
-
return _this._decrementCounts(definition).then(function () { return _this._updateSets(name, definition.sets); });
|
|
93
|
-
}
|
|
94
|
-
}).then(function () {
|
|
95
|
-
return _this.wrapper.del(_this.keys.buildDefinitionKey(name));
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Get definition.
|
|
100
|
-
* The returned promise is resolved with the definition or null if it's not defined,
|
|
101
|
-
* or rejected if wrapper operation fails.
|
|
102
|
-
*/
|
|
103
|
-
DefinitionsCachePluggable.prototype.get = function (name) {
|
|
104
|
-
return this.wrapper.get(this.keys.buildDefinitionKey(name))
|
|
105
|
-
.then(function (maybeDefinition) { return maybeDefinition && JSON.parse(maybeDefinition); });
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Get list of definitions.
|
|
109
|
-
* The returned promise is resolved with a map of names to their definition or null if it's not defined,
|
|
110
|
-
* or rejected if wrapper operation fails.
|
|
111
|
-
*/
|
|
112
|
-
DefinitionsCachePluggable.prototype.getMany = function (names) {
|
|
113
|
-
var _this = this;
|
|
114
|
-
var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
|
|
115
|
-
return this.wrapper.getMany(keys).then(function (stringifiedDefinitions) {
|
|
116
|
-
var definitions = {};
|
|
117
|
-
names.forEach(function (name, idx) {
|
|
118
|
-
var definition = stringifiedDefinitions[idx];
|
|
119
|
-
definitions[name] = definition && JSON.parse(definition);
|
|
120
|
-
});
|
|
121
|
-
return Promise.resolve(definitions);
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Get list of all definitions.
|
|
126
|
-
* The returned promise is resolved with the list of definitions,
|
|
127
|
-
* or rejected if wrapper operation fails.
|
|
128
|
-
*/
|
|
129
|
-
DefinitionsCachePluggable.prototype.getAll = function () {
|
|
130
|
-
var _this = this;
|
|
131
|
-
return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix())
|
|
132
|
-
.then(function (listOfKeys) { return _this.wrapper.getMany(listOfKeys); })
|
|
133
|
-
.then(function (definitions) { return definitions.map(function (definition) {
|
|
134
|
-
return JSON.parse(definition);
|
|
135
|
-
}); });
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Get list of definition names.
|
|
139
|
-
* The returned promise is resolved with the list of names,
|
|
140
|
-
* or rejected if wrapper operation fails.
|
|
141
|
-
*/
|
|
142
|
-
DefinitionsCachePluggable.prototype.getNames = function () {
|
|
143
|
-
var _this = this;
|
|
144
|
-
return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
|
|
145
|
-
};
|
|
146
|
-
/**
|
|
147
|
-
* Get list of definition names related to a given list of set names.
|
|
148
|
-
* The returned promise is resolved with the list of names per set.
|
|
149
|
-
* It never rejects (If there is a wrapper error for some set, an empty set is returned for it).
|
|
150
|
-
*/
|
|
151
|
-
DefinitionsCachePluggable.prototype.getNamesBySets = function (sets) {
|
|
152
|
-
var _this = this;
|
|
153
|
-
return Promise.all(sets.map(function (set) {
|
|
154
|
-
var setKey = _this.keys.buildSetKey(set);
|
|
155
|
-
return _this.wrapper.getItems(setKey).catch(function () { return []; });
|
|
156
|
-
})).then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Check traffic type existence.
|
|
160
|
-
* The returned promise is resolved with a boolean indicating whether the TT exist or not.
|
|
161
|
-
* In case of wrapper operation failures, the promise resolves with a true value, assuming that the TT might exist.
|
|
162
|
-
* It will never be rejected.
|
|
163
|
-
*/
|
|
164
|
-
DefinitionsCachePluggable.prototype.trafficTypeExists = function (trafficType) {
|
|
165
|
-
var _this = this;
|
|
166
|
-
// If there is a number there should be > 0, otherwise the TT is considered as not existent.
|
|
167
|
-
return this.wrapper.get(this.keys.buildTrafficTypeKey(trafficType))
|
|
168
|
-
.then(function (ttCount) {
|
|
169
|
-
if (ttCount === null)
|
|
170
|
-
return false; // if entry doesn't exist, means that TT doesn't exist
|
|
171
|
-
ttCount = parseInt(ttCount, 10);
|
|
172
|
-
if (!(0, lang_1.isFiniteNumber)(ttCount) || ttCount < 0) {
|
|
173
|
-
_this.log.info(constants_1.LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to data corruption of some sorts."));
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
return ttCount > 0;
|
|
177
|
-
}).catch(function (e) {
|
|
178
|
-
_this.log.error(constants_1.LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to an error: ").concat(e, "."));
|
|
179
|
-
// If there is an error, bypass the validation so the event can get tracked.
|
|
180
|
-
return true;
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
/**
|
|
184
|
-
* Set till number.
|
|
185
|
-
* The returned promise is resolved when the operation success,
|
|
186
|
-
* or rejected if it fails (e.g., wrapper operation fails).
|
|
187
|
-
*/
|
|
188
|
-
DefinitionsCachePluggable.prototype.setChangeNumber = function (changeNumber) {
|
|
189
|
-
return this.wrapper.set(this.keys.buildDefinitionsTillKey(), changeNumber + '');
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Get till number or -1 if it's not defined.
|
|
193
|
-
* The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
|
|
194
|
-
* The promise will never be rejected.
|
|
195
|
-
*/
|
|
196
|
-
DefinitionsCachePluggable.prototype.getChangeNumber = function () {
|
|
197
|
-
var _this = this;
|
|
198
|
-
return this.wrapper.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
|
|
199
|
-
var i = parseInt(value, 10);
|
|
200
|
-
return (0, lang_1.isNaNNumber)(i) ? -1 : i;
|
|
201
|
-
}).catch(function (e) {
|
|
202
|
-
_this.log.error(constants_1.LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
|
|
203
|
-
return -1;
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
// @TODO implement if required by DataLoader or producer mode
|
|
207
|
-
DefinitionsCachePluggable.prototype.clear = function () {
|
|
208
|
-
return Promise.resolve(true);
|
|
209
|
-
};
|
|
210
|
-
return DefinitionsCachePluggable;
|
|
211
|
-
}(AbstractDefinitionsCacheAsync_1.AbstractDefinitionsCacheAsync));
|
|
212
|
-
exports.DefinitionsCachePluggable = DefinitionsCachePluggable;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.definitionsSyncTaskFactory = void 0;
|
|
4
|
-
var syncTask_1 = require("../../syncTask");
|
|
5
|
-
var definitionChangesUpdater_1 = require("../updaters/definitionChangesUpdater");
|
|
6
|
-
/**
|
|
7
|
-
* Creates a sync task that periodically executes a `definitionChangesUpdater` task
|
|
8
|
-
*/
|
|
9
|
-
function definitionsSyncTaskFactory(definitionChangesFetcher, storage, readiness, settings, segmentsSyncTask // undefined for client-side
|
|
10
|
-
) {
|
|
11
|
-
return (0, syncTask_1.syncTaskFactory)(settings.log, (0, definitionChangesUpdater_1.definitionChangesUpdaterFactory)(settings.log, definitionChangesFetcher, storage, settings.sync.__splitFiltersValidation, readiness.definitions, settings.startup.requestTimeoutBeforeReady, settings.startup.retriesOnFailureBeforeReady, segmentsSyncTask), settings.scheduler.featuresRefreshRate, 'definitionChangesUpdater');
|
|
12
|
-
}
|
|
13
|
-
exports.definitionsSyncTaskFactory = definitionsSyncTaskFactory;
|