@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,391 +0,0 @@
1
- "use strict";
2
- // Copyright Joyent, Inc. and other Node contributors.
3
- //
4
- // Permission is hereby granted, free of charge, to any person obtaining a
5
- // copy of this software and associated documentation files (the
6
- // "Software"), to deal in the Software without restriction, including
7
- // without limitation the rights to use, copy, modify, merge, publish,
8
- // distribute, sublicense, and/or sell copies of the Software, and to permit
9
- // persons to whom the Software is furnished to do so, subject to the
10
- // following conditions:
11
- //
12
- // The above copyright notice and this permission notice shall be included
13
- // in all copies or substantial portions of the Software.
14
- //
15
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.EventEmitter = void 0;
24
- // Adaptation of "events" library (https://www.npmjs.com/package/events)
25
- // exported as an ES module instead of CommonJS, to avoid extra configuration steps when using
26
- // the ESM build of the SDK with tools that doesn't support CommonJS by default (e.g. Rollup).
27
- var R = typeof Reflect === 'object' ? Reflect : null;
28
- var ReflectApply = R && typeof R.apply === 'function'
29
- ? R.apply
30
- : function ReflectApply(target, receiver, args) {
31
- return Function.prototype.apply.call(target, receiver, args);
32
- };
33
- var ReflectOwnKeys;
34
- if (R && typeof R.ownKeys === 'function') {
35
- ReflectOwnKeys = R.ownKeys;
36
- }
37
- else if (Object.getOwnPropertySymbols) {
38
- ReflectOwnKeys = function ReflectOwnKeys(target) {
39
- return Object.getOwnPropertyNames(target)
40
- .concat(Object.getOwnPropertySymbols(target));
41
- };
42
- }
43
- else {
44
- ReflectOwnKeys = function ReflectOwnKeys(target) {
45
- return Object.getOwnPropertyNames(target);
46
- };
47
- }
48
- function ProcessEmitWarning(warning) {
49
- if (console && console.warn)
50
- console.warn(warning);
51
- }
52
- // eslint-disable-next-line compat/compat
53
- var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
54
- return value !== value;
55
- };
56
- function EventEmitter() {
57
- EventEmitter.init.call(this);
58
- }
59
- exports.EventEmitter = EventEmitter;
60
- EventEmitter.prototype._events = undefined;
61
- EventEmitter.prototype._eventsCount = 0;
62
- EventEmitter.prototype._maxListeners = undefined;
63
- // By default EventEmitters will print a warning if more than 10 listeners are
64
- // added to it. This is a useful default which helps finding memory leaks.
65
- var defaultMaxListeners = 10;
66
- function checkListener(listener) {
67
- if (typeof listener !== 'function') {
68
- throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
69
- }
70
- }
71
- Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
72
- enumerable: true,
73
- get: function () {
74
- return defaultMaxListeners;
75
- },
76
- set: function (arg) {
77
- if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
78
- throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
79
- }
80
- defaultMaxListeners = arg;
81
- }
82
- });
83
- EventEmitter.init = function () {
84
- if (this._events === undefined ||
85
- this._events === Object.getPrototypeOf(this)._events) {
86
- this._events = Object.create(null);
87
- this._eventsCount = 0;
88
- }
89
- this._maxListeners = this._maxListeners || undefined;
90
- };
91
- // Obviously not all Emitters should be limited to 10. This function allows
92
- // that to be increased. Set to zero for unlimited.
93
- EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
94
- if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
95
- throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
96
- }
97
- this._maxListeners = n;
98
- return this;
99
- };
100
- function _getMaxListeners(that) {
101
- if (that._maxListeners === undefined)
102
- return EventEmitter.defaultMaxListeners;
103
- return that._maxListeners;
104
- }
105
- EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
106
- return _getMaxListeners(this);
107
- };
108
- EventEmitter.prototype.emit = function emit(type) {
109
- var args = [];
110
- for (var i = 1; i < arguments.length; i++)
111
- args.push(arguments[i]);
112
- var doError = (type === 'error');
113
- var events = this._events;
114
- if (events !== undefined)
115
- doError = (doError && events.error === undefined);
116
- else if (!doError)
117
- return false;
118
- // If there is no 'error' event listener then throw.
119
- if (doError) {
120
- var er;
121
- if (args.length > 0)
122
- er = args[0];
123
- if (er instanceof Error) {
124
- // Note: The comments on the `throw` lines are intentional, they show
125
- // up in Node.js output if this results in an unhandled exception.
126
- throw er; // Unhandled 'error' event
127
- }
128
- // At least give some kind of context to the user
129
- var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
130
- err.context = er;
131
- throw err; // Unhandled 'error' event
132
- }
133
- var handler = events[type];
134
- if (handler === undefined)
135
- return false;
136
- if (typeof handler === 'function') {
137
- ReflectApply(handler, this, args);
138
- }
139
- else {
140
- var len = handler.length;
141
- var listeners = arrayClone(handler, len); // eslint-disable-next-line no-redeclare
142
- for (var i = 0; i < len; ++i)
143
- ReflectApply(listeners[i], this, args);
144
- }
145
- return true;
146
- };
147
- function _addListener(target, type, listener, prepend) {
148
- var m;
149
- var events;
150
- var existing;
151
- checkListener(listener);
152
- events = target._events;
153
- if (events === undefined) {
154
- events = target._events = Object.create(null);
155
- target._eventsCount = 0;
156
- }
157
- else {
158
- // To avoid recursion in the case that type === "newListener"! Before
159
- // adding it to the listeners, first emit "newListener".
160
- if (events.newListener !== undefined) {
161
- target.emit('newListener', type, listener.listener ? listener.listener : listener);
162
- // Re-assign `events` because a newListener handler could have caused the
163
- // this._events to be assigned to a new object
164
- events = target._events;
165
- }
166
- existing = events[type];
167
- }
168
- if (existing === undefined) {
169
- // Optimize the case of one listener. Don't need the extra array object.
170
- existing = events[type] = listener;
171
- ++target._eventsCount;
172
- }
173
- else {
174
- if (typeof existing === 'function') {
175
- // Adding the second element, need to change to array.
176
- existing = events[type] =
177
- prepend ? [listener, existing] : [existing, listener];
178
- // If we've already got an array, just append.
179
- }
180
- else if (prepend) {
181
- existing.unshift(listener);
182
- }
183
- else {
184
- existing.push(listener);
185
- }
186
- // Check for listener leak
187
- m = _getMaxListeners(target);
188
- if (m > 0 && existing.length > m && !existing.warned) {
189
- existing.warned = true;
190
- // No error code for this since it is a Warning
191
- // eslint-disable-next-line no-restricted-syntax
192
- var w = new Error('Possible EventEmitter memory leak detected. ' +
193
- existing.length + ' ' + String(type) + ' listeners ' +
194
- 'added. Use emitter.setMaxListeners() to ' +
195
- 'increase limit');
196
- w.name = 'MaxListenersExceededWarning';
197
- w.emitter = target;
198
- w.type = type;
199
- w.count = existing.length;
200
- ProcessEmitWarning(w);
201
- }
202
- }
203
- return target;
204
- }
205
- EventEmitter.prototype.addListener = function addListener(type, listener) {
206
- return _addListener(this, type, listener, false);
207
- };
208
- EventEmitter.prototype.on = EventEmitter.prototype.addListener;
209
- EventEmitter.prototype.prependListener =
210
- function prependListener(type, listener) {
211
- return _addListener(this, type, listener, true);
212
- };
213
- function onceWrapper() {
214
- if (!this.fired) {
215
- this.target.removeListener(this.type, this.wrapFn);
216
- this.fired = true;
217
- if (arguments.length === 0)
218
- return this.listener.call(this.target);
219
- return this.listener.apply(this.target, arguments);
220
- }
221
- }
222
- function _onceWrap(target, type, listener) {
223
- var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
224
- var wrapped = onceWrapper.bind(state);
225
- wrapped.listener = listener;
226
- state.wrapFn = wrapped;
227
- return wrapped;
228
- }
229
- EventEmitter.prototype.once = function once(type, listener) {
230
- checkListener(listener);
231
- this.on(type, _onceWrap(this, type, listener));
232
- return this;
233
- };
234
- EventEmitter.prototype.prependOnceListener =
235
- function prependOnceListener(type, listener) {
236
- checkListener(listener);
237
- this.prependListener(type, _onceWrap(this, type, listener));
238
- return this;
239
- };
240
- // Emits a 'removeListener' event if and only if the listener was removed.
241
- EventEmitter.prototype.removeListener =
242
- function removeListener(type, listener) {
243
- var list, events, position, i, originalListener;
244
- checkListener(listener);
245
- events = this._events;
246
- if (events === undefined)
247
- return this;
248
- list = events[type];
249
- if (list === undefined)
250
- return this;
251
- if (list === listener || list.listener === listener) {
252
- if (--this._eventsCount === 0)
253
- this._events = Object.create(null);
254
- else {
255
- delete events[type];
256
- if (events.removeListener)
257
- this.emit('removeListener', type, list.listener || listener);
258
- }
259
- }
260
- else if (typeof list !== 'function') {
261
- position = -1;
262
- for (i = list.length - 1; i >= 0; i--) {
263
- if (list[i] === listener || list[i].listener === listener) {
264
- originalListener = list[i].listener;
265
- position = i;
266
- break;
267
- }
268
- }
269
- if (position < 0)
270
- return this;
271
- if (position === 0)
272
- list.shift();
273
- else {
274
- spliceOne(list, position);
275
- }
276
- if (list.length === 1)
277
- events[type] = list[0];
278
- if (events.removeListener !== undefined)
279
- this.emit('removeListener', type, originalListener || listener);
280
- }
281
- return this;
282
- };
283
- EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
284
- EventEmitter.prototype.removeAllListeners =
285
- function removeAllListeners(type) {
286
- var listeners, events, i;
287
- events = this._events;
288
- if (events === undefined)
289
- return this;
290
- // not listening for removeListener, no need to emit
291
- if (events.removeListener === undefined) {
292
- if (arguments.length === 0) {
293
- this._events = Object.create(null);
294
- this._eventsCount = 0;
295
- }
296
- else if (events[type] !== undefined) {
297
- if (--this._eventsCount === 0)
298
- this._events = Object.create(null);
299
- else
300
- delete events[type];
301
- }
302
- return this;
303
- }
304
- // emit removeListener for all listeners on all events
305
- if (arguments.length === 0) {
306
- var keys = Object.keys(events);
307
- var key;
308
- for (i = 0; i < keys.length; ++i) {
309
- key = keys[i];
310
- if (key === 'removeListener')
311
- continue;
312
- this.removeAllListeners(key);
313
- }
314
- this.removeAllListeners('removeListener');
315
- this._events = Object.create(null);
316
- this._eventsCount = 0;
317
- return this;
318
- }
319
- listeners = events[type];
320
- if (typeof listeners === 'function') {
321
- this.removeListener(type, listeners);
322
- }
323
- else if (listeners !== undefined) {
324
- // LIFO order
325
- for (i = listeners.length - 1; i >= 0; i--) {
326
- this.removeListener(type, listeners[i]);
327
- }
328
- }
329
- return this;
330
- };
331
- function _listeners(target, type, unwrap) {
332
- var events = target._events;
333
- if (events === undefined)
334
- return [];
335
- var evlistener = events[type];
336
- if (evlistener === undefined)
337
- return [];
338
- if (typeof evlistener === 'function')
339
- return unwrap ? [evlistener.listener || evlistener] : [evlistener];
340
- return unwrap ?
341
- unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
342
- }
343
- EventEmitter.prototype.listeners = function listeners(type) {
344
- return _listeners(this, type, true);
345
- };
346
- EventEmitter.prototype.rawListeners = function rawListeners(type) {
347
- return _listeners(this, type, false);
348
- };
349
- EventEmitter.listenerCount = function (emitter, type) {
350
- if (typeof emitter.listenerCount === 'function') {
351
- return emitter.listenerCount(type);
352
- }
353
- else {
354
- return listenerCount.call(emitter, type);
355
- }
356
- };
357
- EventEmitter.prototype.listenerCount = listenerCount;
358
- function listenerCount(type) {
359
- var events = this._events;
360
- if (events !== undefined) {
361
- var evlistener = events[type];
362
- if (typeof evlistener === 'function') {
363
- return 1;
364
- }
365
- else if (evlistener !== undefined) {
366
- return evlistener.length;
367
- }
368
- }
369
- return 0;
370
- }
371
- EventEmitter.prototype.eventNames = function eventNames() {
372
- return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
373
- };
374
- function arrayClone(arr, n) {
375
- var copy = new Array(n);
376
- for (var i = 0; i < n; ++i)
377
- copy[i] = arr[i];
378
- return copy;
379
- }
380
- function spliceOne(list, index) {
381
- for (; index + 1 < list.length; index++)
382
- list[index] = list[index + 1];
383
- list.pop();
384
- }
385
- function unwrapListeners(arr) {
386
- var ret = new Array(arr.length);
387
- for (var i = 0; i < ret.length; ++i) {
388
- ret[i] = arr[i].listener || arr[i];
389
- }
390
- return ret;
391
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bloomFilterFactory = void 0;
4
- // bloom-filters is supported on the following platforms:
5
- // - Node.js: v4.0.0 or higher
6
- // - Google Chrome: v41 or higher
7
- // - Mozilla Firefox: v34 or higher
8
- // - Microsoft Edge: v12 or higher
9
- var bloom_filters_1 = require("bloom-filters");
10
- var EXPECTED_INSERTIONS = 10000000;
11
- var ERROR_RATE = 0.01;
12
- var REFRESH_RATE = 24 * 60 * 60000; // 24HS
13
- function bloomFilterFactory(expectedInsertions, errorRate, refreshRate) {
14
- if (expectedInsertions === void 0) { expectedInsertions = EXPECTED_INSERTIONS; }
15
- if (errorRate === void 0) { errorRate = ERROR_RATE; }
16
- if (refreshRate === void 0) { refreshRate = REFRESH_RATE; }
17
- var filter = bloom_filters_1.BloomFilter.create(expectedInsertions, errorRate);
18
- return {
19
- refreshRate: refreshRate,
20
- add: function (key, value) {
21
- var data = "".concat(key, ":").concat(value);
22
- if (filter.has(data)) {
23
- return false;
24
- }
25
- filter.add(data);
26
- return true;
27
- },
28
- contains: function (key, value) {
29
- var data = "".concat(key, ":").concat(value);
30
- return filter.has(data);
31
- },
32
- clear: function () {
33
- filter = bloom_filters_1.BloomFilter.create(expectedInsertions, errorRate);
34
- }
35
- };
36
- }
37
- exports.bloomFilterFactory = bloomFilterFactory;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateDefinitions = void 0;
4
- var constants_1 = require("../../logger/constants");
5
- var lang_1 = require("../lang");
6
- var definition_1 = require("./definition");
7
- function validateDefinitions(log, maybeDefinitions, method, listName, item) {
8
- if (listName === void 0) { listName = 'feature flag names'; }
9
- if (item === void 0) { item = 'feature flag name'; }
10
- if (Array.isArray(maybeDefinitions) && maybeDefinitions.length > 0) {
11
- var validatedArray_1 = [];
12
- // Remove invalid values
13
- maybeDefinitions.forEach(function (maybeDefinition) {
14
- var definitionName = (0, definition_1.validateDefinition)(log, maybeDefinition, method, item);
15
- if (definitionName)
16
- validatedArray_1.push(definitionName);
17
- });
18
- // Strip off duplicated values if we have valid definition names then return
19
- if (validatedArray_1.length)
20
- return (0, lang_1.uniq)(validatedArray_1);
21
- }
22
- log.error(constants_1.ERROR_EMPTY_ARRAY, [method, listName]);
23
- return false;
24
- }
25
- exports.validateDefinitions = validateDefinitions;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateTarget = void 0;
4
- var tslib_1 = require("tslib");
5
- var lang_1 = require("../lang");
6
- var key_1 = require("./key");
7
- var attributes_1 = require("./attributes");
8
- var constants_1 = require("../../logger/constants");
9
- function validateTarget(log, maybeTarget, method) {
10
- if (!(0, lang_1.isObject)(maybeTarget)) {
11
- log.error(constants_1.ERROR_NOT_PLAIN_OBJECT, [method, 'target']);
12
- return false;
13
- }
14
- var key = (0, key_1.validateKey)(log, maybeTarget.key, method);
15
- if (key === false)
16
- return false;
17
- var attributes = (0, attributes_1.validateAttributes)(log, maybeTarget.attributes, method);
18
- if (attributes === false)
19
- return false;
20
- return tslib_1.__assign(tslib_1.__assign({}, maybeTarget), { key: key, attributes: attributes });
21
- }
22
- exports.validateTarget = validateTarget;
@@ -1,12 +0,0 @@
1
- import { EventEmitter } from '../utils/EventEmitter';
2
- import { getFetch } from '../platform/getFetch/browser';
3
- import { getEventSource } from '../platform/getEventSource/browser';
4
- import { BrowserSignalListener } from '../listeners/browser';
5
- import { now } from '../utils/timeTracker/now/browser';
6
- export var platform = {
7
- getFetch: getFetch,
8
- getEventSource: getEventSource,
9
- EventEmitter: EventEmitter,
10
- now: now,
11
- SignalListener: BrowserSignalListener
12
- };
@@ -1,4 +0,0 @@
1
- export function getEventSource() {
2
- // eslint-disable-next-line no-undef -- Feature detection for EventSource
3
- return typeof EventSource === 'function' ? EventSource : undefined;
4
- }