@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
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryStorageCSFactory = void 0;
|
|
4
|
-
var
|
|
4
|
+
var DefinitionsCacheInMemory_1 = require("./DefinitionsCacheInMemory");
|
|
5
5
|
var MySegmentsCacheInMemory_1 = require("./MySegmentsCacheInMemory");
|
|
6
6
|
var ImpressionsCacheInMemory_1 = require("./ImpressionsCacheInMemory");
|
|
7
7
|
var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
|
|
@@ -17,25 +17,25 @@ var RBSegmentsCacheInMemory_1 = require("./RBSegmentsCacheInMemory");
|
|
|
17
17
|
*/
|
|
18
18
|
function InMemoryStorageCSFactory(params) {
|
|
19
19
|
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
20
|
-
var
|
|
20
|
+
var definitions = new DefinitionsCacheInMemory_1.DefinitionsCacheInMemory(__splitFiltersValidation);
|
|
21
21
|
var rbSegments = new RBSegmentsCacheInMemory_1.RBSegmentsCacheInMemory();
|
|
22
22
|
var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
23
23
|
var largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
24
24
|
var storage = {
|
|
25
|
-
|
|
25
|
+
definitions: definitions,
|
|
26
26
|
rbSegments: rbSegments,
|
|
27
27
|
segments: segments,
|
|
28
28
|
largeSegments: largeSegments,
|
|
29
29
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
30
30
|
impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
31
31
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
32
|
-
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(
|
|
32
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(definitions, segments) : undefined,
|
|
33
33
|
uniqueKeys: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
|
|
34
34
|
destroy: function () { },
|
|
35
35
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are unique per key)
|
|
36
36
|
shared: function () {
|
|
37
37
|
return {
|
|
38
|
-
|
|
38
|
+
definitions: this.definitions,
|
|
39
39
|
rbSegments: this.rbSegments,
|
|
40
40
|
segments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
|
|
41
41
|
largeSegments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RBSegmentsCacheInMemory = void 0;
|
|
4
4
|
var sets_1 = require("../../utils/lang/sets");
|
|
5
|
-
var
|
|
5
|
+
var AbstractDefinitionsCacheSync_1 = require("../AbstractDefinitionsCacheSync");
|
|
6
6
|
var RBSegmentsCacheInMemory = /** @class */ (function () {
|
|
7
7
|
function RBSegmentsCacheInMemory() {
|
|
8
8
|
this.cache = {};
|
|
@@ -24,10 +24,10 @@ var RBSegmentsCacheInMemory = /** @class */ (function () {
|
|
|
24
24
|
RBSegmentsCacheInMemory.prototype.add = function (rbSegment) {
|
|
25
25
|
var name = rbSegment.name;
|
|
26
26
|
var previous = this.get(name);
|
|
27
|
-
if (previous && (0,
|
|
27
|
+
if (previous && (0, AbstractDefinitionsCacheSync_1.usesSegments)(previous))
|
|
28
28
|
this.segmentsCount--;
|
|
29
29
|
this.cache[name] = rbSegment;
|
|
30
|
-
if ((0,
|
|
30
|
+
if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(rbSegment))
|
|
31
31
|
this.segmentsCount++;
|
|
32
32
|
return true;
|
|
33
33
|
};
|
|
@@ -36,7 +36,7 @@ var RBSegmentsCacheInMemory = /** @class */ (function () {
|
|
|
36
36
|
if (!rbSegment)
|
|
37
37
|
return false;
|
|
38
38
|
delete this.cache[name];
|
|
39
|
-
if ((0,
|
|
39
|
+
if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(rbSegment))
|
|
40
40
|
this.segmentsCount--;
|
|
41
41
|
return true;
|
|
42
42
|
};
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SegmentsCacheInMemory = void 0;
|
|
4
4
|
var lang_1 = require("../../utils/lang");
|
|
5
5
|
/**
|
|
6
|
-
* Default
|
|
6
|
+
* Default IDefinitionsCacheSync implementation for server-side that stores segments definitions in memory.
|
|
7
7
|
*/
|
|
8
8
|
var SegmentsCacheInMemory = /** @class */ (function () {
|
|
9
9
|
function SegmentsCacheInMemory() {
|
|
@@ -24,8 +24,8 @@ function shouldRecordTelemetry(_a) {
|
|
|
24
24
|
}
|
|
25
25
|
exports.shouldRecordTelemetry = shouldRecordTelemetry;
|
|
26
26
|
var TelemetryCacheInMemory = /** @class */ (function () {
|
|
27
|
-
function TelemetryCacheInMemory(
|
|
28
|
-
this.
|
|
27
|
+
function TelemetryCacheInMemory(definitions, segments, largeSegments) {
|
|
28
|
+
this.definitions = definitions;
|
|
29
29
|
this.segments = segments;
|
|
30
30
|
this.largeSegments = largeSegments;
|
|
31
31
|
this.name = 'telemetry stats';
|
|
@@ -61,7 +61,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
61
61
|
iQ: this.getImpressionStats(constants_1.QUEUED),
|
|
62
62
|
iDe: this.getImpressionStats(constants_1.DEDUPED),
|
|
63
63
|
iDr: this.getImpressionStats(constants_1.DROPPED),
|
|
64
|
-
spC: this.
|
|
64
|
+
spC: this.definitions && this.definitions.getNames().length,
|
|
65
65
|
seC: this.segments && this.segments.getRegisteredSegments().length,
|
|
66
66
|
skC: this.segments && this.segments.getKeysCount(),
|
|
67
67
|
lsC: this.largeSegments && this.largeSegments.getRegisteredSegments().length,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DefinitionsCacheInRedis = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var lang_1 = require("../../utils/lang");
|
|
6
6
|
var constants_1 = require("./constants");
|
|
7
|
-
var
|
|
7
|
+
var AbstractDefinitionsCacheAsync_1 = require("../AbstractDefinitionsCacheAsync");
|
|
8
8
|
var sets_1 = require("../../utils/lang/sets");
|
|
9
9
|
/**
|
|
10
10
|
* Discard errors for an answer of multiple operations.
|
|
@@ -17,17 +17,17 @@ function processPipelineAnswer(results) {
|
|
|
17
17
|
}, []) : [];
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* IDefinitionsCacheAsync implementation that stores definitions in Redis.
|
|
21
21
|
* Supported by Node.js
|
|
22
22
|
*/
|
|
23
|
-
var
|
|
24
|
-
tslib_1.__extends(
|
|
25
|
-
function
|
|
23
|
+
var DefinitionsCacheInRedis = /** @class */ (function (_super) {
|
|
24
|
+
tslib_1.__extends(DefinitionsCacheInRedis, _super);
|
|
25
|
+
function DefinitionsCacheInRedis(log, keys, redis, splitFiltersValidation) {
|
|
26
26
|
var _this = _super.call(this) || this;
|
|
27
27
|
_this.log = log;
|
|
28
28
|
_this.redis = redis;
|
|
29
29
|
_this.keys = keys;
|
|
30
|
-
_this.
|
|
30
|
+
_this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
31
31
|
// 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.
|
|
32
32
|
// But it is done just to avoid getting the ioredis message `Unhandled error event`.
|
|
33
33
|
_this.redis.on('error', function (e) {
|
|
@@ -38,104 +38,104 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
38
38
|
});
|
|
39
39
|
return _this;
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
DefinitionsCacheInRedis.prototype._decrementCounts = function (definition) {
|
|
42
42
|
var _this = this;
|
|
43
|
-
var ttKey = this.keys.buildTrafficTypeKey(
|
|
43
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
44
44
|
return this.redis.decr(ttKey).then(function (count) {
|
|
45
45
|
if (count === 0)
|
|
46
46
|
return _this.redis.del(ttKey);
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
|
-
|
|
50
|
-
var ttKey = this.keys.buildTrafficTypeKey(
|
|
49
|
+
DefinitionsCacheInRedis.prototype._incrementCounts = function (definition) {
|
|
50
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
51
51
|
return this.redis.incr(ttKey);
|
|
52
52
|
};
|
|
53
|
-
|
|
53
|
+
DefinitionsCacheInRedis.prototype._updateSets = function (definitionName, setsOfRemovedDefinition, setsOfAddedDefinition) {
|
|
54
54
|
var _this = this;
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
if (this.
|
|
58
|
-
|
|
59
|
-
return _this.
|
|
55
|
+
var removeFromSets = (0, sets_1.returnDifference)(setsOfRemovedDefinition, setsOfAddedDefinition);
|
|
56
|
+
var addToSets = (0, sets_1.returnDifference)(setsOfAddedDefinition, setsOfRemovedDefinition);
|
|
57
|
+
if (this.setsFilter.length > 0) {
|
|
58
|
+
addToSets = addToSets.filter(function (set) {
|
|
59
|
+
return _this.setsFilter.some(function (filterSet) { return filterSet === set; });
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
var items = [
|
|
63
|
-
return Promise.all(tslib_1.__spreadArray(tslib_1.__spreadArray([],
|
|
62
|
+
var items = [definitionName];
|
|
63
|
+
return Promise.all(tslib_1.__spreadArray(tslib_1.__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));
|
|
64
64
|
};
|
|
65
65
|
/**
|
|
66
|
-
* Add a given
|
|
66
|
+
* Add a given definition.
|
|
67
67
|
* The returned promise is resolved when the operation success
|
|
68
68
|
* or rejected if it fails (e.g., redis operation fails)
|
|
69
69
|
*/
|
|
70
|
-
|
|
70
|
+
DefinitionsCacheInRedis.prototype.add = function (definition) {
|
|
71
71
|
var _this = this;
|
|
72
|
-
var name =
|
|
73
|
-
var
|
|
74
|
-
return this.redis.get(
|
|
72
|
+
var name = definition.name;
|
|
73
|
+
var definitionKey = this.keys.buildDefinitionKey(name);
|
|
74
|
+
return this.redis.get(definitionKey).then(function (definitionFromStorage) {
|
|
75
75
|
// handling parsing error
|
|
76
|
-
var
|
|
76
|
+
var parsedPreviousDefinition, stringifiedNewDefinition;
|
|
77
77
|
try {
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
|
|
79
|
+
stringifiedNewDefinition = JSON.stringify(definition);
|
|
80
80
|
}
|
|
81
81
|
catch (e) {
|
|
82
82
|
throw new Error('Error parsing feature flag definition: ' + e);
|
|
83
83
|
}
|
|
84
|
-
return _this.redis.set(
|
|
84
|
+
return _this.redis.set(definitionKey, stringifiedNewDefinition).then(function () {
|
|
85
85
|
// avoid unnecessary increment/decrement operations
|
|
86
|
-
if (
|
|
86
|
+
if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName)
|
|
87
87
|
return;
|
|
88
88
|
// update traffic type counts
|
|
89
|
-
return _this._incrementCounts(
|
|
90
|
-
if (
|
|
91
|
-
return _this._decrementCounts(
|
|
89
|
+
return _this._incrementCounts(definition).then(function () {
|
|
90
|
+
if (parsedPreviousDefinition)
|
|
91
|
+
return _this._decrementCounts(parsedPreviousDefinition);
|
|
92
92
|
});
|
|
93
|
-
}).then(function () { return _this.
|
|
93
|
+
}).then(function () { return _this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets); });
|
|
94
94
|
}).then(function () { return true; });
|
|
95
95
|
};
|
|
96
96
|
/**
|
|
97
|
-
* Remove a given
|
|
98
|
-
* The returned promise is resolved when the operation success, with true or false indicating if the
|
|
97
|
+
* Remove a given definition.
|
|
98
|
+
* The returned promise is resolved when the operation success, with true or false indicating if the definition existed (and was removed) or not.
|
|
99
99
|
* or rejected if it fails (e.g., redis operation fails).
|
|
100
100
|
*/
|
|
101
|
-
|
|
101
|
+
DefinitionsCacheInRedis.prototype.remove = function (name) {
|
|
102
102
|
var _this = this;
|
|
103
|
-
return this.
|
|
104
|
-
if (
|
|
105
|
-
return _this._decrementCounts(
|
|
103
|
+
return this.get(name).then(function (definition) {
|
|
104
|
+
if (definition) {
|
|
105
|
+
return _this._decrementCounts(definition).then(function () { return _this._updateSets(name, definition.sets); });
|
|
106
106
|
}
|
|
107
107
|
}).then(function () {
|
|
108
|
-
return _this.redis.del(_this.keys.
|
|
108
|
+
return _this.redis.del(_this.keys.buildDefinitionKey(name)).then(function (status) { return status === 1; });
|
|
109
109
|
});
|
|
110
110
|
};
|
|
111
111
|
/**
|
|
112
|
-
* Get
|
|
112
|
+
* Get definition or null if it's not defined.
|
|
113
113
|
* Returned promise is rejected if redis operation fails.
|
|
114
114
|
*/
|
|
115
|
-
|
|
115
|
+
DefinitionsCacheInRedis.prototype.get = function (name) {
|
|
116
116
|
if (this.redisError) {
|
|
117
117
|
this.log.error(constants_1.LOG_PREFIX + this.redisError);
|
|
118
118
|
return Promise.reject(this.redisError);
|
|
119
119
|
}
|
|
120
|
-
return this.redis.get(this.keys.
|
|
121
|
-
.then(function (
|
|
120
|
+
return this.redis.get(this.keys.buildDefinitionKey(name))
|
|
121
|
+
.then(function (maybeDefinition) { return maybeDefinition && JSON.parse(maybeDefinition); });
|
|
122
122
|
};
|
|
123
123
|
/**
|
|
124
124
|
* Set till number.
|
|
125
125
|
* The returned promise is resolved when the operation success,
|
|
126
126
|
* or rejected if it fails.
|
|
127
127
|
*/
|
|
128
|
-
|
|
129
|
-
return this.redis.set(this.keys.
|
|
128
|
+
DefinitionsCacheInRedis.prototype.setChangeNumber = function (changeNumber) {
|
|
129
|
+
return this.redis.set(this.keys.buildDefinitionsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
|
|
130
130
|
};
|
|
131
131
|
/**
|
|
132
132
|
* Get till number or -1 if it's not defined.
|
|
133
133
|
* The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a redis operation fails.
|
|
134
134
|
* The promise will never be rejected.
|
|
135
135
|
*/
|
|
136
|
-
|
|
136
|
+
DefinitionsCacheInRedis.prototype.getChangeNumber = function () {
|
|
137
137
|
var _this = this;
|
|
138
|
-
return this.redis.get(this.keys.
|
|
138
|
+
return this.redis.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
|
|
139
139
|
var i = parseInt(value, 10);
|
|
140
140
|
return (0, lang_1.isNaNNumber)(i) ? -1 : i;
|
|
141
141
|
}).catch(function (e) {
|
|
@@ -144,44 +144,44 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
144
144
|
});
|
|
145
145
|
};
|
|
146
146
|
/**
|
|
147
|
-
* Get list of all
|
|
148
|
-
* The returned promise is resolved with the list of
|
|
147
|
+
* Get list of all definitions.
|
|
148
|
+
* The returned promise is resolved with the list of definitions,
|
|
149
149
|
* or rejected if redis operation fails.
|
|
150
150
|
*/
|
|
151
151
|
// @TODO we need to benchmark which is the maximun number of commands we could pipeline without kill redis performance.
|
|
152
|
-
|
|
152
|
+
DefinitionsCacheInRedis.prototype.getAll = function () {
|
|
153
153
|
var _this = this;
|
|
154
|
-
return this.redis.keys(this.keys.
|
|
154
|
+
return this.redis.keys(this.keys.searchPatternForDefinitionKeys())
|
|
155
155
|
.then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
|
|
156
156
|
.then(processPipelineAnswer)
|
|
157
|
-
.then(function (
|
|
158
|
-
return JSON.parse(
|
|
157
|
+
.then(function (definitions) { return definitions.map(function (definition) {
|
|
158
|
+
return JSON.parse(definition);
|
|
159
159
|
}); });
|
|
160
160
|
};
|
|
161
161
|
/**
|
|
162
|
-
* Get list of
|
|
163
|
-
* The returned promise is resolved with the list of
|
|
162
|
+
* Get list of definition names.
|
|
163
|
+
* The returned promise is resolved with the list of names,
|
|
164
164
|
* or rejected if redis operation fails.
|
|
165
165
|
*/
|
|
166
|
-
|
|
166
|
+
DefinitionsCacheInRedis.prototype.getNames = function () {
|
|
167
167
|
var _this = this;
|
|
168
|
-
return this.redis.keys(this.keys.
|
|
168
|
+
return this.redis.keys(this.keys.searchPatternForDefinitionKeys()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
|
|
169
169
|
};
|
|
170
170
|
/**
|
|
171
|
-
* Get list of
|
|
172
|
-
* The returned promise is resolved with the list of
|
|
171
|
+
* Get list of definition names related to a given list of set names.
|
|
172
|
+
* The returned promise is resolved with the list of names per set,
|
|
173
173
|
* or rejected if the pipelined redis operation fails (e.g., timeout).
|
|
174
174
|
*/
|
|
175
|
-
|
|
175
|
+
DefinitionsCacheInRedis.prototype.getNamesBySets = function (sets) {
|
|
176
176
|
var _this = this;
|
|
177
|
-
return this.redis.pipeline(
|
|
177
|
+
return this.redis.pipeline(sets.map(function (set) { return ['smembers', _this.keys.buildSetKey(set)]; })).exec()
|
|
178
178
|
.then(function (results) { return results ? results.map(function (_a, index) {
|
|
179
179
|
var e = _a[0], value = _a[1];
|
|
180
180
|
if (e === null)
|
|
181
181
|
return value;
|
|
182
|
-
_this.log.error(constants_1.LOG_PREFIX + "Could not read result from get members of
|
|
182
|
+
_this.log.error(constants_1.LOG_PREFIX + "Could not read result from get members of set ".concat(sets[index], " due to an error: ").concat(e));
|
|
183
183
|
}) : []; })
|
|
184
|
-
.then(function (
|
|
184
|
+
.then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
|
|
185
185
|
};
|
|
186
186
|
/**
|
|
187
187
|
* Check traffic type existence.
|
|
@@ -189,7 +189,7 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
189
189
|
* In case of redis operation failure, the promise resolves with a true value, assuming that the TT might exist.
|
|
190
190
|
* It will never be rejected.
|
|
191
191
|
*/
|
|
192
|
-
|
|
192
|
+
DefinitionsCacheInRedis.prototype.trafficTypeExists = function (trafficType) {
|
|
193
193
|
var _this = this;
|
|
194
194
|
// If there is a number there should be > 0, otherwise the TT is considered as not existent.
|
|
195
195
|
return this.redis.get(this.keys.buildTrafficTypeKey(trafficType))
|
|
@@ -210,34 +210,34 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
210
210
|
});
|
|
211
211
|
};
|
|
212
212
|
// @TODO remove or implement. It is not being used.
|
|
213
|
-
|
|
213
|
+
DefinitionsCacheInRedis.prototype.clear = function () {
|
|
214
214
|
return Promise.resolve();
|
|
215
215
|
};
|
|
216
216
|
/**
|
|
217
|
-
* Fetches multiple
|
|
217
|
+
* Fetches multiple definitions.
|
|
218
218
|
* Returned promise is rejected if redis operation fails.
|
|
219
219
|
*/
|
|
220
|
-
|
|
220
|
+
DefinitionsCacheInRedis.prototype.getMany = function (names) {
|
|
221
221
|
var _a;
|
|
222
222
|
var _this = this;
|
|
223
223
|
if (this.redisError) {
|
|
224
224
|
this.log.error(constants_1.LOG_PREFIX + this.redisError);
|
|
225
225
|
return Promise.reject(this.redisError);
|
|
226
226
|
}
|
|
227
|
-
var keys = names.map(function (name) { return _this.keys.
|
|
228
|
-
return (_a = this.redis).mget.apply(_a, keys).then(function (
|
|
229
|
-
var
|
|
227
|
+
var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
|
|
228
|
+
return (_a = this.redis).mget.apply(_a, keys).then(function (stringifiedDefinitions) {
|
|
229
|
+
var definitions = {};
|
|
230
230
|
names.forEach(function (name, idx) {
|
|
231
|
-
var
|
|
232
|
-
|
|
231
|
+
var definition = stringifiedDefinitions[idx];
|
|
232
|
+
definitions[name] = definition && JSON.parse(definition);
|
|
233
233
|
});
|
|
234
|
-
return Promise.resolve(
|
|
234
|
+
return Promise.resolve(definitions);
|
|
235
235
|
})
|
|
236
236
|
.catch(function (e) {
|
|
237
237
|
_this.log.error(constants_1.LOG_PREFIX + "Could not grab feature flags due to an error: ".concat(e, "."));
|
|
238
238
|
return Promise.reject(e);
|
|
239
239
|
});
|
|
240
240
|
};
|
|
241
|
-
return
|
|
242
|
-
}(
|
|
243
|
-
exports.
|
|
241
|
+
return DefinitionsCacheInRedis;
|
|
242
|
+
}(AbstractDefinitionsCacheAsync_1.AbstractDefinitionsCacheAsync));
|
|
243
|
+
exports.DefinitionsCacheInRedis = DefinitionsCacheInRedis;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.InRedisStorage = void 0;
|
|
4
4
|
var KeyBuilder_1 = require("../KeyBuilder");
|
|
5
5
|
var KeyBuilderSS_1 = require("../KeyBuilderSS");
|
|
6
|
-
var
|
|
6
|
+
var DefinitionsCacheInRedis_1 = require("./DefinitionsCacheInRedis");
|
|
7
7
|
var SegmentsCacheInRedis_1 = require("./SegmentsCacheInRedis");
|
|
8
8
|
var ImpressionsCacheInRedis_1 = require("./ImpressionsCacheInRedis");
|
|
9
9
|
var EventsCacheInRedis_1 = require("./EventsCacheInRedis");
|
|
@@ -48,7 +48,7 @@ function InRedisStorage(options) {
|
|
|
48
48
|
telemetry.recordConfig();
|
|
49
49
|
});
|
|
50
50
|
return {
|
|
51
|
-
|
|
51
|
+
definitions: new DefinitionsCacheInRedis_1.DefinitionsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
|
|
52
52
|
rbSegments: new RBSegmentsCacheInRedis_1.RBSegmentsCacheInRedis(log, keys, redisClient),
|
|
53
53
|
segments: new SegmentsCacheInRedis_1.SegmentsCacheInRedis(log, keys, redisClient),
|
|
54
54
|
impressions: new ImpressionsCacheInRedis_1.ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
@@ -0,0 +1,212 @@
|
|
|
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;
|