@barchart/portfolio-api-common 1.0.229 → 1.0.233
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/lib/api/failures/PortfolioFailureType.js +10 -3
- package/lib/data/TransactionType.js +36 -22
- package/package-lock.json +5484 -0
- package/package.json +1 -1
- package/test/SpecRunner.js +48 -113
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){function
|
|
1
|
+
(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
|
|
2
2
|
const uuid = require('uuid');
|
|
3
3
|
|
|
4
4
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
@@ -462,9 +462,10 @@ module.exports = (() => {
|
|
|
462
462
|
* @param {Boolean} income
|
|
463
463
|
* @param {Boolean} opening
|
|
464
464
|
* @param {Boolean} closing
|
|
465
|
+
* @param {Boolean} fee
|
|
465
466
|
*/
|
|
466
467
|
class TransactionType extends Enum {
|
|
467
|
-
constructor(code, description, display, purchase, sale, income, opening, closing) {
|
|
468
|
+
constructor(code, description, display, purchase, sale, income, opening, closing, fee) {
|
|
468
469
|
super(code, description);
|
|
469
470
|
|
|
470
471
|
assert.argumentIsRequired(display, 'display', String);
|
|
@@ -473,6 +474,7 @@ module.exports = (() => {
|
|
|
473
474
|
assert.argumentIsRequired(income, 'income', Boolean);
|
|
474
475
|
assert.argumentIsRequired(opening, 'opening', Boolean);
|
|
475
476
|
assert.argumentIsRequired(closing, 'closing', Boolean);
|
|
477
|
+
assert.argumentIsRequired(fee, 'fee', Boolean);
|
|
476
478
|
|
|
477
479
|
this._display = display;
|
|
478
480
|
this._purchase = purchase;
|
|
@@ -480,6 +482,7 @@ module.exports = (() => {
|
|
|
480
482
|
this._income = income;
|
|
481
483
|
this._opening = opening;
|
|
482
484
|
this._closing = closing;
|
|
485
|
+
this._fee = fee
|
|
483
486
|
}
|
|
484
487
|
|
|
485
488
|
/**
|
|
@@ -554,6 +557,17 @@ module.exports = (() => {
|
|
|
554
557
|
return this._closing;
|
|
555
558
|
}
|
|
556
559
|
|
|
560
|
+
/**
|
|
561
|
+
* Indicates if the transactions is a fee (which neither opens or closes) the
|
|
562
|
+
* position.
|
|
563
|
+
*
|
|
564
|
+
* @public
|
|
565
|
+
* @returns {Boolean}
|
|
566
|
+
*/
|
|
567
|
+
get fee() {
|
|
568
|
+
return this._fee;
|
|
569
|
+
}
|
|
570
|
+
|
|
557
571
|
/**
|
|
558
572
|
* A purchase.
|
|
559
573
|
*
|
|
@@ -757,27 +771,27 @@ module.exports = (() => {
|
|
|
757
771
|
}
|
|
758
772
|
}
|
|
759
773
|
|
|
760
|
-
const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false);
|
|
761
|
-
const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true);
|
|
762
|
-
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true);
|
|
763
|
-
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false);
|
|
764
|
-
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false);
|
|
765
|
-
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false);
|
|
766
|
-
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false);
|
|
767
|
-
const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false);
|
|
768
|
-
const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, true, false);
|
|
769
|
-
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, false);
|
|
774
|
+
const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false);
|
|
775
|
+
const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false);
|
|
776
|
+
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false);
|
|
777
|
+
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false);
|
|
778
|
+
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false);
|
|
779
|
+
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false);
|
|
780
|
+
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false);
|
|
781
|
+
const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false);
|
|
782
|
+
const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, true, false, true);
|
|
783
|
+
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false);
|
|
770
784
|
|
|
771
|
-
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false);
|
|
772
|
-
const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false);
|
|
785
|
+
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false);
|
|
786
|
+
const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false);
|
|
773
787
|
|
|
774
|
-
const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false);
|
|
775
|
-
const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false);
|
|
776
|
-
const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false);
|
|
777
|
-
const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false);
|
|
788
|
+
const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false);
|
|
789
|
+
const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false);
|
|
790
|
+
const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false);
|
|
791
|
+
const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false);
|
|
778
792
|
|
|
779
|
-
const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false);
|
|
780
|
-
const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false);
|
|
793
|
+
const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false);
|
|
794
|
+
const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false);
|
|
781
795
|
|
|
782
796
|
return TransactionType;
|
|
783
797
|
})();
|
|
@@ -3479,31 +3493,14 @@ module.exports = function () {
|
|
|
3479
3493
|
}
|
|
3480
3494
|
|
|
3481
3495
|
/**
|
|
3482
|
-
*
|
|
3496
|
+
* Returns the parent node. If this is the root node, a null value is returned.
|
|
3483
3497
|
*
|
|
3484
3498
|
* @public
|
|
3485
|
-
* @returns {Tree}
|
|
3499
|
+
* @returns {Tree|null}
|
|
3486
3500
|
*/
|
|
3487
3501
|
|
|
3488
3502
|
|
|
3489
3503
|
_createClass(Tree, [{
|
|
3490
|
-
key: 'getRoot',
|
|
3491
|
-
value: function getRoot() {
|
|
3492
|
-
if (this.getIsRoot()) {
|
|
3493
|
-
return this;
|
|
3494
|
-
} else {
|
|
3495
|
-
return this._parent.getRoot();
|
|
3496
|
-
}
|
|
3497
|
-
}
|
|
3498
|
-
|
|
3499
|
-
/**
|
|
3500
|
-
* Returns the parent node. If this is the root node, a null value is returned.
|
|
3501
|
-
*
|
|
3502
|
-
* @public
|
|
3503
|
-
* @returns {Tree|null}
|
|
3504
|
-
*/
|
|
3505
|
-
|
|
3506
|
-
}, {
|
|
3507
3504
|
key: 'getParent',
|
|
3508
3505
|
value: function getParent() {
|
|
3509
3506
|
return this._parent;
|
|
@@ -3604,23 +3601,6 @@ module.exports = function () {
|
|
|
3604
3601
|
}
|
|
3605
3602
|
}
|
|
3606
3603
|
|
|
3607
|
-
/**
|
|
3608
|
-
* Removes the current node from the parent tree. Use on a root node
|
|
3609
|
-
* has no effect.
|
|
3610
|
-
*
|
|
3611
|
-
* @public
|
|
3612
|
-
*/
|
|
3613
|
-
|
|
3614
|
-
}, {
|
|
3615
|
-
key: 'sever',
|
|
3616
|
-
value: function sever() {
|
|
3617
|
-
if (this.getIsRoot()) {
|
|
3618
|
-
return;
|
|
3619
|
-
}
|
|
3620
|
-
|
|
3621
|
-
this.getParent().removeChild(this);
|
|
3622
|
-
}
|
|
3623
|
-
|
|
3624
3604
|
/**
|
|
3625
3605
|
* Searches the children nodes for the first child node that matches the
|
|
3626
3606
|
* predicate.
|
|
@@ -5015,20 +4995,6 @@ module.exports = function () {
|
|
|
5015
4995
|
return this._big.gt(getBig(other));
|
|
5016
4996
|
}
|
|
5017
4997
|
|
|
5018
|
-
/**
|
|
5019
|
-
* Returns true if the current instance is greater than or equal to the value.
|
|
5020
|
-
*
|
|
5021
|
-
* @public
|
|
5022
|
-
* @param {Decimal|Number|String} other - The value to compare.
|
|
5023
|
-
* @returns {Boolean}
|
|
5024
|
-
*/
|
|
5025
|
-
|
|
5026
|
-
}, {
|
|
5027
|
-
key: 'getIsGreaterThanOrEqual',
|
|
5028
|
-
value: function getIsGreaterThanOrEqual(other) {
|
|
5029
|
-
return this._big.gte(getBig(other));
|
|
5030
|
-
}
|
|
5031
|
-
|
|
5032
4998
|
/**
|
|
5033
4999
|
* Returns true if the current instance is less than the value.
|
|
5034
5000
|
*
|
|
@@ -5043,20 +5009,6 @@ module.exports = function () {
|
|
|
5043
5009
|
return this._big.lt(getBig(other));
|
|
5044
5010
|
}
|
|
5045
5011
|
|
|
5046
|
-
/**
|
|
5047
|
-
* Returns true if the current instance is less than or equal to the value.
|
|
5048
|
-
*
|
|
5049
|
-
* @public
|
|
5050
|
-
* @param {Decimal|Number|String} other - The value to compare.
|
|
5051
|
-
* @returns {Boolean}
|
|
5052
|
-
*/
|
|
5053
|
-
|
|
5054
|
-
}, {
|
|
5055
|
-
key: 'getIsLessThanOrEqual',
|
|
5056
|
-
value: function getIsLessThanOrEqual(other) {
|
|
5057
|
-
return this._big.lte(getBig(other));
|
|
5058
|
-
}
|
|
5059
|
-
|
|
5060
5012
|
/**
|
|
5061
5013
|
* Returns true if the current instance is equal to the value.
|
|
5062
5014
|
*
|
|
@@ -5256,9 +5208,9 @@ module.exports = function () {
|
|
|
5256
5208
|
assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
|
|
5257
5209
|
assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
|
|
5258
5210
|
|
|
5259
|
-
if (a._big.gt(b
|
|
5211
|
+
if (a._big.gt(b)) {
|
|
5260
5212
|
return 1;
|
|
5261
|
-
} else if (a._big.lt(b
|
|
5213
|
+
} else if (a._big.lt(b)) {
|
|
5262
5214
|
return -1;
|
|
5263
5215
|
} else {
|
|
5264
5216
|
return 0;
|
|
@@ -5719,10 +5671,12 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
|
5719
5671
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5720
5672
|
|
|
5721
5673
|
var assert = require('./assert'),
|
|
5674
|
+
is = require('./is'),
|
|
5722
5675
|
memoize = require('./memoize');
|
|
5723
5676
|
|
|
5724
5677
|
var Currency = require('./Currency'),
|
|
5725
|
-
Decimal = require('./Decimal')
|
|
5678
|
+
Decimal = require('./Decimal'),
|
|
5679
|
+
Enum = require('./Enum');
|
|
5726
5680
|
|
|
5727
5681
|
module.exports = function () {
|
|
5728
5682
|
'use strict';
|
|
@@ -5902,7 +5856,12 @@ module.exports = function () {
|
|
|
5902
5856
|
assert.argumentIsRequired(amount, 'amount', Decimal, 'Decimal');
|
|
5903
5857
|
assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
|
|
5904
5858
|
assert.argumentIsRequired(desiredCurrency, 'desiredCurrency', Currency, 'Currency');
|
|
5905
|
-
|
|
5859
|
+
|
|
5860
|
+
for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
5861
|
+
rates[_key - 3] = arguments[_key];
|
|
5862
|
+
}
|
|
5863
|
+
|
|
5864
|
+
assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
|
|
5906
5865
|
|
|
5907
5866
|
var converted = void 0;
|
|
5908
5867
|
|
|
@@ -5912,10 +5871,6 @@ module.exports = function () {
|
|
|
5912
5871
|
var numerator = desiredCurrency;
|
|
5913
5872
|
var denominator = currency;
|
|
5914
5873
|
|
|
5915
|
-
for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
5916
|
-
rates[_key - 3] = arguments[_key];
|
|
5917
|
-
}
|
|
5918
|
-
|
|
5919
5874
|
var rate = rates.find(function (r) {
|
|
5920
5875
|
return r.numerator === numerator && r.denominator === denominator || r.numerator === denominator && r.denominator === numerator;
|
|
5921
5876
|
});
|
|
@@ -5966,7 +5921,7 @@ module.exports = function () {
|
|
|
5966
5921
|
return Rate;
|
|
5967
5922
|
}();
|
|
5968
5923
|
|
|
5969
|
-
},{"./Currency":15,"./Decimal":17,"./assert":22,"./memoize":25}],21:[function(require,module,exports){
|
|
5924
|
+
},{"./Currency":15,"./Decimal":17,"./Enum":19,"./assert":22,"./is":24,"./memoize":25}],21:[function(require,module,exports){
|
|
5970
5925
|
'use strict';
|
|
5971
5926
|
|
|
5972
5927
|
var assert = require('./assert'),
|
|
@@ -6343,26 +6298,6 @@ module.exports = function () {
|
|
|
6343
6298
|
});
|
|
6344
6299
|
|
|
6345
6300
|
return returnRef;
|
|
6346
|
-
},
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
/**
|
|
6350
|
-
* Removes the first item from an array which matches a predicate.
|
|
6351
|
-
*
|
|
6352
|
-
* @static
|
|
6353
|
-
* @public
|
|
6354
|
-
* @param {Array} a
|
|
6355
|
-
* @param {Function} predicate
|
|
6356
|
-
*/
|
|
6357
|
-
remove: function remove(a, predicate) {
|
|
6358
|
-
assert.argumentIsArray(a, 'a');
|
|
6359
|
-
assert.argumentIsRequired(predicate, 'predicate', Function);
|
|
6360
|
-
|
|
6361
|
-
var index = a.findIndex(predicate);
|
|
6362
|
-
|
|
6363
|
-
if (!(index < 0)) {
|
|
6364
|
-
a.splice(index, 1);
|
|
6365
|
-
}
|
|
6366
6301
|
}
|
|
6367
6302
|
};
|
|
6368
6303
|
}();
|