@barchart/portfolio-api-common 1.3.22 → 1.3.23
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/.jshintrc +2 -1
- package/README.md +2 -0
- package/buildspec.yml +15 -0
- package/gulpfile.js +20 -30
- package/lib/data/TransactionValidator.js +5 -5
- package/lib/serialization/TransactionSchema.js +2 -2
- package/package.json +2 -3
- package/test/SpecRunner.js +13 -11
- package/test/specs/data/TransactionValidatorSpec.js +4 -4
package/.jshintrc
CHANGED
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @barchart/portfolio-api-common
|
|
2
2
|
|
|
3
|
+
[](https://github.com/barchart/portfolio-api-common)
|
|
4
|
+
|
|
3
5
|
A *private* library of shared JavaScript code pertaining to the paper-trading portfolio system.
|
|
4
6
|
|
|
5
7
|
### Overview
|
package/buildspec.yml
ADDED
package/gulpfile.js
CHANGED
|
@@ -5,7 +5,6 @@ const fs = require('fs');
|
|
|
5
5
|
const browserify = require('browserify'),
|
|
6
6
|
buffer = require('vinyl-buffer'),
|
|
7
7
|
bump = require('gulp-bump'),
|
|
8
|
-
exec = require('child_process').exec,
|
|
9
8
|
git = require('gulp-git'),
|
|
10
9
|
gitStatus = require('git-get-status'),
|
|
11
10
|
glob = require('glob'),
|
|
@@ -14,7 +13,7 @@ const browserify = require('browserify'),
|
|
|
14
13
|
source = require('vinyl-source-stream');
|
|
15
14
|
|
|
16
15
|
function getVersionFromPackage() {
|
|
17
|
-
|
|
16
|
+
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
gulp.task('ensure-clean-working-directory', (cb) => {
|
|
@@ -33,35 +32,26 @@ gulp.task('bump-version', () => {
|
|
|
33
32
|
.pipe(gulp.dest('./'));
|
|
34
33
|
});
|
|
35
34
|
|
|
36
|
-
gulp.task('document', (cb) => {
|
|
37
|
-
exec('jsdoc . -c jsdoc.json -r -d docs', (error, stdout, stderr) => {
|
|
38
|
-
console.log(stdout);
|
|
39
|
-
console.log(stderr);
|
|
40
|
-
|
|
41
|
-
cb();
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
35
|
gulp.task('commit-changes', () => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
return gulp.src([ './', './test/', './package.json' ])
|
|
37
|
+
.pipe(git.add())
|
|
38
|
+
.pipe(git.commit('Release. Bump version number'));
|
|
49
39
|
});
|
|
50
40
|
|
|
51
41
|
gulp.task('push-changes', (cb) => {
|
|
52
|
-
|
|
42
|
+
git.push('origin', 'master', cb);
|
|
53
43
|
});
|
|
54
44
|
|
|
55
45
|
gulp.task('create-tag', (cb) => {
|
|
56
|
-
|
|
46
|
+
const version = getVersionFromPackage();
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
git.tag(version, 'Release ' + version, (error) => {
|
|
49
|
+
if (error) {
|
|
50
|
+
return cb(error);
|
|
51
|
+
}
|
|
62
52
|
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
git.push('origin', 'master', { args: '--tags' }, cb);
|
|
54
|
+
});
|
|
65
55
|
});
|
|
66
56
|
|
|
67
57
|
gulp.task('build-test-bundle', () => {
|
|
@@ -73,13 +63,13 @@ gulp.task('build-test-bundle', () => {
|
|
|
73
63
|
});
|
|
74
64
|
|
|
75
65
|
gulp.task('execute-browser-tests', () => {
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
return gulp.src('test/SpecRunner.js')
|
|
67
|
+
.pipe(jasmine());
|
|
78
68
|
});
|
|
79
69
|
|
|
80
70
|
gulp.task('execute-node-tests', () => {
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
return gulp.src(['test/specs/**/*.js'])
|
|
72
|
+
.pipe(jasmine());
|
|
83
73
|
});
|
|
84
74
|
|
|
85
75
|
gulp.task('execute-tests', gulp.series(
|
|
@@ -91,7 +81,6 @@ gulp.task('execute-tests', gulp.series(
|
|
|
91
81
|
gulp.task('release', gulp.series(
|
|
92
82
|
'ensure-clean-working-directory',
|
|
93
83
|
'execute-tests',
|
|
94
|
-
'document',
|
|
95
84
|
'bump-version',
|
|
96
85
|
'commit-changes',
|
|
97
86
|
'push-changes',
|
|
@@ -99,9 +88,10 @@ gulp.task('release', gulp.series(
|
|
|
99
88
|
));
|
|
100
89
|
|
|
101
90
|
gulp.task('lint', () => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
return gulp.src([ './**/*.js', './test/specs/**/*.js', '!./node_modules/**', '!./docs/**', '!./test/SpecRunner.js' ])
|
|
92
|
+
.pipe(jshint({'esversion': 6}))
|
|
93
|
+
.pipe(jshint.reporter('default'))
|
|
94
|
+
.pipe(jshint.reporter('fail'));
|
|
105
95
|
});
|
|
106
96
|
|
|
107
97
|
gulp.task('test', gulp.series('execute-tests'));
|
|
@@ -70,20 +70,20 @@ module.exports = (() => {
|
|
|
70
70
|
return transactions.every((t) => {
|
|
71
71
|
let valid = true;
|
|
72
72
|
|
|
73
|
-
if (is.object(t.reference) && is.string(t.reference.root) && is.
|
|
73
|
+
if (is.object(t.reference) && is.string(t.reference.root) && is.string(t.reference.transaction)) {
|
|
74
74
|
const root = t.reference.root;
|
|
75
|
-
const
|
|
75
|
+
const transaction = t.reference.transaction;
|
|
76
76
|
|
|
77
77
|
if (!references.hasOwnProperty(root)) {
|
|
78
78
|
references[root] = [ ];
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const
|
|
81
|
+
const transactions = references[root];
|
|
82
82
|
|
|
83
|
-
if (
|
|
83
|
+
if (transactions.some(t => t === transaction)) {
|
|
84
84
|
valid = false;
|
|
85
85
|
} else {
|
|
86
|
-
|
|
86
|
+
transactions.push(transaction);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -138,7 +138,7 @@ module.exports = (() => {
|
|
|
138
138
|
.withField('quantity', DataType.DECIMAL)
|
|
139
139
|
.withField('fee', DataType.DECIMAL, true)
|
|
140
140
|
.withField('reference.position', DataType.STRING, true)
|
|
141
|
-
.withField('reference.
|
|
141
|
+
.withField('reference.transaction', DataType.STRING, true)
|
|
142
142
|
.withField('snapshot.open', DataType.DECIMAL)
|
|
143
143
|
.withField('snapshot.direction', DataType.forEnum(PositionDirection, 'PositionDirection'))
|
|
144
144
|
.withField('snapshot.buys', DataType.DECIMAL)
|
|
@@ -187,7 +187,7 @@ module.exports = (() => {
|
|
|
187
187
|
.withField('quantity', DataType.DECIMAL)
|
|
188
188
|
.withField('fee', DataType.DECIMAL, true)
|
|
189
189
|
.withField('reference.position', DataType.STRING, true)
|
|
190
|
-
.withField('reference.
|
|
190
|
+
.withField('reference.transaction', DataType.NUMBER, true)
|
|
191
191
|
.withField('snapshot.open', DataType.DECIMAL)
|
|
192
192
|
.withField('snapshot.direction', DataType.forEnum(PositionDirection, 'PositionDirection'))
|
|
193
193
|
.withField('snapshot.buys', DataType.DECIMAL)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barchart/portfolio-api-common",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "Common
|
|
3
|
+
"version": "1.3.23",
|
|
4
|
+
"description": "Common code used by the Portfolio system",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bryan Ingle",
|
|
7
7
|
"email": "bryan.ingle@barchart.com",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"gulp-bump": "~1.0.0",
|
|
23
23
|
"gulp-git": "^2.9.0",
|
|
24
24
|
"gulp-jasmine": "^2.2.1",
|
|
25
|
-
"gulp-jsdoc3": "^1.0.1",
|
|
26
25
|
"gulp-jshint": "~2.1.0",
|
|
27
26
|
"jsdoc": "^3.5.5",
|
|
28
27
|
"jshint": "2.9.5",
|
package/test/SpecRunner.js
CHANGED
|
@@ -1357,20 +1357,20 @@ module.exports = (() => {
|
|
|
1357
1357
|
return transactions.every((t) => {
|
|
1358
1358
|
let valid = true;
|
|
1359
1359
|
|
|
1360
|
-
if (is.object(t.reference) && is.string(t.reference.root) && is.
|
|
1360
|
+
if (is.object(t.reference) && is.string(t.reference.root) && is.string(t.reference.transaction)) {
|
|
1361
1361
|
const root = t.reference.root;
|
|
1362
|
-
const
|
|
1362
|
+
const transaction = t.reference.transaction;
|
|
1363
1363
|
|
|
1364
1364
|
if (!references.hasOwnProperty(root)) {
|
|
1365
1365
|
references[root] = [ ];
|
|
1366
1366
|
}
|
|
1367
1367
|
|
|
1368
|
-
const
|
|
1368
|
+
const transactions = references[root];
|
|
1369
1369
|
|
|
1370
|
-
if (
|
|
1370
|
+
if (transactions.some(t => t === transaction)) {
|
|
1371
1371
|
valid = false;
|
|
1372
1372
|
} else {
|
|
1373
|
-
|
|
1373
|
+
transactions.push(transaction);
|
|
1374
1374
|
}
|
|
1375
1375
|
}
|
|
1376
1376
|
|
|
@@ -4988,7 +4988,7 @@ module.exports = (() => {
|
|
|
4988
4988
|
.withField('quantity', DataType.DECIMAL)
|
|
4989
4989
|
.withField('fee', DataType.DECIMAL, true)
|
|
4990
4990
|
.withField('reference.position', DataType.STRING, true)
|
|
4991
|
-
.withField('reference.
|
|
4991
|
+
.withField('reference.transaction', DataType.STRING, true)
|
|
4992
4992
|
.withField('snapshot.open', DataType.DECIMAL)
|
|
4993
4993
|
.withField('snapshot.direction', DataType.forEnum(PositionDirection, 'PositionDirection'))
|
|
4994
4994
|
.withField('snapshot.buys', DataType.DECIMAL)
|
|
@@ -5037,7 +5037,7 @@ module.exports = (() => {
|
|
|
5037
5037
|
.withField('quantity', DataType.DECIMAL)
|
|
5038
5038
|
.withField('fee', DataType.DECIMAL, true)
|
|
5039
5039
|
.withField('reference.position', DataType.STRING, true)
|
|
5040
|
-
.withField('reference.
|
|
5040
|
+
.withField('reference.transaction', DataType.NUMBER, true)
|
|
5041
5041
|
.withField('snapshot.open', DataType.DECIMAL)
|
|
5042
5042
|
.withField('snapshot.direction', DataType.forEnum(PositionDirection, 'PositionDirection'))
|
|
5043
5043
|
.withField('snapshot.buys', DataType.DECIMAL)
|
|
@@ -7488,6 +7488,7 @@ module.exports = (() => {
|
|
|
7488
7488
|
* item's value. If no matching item can be found, a null value is returned.
|
|
7489
7489
|
*
|
|
7490
7490
|
* @public
|
|
7491
|
+
* @static
|
|
7491
7492
|
* @param {Function} type - The enumeration type.
|
|
7492
7493
|
* @param {String} code - The enumeration item's code.
|
|
7493
7494
|
* @returns {*|null}
|
|
@@ -7501,6 +7502,7 @@ module.exports = (() => {
|
|
|
7501
7502
|
* Returns all of the enumeration's items (given an enumeration type).
|
|
7502
7503
|
*
|
|
7503
7504
|
* @public
|
|
7505
|
+
* @static
|
|
7504
7506
|
* @param {Function} type - The enumeration to list.
|
|
7505
7507
|
* @returns {Array}
|
|
7506
7508
|
*/
|
|
@@ -17842,8 +17844,8 @@ describe('When validating transaction order', () => {
|
|
|
17842
17844
|
describe('When validating transaction references', () => {
|
|
17843
17845
|
'use strict';
|
|
17844
17846
|
|
|
17845
|
-
const build = (root,
|
|
17846
|
-
return { reference: { root: root,
|
|
17847
|
+
const build = (root, transaction) => {
|
|
17848
|
+
return { reference: { root: root, transaction: transaction } };
|
|
17847
17849
|
};
|
|
17848
17850
|
|
|
17849
17851
|
it('An array of zero transactions should be valid', () => {
|
|
@@ -17855,11 +17857,11 @@ describe('When validating transaction references', () => {
|
|
|
17855
17857
|
});
|
|
17856
17858
|
|
|
17857
17859
|
it('An array with distinct references should be valid', () => {
|
|
17858
|
-
expect(TransactionValidator.validateReferences([ build('a',
|
|
17860
|
+
expect(TransactionValidator.validateReferences([ build('a', 'x'), build('a', 'y'), build('b', 'y') ])).toEqual(true);
|
|
17859
17861
|
});
|
|
17860
17862
|
|
|
17861
17863
|
it('An array with non-distinct references should be not valid', () => {
|
|
17862
|
-
expect(TransactionValidator.validateReferences([ build('a',
|
|
17864
|
+
expect(TransactionValidator.validateReferences([ build('a', 'x'), build('a', 'y'), build('b', 'x'), build('a', 'y') ])).toEqual(false);
|
|
17863
17865
|
});
|
|
17864
17866
|
});
|
|
17865
17867
|
|
|
@@ -58,8 +58,8 @@ describe('When validating transaction order', () => {
|
|
|
58
58
|
describe('When validating transaction references', () => {
|
|
59
59
|
'use strict';
|
|
60
60
|
|
|
61
|
-
const build = (root,
|
|
62
|
-
return { reference: { root: root,
|
|
61
|
+
const build = (root, transaction) => {
|
|
62
|
+
return { reference: { root: root, transaction: transaction } };
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
it('An array of zero transactions should be valid', () => {
|
|
@@ -71,11 +71,11 @@ describe('When validating transaction references', () => {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it('An array with distinct references should be valid', () => {
|
|
74
|
-
expect(TransactionValidator.validateReferences([ build('a',
|
|
74
|
+
expect(TransactionValidator.validateReferences([ build('a', 'x'), build('a', 'y'), build('b', 'y') ])).toEqual(true);
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
it('An array with non-distinct references should be not valid', () => {
|
|
78
|
-
expect(TransactionValidator.validateReferences([ build('a',
|
|
78
|
+
expect(TransactionValidator.validateReferences([ build('a', 'x'), build('a', 'y'), build('b', 'x'), build('a', 'y') ])).toEqual(false);
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
81
|
|