@splitsoftware/splitio-commons 1.8.1 → 1.8.2-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGES.txt CHANGED
@@ -1,3 +1,6 @@
1
+ 1.8.2 (February 27, 2023)
2
+ - Updated internal splitChangesUpdater module to be resilient to duplicated split definitions when fetching split changes from Split backend.
3
+
1
4
  1.8.1 (February 7, 2023)
2
5
  - Updated a module import to remove a trailing comma that can cause issues with some bundlers.
3
6
 
@@ -5,6 +5,7 @@ var sets_1 = require("../../../utils/lang/sets");
5
5
  var timeout_1 = require("../../../utils/promise/timeout");
6
6
  var constants_1 = require("../../../readiness/constants");
7
7
  var constants_2 = require("../../../logger/constants");
8
+ var maps_1 = require("../../../utils/lang/maps");
8
9
  // Checks that all registered segments have been fetched (changeNumber !== -1 for every segment).
9
10
  // Returns a promise that could be rejected.
10
11
  // @TODO review together with Segments and MySegments storage APIs
@@ -38,19 +39,25 @@ exports.parseSegments = parseSegments;
38
39
  * Exported for testing purposes.
39
40
  */
40
41
  function computeSplitsMutation(entries) {
42
+ var uniqueEntries = new maps_1._Map();
43
+ entries.forEach(function (split) {
44
+ var prevSplit = uniqueEntries.get(split.name);
45
+ if (!prevSplit || prevSplit.changeNumber < split.changeNumber)
46
+ uniqueEntries.set(split.name, split);
47
+ });
41
48
  var segments = new sets_1._Set();
42
- var computed = entries.reduce(function (accum, split) {
49
+ var computed = { added: [], removed: [], segments: [] };
50
+ uniqueEntries.forEach(function (split) {
43
51
  if (split.status === 'ACTIVE') {
44
- accum.added.push([split.name, split]);
52
+ computed.added.push([split.name, split]);
45
53
  parseSegments(split).forEach(function (segmentName) {
46
54
  segments.add(segmentName);
47
55
  });
48
56
  }
49
57
  else {
50
- accum.removed.push(split.name);
58
+ computed.removed.push(split.name);
51
59
  }
52
- return accum;
53
- }, { added: [], removed: [], segments: [] });
60
+ });
54
61
  computed.segments = (0, sets_1.setToArray)(segments);
55
62
  return computed;
56
63
  }
@@ -2,6 +2,7 @@ import { _Set, setToArray } from '../../../utils/lang/sets';
2
2
  import { timeout } from '../../../utils/promise/timeout';
3
3
  import { SDK_SPLITS_ARRIVED, SDK_SPLITS_CACHE_LOADED } from '../../../readiness/constants';
4
4
  import { SYNC_SPLITS_FETCH, SYNC_SPLITS_NEW, SYNC_SPLITS_REMOVED, SYNC_SPLITS_SEGMENTS, SYNC_SPLITS_FETCH_FAILS, SYNC_SPLITS_FETCH_RETRY } from '../../../logger/constants';
5
+ import { _Map } from '../../../utils/lang/maps';
5
6
  // Checks that all registered segments have been fetched (changeNumber !== -1 for every segment).
6
7
  // Returns a promise that could be rejected.
7
8
  // @TODO review together with Segments and MySegments storage APIs
@@ -34,19 +35,25 @@ export function parseSegments(_a) {
34
35
  * Exported for testing purposes.
35
36
  */
36
37
  export function computeSplitsMutation(entries) {
38
+ var uniqueEntries = new _Map();
39
+ entries.forEach(function (split) {
40
+ var prevSplit = uniqueEntries.get(split.name);
41
+ if (!prevSplit || prevSplit.changeNumber < split.changeNumber)
42
+ uniqueEntries.set(split.name, split);
43
+ });
37
44
  var segments = new _Set();
38
- var computed = entries.reduce(function (accum, split) {
45
+ var computed = { added: [], removed: [], segments: [] };
46
+ uniqueEntries.forEach(function (split) {
39
47
  if (split.status === 'ACTIVE') {
40
- accum.added.push([split.name, split]);
48
+ computed.added.push([split.name, split]);
41
49
  parseSegments(split).forEach(function (segmentName) {
42
50
  segments.add(segmentName);
43
51
  });
44
52
  }
45
53
  else {
46
- accum.removed.push(split.name);
54
+ computed.removed.push(split.name);
47
55
  }
48
- return accum;
49
- }, { added: [], removed: [], segments: [] });
56
+ });
50
57
  computed.segments = setToArray(segments);
51
58
  return computed;
52
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.8.1",
3
+ "version": "1.8.2-rc.0",
4
4
  "description": "Split Javascript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -22,7 +22,7 @@
22
22
  "build": "npm run build:cjs && npm run build:esm",
23
23
  "build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types",
24
24
  "build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs",
25
- "test": "jest",
25
+ "test": "jest --runInBand",
26
26
  "test:coverage": "jest --coverage",
27
27
  "all": "npm run check && npm run build && npm run test",
28
28
  "publish:rc": "npm run check && npm run test && npm run build && npm publish --tag rc",
@@ -7,6 +7,7 @@ import { timeout } from '../../../utils/promise/timeout';
7
7
  import { SDK_SPLITS_ARRIVED, SDK_SPLITS_CACHE_LOADED } from '../../../readiness/constants';
8
8
  import { ILogger } from '../../../logger/types';
9
9
  import { SYNC_SPLITS_FETCH, SYNC_SPLITS_NEW, SYNC_SPLITS_REMOVED, SYNC_SPLITS_SEGMENTS, SYNC_SPLITS_FETCH_FAILS, SYNC_SPLITS_FETCH_RETRY } from '../../../logger/constants';
10
+ import { _Map } from '../../../utils/lang/maps';
10
11
 
11
12
  type ISplitChangesUpdater = (noCache?: boolean, till?: number) => Promise<boolean>
12
13
 
@@ -51,20 +52,25 @@ interface ISplitMutations {
51
52
  * Exported for testing purposes.
52
53
  */
53
54
  export function computeSplitsMutation(entries: ISplit[]): ISplitMutations {
55
+ const uniqueEntries = new _Map();
56
+ entries.forEach(split => {
57
+ const prevSplit = uniqueEntries.get(split.name);
58
+ if (!prevSplit || prevSplit.changeNumber < split.changeNumber) uniqueEntries.set(split.name, split);
59
+ });
60
+
54
61
  const segments = new _Set<string>();
55
- const computed = entries.reduce((accum, split) => {
62
+ const computed = { added: [], removed: [], segments: [] } as ISplitMutations;
63
+ uniqueEntries.forEach((split) => {
56
64
  if (split.status === 'ACTIVE') {
57
- accum.added.push([split.name, split]);
65
+ computed.added.push([split.name, split]);
58
66
 
59
67
  parseSegments(split).forEach((segmentName: string) => {
60
68
  segments.add(segmentName);
61
69
  });
62
70
  } else {
63
- accum.removed.push(split.name);
71
+ computed.removed.push(split.name);
64
72
  }
65
-
66
- return accum;
67
- }, { added: [], removed: [], segments: [] } as ISplitMutations);
73
+ });
68
74
 
69
75
  computed.segments = setToArray(segments);
70
76