@barchart/portfolio-api-common 1.0.178 → 1.0.182

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.
@@ -629,7 +629,7 @@ module.exports = (() => {
629
629
  const items = populatedObjects[key];
630
630
  const first = items[0];
631
631
 
632
- list.push(new PositionGroup(this, parent, levelDefinition, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
632
+ list.push(new PositionGroup(this, parent, levelDefinition, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.aggregateCash));
633
633
 
634
634
  return list;
635
635
  }, [ ]);
@@ -793,11 +793,13 @@ module.exports = (() => {
793
793
  array.remove(this._currencies[currency.code], i => i === positionItem);
794
794
  }
795
795
 
796
- this._trees[key].walk((group, groupNode) => {
797
- if (group.definition.type === PositionLevelType.POSITION && group.key === positionItem.position.position) {
798
- groupNode.sever();
799
- }
800
- }, true, false);
796
+ Object.keys(this._trees).forEach((key) => {
797
+ this._trees[key].walk((group, groupNode) => {
798
+ if (group.definition.type === PositionLevelType.POSITION && group.key === positionItem.position.position) {
799
+ groupNode.sever();
800
+ }
801
+ }, true, false);
802
+ });
801
803
 
802
804
  positionItem.dispose();
803
805
  }
@@ -28,11 +28,10 @@ module.exports = (() => {
28
28
  * @param {Currency} currency
29
29
  * @param {String} key
30
30
  * @param {String} description
31
- * @param {Boolean=} single
32
31
  * @param {Boolean=} aggregateCash
33
32
  */
34
33
  class PositionGroup {
35
- constructor(container, parent, definition, items, currency, key, description, single, aggregateCash) {
34
+ constructor(container, parent, definition, items, currency, key, description, aggregateCash) {
36
35
  this._id = counter++;
37
36
 
38
37
  this._definition = definition;
@@ -46,7 +45,7 @@ module.exports = (() => {
46
45
  this._key = key;
47
46
  this._description = description;
48
47
 
49
- this._single = is.boolean(single) && single;
48
+ this._single = this._definition.single;
50
49
  this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
51
50
 
52
51
  this._excluded = false;
@@ -79,7 +78,7 @@ module.exports = (() => {
79
78
  this._dataActual.quantity = null;
80
79
  this._dataActual.basisPrice = null;
81
80
 
82
- if (this._single) {
81
+ if (this._single && items.length === 1) {
83
82
  const item = items[0];
84
83
 
85
84
  this._dataFormat.portfolio = item.portfolio.portfolio;
@@ -565,7 +564,7 @@ module.exports = (() => {
565
564
 
566
565
  calculateUnrealizedPercent(group);
567
566
 
568
- if (group.single) {
567
+ if (group.single && group._items.length === 1) {
569
568
  const item = group._items[0];
570
569
 
571
570
  actual.quantity = item.position.snapshot.open;
@@ -20,12 +20,11 @@ module.exports = (() => {
20
20
  * @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
21
21
  * @param {PositionLevelDefinition~currencySelector} currencySelector
22
22
  * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
23
- * @param {Boolean=} single
24
23
  * @param {Boolean=} aggregateCash
25
24
  * @param {Function=} requiredGroupGenerator
26
25
  */
27
26
  class PositionLevelDefinition {
28
- constructor(name, type, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash, requiredGroupGenerator) {
27
+ constructor(name, type, keySelector, descriptionSelector, currencySelector, requiredGroups, aggregateCash, requiredGroupGenerator) {
29
28
  assert.argumentIsRequired(name, 'name', String);
30
29
  assert.argumentIsRequired(type, 'type', PositionLevelType, 'PositionLevelType');
31
30
  assert.argumentIsRequired(keySelector, 'keySelector', Function);
@@ -36,7 +35,6 @@ module.exports = (() => {
36
35
  assert.argumentIsArray(requiredGroups, 'requiredGroups', String);
37
36
  }
38
37
 
39
- assert.argumentIsOptional(single, 'single', Boolean);
40
38
  assert.argumentIsOptional(aggregateCash, 'aggregateCash', Boolean);
41
39
  assert.argumentIsOptional(requiredGroupGenerator, 'requiredGroupGenerator', Function);
42
40
 
@@ -49,7 +47,7 @@ module.exports = (() => {
49
47
 
50
48
  this._requiredGroups = requiredGroups || [ ];
51
49
 
52
- this._single = is.boolean(single) && single;
50
+ this._single = type === PositionLevelType.POSITION;
53
51
  this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
54
52
 
55
53
  this._requiredGroupGenerator = requiredGroupGenerator || (input => null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.178",
3
+ "version": "1.0.182",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1345,7 +1345,7 @@ module.exports = (() => {
1345
1345
  const items = populatedObjects[key];
1346
1346
  const first = items[0];
1347
1347
 
1348
- list.push(new PositionGroup(this, parent, levelDefinition, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
1348
+ list.push(new PositionGroup(this, parent, levelDefinition, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.aggregateCash));
1349
1349
 
1350
1350
  return list;
1351
1351
  }, [ ]);
@@ -1509,11 +1509,13 @@ module.exports = (() => {
1509
1509
  array.remove(this._currencies[currency.code], i => i === positionItem);
1510
1510
  }
1511
1511
 
1512
- this._trees[key].walk((group, groupNode) => {
1513
- if (group.definition.type === PositionLevelType.POSITION && group.key === positionItem.position.position) {
1514
- groupNode.sever();
1515
- }
1516
- }, true, false);
1512
+ Object.keys(this._trees).forEach((key) => {
1513
+ this._trees[key].walk((group, groupNode) => {
1514
+ if (group.definition.type === PositionLevelType.POSITION && group.key === positionItem.position.position) {
1515
+ groupNode.sever();
1516
+ }
1517
+ }, true, false);
1518
+ });
1517
1519
 
1518
1520
  positionItem.dispose();
1519
1521
  }
@@ -1552,11 +1554,10 @@ module.exports = (() => {
1552
1554
  * @param {Currency} currency
1553
1555
  * @param {String} key
1554
1556
  * @param {String} description
1555
- * @param {Boolean=} single
1556
1557
  * @param {Boolean=} aggregateCash
1557
1558
  */
1558
1559
  class PositionGroup {
1559
- constructor(container, parent, definition, items, currency, key, description, single, aggregateCash) {
1560
+ constructor(container, parent, definition, items, currency, key, description, aggregateCash) {
1560
1561
  this._id = counter++;
1561
1562
 
1562
1563
  this._definition = definition;
@@ -1570,7 +1571,7 @@ module.exports = (() => {
1570
1571
  this._key = key;
1571
1572
  this._description = description;
1572
1573
 
1573
- this._single = is.boolean(single) && single;
1574
+ this._single = this._definition.single;
1574
1575
  this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
1575
1576
 
1576
1577
  this._excluded = false;
@@ -1603,7 +1604,7 @@ module.exports = (() => {
1603
1604
  this._dataActual.quantity = null;
1604
1605
  this._dataActual.basisPrice = null;
1605
1606
 
1606
- if (this._single) {
1607
+ if (this._single && items.length === 1) {
1607
1608
  const item = items[0];
1608
1609
 
1609
1610
  this._dataFormat.portfolio = item.portfolio.portfolio;
@@ -2089,7 +2090,7 @@ module.exports = (() => {
2089
2090
 
2090
2091
  calculateUnrealizedPercent(group);
2091
2092
 
2092
- if (group.single) {
2093
+ if (group.single && group._items.length === 1) {
2093
2094
  const item = group._items[0];
2094
2095
 
2095
2096
  actual.quantity = item.position.snapshot.open;
@@ -2709,12 +2710,11 @@ module.exports = (() => {
2709
2710
  * @param {PositionLevelDefinition~descriptionSelector} descriptionSelector
2710
2711
  * @param {PositionLevelDefinition~currencySelector} currencySelector
2711
2712
  * @param {Array.<PositionLevelDefinition~RequiredGroup>=} requiredGroups
2712
- * @param {Boolean=} single
2713
2713
  * @param {Boolean=} aggregateCash
2714
2714
  * @param {Function=} requiredGroupGenerator
2715
2715
  */
2716
2716
  class PositionLevelDefinition {
2717
- constructor(name, type, keySelector, descriptionSelector, currencySelector, requiredGroups, single, aggregateCash, requiredGroupGenerator) {
2717
+ constructor(name, type, keySelector, descriptionSelector, currencySelector, requiredGroups, aggregateCash, requiredGroupGenerator) {
2718
2718
  assert.argumentIsRequired(name, 'name', String);
2719
2719
  assert.argumentIsRequired(type, 'type', PositionLevelType, 'PositionLevelType');
2720
2720
  assert.argumentIsRequired(keySelector, 'keySelector', Function);
@@ -2725,7 +2725,6 @@ module.exports = (() => {
2725
2725
  assert.argumentIsArray(requiredGroups, 'requiredGroups', String);
2726
2726
  }
2727
2727
 
2728
- assert.argumentIsOptional(single, 'single', Boolean);
2729
2728
  assert.argumentIsOptional(aggregateCash, 'aggregateCash', Boolean);
2730
2729
  assert.argumentIsOptional(requiredGroupGenerator, 'requiredGroupGenerator', Function);
2731
2730
 
@@ -2738,7 +2737,7 @@ module.exports = (() => {
2738
2737
 
2739
2738
  this._requiredGroups = requiredGroups || [ ];
2740
2739
 
2741
- this._single = is.boolean(single) && single;
2740
+ this._single = type === PositionLevelType.POSITION;
2742
2741
  this._aggregateCash = is.boolean(aggregateCash) && aggregateCash;
2743
2742
 
2744
2743
  this._requiredGroupGenerator = requiredGroupGenerator || (input => null);