@splitsoftware/splitio-commons 3.1.1-rc.0 → 3.1.1-rc.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/CHANGES.txt +10 -1
  2. package/cjs/evaluator/condition/index.js +1 -1
  3. package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +8 -5
  4. package/cjs/evaluator/index.js +69 -81
  5. package/cjs/listeners/browser.js +1 -2
  6. package/cjs/listeners/node.js +4 -4
  7. package/cjs/logger/constants.js +20 -15
  8. package/cjs/logger/messages/debug.js +6 -5
  9. package/cjs/logger/messages/error.js +3 -3
  10. package/cjs/logger/messages/info.js +4 -3
  11. package/cjs/logger/messages/warn.js +7 -6
  12. package/cjs/presets/serverSide.js +2 -2
  13. package/cjs/readiness/constants.js +4 -5
  14. package/cjs/readiness/readinessManager.js +23 -23
  15. package/cjs/readiness/sdkReadinessManager.js +17 -1
  16. package/cjs/sdkClient/client.js +34 -9
  17. package/cjs/sdkClient/clientInputValidation.js +17 -6
  18. package/cjs/sdkClient/sdkClient.js +60 -3
  19. package/cjs/sdkFactory/index.js +15 -11
  20. package/cjs/sdkManager/index.js +5 -5
  21. package/cjs/services/decorateHeaders.js +1 -2
  22. package/cjs/services/splitApi.js +1 -14
  23. package/cjs/services/splitHttpClient.js +5 -3
  24. package/cjs/storages/AbstractSplitsCacheAsync.js +51 -0
  25. package/cjs/storages/AbstractSplitsCacheSync.js +76 -0
  26. package/cjs/storages/KeyBuilder.js +6 -6
  27. package/cjs/storages/KeyBuilderCS.js +5 -5
  28. package/cjs/storages/KeyBuilderSS.js +2 -2
  29. package/cjs/storages/getRolloutPlan.js +3 -3
  30. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +2 -1
  31. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
  32. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +194 -0
  33. package/cjs/storages/inLocalStorage/index.js +6 -6
  34. package/cjs/storages/inLocalStorage/validateCache.js +3 -3
  35. package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
  36. package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
  37. package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +5 -5
  38. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  39. package/cjs/storages/inMemory/SplitsCacheInMemory.js +121 -0
  40. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  41. package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  42. package/cjs/storages/inRedis/RedisAdapter.js +8 -5
  43. package/cjs/storages/inRedis/{DefinitionsCacheInRedis.js → SplitsCacheInRedis.js} +77 -77
  44. package/cjs/storages/inRedis/index.js +2 -2
  45. package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  46. package/cjs/storages/pluggable/SplitsCachePluggable.js +212 -0
  47. package/cjs/storages/pluggable/index.js +2 -2
  48. package/cjs/storages/setRolloutPlan.js +4 -4
  49. package/cjs/storages/utils.js +0 -1
  50. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
  51. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +15 -24
  52. package/cjs/sync/polling/pollingManagerCS.js +20 -20
  53. package/cjs/sync/polling/pollingManagerSS.js +15 -15
  54. package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +3 -2
  55. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +13 -0
  56. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  57. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
  58. package/cjs/sync/polling/updaters/{definitionChangesUpdater.js → splitChangesUpdater.js} +68 -65
  59. package/cjs/sync/streaming/AuthClient/index.js +1 -1
  60. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
  61. package/cjs/sync/streaming/SSEHandler/index.js +1 -1
  62. package/cjs/sync/streaming/UpdateWorkers/{DefinitionsUpdateWorker.js → SplitsUpdateWorker.js} +19 -16
  63. package/cjs/sync/streaming/constants.js +3 -3
  64. package/cjs/sync/streaming/parseUtils.js +11 -11
  65. package/cjs/sync/streaming/pushManager.js +16 -16
  66. package/cjs/sync/submitters/eventsSubmitter.js +1 -1
  67. package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
  68. package/cjs/sync/submitters/impressionsSubmitter.js +4 -5
  69. package/cjs/sync/submitters/telemetrySubmitter.js +4 -3
  70. package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
  71. package/cjs/sync/syncManagerOnline.js +7 -12
  72. package/cjs/utils/Backoff.js +0 -20
  73. package/cjs/utils/inputValidation/index.js +7 -7
  74. package/cjs/utils/inputValidation/isOperational.js +4 -4
  75. package/cjs/utils/inputValidation/{definition.js → split.js} +10 -10
  76. package/cjs/utils/inputValidation/{definitionExistence.js → splitExistence.js} +6 -6
  77. package/cjs/utils/inputValidation/splits.js +25 -0
  78. package/cjs/utils/labels/index.js +3 -3
  79. package/cjs/utils/settingsValidation/index.js +0 -2
  80. package/cjs/utils/settingsValidation/splitFilters.js +3 -3
  81. package/cjs/utils/settingsValidation/url.js +2 -6
  82. package/esm/evaluator/condition/index.js +1 -1
  83. package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +8 -5
  84. package/esm/evaluator/index.js +69 -80
  85. package/esm/listeners/browser.js +1 -2
  86. package/esm/listeners/node.js +4 -4
  87. package/esm/logger/constants.js +17 -12
  88. package/esm/logger/messages/debug.js +6 -5
  89. package/esm/logger/messages/error.js +3 -3
  90. package/esm/logger/messages/info.js +4 -3
  91. package/esm/logger/messages/warn.js +7 -6
  92. package/esm/presets/serverSide.js +2 -2
  93. package/esm/readiness/constants.js +3 -4
  94. package/esm/readiness/readinessManager.js +24 -24
  95. package/esm/readiness/sdkReadinessManager.js +18 -2
  96. package/esm/sdkClient/client.js +35 -9
  97. package/esm/sdkClient/clientInputValidation.js +19 -8
  98. package/esm/sdkClient/sdkClient.js +60 -3
  99. package/esm/sdkFactory/index.js +16 -12
  100. package/esm/sdkManager/index.js +6 -6
  101. package/esm/services/decorateHeaders.js +1 -2
  102. package/esm/services/splitApi.js +1 -14
  103. package/esm/services/splitHttpClient.js +5 -3
  104. package/esm/storages/AbstractSplitsCacheAsync.js +48 -0
  105. package/esm/storages/AbstractSplitsCacheSync.js +71 -0
  106. package/esm/storages/KeyBuilder.js +6 -6
  107. package/esm/storages/KeyBuilderCS.js +5 -5
  108. package/esm/storages/KeyBuilderSS.js +2 -2
  109. package/esm/storages/getRolloutPlan.js +3 -3
  110. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +2 -1
  111. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
  112. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +191 -0
  113. package/esm/storages/inLocalStorage/index.js +6 -6
  114. package/esm/storages/inLocalStorage/validateCache.js +3 -3
  115. package/esm/storages/inMemory/InMemoryStorage.js +4 -4
  116. package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
  117. package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -2
  118. package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  119. package/esm/storages/inMemory/SplitsCacheInMemory.js +118 -0
  120. package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  121. package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  122. package/esm/storages/inRedis/RedisAdapter.js +8 -5
  123. package/esm/storages/inRedis/{DefinitionsCacheInRedis.js → SplitsCacheInRedis.js} +76 -76
  124. package/esm/storages/inRedis/index.js +2 -2
  125. package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  126. package/esm/storages/pluggable/SplitsCachePluggable.js +209 -0
  127. package/esm/storages/pluggable/index.js +2 -2
  128. package/esm/storages/setRolloutPlan.js +4 -4
  129. package/esm/storages/utils.js +0 -1
  130. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
  131. package/esm/sync/polling/fetchers/splitChangesFetcher.js +16 -25
  132. package/esm/sync/polling/pollingManagerCS.js +17 -17
  133. package/esm/sync/polling/pollingManagerSS.js +15 -15
  134. package/esm/sync/polling/syncTasks/segmentsSyncTask.js +3 -2
  135. package/esm/sync/polling/syncTasks/splitsSyncTask.js +9 -0
  136. package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  137. package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
  138. package/esm/sync/polling/updaters/{definitionChangesUpdater.js → splitChangesUpdater.js} +68 -65
  139. package/esm/sync/streaming/AuthClient/index.js +1 -1
  140. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
  141. package/esm/sync/streaming/SSEHandler/index.js +2 -2
  142. package/esm/sync/streaming/UpdateWorkers/{DefinitionsUpdateWorker.js → SplitsUpdateWorker.js} +18 -15
  143. package/esm/sync/streaming/constants.js +2 -2
  144. package/esm/sync/streaming/parseUtils.js +9 -9
  145. package/esm/sync/streaming/pushManager.js +18 -18
  146. package/esm/sync/submitters/eventsSubmitter.js +1 -1
  147. package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
  148. package/esm/sync/submitters/impressionsSubmitter.js +4 -5
  149. package/esm/sync/submitters/telemetrySubmitter.js +4 -3
  150. package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
  151. package/esm/sync/syncManagerOnline.js +6 -11
  152. package/esm/utils/Backoff.js +0 -20
  153. package/esm/utils/inputValidation/index.js +3 -3
  154. package/esm/utils/inputValidation/isOperational.js +4 -4
  155. package/esm/utils/inputValidation/{definition.js → split.js} +8 -8
  156. package/esm/utils/inputValidation/splitExistence.js +15 -0
  157. package/esm/utils/inputValidation/splits.js +21 -0
  158. package/esm/utils/labels/index.js +2 -2
  159. package/esm/utils/settingsValidation/index.js +0 -2
  160. package/esm/utils/settingsValidation/splitFilters.js +3 -3
  161. package/esm/utils/settingsValidation/url.js +2 -6
  162. package/package.json +6 -7
  163. package/src/dtos/types.ts +1 -1
  164. package/src/evaluator/Engine.ts +3 -3
  165. package/src/evaluator/condition/index.ts +2 -2
  166. package/src/evaluator/index.ts +27 -35
  167. package/src/evaluator/types.ts +2 -6
  168. package/src/presets/serverSide.ts +3 -3
  169. package/src/sdkClient/client.ts +22 -24
  170. package/src/sdkClient/sdkLifecycle.ts +3 -0
  171. package/src/services/authProvider.ts +41 -19
  172. package/src/services/secureSplitHttpClient.ts +10 -18
  173. package/src/services/serviceApi.ts +27 -24
  174. package/src/services/splitApi.ts +10 -9
  175. package/src/services/types.ts +5 -4
  176. package/src/storages/inRedis/RedisAdapter.ts +8 -5
  177. package/src/sync/polling/pollingManagerCS.ts +80 -78
  178. package/src/sync/polling/pollingManagerSS.ts +49 -45
  179. package/src/sync/polling/updaters/definitionChangesUpdater.ts +3 -3
  180. package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
  181. package/src/sync/streaming/AuthClient/index.ts +14 -15
  182. package/src/sync/streaming/AuthClient/types.ts +9 -13
  183. package/src/sync/streaming/SSEClient/index.ts +2 -2
  184. package/src/sync/streaming/SSEClient/types.ts +2 -2
  185. package/src/sync/streaming/SSEHandler/index.ts +2 -1
  186. package/src/sync/streaming/SSEHandler/types.ts +2 -2
  187. package/src/sync/streaming/constants.ts +1 -0
  188. package/src/sync/streaming/pushManager.ts +32 -42
  189. package/src/sync/streaming/types.ts +3 -2
  190. package/src/sync/submitters/impressionsSubmitter.ts +3 -3
  191. package/src/sync/submitters/types.ts +2 -2
  192. package/src/sync/syncManagerOnline.ts +2 -8
  193. package/src/utils/Backoff.ts +16 -4
  194. package/types/splitio.d.ts +5 -4
  195. package/cjs/platform/browser.js +0 -15
  196. package/cjs/platform/getEventSource/browser.js +0 -8
  197. package/cjs/platform/getEventSource/eventsource.js +0 -480
  198. package/cjs/platform/getEventSource/node.js +0 -26
  199. package/cjs/platform/getFetch/browser.js +0 -9
  200. package/cjs/platform/getFetch/node.js +0 -27
  201. package/cjs/platform/getOptions/node.js +0 -25
  202. package/cjs/platform/node.js +0 -17
  203. package/cjs/sdkClient/sdkLifecycle.js +0 -72
  204. package/cjs/sdkClient/trackMethod.js +0 -56
  205. package/cjs/services/authProvider.js +0 -67
  206. package/cjs/services/secureSplitHttpClient.js +0 -39
  207. package/cjs/services/serviceApi.js +0 -145
  208. package/cjs/storages/AbstractDefinitionsCacheAsync.js +0 -51
  209. package/cjs/storages/AbstractDefinitionsCacheSync.js +0 -76
  210. package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +0 -194
  211. package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +0 -121
  212. package/cjs/storages/pluggable/DefinitionsCachePluggable.js +0 -212
  213. package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +0 -13
  214. package/cjs/utils/EventEmitter.js +0 -391
  215. package/cjs/utils/filter/bloomFilter.js +0 -37
  216. package/cjs/utils/inputValidation/definitions.js +0 -25
  217. package/cjs/utils/inputValidation/target.js +0 -22
  218. package/esm/platform/browser.js +0 -12
  219. package/esm/platform/getEventSource/browser.js +0 -4
  220. package/esm/platform/getEventSource/eventsource.js +0 -480
  221. package/esm/platform/getEventSource/node.js +0 -20
  222. package/esm/platform/getFetch/browser.js +0 -5
  223. package/esm/platform/getFetch/node.js +0 -22
  224. package/esm/platform/getOptions/node.js +0 -20
  225. package/esm/platform/node.js +0 -14
  226. package/esm/sdkClient/sdkLifecycle.js +0 -68
  227. package/esm/sdkClient/trackMethod.js +0 -52
  228. package/esm/services/authProvider.js +0 -63
  229. package/esm/services/secureSplitHttpClient.js +0 -35
  230. package/esm/services/serviceApi.js +0 -141
  231. package/esm/storages/AbstractDefinitionsCacheAsync.js +0 -48
  232. package/esm/storages/AbstractDefinitionsCacheSync.js +0 -71
  233. package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +0 -191
  234. package/esm/storages/inMemory/DefinitionsCacheInMemory.js +0 -118
  235. package/esm/storages/pluggable/DefinitionsCachePluggable.js +0 -209
  236. package/esm/sync/polling/syncTasks/definitionsSyncTask.js +0 -9
  237. package/esm/utils/EventEmitter.js +0 -387
  238. package/esm/utils/filter/bloomFilter.js +0 -33
  239. package/esm/utils/inputValidation/definitionExistence.js +0 -15
  240. package/esm/utils/inputValidation/definitions.js +0 -21
  241. package/esm/utils/inputValidation/target.js +0 -18
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefinitionsCacheInMemory = void 0;
4
- var tslib_1 = require("tslib");
5
- var AbstractDefinitionsCacheSync_1 = require("../AbstractDefinitionsCacheSync");
6
- var lang_1 = require("../../utils/lang");
7
- /**
8
- * Default IDefinitionsCacheSync implementation that stores split definitions in memory.
9
- */
10
- var DefinitionsCacheInMemory = /** @class */ (function (_super) {
11
- tslib_1.__extends(DefinitionsCacheInMemory, _super);
12
- function DefinitionsCacheInMemory(splitFiltersValidation) {
13
- var _this = _super.call(this) || this;
14
- _this.definitionsCache = {};
15
- _this.ttCache = {};
16
- _this.changeNumber = -1;
17
- _this.segmentsCount = 0;
18
- _this.setsCache = {};
19
- _this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
20
- return _this;
21
- }
22
- DefinitionsCacheInMemory.prototype.clear = function () {
23
- this.definitionsCache = {};
24
- this.ttCache = {};
25
- this.changeNumber = -1;
26
- this.segmentsCount = 0;
27
- this.setsCache = {};
28
- };
29
- DefinitionsCacheInMemory.prototype.add = function (definition) {
30
- var name = definition.name;
31
- var previousDefinition = this.get(name);
32
- if (previousDefinition) { // We had this Split already
33
- var previousTtName = previousDefinition.trafficTypeName;
34
- this.ttCache[previousTtName]--;
35
- if (!this.ttCache[previousTtName])
36
- delete this.ttCache[previousTtName];
37
- this.removeFromFlagSets(previousDefinition.name, previousDefinition.sets);
38
- // Subtract from segments count for the previous version of this Split
39
- if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(previousDefinition))
40
- this.segmentsCount--;
41
- }
42
- // Store the Split.
43
- this.definitionsCache[name] = definition;
44
- // Update TT cache
45
- var ttName = definition.trafficTypeName;
46
- this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
47
- this.addToFlagSets(definition);
48
- // Add to segments count for the new version of the Split
49
- if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(definition))
50
- this.segmentsCount++;
51
- return true;
52
- };
53
- DefinitionsCacheInMemory.prototype.remove = function (name) {
54
- var definition = this.get(name);
55
- if (!definition)
56
- return false;
57
- // Delete the Split
58
- delete this.definitionsCache[name];
59
- var ttName = definition.trafficTypeName;
60
- this.ttCache[ttName]--; // Update tt cache
61
- if (!this.ttCache[ttName])
62
- delete this.ttCache[ttName];
63
- this.removeFromFlagSets(definition.name, definition.sets);
64
- // Update the segments count.
65
- if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(definition))
66
- this.segmentsCount--;
67
- return true;
68
- };
69
- DefinitionsCacheInMemory.prototype.get = function (name) {
70
- return this.definitionsCache[name] || null;
71
- };
72
- DefinitionsCacheInMemory.prototype.setChangeNumber = function (changeNumber) {
73
- this.changeNumber = changeNumber;
74
- return true;
75
- };
76
- DefinitionsCacheInMemory.prototype.getChangeNumber = function () {
77
- return this.changeNumber;
78
- };
79
- DefinitionsCacheInMemory.prototype.getNames = function () {
80
- return Object.keys(this.definitionsCache);
81
- };
82
- DefinitionsCacheInMemory.prototype.trafficTypeExists = function (trafficType) {
83
- return (0, lang_1.isFiniteNumber)(this.ttCache[trafficType]) && this.ttCache[trafficType] > 0;
84
- };
85
- DefinitionsCacheInMemory.prototype.usesSegments = function () {
86
- return this.getChangeNumber() === -1 || this.segmentsCount > 0;
87
- };
88
- DefinitionsCacheInMemory.prototype.getNamesBySets = function (sets) {
89
- var _this = this;
90
- return sets.map(function (set) { return _this.setsCache[set] || new Set(); });
91
- };
92
- DefinitionsCacheInMemory.prototype.addToFlagSets = function (featureFlag) {
93
- var _this = this;
94
- if (!featureFlag.sets)
95
- return;
96
- featureFlag.sets.forEach(function (featureFlagSet) {
97
- if (_this.setsFilter.length > 0 && !_this.setsFilter.some(function (filterFlagSet) { return filterFlagSet === featureFlagSet; }))
98
- return;
99
- if (!_this.setsCache[featureFlagSet])
100
- _this.setsCache[featureFlagSet] = new Set([]);
101
- _this.setsCache[featureFlagSet].add(featureFlag.name);
102
- });
103
- };
104
- DefinitionsCacheInMemory.prototype.removeFromFlagSets = function (featureFlagName, sets) {
105
- var _this = this;
106
- if (!sets)
107
- return;
108
- sets.forEach(function (set) {
109
- _this.removeNames(set, featureFlagName);
110
- });
111
- };
112
- DefinitionsCacheInMemory.prototype.removeNames = function (setName, featureFlagName) {
113
- if (!this.setsCache[setName])
114
- return;
115
- this.setsCache[setName].delete(featureFlagName);
116
- if (this.setsCache[setName].size === 0)
117
- delete this.setsCache[setName];
118
- };
119
- return DefinitionsCacheInMemory;
120
- }(AbstractDefinitionsCacheSync_1.AbstractDefinitionsCacheSync));
121
- exports.DefinitionsCacheInMemory = DefinitionsCacheInMemory;
@@ -1,212 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefinitionsCachePluggable = void 0;
4
- var tslib_1 = require("tslib");
5
- var lang_1 = require("../../utils/lang");
6
- var constants_1 = require("./constants");
7
- var AbstractDefinitionsCacheAsync_1 = require("../AbstractDefinitionsCacheAsync");
8
- var sets_1 = require("../../utils/lang/sets");
9
- /**
10
- * IDefinitionsCacheAsync implementation for pluggable storages.
11
- */
12
- var DefinitionsCachePluggable = /** @class */ (function (_super) {
13
- tslib_1.__extends(DefinitionsCachePluggable, _super);
14
- /**
15
- * Create a DefinitionsCache that uses a storage wrapper.
16
- * @param log - Logger instance.
17
- * @param keys - Key builder.
18
- * @param wrapper - Adapted wrapper storage.
19
- */
20
- function DefinitionsCachePluggable(log, keys, wrapper, splitFiltersValidation) {
21
- var _this = _super.call(this) || this;
22
- _this.log = log;
23
- _this.keys = keys;
24
- _this.wrapper = wrapper;
25
- _this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
26
- return _this;
27
- }
28
- DefinitionsCachePluggable.prototype._decrementCounts = function (definition) {
29
- var _this = this;
30
- var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
31
- return this.wrapper.decr(ttKey).then(function (count) {
32
- if (count === 0)
33
- return _this.wrapper.del(ttKey);
34
- });
35
- };
36
- DefinitionsCachePluggable.prototype._incrementCounts = function (definition) {
37
- var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
38
- return this.wrapper.incr(ttKey);
39
- };
40
- DefinitionsCachePluggable.prototype._updateSets = function (definitionName, setsOfRemovedDefinition, setsOfAddedDefinition) {
41
- var _this = this;
42
- var removeFromSets = (0, sets_1.returnDifference)(setsOfRemovedDefinition, setsOfAddedDefinition);
43
- var addToSets = (0, sets_1.returnDifference)(setsOfAddedDefinition, setsOfRemovedDefinition);
44
- if (this.setsFilter.length > 0) {
45
- addToSets = addToSets.filter(function (set) {
46
- return _this.setsFilter.some(function (filterSet) { return filterSet === set; });
47
- });
48
- }
49
- var items = [definitionName];
50
- return Promise.all(tslib_1.__spreadArray(tslib_1.__spreadArray([], removeFromSets.map(function (setName) { return _this.wrapper.removeItems(_this.keys.buildSetKey(setName), items); }), true), addToSets.map(function (setName) { return _this.wrapper.addItems(_this.keys.buildSetKey(setName), items); }), true));
51
- };
52
- /**
53
- * Add a given definition.
54
- * The returned promise is resolved when the operation success
55
- * or rejected if it fails (e.g., wrapper operation fails)
56
- */
57
- DefinitionsCachePluggable.prototype.add = function (definition) {
58
- var _this = this;
59
- var name = definition.name;
60
- var definitionKey = this.keys.buildDefinitionKey(name);
61
- return this.wrapper.get(definitionKey).then(function (definitionFromStorage) {
62
- // handling parsing error
63
- var parsedPreviousDefinition, stringifiedNewDefinition;
64
- try {
65
- parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
66
- stringifiedNewDefinition = JSON.stringify(definition);
67
- }
68
- catch (e) {
69
- throw new Error('Error parsing feature flag definition: ' + e);
70
- }
71
- return _this.wrapper.set(definitionKey, stringifiedNewDefinition).then(function () {
72
- // avoid unnecessary increment/decrement operations
73
- if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName)
74
- return;
75
- // update traffic type counts
76
- return _this._incrementCounts(definition).then(function () {
77
- if (parsedPreviousDefinition)
78
- return _this._decrementCounts(parsedPreviousDefinition);
79
- });
80
- }).then(function () { return _this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets); });
81
- }).then(function () { return true; });
82
- };
83
- /**
84
- * Remove a given definition.
85
- * The returned promise is resolved when the operation success, with a boolean indicating if the definition existed or not.
86
- * or rejected if it fails (e.g., wrapper operation fails).
87
- */
88
- DefinitionsCachePluggable.prototype.remove = function (name) {
89
- var _this = this;
90
- return this.get(name).then(function (definition) {
91
- if (definition) {
92
- return _this._decrementCounts(definition).then(function () { return _this._updateSets(name, definition.sets); });
93
- }
94
- }).then(function () {
95
- return _this.wrapper.del(_this.keys.buildDefinitionKey(name));
96
- });
97
- };
98
- /**
99
- * Get definition.
100
- * The returned promise is resolved with the definition or null if it's not defined,
101
- * or rejected if wrapper operation fails.
102
- */
103
- DefinitionsCachePluggable.prototype.get = function (name) {
104
- return this.wrapper.get(this.keys.buildDefinitionKey(name))
105
- .then(function (maybeDefinition) { return maybeDefinition && JSON.parse(maybeDefinition); });
106
- };
107
- /**
108
- * Get list of definitions.
109
- * The returned promise is resolved with a map of names to their definition or null if it's not defined,
110
- * or rejected if wrapper operation fails.
111
- */
112
- DefinitionsCachePluggable.prototype.getMany = function (names) {
113
- var _this = this;
114
- var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
115
- return this.wrapper.getMany(keys).then(function (stringifiedDefinitions) {
116
- var definitions = {};
117
- names.forEach(function (name, idx) {
118
- var definition = stringifiedDefinitions[idx];
119
- definitions[name] = definition && JSON.parse(definition);
120
- });
121
- return Promise.resolve(definitions);
122
- });
123
- };
124
- /**
125
- * Get list of all definitions.
126
- * The returned promise is resolved with the list of definitions,
127
- * or rejected if wrapper operation fails.
128
- */
129
- DefinitionsCachePluggable.prototype.getAll = function () {
130
- var _this = this;
131
- return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix())
132
- .then(function (listOfKeys) { return _this.wrapper.getMany(listOfKeys); })
133
- .then(function (definitions) { return definitions.map(function (definition) {
134
- return JSON.parse(definition);
135
- }); });
136
- };
137
- /**
138
- * Get list of definition names.
139
- * The returned promise is resolved with the list of names,
140
- * or rejected if wrapper operation fails.
141
- */
142
- DefinitionsCachePluggable.prototype.getNames = function () {
143
- var _this = this;
144
- return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
145
- };
146
- /**
147
- * Get list of definition names related to a given list of set names.
148
- * The returned promise is resolved with the list of names per set.
149
- * It never rejects (If there is a wrapper error for some set, an empty set is returned for it).
150
- */
151
- DefinitionsCachePluggable.prototype.getNamesBySets = function (sets) {
152
- var _this = this;
153
- return Promise.all(sets.map(function (set) {
154
- var setKey = _this.keys.buildSetKey(set);
155
- return _this.wrapper.getItems(setKey).catch(function () { return []; });
156
- })).then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
157
- };
158
- /**
159
- * Check traffic type existence.
160
- * The returned promise is resolved with a boolean indicating whether the TT exist or not.
161
- * In case of wrapper operation failures, the promise resolves with a true value, assuming that the TT might exist.
162
- * It will never be rejected.
163
- */
164
- DefinitionsCachePluggable.prototype.trafficTypeExists = function (trafficType) {
165
- var _this = this;
166
- // If there is a number there should be > 0, otherwise the TT is considered as not existent.
167
- return this.wrapper.get(this.keys.buildTrafficTypeKey(trafficType))
168
- .then(function (ttCount) {
169
- if (ttCount === null)
170
- return false; // if entry doesn't exist, means that TT doesn't exist
171
- ttCount = parseInt(ttCount, 10);
172
- if (!(0, lang_1.isFiniteNumber)(ttCount) || ttCount < 0) {
173
- _this.log.info(constants_1.LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to data corruption of some sorts."));
174
- return false;
175
- }
176
- return ttCount > 0;
177
- }).catch(function (e) {
178
- _this.log.error(constants_1.LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to an error: ").concat(e, "."));
179
- // If there is an error, bypass the validation so the event can get tracked.
180
- return true;
181
- });
182
- };
183
- /**
184
- * Set till number.
185
- * The returned promise is resolved when the operation success,
186
- * or rejected if it fails (e.g., wrapper operation fails).
187
- */
188
- DefinitionsCachePluggable.prototype.setChangeNumber = function (changeNumber) {
189
- return this.wrapper.set(this.keys.buildDefinitionsTillKey(), changeNumber + '');
190
- };
191
- /**
192
- * Get till number or -1 if it's not defined.
193
- * The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
194
- * The promise will never be rejected.
195
- */
196
- DefinitionsCachePluggable.prototype.getChangeNumber = function () {
197
- var _this = this;
198
- return this.wrapper.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
199
- var i = parseInt(value, 10);
200
- return (0, lang_1.isNaNNumber)(i) ? -1 : i;
201
- }).catch(function (e) {
202
- _this.log.error(constants_1.LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
203
- return -1;
204
- });
205
- };
206
- // @TODO implement if required by DataLoader or producer mode
207
- DefinitionsCachePluggable.prototype.clear = function () {
208
- return Promise.resolve(true);
209
- };
210
- return DefinitionsCachePluggable;
211
- }(AbstractDefinitionsCacheAsync_1.AbstractDefinitionsCacheAsync));
212
- exports.DefinitionsCachePluggable = DefinitionsCachePluggable;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.definitionsSyncTaskFactory = void 0;
4
- var syncTask_1 = require("../../syncTask");
5
- var definitionChangesUpdater_1 = require("../updaters/definitionChangesUpdater");
6
- /**
7
- * Creates a sync task that periodically executes a `definitionChangesUpdater` task
8
- */
9
- function definitionsSyncTaskFactory(definitionChangesFetcher, storage, readiness, settings, segmentsSyncTask // undefined for client-side
10
- ) {
11
- return (0, syncTask_1.syncTaskFactory)(settings.log, (0, definitionChangesUpdater_1.definitionChangesUpdaterFactory)(settings.log, definitionChangesFetcher, storage, settings.sync.__splitFiltersValidation, readiness.definitions, settings.startup.requestTimeoutBeforeReady, settings.startup.retriesOnFailureBeforeReady, segmentsSyncTask), settings.scheduler.featuresRefreshRate, 'definitionChangesUpdater');
12
- }
13
- exports.definitionsSyncTaskFactory = definitionsSyncTaskFactory;