@splitsoftware/splitio-commons 2.2.1-rc.4 → 2.3.0
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 +26 -26
- package/README.md +0 -1
- package/cjs/evaluator/combiners/and.js +6 -2
- package/cjs/evaluator/combiners/ifelseif.js +6 -6
- package/cjs/evaluator/condition/index.js +5 -6
- package/cjs/evaluator/index.js +7 -7
- package/cjs/evaluator/matchers/index.js +1 -3
- package/cjs/evaluator/matchers/matcherTypes.js +0 -1
- package/cjs/evaluator/matchersTransform/index.js +0 -4
- package/cjs/evaluator/parser/index.js +2 -2
- package/cjs/evaluator/value/sanitize.js +0 -1
- package/cjs/logger/constants.js +3 -4
- package/cjs/logger/messages/debug.js +2 -3
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/services/splitApi.js +4 -3
- package/cjs/services/splitHttpClient.js +4 -1
- package/cjs/storages/AbstractSplitsCacheSync.js +2 -5
- package/cjs/storages/KeyBuilder.js +0 -9
- package/cjs/storages/KeyBuilderCS.js +0 -3
- package/cjs/storages/KeyBuilderSS.js +0 -3
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/cjs/storages/inLocalStorage/index.js +1 -5
- package/cjs/storages/inLocalStorage/validateCache.js +1 -2
- package/cjs/storages/inMemory/InMemoryStorage.js +0 -3
- package/cjs/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -1
- package/cjs/storages/inRedis/index.js +0 -2
- package/cjs/storages/pluggable/index.js +0 -2
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +4 -54
- package/cjs/sync/polling/pollingManagerCS.js +7 -7
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +33 -59
- package/cjs/sync/streaming/SSEHandler/index.js +0 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +77 -106
- package/cjs/sync/streaming/constants.js +1 -2
- package/cjs/sync/streaming/pushManager.js +16 -3
- package/cjs/sync/syncManagerOnline.js +2 -2
- package/cjs/utils/constants/index.js +2 -6
- package/esm/evaluator/combiners/and.js +6 -2
- package/esm/evaluator/combiners/ifelseif.js +7 -7
- package/esm/evaluator/condition/index.js +5 -6
- package/esm/evaluator/index.js +7 -7
- package/esm/evaluator/matchers/index.js +1 -3
- package/esm/evaluator/matchers/matcherTypes.js +0 -1
- package/esm/evaluator/matchersTransform/index.js +0 -4
- package/esm/evaluator/parser/index.js +2 -2
- package/esm/evaluator/value/sanitize.js +0 -1
- package/esm/logger/constants.js +0 -1
- package/esm/logger/messages/debug.js +2 -3
- package/esm/logger/messages/warn.js +1 -1
- package/esm/services/splitApi.js +4 -3
- package/esm/services/splitHttpClient.js +4 -1
- package/esm/storages/AbstractSplitsCacheSync.js +2 -5
- package/esm/storages/KeyBuilder.js +0 -9
- package/esm/storages/KeyBuilderCS.js +0 -3
- package/esm/storages/KeyBuilderSS.js +0 -3
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/esm/storages/inLocalStorage/index.js +1 -5
- package/esm/storages/inLocalStorage/validateCache.js +1 -2
- package/esm/storages/inMemory/InMemoryStorage.js +0 -3
- package/esm/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -1
- package/esm/storages/inRedis/index.js +0 -2
- package/esm/storages/pluggable/index.js +0 -2
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +4 -54
- package/esm/sync/polling/pollingManagerCS.js +7 -7
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/esm/sync/polling/updaters/splitChangesUpdater.js +33 -59
- package/esm/sync/streaming/SSEHandler/index.js +1 -2
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +73 -102
- package/esm/sync/streaming/constants.js +0 -1
- package/esm/sync/streaming/pushManager.js +19 -6
- package/esm/sync/syncManagerOnline.js +2 -2
- package/esm/utils/constants/index.js +1 -5
- package/package.json +1 -1
- package/src/dtos/types.ts +8 -37
- package/src/evaluator/Engine.ts +1 -1
- package/src/evaluator/combiners/and.ts +4 -5
- package/src/evaluator/combiners/ifelseif.ts +9 -7
- package/src/evaluator/condition/engineUtils.ts +1 -1
- package/src/evaluator/condition/index.ts +12 -12
- package/src/evaluator/index.ts +7 -7
- package/src/evaluator/matchers/index.ts +1 -3
- package/src/evaluator/matchers/matcherTypes.ts +0 -1
- package/src/evaluator/matchersTransform/index.ts +0 -3
- package/src/evaluator/parser/index.ts +3 -3
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +4 -5
- package/src/logger/constants.ts +0 -1
- package/src/logger/messages/debug.ts +2 -3
- package/src/logger/messages/warn.ts +1 -1
- package/src/sdkFactory/types.ts +1 -1
- package/src/sdkManager/index.ts +1 -1
- package/src/services/splitApi.ts +4 -3
- package/src/services/splitHttpClient.ts +4 -1
- package/src/services/types.ts +1 -1
- package/src/storages/AbstractSplitsCacheSync.ts +3 -6
- package/src/storages/KeyBuilder.ts +0 -12
- package/src/storages/KeyBuilderCS.ts +0 -4
- package/src/storages/KeyBuilderSS.ts +0 -4
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +14 -10
- package/src/storages/inLocalStorage/index.ts +1 -5
- package/src/storages/inLocalStorage/validateCache.ts +1 -3
- package/src/storages/inMemory/InMemoryStorage.ts +0 -3
- package/src/storages/inMemory/InMemoryStorageCS.ts +0 -4
- package/src/storages/inMemory/SplitsCacheInMemory.ts +0 -1
- package/src/storages/inRedis/index.ts +0 -2
- package/src/storages/pluggable/index.ts +0 -2
- package/src/storages/types.ts +1 -33
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +4 -65
- package/src/sync/polling/fetchers/types.ts +0 -1
- package/src/sync/polling/pollingManagerCS.ts +7 -7
- package/src/sync/polling/syncTasks/splitsSyncTask.ts +1 -1
- package/src/sync/polling/types.ts +2 -2
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -2
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
- package/src/sync/polling/updaters/splitChangesUpdater.ts +43 -70
- package/src/sync/streaming/SSEHandler/index.ts +1 -2
- package/src/sync/streaming/SSEHandler/types.ts +2 -2
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +68 -98
- package/src/sync/streaming/constants.ts +0 -1
- package/src/sync/streaming/parseUtils.ts +2 -2
- package/src/sync/streaming/pushManager.ts +18 -6
- package/src/sync/streaming/types.ts +2 -3
- package/src/sync/syncManagerOnline.ts +2 -2
- package/src/utils/constants/index.ts +1 -6
- package/src/utils/lang/index.ts +1 -1
- package/cjs/evaluator/matchers/rbsegment.js +0 -54
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +0 -117
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +0 -61
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +0 -64
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +0 -64
- package/esm/evaluator/matchers/rbsegment.js +0 -50
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +0 -114
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +0 -58
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +0 -61
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +0 -61
- package/src/evaluator/matchers/rbsegment.ts +0 -71
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +0 -136
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +0 -68
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +0 -79
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +0 -76
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ruleBasedSegmentMatcherContext = void 0;
|
|
4
|
-
var thenable_1 = require("../../utils/promise/thenable");
|
|
5
|
-
var key_1 = require("../../utils/key");
|
|
6
|
-
var parser_1 = require("../parser");
|
|
7
|
-
var constants_1 = require("../../utils/constants");
|
|
8
|
-
function ruleBasedSegmentMatcherContext(segmentName, storage, log) {
|
|
9
|
-
return function ruleBasedSegmentMatcher(_a, splitEvaluator) {
|
|
10
|
-
var key = _a.key, attributes = _a.attributes;
|
|
11
|
-
var matchingKey = (0, key_1.getMatching)(key);
|
|
12
|
-
function matchConditions(rbsegment) {
|
|
13
|
-
var conditions = rbsegment.conditions || [];
|
|
14
|
-
var evaluator = (0, parser_1.parser)(log, conditions, storage);
|
|
15
|
-
var evaluation = evaluator((0, key_1.keyParser)(key), undefined, undefined, undefined, attributes, splitEvaluator);
|
|
16
|
-
return (0, thenable_1.thenable)(evaluation) ?
|
|
17
|
-
evaluation.then(function (evaluation) { return evaluation ? true : false; }) :
|
|
18
|
-
evaluation ? true : false;
|
|
19
|
-
}
|
|
20
|
-
function isInExcludedSegment(_a) {
|
|
21
|
-
var type = _a.type, name = _a.name;
|
|
22
|
-
return type === constants_1.STANDARD_SEGMENT ?
|
|
23
|
-
storage.segments.isInSegment(name, matchingKey) :
|
|
24
|
-
type === constants_1.RULE_BASED_SEGMENT ?
|
|
25
|
-
ruleBasedSegmentMatcherContext(name, storage, log)({ key: key, attributes: attributes }, splitEvaluator) :
|
|
26
|
-
type === constants_1.LARGE_SEGMENT && storage.largeSegments ?
|
|
27
|
-
storage.largeSegments.isInSegment(name, matchingKey) :
|
|
28
|
-
false;
|
|
29
|
-
}
|
|
30
|
-
function isExcluded(rbSegment) {
|
|
31
|
-
var excluded = rbSegment.excluded || {};
|
|
32
|
-
if (excluded.keys && excluded.keys.indexOf(matchingKey) !== -1)
|
|
33
|
-
return true;
|
|
34
|
-
return (excluded.segments || []).reduce(function (result, excludedSegment) {
|
|
35
|
-
return (0, thenable_1.thenable)(result) ?
|
|
36
|
-
result.then(function (result) { return result || isInExcludedSegment(excludedSegment); }) :
|
|
37
|
-
result || isInExcludedSegment(excludedSegment);
|
|
38
|
-
}, false);
|
|
39
|
-
}
|
|
40
|
-
function isInRBSegment(rbSegment) {
|
|
41
|
-
if (!rbSegment)
|
|
42
|
-
return false;
|
|
43
|
-
var excluded = isExcluded(rbSegment);
|
|
44
|
-
return (0, thenable_1.thenable)(excluded) ?
|
|
45
|
-
excluded.then(function (excluded) { return excluded ? false : matchConditions(rbSegment); }) :
|
|
46
|
-
excluded ? false : matchConditions(rbSegment);
|
|
47
|
-
}
|
|
48
|
-
var rbSegment = storage.rbSegments.get(segmentName);
|
|
49
|
-
return (0, thenable_1.thenable)(rbSegment) ?
|
|
50
|
-
rbSegment.then(isInRBSegment) :
|
|
51
|
-
isInRBSegment(rbSegment);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
exports.ruleBasedSegmentMatcherContext = ruleBasedSegmentMatcherContext;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RBSegmentsCacheInLocal = void 0;
|
|
4
|
-
var lang_1 = require("../../utils/lang");
|
|
5
|
-
var sets_1 = require("../../utils/lang/sets");
|
|
6
|
-
var AbstractSplitsCacheSync_1 = require("../AbstractSplitsCacheSync");
|
|
7
|
-
var constants_1 = require("./constants");
|
|
8
|
-
var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
9
|
-
function RBSegmentsCacheInLocal(settings, keys) {
|
|
10
|
-
this.keys = keys;
|
|
11
|
-
this.log = settings.log;
|
|
12
|
-
}
|
|
13
|
-
RBSegmentsCacheInLocal.prototype.clear = function () {
|
|
14
|
-
var _this = this;
|
|
15
|
-
this.getNames().forEach(function (name) { return _this.remove(name); });
|
|
16
|
-
localStorage.removeItem(this.keys.buildRBSegmentsTillKey());
|
|
17
|
-
};
|
|
18
|
-
RBSegmentsCacheInLocal.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
19
|
-
var _this = this;
|
|
20
|
-
this.setChangeNumber(changeNumber);
|
|
21
|
-
var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
|
|
22
|
-
return toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
|
|
23
|
-
};
|
|
24
|
-
RBSegmentsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
25
|
-
try {
|
|
26
|
-
localStorage.setItem(this.keys.buildRBSegmentsTillKey(), changeNumber + '');
|
|
27
|
-
localStorage.setItem(this.keys.buildLastUpdatedKey(), Date.now() + '');
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
this.log.error(constants_1.LOG_PREFIX + e);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
RBSegmentsCacheInLocal.prototype.updateSegmentCount = function (diff) {
|
|
34
|
-
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
35
|
-
var count = (0, lang_1.toNumber)(localStorage.getItem(segmentsCountKey)) + diff;
|
|
36
|
-
// @ts-expect-error
|
|
37
|
-
if (count > 0)
|
|
38
|
-
localStorage.setItem(segmentsCountKey, count);
|
|
39
|
-
else
|
|
40
|
-
localStorage.removeItem(segmentsCountKey);
|
|
41
|
-
};
|
|
42
|
-
RBSegmentsCacheInLocal.prototype.add = function (rbSegment) {
|
|
43
|
-
try {
|
|
44
|
-
var name_1 = rbSegment.name;
|
|
45
|
-
var rbSegmentKey = this.keys.buildRBSegmentKey(name_1);
|
|
46
|
-
var rbSegmentFromLocalStorage = localStorage.getItem(rbSegmentKey);
|
|
47
|
-
var previous = rbSegmentFromLocalStorage ? JSON.parse(rbSegmentFromLocalStorage) : null;
|
|
48
|
-
localStorage.setItem(rbSegmentKey, JSON.stringify(rbSegment));
|
|
49
|
-
var usesSegmentsDiff = 0;
|
|
50
|
-
if (previous && (0, AbstractSplitsCacheSync_1.usesSegments)(previous))
|
|
51
|
-
usesSegmentsDiff--;
|
|
52
|
-
if ((0, AbstractSplitsCacheSync_1.usesSegments)(rbSegment))
|
|
53
|
-
usesSegmentsDiff++;
|
|
54
|
-
if (usesSegmentsDiff !== 0)
|
|
55
|
-
this.updateSegmentCount(usesSegmentsDiff);
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
this.log.error(constants_1.LOG_PREFIX + e);
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
RBSegmentsCacheInLocal.prototype.remove = function (name) {
|
|
64
|
-
try {
|
|
65
|
-
var rbSegment = this.get(name);
|
|
66
|
-
if (!rbSegment)
|
|
67
|
-
return false;
|
|
68
|
-
localStorage.removeItem(this.keys.buildRBSegmentKey(name));
|
|
69
|
-
if ((0, AbstractSplitsCacheSync_1.usesSegments)(rbSegment))
|
|
70
|
-
this.updateSegmentCount(-1);
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
this.log.error(constants_1.LOG_PREFIX + e);
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
RBSegmentsCacheInLocal.prototype.getNames = function () {
|
|
79
|
-
var len = localStorage.length;
|
|
80
|
-
var accum = [];
|
|
81
|
-
var cur = 0;
|
|
82
|
-
while (cur < len) {
|
|
83
|
-
var key = localStorage.key(cur);
|
|
84
|
-
if (key != null && this.keys.isRBSegmentKey(key))
|
|
85
|
-
accum.push(this.keys.extractKey(key));
|
|
86
|
-
cur++;
|
|
87
|
-
}
|
|
88
|
-
return accum;
|
|
89
|
-
};
|
|
90
|
-
RBSegmentsCacheInLocal.prototype.get = function (name) {
|
|
91
|
-
var item = localStorage.getItem(this.keys.buildRBSegmentKey(name));
|
|
92
|
-
return item && JSON.parse(item);
|
|
93
|
-
};
|
|
94
|
-
RBSegmentsCacheInLocal.prototype.contains = function (names) {
|
|
95
|
-
var namesArray = (0, sets_1.setToArray)(names);
|
|
96
|
-
var namesInStorage = this.getNames();
|
|
97
|
-
return namesArray.every(function (name) { return namesInStorage.indexOf(name) !== -1; });
|
|
98
|
-
};
|
|
99
|
-
RBSegmentsCacheInLocal.prototype.getChangeNumber = function () {
|
|
100
|
-
var n = -1;
|
|
101
|
-
var value = localStorage.getItem(this.keys.buildRBSegmentsTillKey());
|
|
102
|
-
if (value !== null) {
|
|
103
|
-
value = parseInt(value, 10);
|
|
104
|
-
return (0, lang_1.isNaNNumber)(value) ? n : value;
|
|
105
|
-
}
|
|
106
|
-
return n;
|
|
107
|
-
};
|
|
108
|
-
RBSegmentsCacheInLocal.prototype.usesSegments = function () {
|
|
109
|
-
var storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
110
|
-
var splitsWithSegmentsCount = storedCount === null ? 0 : (0, lang_1.toNumber)(storedCount);
|
|
111
|
-
return (0, lang_1.isFiniteNumber)(splitsWithSegmentsCount) ?
|
|
112
|
-
splitsWithSegmentsCount > 0 :
|
|
113
|
-
true;
|
|
114
|
-
};
|
|
115
|
-
return RBSegmentsCacheInLocal;
|
|
116
|
-
}());
|
|
117
|
-
exports.RBSegmentsCacheInLocal = RBSegmentsCacheInLocal;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RBSegmentsCacheInMemory = void 0;
|
|
4
|
-
var sets_1 = require("../../utils/lang/sets");
|
|
5
|
-
var AbstractSplitsCacheSync_1 = require("../AbstractSplitsCacheSync");
|
|
6
|
-
var RBSegmentsCacheInMemory = /** @class */ (function () {
|
|
7
|
-
function RBSegmentsCacheInMemory() {
|
|
8
|
-
this.cache = {};
|
|
9
|
-
this.changeNumber = -1;
|
|
10
|
-
this.segmentsCount = 0;
|
|
11
|
-
}
|
|
12
|
-
RBSegmentsCacheInMemory.prototype.clear = function () {
|
|
13
|
-
this.cache = {};
|
|
14
|
-
this.changeNumber = -1;
|
|
15
|
-
this.segmentsCount = 0;
|
|
16
|
-
};
|
|
17
|
-
RBSegmentsCacheInMemory.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
18
|
-
var _this = this;
|
|
19
|
-
this.changeNumber = changeNumber;
|
|
20
|
-
var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
|
|
21
|
-
return toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
|
|
22
|
-
};
|
|
23
|
-
RBSegmentsCacheInMemory.prototype.add = function (rbSegment) {
|
|
24
|
-
var name = rbSegment.name;
|
|
25
|
-
var previous = this.get(name);
|
|
26
|
-
if (previous && (0, AbstractSplitsCacheSync_1.usesSegments)(previous))
|
|
27
|
-
this.segmentsCount--;
|
|
28
|
-
this.cache[name] = rbSegment;
|
|
29
|
-
if ((0, AbstractSplitsCacheSync_1.usesSegments)(rbSegment))
|
|
30
|
-
this.segmentsCount++;
|
|
31
|
-
return true;
|
|
32
|
-
};
|
|
33
|
-
RBSegmentsCacheInMemory.prototype.remove = function (name) {
|
|
34
|
-
var rbSegment = this.get(name);
|
|
35
|
-
if (!rbSegment)
|
|
36
|
-
return false;
|
|
37
|
-
delete this.cache[name];
|
|
38
|
-
if ((0, AbstractSplitsCacheSync_1.usesSegments)(rbSegment))
|
|
39
|
-
this.segmentsCount--;
|
|
40
|
-
return true;
|
|
41
|
-
};
|
|
42
|
-
RBSegmentsCacheInMemory.prototype.getNames = function () {
|
|
43
|
-
return Object.keys(this.cache);
|
|
44
|
-
};
|
|
45
|
-
RBSegmentsCacheInMemory.prototype.get = function (name) {
|
|
46
|
-
return this.cache[name] || null;
|
|
47
|
-
};
|
|
48
|
-
RBSegmentsCacheInMemory.prototype.contains = function (names) {
|
|
49
|
-
var namesArray = (0, sets_1.setToArray)(names);
|
|
50
|
-
var namesInStorage = this.getNames();
|
|
51
|
-
return namesArray.every(function (name) { return namesInStorage.indexOf(name) !== -1; });
|
|
52
|
-
};
|
|
53
|
-
RBSegmentsCacheInMemory.prototype.getChangeNumber = function () {
|
|
54
|
-
return this.changeNumber;
|
|
55
|
-
};
|
|
56
|
-
RBSegmentsCacheInMemory.prototype.usesSegments = function () {
|
|
57
|
-
return this.segmentsCount > 0;
|
|
58
|
-
};
|
|
59
|
-
return RBSegmentsCacheInMemory;
|
|
60
|
-
}());
|
|
61
|
-
exports.RBSegmentsCacheInMemory = RBSegmentsCacheInMemory;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RBSegmentsCacheInRedis = void 0;
|
|
4
|
-
var lang_1 = require("../../utils/lang");
|
|
5
|
-
var constants_1 = require("./constants");
|
|
6
|
-
var sets_1 = require("../../utils/lang/sets");
|
|
7
|
-
var RBSegmentsCacheInRedis = /** @class */ (function () {
|
|
8
|
-
function RBSegmentsCacheInRedis(log, keys, redis) {
|
|
9
|
-
this.log = log;
|
|
10
|
-
this.keys = keys;
|
|
11
|
-
this.redis = redis;
|
|
12
|
-
}
|
|
13
|
-
RBSegmentsCacheInRedis.prototype.get = function (name) {
|
|
14
|
-
return this.redis.get(this.keys.buildRBSegmentKey(name))
|
|
15
|
-
.then(function (maybeRBSegment) { return maybeRBSegment && JSON.parse(maybeRBSegment); });
|
|
16
|
-
};
|
|
17
|
-
RBSegmentsCacheInRedis.prototype.getNames = function () {
|
|
18
|
-
var _this = this;
|
|
19
|
-
return this.redis.keys(this.keys.searchPatternForRBSegmentKeys()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
|
|
20
|
-
};
|
|
21
|
-
RBSegmentsCacheInRedis.prototype.contains = function (names) {
|
|
22
|
-
var namesArray = (0, sets_1.setToArray)(names);
|
|
23
|
-
return this.getNames().then(function (namesInStorage) {
|
|
24
|
-
return namesArray.every(function (name) { return namesInStorage.includes(name); });
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
RBSegmentsCacheInRedis.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
28
|
-
var _this = this;
|
|
29
|
-
return Promise.all([
|
|
30
|
-
this.setChangeNumber(changeNumber),
|
|
31
|
-
Promise.all(toAdd.map(function (toAdd) {
|
|
32
|
-
var key = _this.keys.buildRBSegmentKey(toAdd.name);
|
|
33
|
-
var stringifiedNewRBSegment = JSON.stringify(toAdd);
|
|
34
|
-
return _this.redis.set(key, stringifiedNewRBSegment).then(function () { return true; });
|
|
35
|
-
})),
|
|
36
|
-
Promise.all(toRemove.map(function (toRemove) {
|
|
37
|
-
var key = _this.keys.buildRBSegmentKey(toRemove.name);
|
|
38
|
-
return _this.redis.del(key).then(function (status) { return status === 1; });
|
|
39
|
-
}))
|
|
40
|
-
]).then(function (_a) {
|
|
41
|
-
var added = _a[1], removed = _a[2];
|
|
42
|
-
return added.some(function (result) { return result; }) || removed.some(function (result) { return result; });
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
RBSegmentsCacheInRedis.prototype.setChangeNumber = function (changeNumber) {
|
|
46
|
-
return this.redis.set(this.keys.buildRBSegmentsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
|
|
47
|
-
};
|
|
48
|
-
RBSegmentsCacheInRedis.prototype.getChangeNumber = function () {
|
|
49
|
-
var _this = this;
|
|
50
|
-
return this.redis.get(this.keys.buildRBSegmentsTillKey()).then(function (value) {
|
|
51
|
-
var i = parseInt(value, 10);
|
|
52
|
-
return (0, lang_1.isNaNNumber)(i) ? -1 : i;
|
|
53
|
-
}).catch(function (e) {
|
|
54
|
-
_this.log.error(constants_1.LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
|
|
55
|
-
return -1;
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
// @TODO implement if required by DataLoader or producer mode
|
|
59
|
-
RBSegmentsCacheInRedis.prototype.clear = function () {
|
|
60
|
-
return Promise.resolve();
|
|
61
|
-
};
|
|
62
|
-
return RBSegmentsCacheInRedis;
|
|
63
|
-
}());
|
|
64
|
-
exports.RBSegmentsCacheInRedis = RBSegmentsCacheInRedis;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RBSegmentsCachePluggable = void 0;
|
|
4
|
-
var lang_1 = require("../../utils/lang");
|
|
5
|
-
var constants_1 = require("./constants");
|
|
6
|
-
var sets_1 = require("../../utils/lang/sets");
|
|
7
|
-
var RBSegmentsCachePluggable = /** @class */ (function () {
|
|
8
|
-
function RBSegmentsCachePluggable(log, keys, wrapper) {
|
|
9
|
-
this.log = log;
|
|
10
|
-
this.keys = keys;
|
|
11
|
-
this.wrapper = wrapper;
|
|
12
|
-
}
|
|
13
|
-
RBSegmentsCachePluggable.prototype.get = function (name) {
|
|
14
|
-
return this.wrapper.get(this.keys.buildRBSegmentKey(name))
|
|
15
|
-
.then(function (maybeRBSegment) { return maybeRBSegment && JSON.parse(maybeRBSegment); });
|
|
16
|
-
};
|
|
17
|
-
RBSegmentsCachePluggable.prototype.getNames = function () {
|
|
18
|
-
var _this = this;
|
|
19
|
-
return this.wrapper.getKeysByPrefix(this.keys.buildRBSegmentKeyPrefix()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
|
|
20
|
-
};
|
|
21
|
-
RBSegmentsCachePluggable.prototype.contains = function (names) {
|
|
22
|
-
var namesArray = (0, sets_1.setToArray)(names);
|
|
23
|
-
return this.getNames().then(function (namesInStorage) {
|
|
24
|
-
return namesArray.every(function (name) { return namesInStorage.includes(name); });
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
RBSegmentsCachePluggable.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
28
|
-
var _this = this;
|
|
29
|
-
return Promise.all([
|
|
30
|
-
this.setChangeNumber(changeNumber),
|
|
31
|
-
Promise.all(toAdd.map(function (toAdd) {
|
|
32
|
-
var key = _this.keys.buildRBSegmentKey(toAdd.name);
|
|
33
|
-
var stringifiedNewRBSegment = JSON.stringify(toAdd);
|
|
34
|
-
return _this.wrapper.set(key, stringifiedNewRBSegment).then(function () { return true; });
|
|
35
|
-
})),
|
|
36
|
-
Promise.all(toRemove.map(function (toRemove) {
|
|
37
|
-
var key = _this.keys.buildRBSegmentKey(toRemove.name);
|
|
38
|
-
return _this.wrapper.del(key);
|
|
39
|
-
}))
|
|
40
|
-
]).then(function (_a) {
|
|
41
|
-
var added = _a[1], removed = _a[2];
|
|
42
|
-
return added.some(function (result) { return result; }) || removed.some(function (result) { return result; });
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
RBSegmentsCachePluggable.prototype.setChangeNumber = function (changeNumber) {
|
|
46
|
-
return this.wrapper.set(this.keys.buildRBSegmentsTillKey(), changeNumber + '');
|
|
47
|
-
};
|
|
48
|
-
RBSegmentsCachePluggable.prototype.getChangeNumber = function () {
|
|
49
|
-
var _this = this;
|
|
50
|
-
return this.wrapper.get(this.keys.buildRBSegmentsTillKey()).then(function (value) {
|
|
51
|
-
var i = parseInt(value, 10);
|
|
52
|
-
return (0, lang_1.isNaNNumber)(i) ? -1 : i;
|
|
53
|
-
}).catch(function (e) {
|
|
54
|
-
_this.log.error(constants_1.LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
|
|
55
|
-
return -1;
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
// @TODO implement if required by DataLoader or producer mode
|
|
59
|
-
RBSegmentsCachePluggable.prototype.clear = function () {
|
|
60
|
-
return Promise.resolve();
|
|
61
|
-
};
|
|
62
|
-
return RBSegmentsCachePluggable;
|
|
63
|
-
}());
|
|
64
|
-
exports.RBSegmentsCachePluggable = RBSegmentsCachePluggable;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { thenable } from '../../utils/promise/thenable';
|
|
2
|
-
import { getMatching, keyParser } from '../../utils/key';
|
|
3
|
-
import { parser } from '../parser';
|
|
4
|
-
import { STANDARD_SEGMENT, RULE_BASED_SEGMENT, LARGE_SEGMENT } from '../../utils/constants';
|
|
5
|
-
export function ruleBasedSegmentMatcherContext(segmentName, storage, log) {
|
|
6
|
-
return function ruleBasedSegmentMatcher(_a, splitEvaluator) {
|
|
7
|
-
var key = _a.key, attributes = _a.attributes;
|
|
8
|
-
var matchingKey = getMatching(key);
|
|
9
|
-
function matchConditions(rbsegment) {
|
|
10
|
-
var conditions = rbsegment.conditions || [];
|
|
11
|
-
var evaluator = parser(log, conditions, storage);
|
|
12
|
-
var evaluation = evaluator(keyParser(key), undefined, undefined, undefined, attributes, splitEvaluator);
|
|
13
|
-
return thenable(evaluation) ?
|
|
14
|
-
evaluation.then(function (evaluation) { return evaluation ? true : false; }) :
|
|
15
|
-
evaluation ? true : false;
|
|
16
|
-
}
|
|
17
|
-
function isInExcludedSegment(_a) {
|
|
18
|
-
var type = _a.type, name = _a.name;
|
|
19
|
-
return type === STANDARD_SEGMENT ?
|
|
20
|
-
storage.segments.isInSegment(name, matchingKey) :
|
|
21
|
-
type === RULE_BASED_SEGMENT ?
|
|
22
|
-
ruleBasedSegmentMatcherContext(name, storage, log)({ key: key, attributes: attributes }, splitEvaluator) :
|
|
23
|
-
type === LARGE_SEGMENT && storage.largeSegments ?
|
|
24
|
-
storage.largeSegments.isInSegment(name, matchingKey) :
|
|
25
|
-
false;
|
|
26
|
-
}
|
|
27
|
-
function isExcluded(rbSegment) {
|
|
28
|
-
var excluded = rbSegment.excluded || {};
|
|
29
|
-
if (excluded.keys && excluded.keys.indexOf(matchingKey) !== -1)
|
|
30
|
-
return true;
|
|
31
|
-
return (excluded.segments || []).reduce(function (result, excludedSegment) {
|
|
32
|
-
return thenable(result) ?
|
|
33
|
-
result.then(function (result) { return result || isInExcludedSegment(excludedSegment); }) :
|
|
34
|
-
result || isInExcludedSegment(excludedSegment);
|
|
35
|
-
}, false);
|
|
36
|
-
}
|
|
37
|
-
function isInRBSegment(rbSegment) {
|
|
38
|
-
if (!rbSegment)
|
|
39
|
-
return false;
|
|
40
|
-
var excluded = isExcluded(rbSegment);
|
|
41
|
-
return thenable(excluded) ?
|
|
42
|
-
excluded.then(function (excluded) { return excluded ? false : matchConditions(rbSegment); }) :
|
|
43
|
-
excluded ? false : matchConditions(rbSegment);
|
|
44
|
-
}
|
|
45
|
-
var rbSegment = storage.rbSegments.get(segmentName);
|
|
46
|
-
return thenable(rbSegment) ?
|
|
47
|
-
rbSegment.then(isInRBSegment) :
|
|
48
|
-
isInRBSegment(rbSegment);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { isFiniteNumber, isNaNNumber, toNumber } from '../../utils/lang';
|
|
2
|
-
import { setToArray } from '../../utils/lang/sets';
|
|
3
|
-
import { usesSegments } from '../AbstractSplitsCacheSync';
|
|
4
|
-
import { LOG_PREFIX } from './constants';
|
|
5
|
-
var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
6
|
-
function RBSegmentsCacheInLocal(settings, keys) {
|
|
7
|
-
this.keys = keys;
|
|
8
|
-
this.log = settings.log;
|
|
9
|
-
}
|
|
10
|
-
RBSegmentsCacheInLocal.prototype.clear = function () {
|
|
11
|
-
var _this = this;
|
|
12
|
-
this.getNames().forEach(function (name) { return _this.remove(name); });
|
|
13
|
-
localStorage.removeItem(this.keys.buildRBSegmentsTillKey());
|
|
14
|
-
};
|
|
15
|
-
RBSegmentsCacheInLocal.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
16
|
-
var _this = this;
|
|
17
|
-
this.setChangeNumber(changeNumber);
|
|
18
|
-
var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
|
|
19
|
-
return toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
|
|
20
|
-
};
|
|
21
|
-
RBSegmentsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
22
|
-
try {
|
|
23
|
-
localStorage.setItem(this.keys.buildRBSegmentsTillKey(), changeNumber + '');
|
|
24
|
-
localStorage.setItem(this.keys.buildLastUpdatedKey(), Date.now() + '');
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
this.log.error(LOG_PREFIX + e);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
RBSegmentsCacheInLocal.prototype.updateSegmentCount = function (diff) {
|
|
31
|
-
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
32
|
-
var count = toNumber(localStorage.getItem(segmentsCountKey)) + diff;
|
|
33
|
-
// @ts-expect-error
|
|
34
|
-
if (count > 0)
|
|
35
|
-
localStorage.setItem(segmentsCountKey, count);
|
|
36
|
-
else
|
|
37
|
-
localStorage.removeItem(segmentsCountKey);
|
|
38
|
-
};
|
|
39
|
-
RBSegmentsCacheInLocal.prototype.add = function (rbSegment) {
|
|
40
|
-
try {
|
|
41
|
-
var name_1 = rbSegment.name;
|
|
42
|
-
var rbSegmentKey = this.keys.buildRBSegmentKey(name_1);
|
|
43
|
-
var rbSegmentFromLocalStorage = localStorage.getItem(rbSegmentKey);
|
|
44
|
-
var previous = rbSegmentFromLocalStorage ? JSON.parse(rbSegmentFromLocalStorage) : null;
|
|
45
|
-
localStorage.setItem(rbSegmentKey, JSON.stringify(rbSegment));
|
|
46
|
-
var usesSegmentsDiff = 0;
|
|
47
|
-
if (previous && usesSegments(previous))
|
|
48
|
-
usesSegmentsDiff--;
|
|
49
|
-
if (usesSegments(rbSegment))
|
|
50
|
-
usesSegmentsDiff++;
|
|
51
|
-
if (usesSegmentsDiff !== 0)
|
|
52
|
-
this.updateSegmentCount(usesSegmentsDiff);
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
this.log.error(LOG_PREFIX + e);
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
RBSegmentsCacheInLocal.prototype.remove = function (name) {
|
|
61
|
-
try {
|
|
62
|
-
var rbSegment = this.get(name);
|
|
63
|
-
if (!rbSegment)
|
|
64
|
-
return false;
|
|
65
|
-
localStorage.removeItem(this.keys.buildRBSegmentKey(name));
|
|
66
|
-
if (usesSegments(rbSegment))
|
|
67
|
-
this.updateSegmentCount(-1);
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
this.log.error(LOG_PREFIX + e);
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
RBSegmentsCacheInLocal.prototype.getNames = function () {
|
|
76
|
-
var len = localStorage.length;
|
|
77
|
-
var accum = [];
|
|
78
|
-
var cur = 0;
|
|
79
|
-
while (cur < len) {
|
|
80
|
-
var key = localStorage.key(cur);
|
|
81
|
-
if (key != null && this.keys.isRBSegmentKey(key))
|
|
82
|
-
accum.push(this.keys.extractKey(key));
|
|
83
|
-
cur++;
|
|
84
|
-
}
|
|
85
|
-
return accum;
|
|
86
|
-
};
|
|
87
|
-
RBSegmentsCacheInLocal.prototype.get = function (name) {
|
|
88
|
-
var item = localStorage.getItem(this.keys.buildRBSegmentKey(name));
|
|
89
|
-
return item && JSON.parse(item);
|
|
90
|
-
};
|
|
91
|
-
RBSegmentsCacheInLocal.prototype.contains = function (names) {
|
|
92
|
-
var namesArray = setToArray(names);
|
|
93
|
-
var namesInStorage = this.getNames();
|
|
94
|
-
return namesArray.every(function (name) { return namesInStorage.indexOf(name) !== -1; });
|
|
95
|
-
};
|
|
96
|
-
RBSegmentsCacheInLocal.prototype.getChangeNumber = function () {
|
|
97
|
-
var n = -1;
|
|
98
|
-
var value = localStorage.getItem(this.keys.buildRBSegmentsTillKey());
|
|
99
|
-
if (value !== null) {
|
|
100
|
-
value = parseInt(value, 10);
|
|
101
|
-
return isNaNNumber(value) ? n : value;
|
|
102
|
-
}
|
|
103
|
-
return n;
|
|
104
|
-
};
|
|
105
|
-
RBSegmentsCacheInLocal.prototype.usesSegments = function () {
|
|
106
|
-
var storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
107
|
-
var splitsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
|
|
108
|
-
return isFiniteNumber(splitsWithSegmentsCount) ?
|
|
109
|
-
splitsWithSegmentsCount > 0 :
|
|
110
|
-
true;
|
|
111
|
-
};
|
|
112
|
-
return RBSegmentsCacheInLocal;
|
|
113
|
-
}());
|
|
114
|
-
export { RBSegmentsCacheInLocal };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { setToArray } from '../../utils/lang/sets';
|
|
2
|
-
import { usesSegments } from '../AbstractSplitsCacheSync';
|
|
3
|
-
var RBSegmentsCacheInMemory = /** @class */ (function () {
|
|
4
|
-
function RBSegmentsCacheInMemory() {
|
|
5
|
-
this.cache = {};
|
|
6
|
-
this.changeNumber = -1;
|
|
7
|
-
this.segmentsCount = 0;
|
|
8
|
-
}
|
|
9
|
-
RBSegmentsCacheInMemory.prototype.clear = function () {
|
|
10
|
-
this.cache = {};
|
|
11
|
-
this.changeNumber = -1;
|
|
12
|
-
this.segmentsCount = 0;
|
|
13
|
-
};
|
|
14
|
-
RBSegmentsCacheInMemory.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
15
|
-
var _this = this;
|
|
16
|
-
this.changeNumber = changeNumber;
|
|
17
|
-
var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
|
|
18
|
-
return toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
|
|
19
|
-
};
|
|
20
|
-
RBSegmentsCacheInMemory.prototype.add = function (rbSegment) {
|
|
21
|
-
var name = rbSegment.name;
|
|
22
|
-
var previous = this.get(name);
|
|
23
|
-
if (previous && usesSegments(previous))
|
|
24
|
-
this.segmentsCount--;
|
|
25
|
-
this.cache[name] = rbSegment;
|
|
26
|
-
if (usesSegments(rbSegment))
|
|
27
|
-
this.segmentsCount++;
|
|
28
|
-
return true;
|
|
29
|
-
};
|
|
30
|
-
RBSegmentsCacheInMemory.prototype.remove = function (name) {
|
|
31
|
-
var rbSegment = this.get(name);
|
|
32
|
-
if (!rbSegment)
|
|
33
|
-
return false;
|
|
34
|
-
delete this.cache[name];
|
|
35
|
-
if (usesSegments(rbSegment))
|
|
36
|
-
this.segmentsCount--;
|
|
37
|
-
return true;
|
|
38
|
-
};
|
|
39
|
-
RBSegmentsCacheInMemory.prototype.getNames = function () {
|
|
40
|
-
return Object.keys(this.cache);
|
|
41
|
-
};
|
|
42
|
-
RBSegmentsCacheInMemory.prototype.get = function (name) {
|
|
43
|
-
return this.cache[name] || null;
|
|
44
|
-
};
|
|
45
|
-
RBSegmentsCacheInMemory.prototype.contains = function (names) {
|
|
46
|
-
var namesArray = setToArray(names);
|
|
47
|
-
var namesInStorage = this.getNames();
|
|
48
|
-
return namesArray.every(function (name) { return namesInStorage.indexOf(name) !== -1; });
|
|
49
|
-
};
|
|
50
|
-
RBSegmentsCacheInMemory.prototype.getChangeNumber = function () {
|
|
51
|
-
return this.changeNumber;
|
|
52
|
-
};
|
|
53
|
-
RBSegmentsCacheInMemory.prototype.usesSegments = function () {
|
|
54
|
-
return this.segmentsCount > 0;
|
|
55
|
-
};
|
|
56
|
-
return RBSegmentsCacheInMemory;
|
|
57
|
-
}());
|
|
58
|
-
export { RBSegmentsCacheInMemory };
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { isNaNNumber } from '../../utils/lang';
|
|
2
|
-
import { LOG_PREFIX } from './constants';
|
|
3
|
-
import { setToArray } from '../../utils/lang/sets';
|
|
4
|
-
var RBSegmentsCacheInRedis = /** @class */ (function () {
|
|
5
|
-
function RBSegmentsCacheInRedis(log, keys, redis) {
|
|
6
|
-
this.log = log;
|
|
7
|
-
this.keys = keys;
|
|
8
|
-
this.redis = redis;
|
|
9
|
-
}
|
|
10
|
-
RBSegmentsCacheInRedis.prototype.get = function (name) {
|
|
11
|
-
return this.redis.get(this.keys.buildRBSegmentKey(name))
|
|
12
|
-
.then(function (maybeRBSegment) { return maybeRBSegment && JSON.parse(maybeRBSegment); });
|
|
13
|
-
};
|
|
14
|
-
RBSegmentsCacheInRedis.prototype.getNames = function () {
|
|
15
|
-
var _this = this;
|
|
16
|
-
return this.redis.keys(this.keys.searchPatternForRBSegmentKeys()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
|
|
17
|
-
};
|
|
18
|
-
RBSegmentsCacheInRedis.prototype.contains = function (names) {
|
|
19
|
-
var namesArray = setToArray(names);
|
|
20
|
-
return this.getNames().then(function (namesInStorage) {
|
|
21
|
-
return namesArray.every(function (name) { return namesInStorage.includes(name); });
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
RBSegmentsCacheInRedis.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
25
|
-
var _this = this;
|
|
26
|
-
return Promise.all([
|
|
27
|
-
this.setChangeNumber(changeNumber),
|
|
28
|
-
Promise.all(toAdd.map(function (toAdd) {
|
|
29
|
-
var key = _this.keys.buildRBSegmentKey(toAdd.name);
|
|
30
|
-
var stringifiedNewRBSegment = JSON.stringify(toAdd);
|
|
31
|
-
return _this.redis.set(key, stringifiedNewRBSegment).then(function () { return true; });
|
|
32
|
-
})),
|
|
33
|
-
Promise.all(toRemove.map(function (toRemove) {
|
|
34
|
-
var key = _this.keys.buildRBSegmentKey(toRemove.name);
|
|
35
|
-
return _this.redis.del(key).then(function (status) { return status === 1; });
|
|
36
|
-
}))
|
|
37
|
-
]).then(function (_a) {
|
|
38
|
-
var added = _a[1], removed = _a[2];
|
|
39
|
-
return added.some(function (result) { return result; }) || removed.some(function (result) { return result; });
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
RBSegmentsCacheInRedis.prototype.setChangeNumber = function (changeNumber) {
|
|
43
|
-
return this.redis.set(this.keys.buildRBSegmentsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
|
|
44
|
-
};
|
|
45
|
-
RBSegmentsCacheInRedis.prototype.getChangeNumber = function () {
|
|
46
|
-
var _this = this;
|
|
47
|
-
return this.redis.get(this.keys.buildRBSegmentsTillKey()).then(function (value) {
|
|
48
|
-
var i = parseInt(value, 10);
|
|
49
|
-
return isNaNNumber(i) ? -1 : i;
|
|
50
|
-
}).catch(function (e) {
|
|
51
|
-
_this.log.error(LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
|
|
52
|
-
return -1;
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
// @TODO implement if required by DataLoader or producer mode
|
|
56
|
-
RBSegmentsCacheInRedis.prototype.clear = function () {
|
|
57
|
-
return Promise.resolve();
|
|
58
|
-
};
|
|
59
|
-
return RBSegmentsCacheInRedis;
|
|
60
|
-
}());
|
|
61
|
-
export { RBSegmentsCacheInRedis };
|