@splitsoftware/splitio-commons 2.1.1-rc.0 → 2.1.1-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 +3 -0
- 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/error.js +1 -1
- package/cjs/logger/messages/warn.js +2 -2
- package/cjs/sdkClient/client.js +29 -19
- package/cjs/sdkClient/clientAttributesDecoration.js +19 -25
- package/cjs/sdkClient/clientInputValidation.js +28 -26
- package/cjs/services/splitApi.js +2 -2
- package/cjs/storages/AbstractSplitsCacheSync.js +2 -5
- package/cjs/storages/KeyBuilder.js +0 -9
- package/cjs/storages/KeyBuilderCS.js +1 -4
- package/cjs/storages/KeyBuilderSS.js +0 -3
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/cjs/storages/inLocalStorage/index.js +0 -4
- package/cjs/storages/inMemory/InMemoryStorage.js +0 -3
- package/cjs/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/cjs/storages/inRedis/index.js +0 -2
- package/cjs/storages/pluggable/index.js +0 -2
- package/cjs/storages/utils.js +1 -0
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/cjs/sync/polling/pollingManagerCS.js +7 -7
- 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 +35 -51
- 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/submitters/impressionsSubmitter.js +3 -2
- package/cjs/sync/syncManagerOnline.js +2 -2
- package/cjs/trackers/strategy/strategyOptimized.js +3 -0
- package/cjs/utils/constants/index.js +2 -3
- package/cjs/utils/inputValidation/eventProperties.js +12 -1
- package/cjs/utils/inputValidation/index.js +3 -1
- 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/error.js +1 -1
- package/esm/logger/messages/warn.js +2 -2
- package/esm/sdkClient/client.js +29 -19
- package/esm/sdkClient/clientAttributesDecoration.js +19 -25
- package/esm/sdkClient/clientInputValidation.js +29 -27
- package/esm/services/splitApi.js +2 -2
- package/esm/storages/AbstractSplitsCacheSync.js +2 -5
- package/esm/storages/KeyBuilder.js +0 -9
- package/esm/storages/KeyBuilderCS.js +1 -4
- package/esm/storages/KeyBuilderSS.js +0 -3
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/esm/storages/inLocalStorage/index.js +0 -4
- package/esm/storages/inMemory/InMemoryStorage.js +0 -3
- package/esm/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/esm/storages/inRedis/index.js +0 -2
- package/esm/storages/pluggable/index.js +0 -2
- package/esm/storages/utils.js +1 -0
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/esm/sync/polling/pollingManagerCS.js +7 -7
- 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 +35 -51
- 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/submitters/impressionsSubmitter.js +3 -2
- package/esm/sync/syncManagerOnline.js +2 -2
- package/esm/trackers/strategy/strategyOptimized.js +3 -0
- package/esm/utils/constants/index.js +1 -2
- package/esm/utils/inputValidation/eventProperties.js +10 -0
- package/esm/utils/inputValidation/index.js +1 -0
- package/package.json +1 -1
- package/src/dtos/types.ts +8 -32
- 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/error.ts +1 -1
- package/src/logger/messages/warn.ts +2 -2
- package/src/sdkClient/client.ts +31 -21
- package/src/sdkClient/clientAttributesDecoration.ts +20 -27
- package/src/sdkClient/clientInputValidation.ts +30 -27
- package/src/sdkManager/index.ts +1 -1
- package/src/services/splitApi.ts +2 -2
- 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 +1 -5
- package/src/storages/KeyBuilderSS.ts +0 -4
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +14 -10
- package/src/storages/inLocalStorage/index.ts +0 -4
- package/src/storages/inMemory/InMemoryStorage.ts +0 -3
- package/src/storages/inMemory/InMemoryStorageCS.ts +0 -4
- 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/storages/utils.ts +1 -0
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +1 -2
- package/src/sync/polling/fetchers/types.ts +0 -1
- package/src/sync/polling/pollingManagerCS.ts +7 -7
- 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 +44 -61
- 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/submitters/impressionsSubmitter.ts +3 -2
- package/src/sync/submitters/types.ts +23 -33
- package/src/sync/syncManagerOnline.ts +2 -2
- package/src/trackers/strategy/strategyOptimized.ts +3 -0
- package/src/utils/constants/index.ts +1 -2
- package/src/utils/inputValidation/eventProperties.ts +10 -0
- package/src/utils/inputValidation/index.ts +1 -0
- package/src/utils/lang/index.ts +1 -1
- package/types/splitio.d.ts +100 -35
- package/cjs/evaluator/matchers/rbsegment.js +0 -43
- 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 -39
- 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 -61
- 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,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,39 +0,0 @@
|
|
|
1
|
-
import { thenable } from '../../utils/promise/thenable';
|
|
2
|
-
import { getMatching, keyParser } from '../../utils/key';
|
|
3
|
-
import { parser } from '../parser';
|
|
4
|
-
export function ruleBasedSegmentMatcherContext(segmentName, storage, log) {
|
|
5
|
-
return function ruleBasedSegmentMatcher(_a, splitEvaluator) {
|
|
6
|
-
var key = _a.key, attributes = _a.attributes;
|
|
7
|
-
function matchConditions(rbsegment) {
|
|
8
|
-
var conditions = rbsegment.conditions;
|
|
9
|
-
var evaluator = parser(log, conditions, storage);
|
|
10
|
-
var evaluation = evaluator(keyParser(key), undefined, undefined, undefined, attributes, splitEvaluator);
|
|
11
|
-
return thenable(evaluation) ?
|
|
12
|
-
evaluation.then(function (evaluation) { return evaluation ? true : false; }) :
|
|
13
|
-
evaluation ? true : false;
|
|
14
|
-
}
|
|
15
|
-
function isExcluded(rbSegment) {
|
|
16
|
-
var matchingKey = getMatching(key);
|
|
17
|
-
if (rbSegment.excluded.keys.indexOf(matchingKey) !== -1)
|
|
18
|
-
return true;
|
|
19
|
-
var isInSegment = rbSegment.excluded.segments.map(function (segmentName) {
|
|
20
|
-
return storage.segments.isInSegment(segmentName, matchingKey);
|
|
21
|
-
});
|
|
22
|
-
return isInSegment.length && thenable(isInSegment[0]) ?
|
|
23
|
-
Promise.all(isInSegment).then(function (results) { return results.some(function (result) { return result; }); }) :
|
|
24
|
-
isInSegment.some(function (result) { return result; });
|
|
25
|
-
}
|
|
26
|
-
function isInSegment(rbSegment) {
|
|
27
|
-
if (!rbSegment)
|
|
28
|
-
return false;
|
|
29
|
-
var excluded = isExcluded(rbSegment);
|
|
30
|
-
return thenable(excluded) ?
|
|
31
|
-
excluded.then(function (excluded) { return excluded ? false : matchConditions(rbSegment); }) :
|
|
32
|
-
excluded ? false : matchConditions(rbSegment);
|
|
33
|
-
}
|
|
34
|
-
var rbSegment = storage.rbSegments.get(segmentName);
|
|
35
|
-
return thenable(rbSegment) ?
|
|
36
|
-
rbSegment.then(isInSegment) :
|
|
37
|
-
isInSegment(rbSegment);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
@@ -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 };
|
|
@@ -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 RBSegmentsCachePluggable = /** @class */ (function () {
|
|
5
|
-
function RBSegmentsCachePluggable(log, keys, wrapper) {
|
|
6
|
-
this.log = log;
|
|
7
|
-
this.keys = keys;
|
|
8
|
-
this.wrapper = wrapper;
|
|
9
|
-
}
|
|
10
|
-
RBSegmentsCachePluggable.prototype.get = function (name) {
|
|
11
|
-
return this.wrapper.get(this.keys.buildRBSegmentKey(name))
|
|
12
|
-
.then(function (maybeRBSegment) { return maybeRBSegment && JSON.parse(maybeRBSegment); });
|
|
13
|
-
};
|
|
14
|
-
RBSegmentsCachePluggable.prototype.getNames = function () {
|
|
15
|
-
var _this = this;
|
|
16
|
-
return this.wrapper.getKeysByPrefix(this.keys.buildRBSegmentKeyPrefix()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
|
|
17
|
-
};
|
|
18
|
-
RBSegmentsCachePluggable.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
|
-
RBSegmentsCachePluggable.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.wrapper.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.wrapper.del(key);
|
|
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
|
-
RBSegmentsCachePluggable.prototype.setChangeNumber = function (changeNumber) {
|
|
43
|
-
return this.wrapper.set(this.keys.buildRBSegmentsTillKey(), changeNumber + '');
|
|
44
|
-
};
|
|
45
|
-
RBSegmentsCachePluggable.prototype.getChangeNumber = function () {
|
|
46
|
-
var _this = this;
|
|
47
|
-
return this.wrapper.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
|
-
RBSegmentsCachePluggable.prototype.clear = function () {
|
|
57
|
-
return Promise.resolve();
|
|
58
|
-
};
|
|
59
|
-
return RBSegmentsCachePluggable;
|
|
60
|
-
}());
|
|
61
|
-
export { RBSegmentsCachePluggable };
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { IRBSegment, MaybeThenable } from '../../dtos/types';
|
|
2
|
-
import { IStorageAsync, IStorageSync } from '../../storages/types';
|
|
3
|
-
import { ILogger } from '../../logger/types';
|
|
4
|
-
import { IDependencyMatcherValue, ISplitEvaluator } from '../types';
|
|
5
|
-
import { thenable } from '../../utils/promise/thenable';
|
|
6
|
-
import { getMatching, keyParser } from '../../utils/key';
|
|
7
|
-
import { parser } from '../parser';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export function ruleBasedSegmentMatcherContext(segmentName: string, storage: IStorageSync | IStorageAsync, log: ILogger) {
|
|
11
|
-
|
|
12
|
-
return function ruleBasedSegmentMatcher({ key, attributes }: IDependencyMatcherValue, splitEvaluator: ISplitEvaluator): MaybeThenable<boolean> {
|
|
13
|
-
|
|
14
|
-
function matchConditions(rbsegment: IRBSegment) {
|
|
15
|
-
const conditions = rbsegment.conditions;
|
|
16
|
-
const evaluator = parser(log, conditions, storage);
|
|
17
|
-
|
|
18
|
-
const evaluation = evaluator(
|
|
19
|
-
keyParser(key),
|
|
20
|
-
undefined,
|
|
21
|
-
undefined,
|
|
22
|
-
undefined,
|
|
23
|
-
attributes,
|
|
24
|
-
splitEvaluator
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
return thenable(evaluation) ?
|
|
28
|
-
evaluation.then(evaluation => evaluation ? true : false) :
|
|
29
|
-
evaluation ? true : false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function isExcluded(rbSegment: IRBSegment) {
|
|
33
|
-
const matchingKey = getMatching(key);
|
|
34
|
-
|
|
35
|
-
if (rbSegment.excluded.keys.indexOf(matchingKey) !== -1) return true;
|
|
36
|
-
|
|
37
|
-
const isInSegment = rbSegment.excluded.segments.map(segmentName => {
|
|
38
|
-
return storage.segments.isInSegment(segmentName, matchingKey);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return isInSegment.length && thenable(isInSegment[0]) ?
|
|
42
|
-
Promise.all(isInSegment).then(results => results.some(result => result)) :
|
|
43
|
-
isInSegment.some(result => result);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function isInSegment(rbSegment: IRBSegment | null) {
|
|
47
|
-
if (!rbSegment) return false;
|
|
48
|
-
const excluded = isExcluded(rbSegment);
|
|
49
|
-
|
|
50
|
-
return thenable(excluded) ?
|
|
51
|
-
excluded.then(excluded => excluded ? false : matchConditions(rbSegment)) :
|
|
52
|
-
excluded ? false : matchConditions(rbSegment);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const rbSegment = storage.rbSegments.get(segmentName);
|
|
56
|
-
|
|
57
|
-
return thenable(rbSegment) ?
|
|
58
|
-
rbSegment.then(isInSegment) :
|
|
59
|
-
isInSegment(rbSegment);
|
|
60
|
-
};
|
|
61
|
-
}
|