@splitsoftware/splitio-commons 3.0.0-rc.0 → 3.0.0-rc.1
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 +8 -3
- package/cjs/evaluator/index.js +11 -11
- package/cjs/logger/constants.js +4 -4
- package/cjs/logger/messages/warn.js +0 -1
- package/cjs/readiness/constants.js +4 -4
- package/cjs/readiness/readinessManager.js +22 -22
- package/cjs/readiness/sdkReadinessManager.js +0 -16
- package/cjs/sdkClient/sdkLifecycle.js +2 -1
- package/cjs/sdkClient/trackMethod.js +2 -2
- package/cjs/sdkFactory/index.js +5 -5
- package/cjs/sdkManager/index.js +2 -2
- package/cjs/services/authProvider.js +67 -0
- package/cjs/services/secureSplitHttpClient.js +39 -0
- package/cjs/services/splitApi.js +7 -2
- package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
- package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
- package/cjs/storages/KeyBuilder.js +6 -6
- package/cjs/storages/KeyBuilderCS.js +5 -5
- package/cjs/storages/KeyBuilderSS.js +2 -2
- package/cjs/storages/getRolloutPlan.js +3 -3
- package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +194 -0
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +9 -9
- package/cjs/storages/inLocalStorage/index.js +6 -6
- package/cjs/storages/inLocalStorage/validateCache.js +3 -3
- package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +121 -0
- package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +4 -4
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +3 -3
- package/cjs/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +77 -77
- package/cjs/storages/inRedis/index.js +2 -2
- package/cjs/storages/pluggable/DefinitionsCachePluggable.js +212 -0
- package/cjs/storages/pluggable/index.js +2 -2
- package/cjs/storages/setRolloutPlan.js +5 -5
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +1 -1
- package/cjs/sync/polling/pollingManagerCS.js +7 -7
- package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/definitionChangesUpdater.js +8 -8
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +1 -1
- package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +15 -15
- package/cjs/sync/streaming/constants.js +3 -3
- package/cjs/sync/streaming/pushManager.js +13 -13
- package/cjs/sync/submitters/telemetrySubmitter.js +1 -2
- package/cjs/sync/syncManagerOnline.js +4 -4
- package/cjs/utils/Backoff.js +20 -0
- package/cjs/utils/lang/sets.js +4 -4
- package/cjs/utils/settingsValidation/url.js +1 -1
- package/esm/evaluator/index.js +11 -11
- package/esm/logger/constants.js +1 -1
- package/esm/logger/messages/warn.js +0 -1
- package/esm/readiness/constants.js +3 -3
- package/esm/readiness/readinessManager.js +23 -23
- package/esm/readiness/sdkReadinessManager.js +1 -17
- package/esm/sdkClient/sdkLifecycle.js +2 -1
- package/esm/sdkClient/trackMethod.js +2 -2
- package/esm/sdkFactory/index.js +6 -6
- package/esm/sdkManager/index.js +2 -2
- package/esm/services/authProvider.js +63 -0
- package/esm/services/secureSplitHttpClient.js +35 -0
- package/esm/services/splitApi.js +7 -2
- package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
- package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
- package/esm/storages/KeyBuilder.js +6 -6
- package/esm/storages/KeyBuilderCS.js +5 -5
- package/esm/storages/KeyBuilderSS.js +2 -2
- package/esm/storages/getRolloutPlan.js +3 -3
- package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +191 -0
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +6 -6
- package/esm/storages/inLocalStorage/index.js +6 -6
- package/esm/storages/inLocalStorage/validateCache.js +3 -3
- package/esm/storages/inMemory/DefinitionsCacheInMemory.js +118 -0
- package/esm/storages/inMemory/InMemoryStorage.js +4 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +3 -3
- package/esm/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +76 -76
- package/esm/storages/inRedis/index.js +2 -2
- package/esm/storages/pluggable/DefinitionsCachePluggable.js +209 -0
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/storages/setRolloutPlan.js +5 -5
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +1 -1
- package/esm/sync/polling/pollingManagerCS.js +4 -4
- package/esm/sync/polling/syncTasks/definitionsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/definitionChangesUpdater.js +9 -9
- package/esm/sync/polling/updaters/mySegmentsUpdater.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/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +14 -14
- package/esm/sync/streaming/constants.js +2 -2
- package/esm/sync/streaming/pushManager.js +14 -14
- package/esm/sync/submitters/telemetrySubmitter.js +1 -2
- package/esm/sync/syncManagerOnline.js +3 -3
- package/esm/utils/Backoff.js +20 -0
- package/esm/utils/lang/sets.js +4 -4
- package/esm/utils/settingsValidation/url.js +1 -1
- package/package.json +1 -1
- package/src/dtos/types.ts +2 -2
- package/src/evaluator/index.ts +11 -11
- package/src/logger/constants.ts +1 -1
- package/src/logger/messages/warn.ts +0 -1
- package/src/readiness/constants.ts +3 -3
- package/src/readiness/readinessManager.ts +22 -22
- package/src/readiness/sdkReadinessManager.ts +1 -16
- package/src/readiness/types.ts +10 -16
- package/src/sdkClient/sdkLifecycle.ts +2 -1
- package/src/sdkClient/trackMethod.ts +2 -2
- package/src/sdkFactory/index.ts +5 -5
- package/src/sdkManager/index.ts +6 -6
- package/src/services/authProvider.ts +86 -0
- package/src/services/secureSplitHttpClient.ts +44 -0
- package/src/services/splitApi.ts +9 -3
- package/src/services/types.ts +4 -0
- package/src/storages/AbstractDefinitionsCacheAsync.ts +63 -0
- package/src/storages/AbstractDefinitionsCacheSync.ts +95 -0
- package/src/storages/KeyBuilder.ts +6 -6
- package/src/storages/KeyBuilderCS.ts +6 -6
- package/src/storages/KeyBuilderSS.ts +2 -2
- package/src/storages/getRolloutPlan.ts +3 -3
- package/src/storages/inLocalStorage/DefinitionsCacheInLocal.ts +234 -0
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +6 -6
- package/src/storages/inLocalStorage/index.ts +6 -6
- package/src/storages/inLocalStorage/validateCache.ts +4 -4
- package/src/storages/inMemory/DefinitionsCacheInMemory.ts +130 -0
- package/src/storages/inMemory/InMemoryStorage.ts +4 -4
- package/src/storages/inMemory/InMemoryStorageCS.ts +5 -5
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +1 -1
- package/src/storages/inMemory/SegmentsCacheInMemory.ts +1 -1
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +3 -3
- package/src/storages/inRedis/{SplitsCacheInRedis.ts → DefinitionsCacheInRedis.ts} +67 -67
- package/src/storages/inRedis/index.ts +2 -2
- package/src/storages/pluggable/DefinitionsCachePluggable.ts +230 -0
- package/src/storages/pluggable/index.ts +2 -2
- package/src/storages/setRolloutPlan.ts +7 -7
- package/src/storages/types.ts +19 -19
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +8 -8
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +3 -3
- package/src/sync/polling/pollingManagerCS.ts +4 -4
- package/src/sync/polling/syncTasks/definitionsSyncTask.ts +1 -1
- package/src/sync/polling/types.ts +1 -1
- package/src/sync/polling/updaters/definitionChangesUpdater.ts +11 -11
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +1 -1
- package/src/sync/streaming/AuthClient/index.ts +2 -2
- package/src/sync/streaming/AuthClient/types.ts +14 -11
- package/src/sync/streaming/SSEClient/index.ts +2 -2
- package/src/sync/streaming/SSEClient/types.ts +2 -2
- package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +2 -2
- package/src/sync/streaming/SSEHandler/index.ts +2 -2
- package/src/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.ts → DefinitionsUpdateWorker.ts} +16 -16
- package/src/sync/streaming/constants.ts +2 -2
- package/src/sync/streaming/pushManager.ts +16 -16
- package/src/sync/streaming/types.ts +2 -2
- package/src/sync/submitters/telemetrySubmitter.ts +1 -2
- package/src/sync/syncManagerOnline.ts +3 -3
- package/src/utils/Backoff.ts +21 -0
- package/src/utils/inputValidation/trafficTypeExistence.ts +2 -2
- package/src/utils/jwt/types.ts +1 -1
- package/src/utils/lang/sets.ts +4 -2
- package/src/utils/settingsValidation/url.ts +1 -1
- package/types/splitio.d.ts +23 -5
- 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/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/src/storages/AbstractSplitsCacheAsync.ts +0 -63
- package/src/storages/AbstractSplitsCacheSync.ts +0 -95
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +0 -234
- package/src/storages/inMemory/SplitsCacheInMemory.ts +0 -130
- package/src/storages/pluggable/SplitsCachePluggable.ts +0 -230
|
@@ -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,104 @@ 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
|
-
return this.redis.set(this.keys.
|
|
125
|
+
DefinitionsCacheInRedis.prototype.setChangeNumber = function (changeNumber) {
|
|
126
|
+
return this.redis.set(this.keys.buildDefinitionsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
|
|
127
127
|
};
|
|
128
128
|
/**
|
|
129
129
|
* Get till number or -1 if it's not defined.
|
|
130
130
|
* The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a redis operation fails.
|
|
131
131
|
* The promise will never be rejected.
|
|
132
132
|
*/
|
|
133
|
-
|
|
133
|
+
DefinitionsCacheInRedis.prototype.getChangeNumber = function () {
|
|
134
134
|
var _this = this;
|
|
135
|
-
return this.redis.get(this.keys.
|
|
135
|
+
return this.redis.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
|
|
136
136
|
var i = parseInt(value, 10);
|
|
137
137
|
return isNaNNumber(i) ? -1 : i;
|
|
138
138
|
}).catch(function (e) {
|
|
@@ -141,44 +141,44 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
141
141
|
});
|
|
142
142
|
};
|
|
143
143
|
/**
|
|
144
|
-
* Get list of all
|
|
145
|
-
* The returned promise is resolved with the list of
|
|
144
|
+
* Get list of all definitions.
|
|
145
|
+
* The returned promise is resolved with the list of definitions,
|
|
146
146
|
* or rejected if redis operation fails.
|
|
147
147
|
*/
|
|
148
148
|
// @TODO we need to benchmark which is the maximun number of commands we could pipeline without kill redis performance.
|
|
149
|
-
|
|
149
|
+
DefinitionsCacheInRedis.prototype.getAll = function () {
|
|
150
150
|
var _this = this;
|
|
151
|
-
return this.redis.keys(this.keys.
|
|
151
|
+
return this.redis.keys(this.keys.searchPatternForDefinitionKeys())
|
|
152
152
|
.then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
|
|
153
153
|
.then(processPipelineAnswer)
|
|
154
|
-
.then(function (
|
|
155
|
-
return JSON.parse(
|
|
154
|
+
.then(function (definitions) { return definitions.map(function (definition) {
|
|
155
|
+
return JSON.parse(definition);
|
|
156
156
|
}); });
|
|
157
157
|
};
|
|
158
158
|
/**
|
|
159
|
-
* Get list of
|
|
160
|
-
* The returned promise is resolved with the list of
|
|
159
|
+
* Get list of definition names.
|
|
160
|
+
* The returned promise is resolved with the list of names,
|
|
161
161
|
* or rejected if redis operation fails.
|
|
162
162
|
*/
|
|
163
|
-
|
|
163
|
+
DefinitionsCacheInRedis.prototype.getNames = function () {
|
|
164
164
|
var _this = this;
|
|
165
|
-
return this.redis.keys(this.keys.
|
|
165
|
+
return this.redis.keys(this.keys.searchPatternForDefinitionKeys()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
|
|
166
166
|
};
|
|
167
167
|
/**
|
|
168
|
-
* Get list of
|
|
169
|
-
* The returned promise is resolved with the list of
|
|
168
|
+
* Get list of definition names related to a given list of set names.
|
|
169
|
+
* The returned promise is resolved with the list of names per set,
|
|
170
170
|
* or rejected if the pipelined redis operation fails (e.g., timeout).
|
|
171
171
|
*/
|
|
172
|
-
|
|
172
|
+
DefinitionsCacheInRedis.prototype.getNamesBySets = function (sets) {
|
|
173
173
|
var _this = this;
|
|
174
|
-
return this.redis.pipeline(
|
|
174
|
+
return this.redis.pipeline(sets.map(function (set) { return ['smembers', _this.keys.buildSetKey(set)]; })).exec()
|
|
175
175
|
.then(function (results) { return results ? results.map(function (_a, index) {
|
|
176
176
|
var e = _a[0], value = _a[1];
|
|
177
177
|
if (e === null)
|
|
178
178
|
return value;
|
|
179
|
-
_this.log.error(LOG_PREFIX + "Could not read result from get members of
|
|
179
|
+
_this.log.error(LOG_PREFIX + "Could not read result from get members of set ".concat(sets[index], " due to an error: ").concat(e));
|
|
180
180
|
}) : []; })
|
|
181
|
-
.then(function (
|
|
181
|
+
.then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
|
|
182
182
|
};
|
|
183
183
|
/**
|
|
184
184
|
* Check traffic type existence.
|
|
@@ -186,7 +186,7 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
186
186
|
* In case of redis operation failure, the promise resolves with a true value, assuming that the TT might exist.
|
|
187
187
|
* It will never be rejected.
|
|
188
188
|
*/
|
|
189
|
-
|
|
189
|
+
DefinitionsCacheInRedis.prototype.trafficTypeExists = function (trafficType) {
|
|
190
190
|
var _this = this;
|
|
191
191
|
// If there is a number there should be > 0, otherwise the TT is considered as not existent.
|
|
192
192
|
return this.redis.get(this.keys.buildTrafficTypeKey(trafficType))
|
|
@@ -207,34 +207,34 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
207
207
|
});
|
|
208
208
|
};
|
|
209
209
|
// @TODO remove or implement. It is not being used.
|
|
210
|
-
|
|
210
|
+
DefinitionsCacheInRedis.prototype.clear = function () {
|
|
211
211
|
return Promise.resolve();
|
|
212
212
|
};
|
|
213
213
|
/**
|
|
214
|
-
* Fetches multiple
|
|
214
|
+
* Fetches multiple definitions.
|
|
215
215
|
* Returned promise is rejected if redis operation fails.
|
|
216
216
|
*/
|
|
217
|
-
|
|
217
|
+
DefinitionsCacheInRedis.prototype.getMany = function (names) {
|
|
218
218
|
var _a;
|
|
219
219
|
var _this = this;
|
|
220
220
|
if (this.redisError) {
|
|
221
221
|
this.log.error(LOG_PREFIX + this.redisError);
|
|
222
222
|
return Promise.reject(this.redisError);
|
|
223
223
|
}
|
|
224
|
-
var keys = names.map(function (name) { return _this.keys.
|
|
225
|
-
return (_a = this.redis).mget.apply(_a, keys).then(function (
|
|
226
|
-
var
|
|
224
|
+
var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
|
|
225
|
+
return (_a = this.redis).mget.apply(_a, keys).then(function (stringifiedDefinitions) {
|
|
226
|
+
var definitions = {};
|
|
227
227
|
names.forEach(function (name, idx) {
|
|
228
|
-
var
|
|
229
|
-
|
|
228
|
+
var definition = stringifiedDefinitions[idx];
|
|
229
|
+
definitions[name] = definition && JSON.parse(definition);
|
|
230
230
|
});
|
|
231
|
-
return Promise.resolve(
|
|
231
|
+
return Promise.resolve(definitions);
|
|
232
232
|
})
|
|
233
233
|
.catch(function (e) {
|
|
234
234
|
_this.log.error(LOG_PREFIX + "Could not grab feature flags due to an error: ".concat(e, "."));
|
|
235
235
|
return Promise.reject(e);
|
|
236
236
|
});
|
|
237
237
|
};
|
|
238
|
-
return
|
|
239
|
-
}(
|
|
240
|
-
export {
|
|
238
|
+
return DefinitionsCacheInRedis;
|
|
239
|
+
}(AbstractDefinitionsCacheAsync));
|
|
240
|
+
export { DefinitionsCacheInRedis };
|
|
@@ -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,209 @@
|
|
|
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
|
+
return this.wrapper.set(this.keys.buildDefinitionsTillKey(), changeNumber + '');
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Get till number or -1 if it's not defined.
|
|
190
|
+
* The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
|
|
191
|
+
* The promise will never be rejected.
|
|
192
|
+
*/
|
|
193
|
+
DefinitionsCachePluggable.prototype.getChangeNumber = function () {
|
|
194
|
+
var _this = this;
|
|
195
|
+
return this.wrapper.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
|
|
196
|
+
var i = parseInt(value, 10);
|
|
197
|
+
return isNaNNumber(i) ? -1 : i;
|
|
198
|
+
}).catch(function (e) {
|
|
199
|
+
_this.log.error(LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
|
|
200
|
+
return -1;
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
// @TODO implement if required by DataLoader or producer mode
|
|
204
|
+
DefinitionsCachePluggable.prototype.clear = function () {
|
|
205
|
+
return Promise.resolve(true);
|
|
206
|
+
};
|
|
207
|
+
return DefinitionsCachePluggable;
|
|
208
|
+
}(AbstractDefinitionsCacheAsync));
|
|
209
|
+
export { DefinitionsCachePluggable };
|
|
@@ -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,16 +20,16 @@ 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();
|
|
32
|
-
rbSegments.update(rbs.d, [], rbs.t);
|
|
32
|
+
rbSegments.update(rbs.d || [], [], rbs.t);
|
|
33
33
|
}
|
|
34
34
|
var segmentChanges = rolloutPlan.segmentChanges;
|
|
35
35
|
if (matchingKey) { // add memberships data (client-side)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { forOwn } from '../../../utils/lang';
|
|
2
2
|
import { syncTaskFactory } from '../../syncTask';
|
|
3
3
|
import { CONTROL } from '../../../utils/constants';
|
|
4
|
-
import {
|
|
4
|
+
import { SDK_DEFINITIONS_ARRIVED, SDK_SEGMENTS_ARRIVED, SDK_DEFINITIONS_CACHE_LOADED, FLAGS_UPDATE, SEGMENTS_UPDATE } from '../../../readiness/constants';
|
|
5
5
|
import { SYNC_OFFLINE_DATA, ERROR_SYNC_OFFLINE_LOADING } from '../../../logger/constants';
|
|
6
6
|
/**
|
|
7
7
|
* Offline equivalent of `splitChangesUpdaterFactory`
|
|
8
8
|
*/
|
|
9
9
|
export function fromObjectUpdaterFactory(splitsParser, storage, readiness, settings) {
|
|
10
|
-
var log = settings.log,
|
|
10
|
+
var log = settings.log, definitions = storage.definitions;
|
|
11
11
|
var startingUp = true;
|
|
12
12
|
return function objectUpdater() {
|
|
13
13
|
var splits = [];
|
|
@@ -36,16 +36,16 @@ export function fromObjectUpdaterFactory(splitsParser, storage, readiness, setti
|
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
return Promise.all([
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
definitions.clear(),
|
|
40
|
+
definitions.update(splits, [], Date.now())
|
|
41
41
|
]).then(function () {
|
|
42
|
-
readiness.
|
|
42
|
+
readiness.definitions.emit(SDK_DEFINITIONS_ARRIVED, { type: FLAGS_UPDATE, names: [] });
|
|
43
43
|
if (startingUp) {
|
|
44
44
|
startingUp = false;
|
|
45
45
|
Promise.resolve(storage.validateCache ? storage.validateCache() : { initialCacheLoad: true /* Fallback: assume initial load when validateCache doesn't exist */ }).then(function (cacheMetadata) {
|
|
46
46
|
// Emits SDK_READY_FROM_CACHE
|
|
47
47
|
if (!cacheMetadata.initialCacheLoad) {
|
|
48
|
-
readiness.
|
|
48
|
+
readiness.definitions.emit(SDK_DEFINITIONS_CACHE_LOADED, cacheMetadata);
|
|
49
49
|
}
|
|
50
50
|
// Emits SDK_READY
|
|
51
51
|
readiness.segments.emit(SDK_SEGMENTS_ARRIVED, { type: SEGMENTS_UPDATE, names: [] });
|
|
@@ -58,7 +58,7 @@ export function splitChangesFetcherFactory(params) {
|
|
|
58
58
|
lastProxyCheckTimestamp = undefined;
|
|
59
59
|
return splitChangesFetcher(-1, undefined, undefined, -1)
|
|
60
60
|
.then(function (splitChangesResponse) {
|
|
61
|
-
return Promise.all([storage.
|
|
61
|
+
return Promise.all([storage.definitions.clear(), storage.rbSegments.clear()])
|
|
62
62
|
.then(function () { return splitChangesResponse; });
|
|
63
63
|
});
|
|
64
64
|
}
|
|
@@ -2,9 +2,9 @@ import { forOwn } from '../../utils/lang';
|
|
|
2
2
|
import { mySegmentsSyncTaskFactory } from './syncTasks/mySegmentsSyncTask';
|
|
3
3
|
import { definitionsSyncTaskFactory } from './syncTasks/definitionsSyncTask';
|
|
4
4
|
import { getMatching } from '../../utils/key';
|
|
5
|
-
import {
|
|
5
|
+
import { SDK_DEFINITIONS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../../readiness/constants';
|
|
6
6
|
import { POLLING_SMART_PAUSING, POLLING_START, POLLING_STOP } from '../../logger/constants';
|
|
7
|
-
import { usesSegmentsSync } from '../../storages/
|
|
7
|
+
import { usesSegmentsSync } from '../../storages/AbstractDefinitionsCacheSync';
|
|
8
8
|
/**
|
|
9
9
|
* Expose start / stop mechanism for polling data from services.
|
|
10
10
|
* For client-side API with multiple clients.
|
|
@@ -29,7 +29,7 @@ export function pollingManagerCSFactory(params, definitionChangesFetcher) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
// smart pausing
|
|
32
|
-
readiness.
|
|
32
|
+
readiness.definitions.on(SDK_DEFINITIONS_ARRIVED, function () {
|
|
33
33
|
if (!definitionsSyncTask.isRunning())
|
|
34
34
|
return; // noop if not doing polling
|
|
35
35
|
var usingSegments = usesSegmentsSync(storage);
|
|
@@ -53,7 +53,7 @@ export function pollingManagerCSFactory(params, definitionChangesFetcher) {
|
|
|
53
53
|
if (!usesSegmentsSync(storage))
|
|
54
54
|
setTimeout(smartReady, 0);
|
|
55
55
|
else
|
|
56
|
-
readiness.
|
|
56
|
+
readiness.definitions.once(SDK_DEFINITIONS_ARRIVED, smartReady);
|
|
57
57
|
mySegmentsSyncTasks[matchingKey] = mySegmentsSyncTask;
|
|
58
58
|
return mySegmentsSyncTask;
|
|
59
59
|
}
|