@barchart/portfolio-api-common 1.0.269 → 1.2.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.
@@ -23,6 +23,17 @@ module.exports = (() => {
23
23
  return portfolioUpdateFailedNoPortfolio;
24
24
  }
25
25
 
26
+ /**
27
+ * The portfolio does not exist.
28
+ *
29
+ * @public
30
+ * @static
31
+ * @returns {FailureType}
32
+ */
33
+ static get PORTFOLIO_DELETE_FAILED_NO_PORTFOLIO() {
34
+ return portfolioDeleteFailedNoPortfolio;
35
+ }
36
+
26
37
  /**
27
38
  * The portfolio does not exist.
28
39
  *
@@ -136,7 +147,8 @@ module.exports = (() => {
136
147
  }
137
148
  }
138
149
 
139
- const portfolioUpdateFailedNoPortfolio = new FailureType('PORTFOLIO_UPDATED_FAILED_NO_PORTFOLIO', 'Unable to update portfolio. The portfolio does not exist, has it been deleted?');
150
+ const portfolioUpdateFailedNoPortfolio = new FailureType('PORTFOLIO_UPDATE_FAILED_NO_PORTFOLIO', 'Unable to update portfolio. The portfolio does not exist, has it been deleted?');
151
+ const portfolioDeleteFailedNoPortfolio = new FailureType('PORTFOLIO_DELETE_FAILED_NO_PORTFOLIO', 'Unable to delete portfolio. The portfolio does not exist, has it already been deleted?');
140
152
 
141
153
  const positionCreateFailedNoPortfolio = new FailureType('POSITION_CREATE_FAILED_NO_PORTFOLIO', 'Unable to create transaction. The portfolio does not exist, has it been deleted?');
142
154
  const positionUpdateFailedNoPosition = new FailureType('POSITION_UPDATE_FAILED_NO_POSITION', 'Unable to update preferences for position. The position does not exist, has it been deleted?');
@@ -1,5 +1,5 @@
1
1
  const assert = require('@barchart/common-js/lang/assert'),
2
- array = require('@barchart/common-js/lang/array')
2
+ array = require('@barchart/common-js/lang/array');
3
3
 
4
4
  const InstrumentType = require('./InstrumentType'),
5
5
  PositionDirection = require('./PositionDirection'),
@@ -25,22 +25,12 @@ module.exports = (() => {
25
25
  * @public
26
26
  * @static
27
27
  * @param {Array.<Object>} transactions
28
- * @param {Boolean=} partial - If true, sequence validation starts with the array's first transaction.
29
28
  * @return {boolean}
30
29
  */
31
- static validateOrder(transactions, partial) {
30
+ static validateOrder(transactions) {
32
31
  assert.argumentIsArray(transactions, 'transactions');
33
- assert.argumentIsOptional(partial, 'partial', Boolean);
34
32
 
35
- let startSequence;
36
-
37
- if (partial && transactions.length !== 0) {
38
- startSequence = array.first(transactions).sequence;
39
- } else {
40
- startSequence = 1;
41
- }
42
-
43
- return transactions.every((t, i) => t.sequence === (i + startSequence) && (i === 0 || !t.date.getIsBefore(transactions[i - 1].date)));
33
+ return transactions.every((t, i) => t.sequence === (i + 1) && (i === 0 || !t.date.getIsBefore(transactions[i - 1].date)));
44
34
  }
45
35
 
46
36
  /**
@@ -410,7 +410,7 @@ module.exports = (() => {
410
410
  }
411
411
 
412
412
  Object.keys(this._trees).forEach((key) => {
413
- this._trees[key].walk(group => group.setForexRates(this._forexQuotes), true, false)
413
+ this._trees[key].walk(group => group.setForexRates(this._forexQuotes), true, false);
414
414
  });
415
415
 
416
416
  recalculatePercentages.call(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.269",
3
+ "version": "1.2.0",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1,4 +1,4 @@
1
- (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
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'),
@@ -957,7 +957,7 @@ module.exports = (() => {
957
957
 
958
958
  },{"@barchart/common-js/lang/Enum":21,"@barchart/common-js/lang/assert":24}],5:[function(require,module,exports){
959
959
  const assert = require('@barchart/common-js/lang/assert'),
960
- array = require('@barchart/common-js/lang/array')
960
+ array = require('@barchart/common-js/lang/array');
961
961
 
962
962
  const InstrumentType = require('./InstrumentType'),
963
963
  PositionDirection = require('./PositionDirection'),
@@ -983,22 +983,12 @@ module.exports = (() => {
983
983
  * @public
984
984
  * @static
985
985
  * @param {Array.<Object>} transactions
986
- * @param {Boolean=} partial - If true, sequence validation starts with the array's first transaction.
987
986
  * @return {boolean}
988
987
  */
989
- static validateOrder(transactions, partial) {
988
+ static validateOrder(transactions) {
990
989
  assert.argumentIsArray(transactions, 'transactions');
991
- assert.argumentIsOptional(partial, 'partial', Boolean);
992
990
 
993
- let startSequence;
994
-
995
- if (partial && transactions.length !== 0) {
996
- startSequence = array.first(transactions).sequence;
997
- } else {
998
- startSequence = 1;
999
- }
1000
-
1001
- return transactions.every((t, i) => t.sequence === (i + startSequence) && (i === 0 || !t.date.getIsBefore(transactions[i - 1].date)));
991
+ return transactions.every((t, i) => t.sequence === (i + 1) && (i === 0 || !t.date.getIsBefore(transactions[i - 1].date)));
1002
992
  }
1003
993
 
1004
994
  /**
@@ -1566,7 +1556,7 @@ module.exports = (() => {
1566
1556
  }
1567
1557
 
1568
1558
  Object.keys(this._trees).forEach((key) => {
1569
- this._trees[key].walk(group => group.setForexRates(this._forexQuotes), true, false)
1559
+ this._trees[key].walk(group => group.setForexRates(this._forexQuotes), true, false);
1570
1560
  });
1571
1561
 
1572
1562
  recalculatePercentages.call(this);
@@ -3961,31 +3951,14 @@ module.exports = function () {
3961
3951
  }
3962
3952
 
3963
3953
  /**
3964
- * Gets the root node.
3954
+ * Returns the parent node. If this is the root node, a null value is returned.
3965
3955
  *
3966
3956
  * @public
3967
- * @returns {Tree}
3957
+ * @returns {Tree|null}
3968
3958
  */
3969
3959
 
3970
3960
 
3971
3961
  _createClass(Tree, [{
3972
- key: 'getRoot',
3973
- value: function getRoot() {
3974
- if (this.getIsRoot()) {
3975
- return this;
3976
- } else {
3977
- return this._parent.getRoot();
3978
- }
3979
- }
3980
-
3981
- /**
3982
- * Returns the parent node. If this is the root node, a null value is returned.
3983
- *
3984
- * @public
3985
- * @returns {Tree|null}
3986
- */
3987
-
3988
- }, {
3989
3962
  key: 'getParent',
3990
3963
  value: function getParent() {
3991
3964
  return this._parent;
@@ -4086,23 +4059,6 @@ module.exports = function () {
4086
4059
  }
4087
4060
  }
4088
4061
 
4089
- /**
4090
- * Removes the current node from the parent tree. Use on a root node
4091
- * has no effect.
4092
- *
4093
- * @public
4094
- */
4095
-
4096
- }, {
4097
- key: 'sever',
4098
- value: function sever() {
4099
- if (this.getIsRoot()) {
4100
- return;
4101
- }
4102
-
4103
- this.getParent().removeChild(this);
4104
- }
4105
-
4106
4062
  /**
4107
4063
  * Searches the children nodes for the first child node that matches the
4108
4064
  * predicate.
@@ -4207,33 +4163,6 @@ module.exports = function () {
4207
4163
  }
4208
4164
  }
4209
4165
 
4210
- /**
4211
- * Climbs the tree, evaluating each parent until a predicate is matched. Once matched,
4212
- * the {@link Tree} node is returned. Otherwise, if the predicate cannot be matched,
4213
- * a null value is returned.
4214
- *
4215
- * @public
4216
- * @param {Tree~nodePredicate} predicate - A predicate that tests each child node. The predicate takes two arguments -- the node's value, and the node itself.
4217
- * @param {boolean=} includeCurrentNode - If true, the predicate will be applied to the current node.
4218
- * @returns {Tree|null}
4219
- */
4220
-
4221
- }, {
4222
- key: 'findParent',
4223
- value: function findParent(predicate, includeCurrentNode) {
4224
- var returnRef = void 0;
4225
-
4226
- if (is.boolean(includeCurrentNode) && includeCurrentNode && predicate(this.getValue(), this)) {
4227
- returnRef = this;
4228
- } else if (this._parent !== null) {
4229
- returnRef = this._parent.findParent(predicate, true);
4230
- } else {
4231
- returnRef = null;
4232
- }
4233
-
4234
- return returnRef;
4235
- }
4236
-
4237
4166
  /**
4238
4167
  * Creates a representation of the tree using JavaScript objects and arrays.
4239
4168
  *
@@ -5524,20 +5453,6 @@ module.exports = function () {
5524
5453
  return this._big.gt(getBig(other));
5525
5454
  }
5526
5455
 
5527
- /**
5528
- * Returns true if the current instance is greater than or equal to the value.
5529
- *
5530
- * @public
5531
- * @param {Decimal|Number|String} other - The value to compare.
5532
- * @returns {Boolean}
5533
- */
5534
-
5535
- }, {
5536
- key: 'getIsGreaterThanOrEqual',
5537
- value: function getIsGreaterThanOrEqual(other) {
5538
- return this._big.gte(getBig(other));
5539
- }
5540
-
5541
5456
  /**
5542
5457
  * Returns true if the current instance is less than the value.
5543
5458
  *
@@ -5552,20 +5467,6 @@ module.exports = function () {
5552
5467
  return this._big.lt(getBig(other));
5553
5468
  }
5554
5469
 
5555
- /**
5556
- * Returns true if the current instance is less than or equal to the value.
5557
- *
5558
- * @public
5559
- * @param {Decimal|Number|String} other - The value to compare.
5560
- * @returns {Boolean}
5561
- */
5562
-
5563
- }, {
5564
- key: 'getIsLessThanOrEqual',
5565
- value: function getIsLessThanOrEqual(other) {
5566
- return this._big.lte(getBig(other));
5567
- }
5568
-
5569
5470
  /**
5570
5471
  * Returns true if the current instance is equal to the value.
5571
5472
  *
@@ -5765,9 +5666,9 @@ module.exports = function () {
5765
5666
  assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
5766
5667
  assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
5767
5668
 
5768
- if (a._big.gt(b._big)) {
5669
+ if (a._big.gt(b)) {
5769
5670
  return 1;
5770
- } else if (a._big.lt(b._big)) {
5671
+ } else if (a._big.lt(b)) {
5771
5672
  return -1;
5772
5673
  } else {
5773
5674
  return 0;
@@ -6228,10 +6129,12 @@ var _createClass = function () { function defineProperties(target, props) { for
6228
6129
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6229
6130
 
6230
6131
  var assert = require('./assert'),
6132
+ is = require('./is'),
6231
6133
  memoize = require('./memoize');
6232
6134
 
6233
6135
  var Currency = require('./Currency'),
6234
- Decimal = require('./Decimal');
6136
+ Decimal = require('./Decimal'),
6137
+ Enum = require('./Enum');
6235
6138
 
6236
6139
  module.exports = function () {
6237
6140
  'use strict';
@@ -6411,7 +6314,12 @@ module.exports = function () {
6411
6314
  assert.argumentIsRequired(amount, 'amount', Decimal, 'Decimal');
6412
6315
  assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
6413
6316
  assert.argumentIsRequired(desiredCurrency, 'desiredCurrency', Currency, 'Currency');
6414
- //assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
6317
+
6318
+ for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
6319
+ rates[_key - 3] = arguments[_key];
6320
+ }
6321
+
6322
+ assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
6415
6323
 
6416
6324
  var converted = void 0;
6417
6325
 
@@ -6421,10 +6329,6 @@ module.exports = function () {
6421
6329
  var numerator = desiredCurrency;
6422
6330
  var denominator = currency;
6423
6331
 
6424
- for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
6425
- rates[_key - 3] = arguments[_key];
6426
- }
6427
-
6428
6332
  var rate = rates.find(function (r) {
6429
6333
  return r.numerator === numerator && r.denominator === denominator || r.numerator === denominator && r.denominator === numerator;
6430
6334
  });
@@ -6475,7 +6379,7 @@ module.exports = function () {
6475
6379
  return Rate;
6476
6380
  }();
6477
6381
 
6478
- },{"./Currency":17,"./Decimal":19,"./assert":24,"./memoize":27}],23:[function(require,module,exports){
6382
+ },{"./Currency":17,"./Decimal":19,"./Enum":21,"./assert":24,"./is":26,"./memoize":27}],23:[function(require,module,exports){
6479
6383
  'use strict';
6480
6384
 
6481
6385
  var assert = require('./assert'),
@@ -6852,26 +6756,6 @@ module.exports = function () {
6852
6756
  });
6853
6757
 
6854
6758
  return returnRef;
6855
- },
6856
-
6857
-
6858
- /**
6859
- * Removes the first item from an array which matches a predicate.
6860
- *
6861
- * @static
6862
- * @public
6863
- * @param {Array} a
6864
- * @param {Function} predicate
6865
- */
6866
- remove: function remove(a, predicate) {
6867
- assert.argumentIsArray(a, 'a');
6868
- assert.argumentIsRequired(predicate, 'predicate', Function);
6869
-
6870
- var index = a.findIndex(predicate);
6871
-
6872
- if (!(index < 0)) {
6873
- a.splice(index, 1);
6874
- }
6875
6759
  }
6876
6760
  };
6877
6761
  }();
@@ -9103,14 +8987,6 @@ describe('When validating transaction order', () => {
9103
8987
  it('An array of transactions with ordered sequences, on the reversed days should not be valid', () => {
9104
8988
  expect(TransactionValidator.validateOrder([ build(1, '2018-05-02'), build(2, '2018-05-01'), build(3, '2018-04-30') ])).toEqual(false);
9105
8989
  });
9106
-
9107
- it('A partial array of transactions with ordered sequences (starting after one), on the same day should be valid', () => {
9108
- expect(TransactionValidator.validateOrder([ build(3, '2018-04-30'), build(4, '2018-04-30'), build(5, '2018-04-30') ], true)).toEqual(true);
9109
- });
9110
-
9111
- it('A partial array of transactions with gap in sequences (starting after one), on the same day should be not valid', () => {
9112
- expect(TransactionValidator.validateOrder([ build(3, '2018-04-30'), build(5, '2018-04-30'), build(6, '2018-04-30') ], true)).toEqual(false);
9113
- });
9114
8990
  });
9115
8991
 
9116
8992
  },{"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":18}],37:[function(require,module,exports){
@@ -40,12 +40,4 @@ describe('When validating transaction order', () => {
40
40
  it('An array of transactions with ordered sequences, on the reversed days should not be valid', () => {
41
41
  expect(TransactionValidator.validateOrder([ build(1, '2018-05-02'), build(2, '2018-05-01'), build(3, '2018-04-30') ])).toEqual(false);
42
42
  });
43
-
44
- it('A partial array of transactions with ordered sequences (starting after one), on the same day should be valid', () => {
45
- expect(TransactionValidator.validateOrder([ build(3, '2018-04-30'), build(4, '2018-04-30'), build(5, '2018-04-30') ], true)).toEqual(true);
46
- });
47
-
48
- it('A partial array of transactions with gap in sequences (starting after one), on the same day should be not valid', () => {
49
- expect(TransactionValidator.validateOrder([ build(3, '2018-04-30'), build(5, '2018-04-30'), build(6, '2018-04-30') ], true)).toEqual(false);
50
- });
51
43
  });