@barchart/portfolio-api-common 1.0.163 → 1.0.164
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.
|
@@ -179,14 +179,45 @@ module.exports = (() => {
|
|
|
179
179
|
|
|
180
180
|
this._definitions.forEach((treeDefinition) => {
|
|
181
181
|
const tree = this._trees[treeDefinition.name];
|
|
182
|
+
const levelDefinitions = treeDefinition.definitions;
|
|
182
183
|
|
|
183
|
-
|
|
184
|
-
const requiredGroup = levelDefinition.generateRequiredGroup(portfolio);
|
|
184
|
+
let portfolioRequiredGroup = null;
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
let portfolioLevelDefinition = null;
|
|
187
|
+
let portfolioLevelDefinitionIndex = null;
|
|
187
188
|
|
|
189
|
+
levelDefinitions.forEach((levelDefinition, i) => {
|
|
190
|
+
if (portfolioRequiredGroup === null) {
|
|
191
|
+
portfolioRequiredGroup = levelDefinition.generateRequiredGroup(portfolio);
|
|
192
|
+
|
|
193
|
+
if (portfolioRequiredGroup !== null) {
|
|
194
|
+
portfolioLevelDefinition = levelDefinition;
|
|
195
|
+
portfolioLevelDefinitionIndex = i;
|
|
196
|
+
}
|
|
188
197
|
}
|
|
189
198
|
});
|
|
199
|
+
|
|
200
|
+
if (portfolioRequiredGroup !== null) {
|
|
201
|
+
let parentTrees = [ ];
|
|
202
|
+
|
|
203
|
+
if (portfolioLevelDefinitionIndex === 0) {
|
|
204
|
+
parentTrees.push(tree);
|
|
205
|
+
} else {
|
|
206
|
+
const parentLevelDefinition = levelDefinitions[ portfolioLevelDefinitionIndex - 1 ];
|
|
207
|
+
|
|
208
|
+
tree.walk((group, groupTree) => {
|
|
209
|
+
if (group.definition === parentLevelDefinition) {
|
|
210
|
+
parentTrees.push(groupTree);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const overrideRequiredGroups = [ portfolioRequiredGroup ];
|
|
216
|
+
|
|
217
|
+
parentTrees.forEach((t) => {
|
|
218
|
+
createGroups.call(this, tree, t, [ ], treeDefinition, levelDefinitions.slice(portfolioLevelDefinitionIndex), overrideRequiredGroups);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
190
221
|
});
|
|
191
222
|
}
|
|
192
223
|
}
|
|
@@ -444,7 +475,7 @@ module.exports = (() => {
|
|
|
444
475
|
this._groupBindings[id].push(dispoable);
|
|
445
476
|
}
|
|
446
477
|
|
|
447
|
-
function createGroups(parentTree, currentTree, items, treeDefinition, levelDefinitions) {
|
|
478
|
+
function createGroups(parentTree, currentTree, items, treeDefinition, levelDefinitions, overrideRequiredGroups) {
|
|
448
479
|
if (levelDefinitions.length === 0) {
|
|
449
480
|
return;
|
|
450
481
|
}
|
|
@@ -458,26 +489,28 @@ module.exports = (() => {
|
|
|
458
489
|
const items = populatedObjects[key];
|
|
459
490
|
const first = items[0];
|
|
460
491
|
|
|
461
|
-
list.push(new PositionGroup(this, parent, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
|
|
492
|
+
list.push(new PositionGroup(this, parent, levelDefinition, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
|
|
462
493
|
|
|
463
494
|
return list;
|
|
464
495
|
}, [ ]);
|
|
465
496
|
|
|
466
|
-
const
|
|
497
|
+
const requiredGroupsToUse = overrideRequiredGroups || levelDefinition.requiredGroups;
|
|
498
|
+
|
|
499
|
+
const missingGroups = array.difference(requiredGroupsToUse.map(group => group.key), populatedGroups.map(group => group.key))
|
|
467
500
|
.map((key) => {
|
|
468
|
-
return
|
|
501
|
+
return requiredGroupsToUse.find(g => g.key === key);
|
|
469
502
|
});
|
|
470
503
|
|
|
471
504
|
const empty = missingGroups.map((group) => {
|
|
472
|
-
return new PositionGroup(this, parent, [ ], group.currency, group.key, group.description);
|
|
505
|
+
return new PositionGroup(this, parent, levelDefinition, [ ], group.currency, group.key, group.description);
|
|
473
506
|
});
|
|
474
507
|
|
|
475
508
|
const compositeGroups = populatedGroups.concat(empty);
|
|
476
509
|
|
|
477
510
|
let builder;
|
|
478
511
|
|
|
479
|
-
if (
|
|
480
|
-
const ordering =
|
|
512
|
+
if (requiredGroupsToUse.length !== 0) {
|
|
513
|
+
const ordering = requiredGroupsToUse.reduce((map, group, index) => {
|
|
481
514
|
map[group.description] = index;
|
|
482
515
|
|
|
483
516
|
return map;
|
|
@@ -22,6 +22,7 @@ module.exports = (() => {
|
|
|
22
22
|
* @public
|
|
23
23
|
* @param {PositionContainer} container
|
|
24
24
|
* @param {PositionGroup|null} parent
|
|
25
|
+
* @param {LevelDefinition} definition
|
|
25
26
|
* @param {Array.<PositionItem>} items
|
|
26
27
|
* @param {Currency} currency
|
|
27
28
|
* @param {String} key
|
|
@@ -30,8 +31,10 @@ module.exports = (() => {
|
|
|
30
31
|
* @param {Boolean=} aggregateCash
|
|
31
32
|
*/
|
|
32
33
|
class PositionGroup {
|
|
33
|
-
constructor(container, parent, items, currency, key, description, single, aggregateCash) {
|
|
34
|
+
constructor(container, parent, definition, items, currency, key, description, single, aggregateCash) {
|
|
34
35
|
this._id = counter++;
|
|
36
|
+
|
|
37
|
+
this._definition = definition;
|
|
35
38
|
this._container = container;
|
|
36
39
|
this._parent = parent || null;
|
|
37
40
|
|
|
@@ -209,6 +212,16 @@ module.exports = (() => {
|
|
|
209
212
|
return this._id;
|
|
210
213
|
}
|
|
211
214
|
|
|
215
|
+
/**
|
|
216
|
+
* The {@link LevelDefinition} which was used to generate this group.
|
|
217
|
+
*
|
|
218
|
+
* @public
|
|
219
|
+
* @returns {LevelDefinition}
|
|
220
|
+
*/
|
|
221
|
+
get definition() {
|
|
222
|
+
return this._definition;
|
|
223
|
+
}
|
|
224
|
+
|
|
212
225
|
/**
|
|
213
226
|
* The key of the group.
|
|
214
227
|
*
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -895,14 +895,45 @@ module.exports = (() => {
|
|
|
895
895
|
|
|
896
896
|
this._definitions.forEach((treeDefinition) => {
|
|
897
897
|
const tree = this._trees[treeDefinition.name];
|
|
898
|
+
const levelDefinitions = treeDefinition.definitions;
|
|
898
899
|
|
|
899
|
-
|
|
900
|
-
const requiredGroup = levelDefinition.generateRequiredGroup(portfolio);
|
|
900
|
+
let portfolioRequiredGroup = null;
|
|
901
901
|
|
|
902
|
-
|
|
902
|
+
let portfolioLevelDefinition = null;
|
|
903
|
+
let portfolioLevelDefinitionIndex = null;
|
|
903
904
|
|
|
905
|
+
levelDefinitions.forEach((levelDefinition, i) => {
|
|
906
|
+
if (portfolioRequiredGroup === null) {
|
|
907
|
+
portfolioRequiredGroup = levelDefinition.generateRequiredGroup(portfolio);
|
|
908
|
+
|
|
909
|
+
if (portfolioRequiredGroup !== null) {
|
|
910
|
+
portfolioLevelDefinition = levelDefinition;
|
|
911
|
+
portfolioLevelDefinitionIndex = i;
|
|
912
|
+
}
|
|
904
913
|
}
|
|
905
914
|
});
|
|
915
|
+
|
|
916
|
+
if (portfolioRequiredGroup !== null) {
|
|
917
|
+
let parentTrees = [ ];
|
|
918
|
+
|
|
919
|
+
if (portfolioLevelDefinitionIndex === 0) {
|
|
920
|
+
parentTrees.push(tree);
|
|
921
|
+
} else {
|
|
922
|
+
const parentLevelDefinition = levelDefinitions[ portfolioLevelDefinitionIndex - 1 ];
|
|
923
|
+
|
|
924
|
+
tree.walk((group, groupTree) => {
|
|
925
|
+
if (group.definition === parentLevelDefinition) {
|
|
926
|
+
parentTrees.push(groupTree);
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
const overrideRequiredGroups = [ portfolioRequiredGroup ];
|
|
932
|
+
|
|
933
|
+
parentTrees.forEach((t) => {
|
|
934
|
+
createGroups.call(this, tree, t, [ ], treeDefinition, levelDefinitions.slice(portfolioLevelDefinitionIndex), overrideRequiredGroups);
|
|
935
|
+
});
|
|
936
|
+
}
|
|
906
937
|
});
|
|
907
938
|
}
|
|
908
939
|
}
|
|
@@ -1160,7 +1191,7 @@ module.exports = (() => {
|
|
|
1160
1191
|
this._groupBindings[id].push(dispoable);
|
|
1161
1192
|
}
|
|
1162
1193
|
|
|
1163
|
-
function createGroups(parentTree, currentTree, items, treeDefinition, levelDefinitions) {
|
|
1194
|
+
function createGroups(parentTree, currentTree, items, treeDefinition, levelDefinitions, overrideRequiredGroups) {
|
|
1164
1195
|
if (levelDefinitions.length === 0) {
|
|
1165
1196
|
return;
|
|
1166
1197
|
}
|
|
@@ -1174,26 +1205,28 @@ module.exports = (() => {
|
|
|
1174
1205
|
const items = populatedObjects[key];
|
|
1175
1206
|
const first = items[0];
|
|
1176
1207
|
|
|
1177
|
-
list.push(new PositionGroup(this, parent, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
|
|
1208
|
+
list.push(new PositionGroup(this, parent, levelDefinition, items, levelDefinition.currencySelector(first), key, levelDefinition.descriptionSelector(first), levelDefinition.single && items.length === 1, levelDefinition.aggregateCash));
|
|
1178
1209
|
|
|
1179
1210
|
return list;
|
|
1180
1211
|
}, [ ]);
|
|
1181
1212
|
|
|
1182
|
-
const
|
|
1213
|
+
const requiredGroupsToUse = overrideRequiredGroups || levelDefinition.requiredGroups;
|
|
1214
|
+
|
|
1215
|
+
const missingGroups = array.difference(requiredGroupsToUse.map(group => group.key), populatedGroups.map(group => group.key))
|
|
1183
1216
|
.map((key) => {
|
|
1184
|
-
return
|
|
1217
|
+
return requiredGroupsToUse.find(g => g.key === key);
|
|
1185
1218
|
});
|
|
1186
1219
|
|
|
1187
1220
|
const empty = missingGroups.map((group) => {
|
|
1188
|
-
return new PositionGroup(this, parent, [ ], group.currency, group.key, group.description);
|
|
1221
|
+
return new PositionGroup(this, parent, levelDefinition, [ ], group.currency, group.key, group.description);
|
|
1189
1222
|
});
|
|
1190
1223
|
|
|
1191
1224
|
const compositeGroups = populatedGroups.concat(empty);
|
|
1192
1225
|
|
|
1193
1226
|
let builder;
|
|
1194
1227
|
|
|
1195
|
-
if (
|
|
1196
|
-
const ordering =
|
|
1228
|
+
if (requiredGroupsToUse.length !== 0) {
|
|
1229
|
+
const ordering = requiredGroupsToUse.reduce((map, group, index) => {
|
|
1197
1230
|
map[group.description] = index;
|
|
1198
1231
|
|
|
1199
1232
|
return map;
|
|
@@ -1305,6 +1338,7 @@ module.exports = (() => {
|
|
|
1305
1338
|
* @public
|
|
1306
1339
|
* @param {PositionContainer} container
|
|
1307
1340
|
* @param {PositionGroup|null} parent
|
|
1341
|
+
* @param {LevelDefinition} definition
|
|
1308
1342
|
* @param {Array.<PositionItem>} items
|
|
1309
1343
|
* @param {Currency} currency
|
|
1310
1344
|
* @param {String} key
|
|
@@ -1313,8 +1347,10 @@ module.exports = (() => {
|
|
|
1313
1347
|
* @param {Boolean=} aggregateCash
|
|
1314
1348
|
*/
|
|
1315
1349
|
class PositionGroup {
|
|
1316
|
-
constructor(container, parent, items, currency, key, description, single, aggregateCash) {
|
|
1350
|
+
constructor(container, parent, definition, items, currency, key, description, single, aggregateCash) {
|
|
1317
1351
|
this._id = counter++;
|
|
1352
|
+
|
|
1353
|
+
this._definition = definition;
|
|
1318
1354
|
this._container = container;
|
|
1319
1355
|
this._parent = parent || null;
|
|
1320
1356
|
|
|
@@ -1492,6 +1528,16 @@ module.exports = (() => {
|
|
|
1492
1528
|
return this._id;
|
|
1493
1529
|
}
|
|
1494
1530
|
|
|
1531
|
+
/**
|
|
1532
|
+
* The {@link LevelDefinition} which was used to generate this group.
|
|
1533
|
+
*
|
|
1534
|
+
* @public
|
|
1535
|
+
* @returns {LevelDefinition}
|
|
1536
|
+
*/
|
|
1537
|
+
get definition() {
|
|
1538
|
+
return this._definition;
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1495
1541
|
/**
|
|
1496
1542
|
* The key of the group.
|
|
1497
1543
|
*
|
|
@@ -2654,7 +2700,7 @@ module.exports = (() => {
|
|
|
2654
2700
|
* bottom-most level of the tree (i.e. leaf nodes).
|
|
2655
2701
|
*
|
|
2656
2702
|
* @public
|
|
2657
|
-
* @returns {Array.<
|
|
2703
|
+
* @returns {Array.<PositionLevelDefinitions>}
|
|
2658
2704
|
*/
|
|
2659
2705
|
get definitions() {
|
|
2660
2706
|
return this._definitions;
|