bfx-api-node-models
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -43,2 +43,3 @@ # Bitfinex Data Models for Node.JS | ||
* {@link PublicTrade} | ||
* {@link PulseMessage} | ||
* {@link StatusMessagesDeriv} | ||
@@ -45,0 +46,0 @@ * {@link Trade} |
@@ -6,2 +6,4 @@ 'use strict' | ||
const _isArray = require('lodash/isArray') | ||
const _isString = require('lodash/isString') | ||
const _isEmpty = require('lodash/isEmpty') | ||
const numberValidator = require('./validators/number') | ||
@@ -13,6 +15,26 @@ const dateValidator = require('./validators/date') | ||
const pulseMessageValidator = { | ||
id: stringValidator, | ||
mts: dateValidator, | ||
userID: stringValidator, | ||
title: stringValidator, | ||
content: stringValidator, | ||
isPin: numberValidator, | ||
isPublic: numberValidator, | ||
tags: stringValidator, | ||
attachments: stringValidator, | ||
likes: numberValidator, | ||
userLiked: numberValidator, | ||
comments: numberValidator | ||
} | ||
const pulseCommentValidator = { | ||
...pulseMessageValidator, | ||
parent: stringValidator | ||
} | ||
const fields = { | ||
id: 0, | ||
mts: 1, | ||
// placeholder | ||
parent: 2, | ||
userID: 3, | ||
@@ -33,3 +55,4 @@ // placeholder | ||
// placeholder | ||
pulseProfile: 18 | ||
pulseProfile: 18, | ||
comments: 19 | ||
} | ||
@@ -45,2 +68,3 @@ | ||
* @param {number} data.mts - millisecond timestamp | ||
* @param {string} data.parent - parent pulse message id | ||
* @param {string} data.userID - pulse User ID | ||
@@ -55,2 +79,3 @@ * @param {string} data.title - title of the pulse message | ||
* @param {number} data.userLiked - flag to show if the private user liked the pulse | ||
* @param {number} data.comments - number of comments | ||
*/ | ||
@@ -96,3 +121,3 @@ constructor (data = {}) { | ||
const { | ||
id, mts, userID, title, content, isPin, isPublic, tags, attachments, likes, userLiked | ||
id, mts, parent, userID, title, content, isPin, isPublic, tags, attachments, likes, userLiked, comments | ||
} = this | ||
@@ -103,2 +128,3 @@ | ||
new Date(mts).toLocaleString(), | ||
parent, | ||
userID, | ||
@@ -112,3 +138,4 @@ title, | ||
likes && `likes(${likes})`, | ||
userLiked | ||
userLiked, | ||
comments && `comments(${comments})` | ||
])).join(' ') | ||
@@ -127,15 +154,3 @@ } | ||
fields, | ||
validators: { | ||
id: stringValidator, | ||
mts: dateValidator, | ||
userID: stringValidator, | ||
title: stringValidator, | ||
content: stringValidator, | ||
isPin: numberValidator, | ||
isPublic: numberValidator, | ||
tags: stringValidator, | ||
attachments: stringValidator, | ||
likes: numberValidator, | ||
userLiked: numberValidator | ||
} | ||
validators: !_isEmpty(data.parent) && _isString(data.parent) ? pulseCommentValidator : pulseMessageValidator | ||
}) | ||
@@ -142,0 +157,0 @@ } |
{ | ||
"name": "bfx-api-node-models", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Object models for usage with the Bitfinex node API", | ||
@@ -36,3 +36,4 @@ "engines": { | ||
"Paolo Ardoino <paolo@bitfinex.com> (https://www.bitfinex.com)", | ||
"Vigan Abdurrahmani <vigan.abdurrahmani@bitfinex.com> (https://www.bitfinex.com)" | ||
"Vigan Abdurrahmani <vigan.abdurrahmani@bitfinex.com> (https://www.bitfinex.com)", | ||
"Abhishek Shrestha <abhishek.shrestha@bitfinex.com> (https://www.bitfinex.com)" | ||
], | ||
@@ -39,0 +40,0 @@ "license": "MIT", |
@@ -37,2 +37,3 @@ # Bitfinex Data Models for Node.JS | ||
* PublicTrade | ||
* PulseMessage | ||
* StatusMessagesDeriv | ||
@@ -39,0 +40,0 @@ * Trade |
@@ -33,3 +33,4 @@ /* eslint-env mocha */ | ||
null, | ||
'pulseProfile' | ||
'pulseProfile', | ||
'comments' | ||
] | ||
@@ -51,3 +52,4 @@ }) | ||
likes: new Array(...(new Array(5))).map(() => Math.random()), | ||
userLiked: new Array(...(new Array(5))).map(() => Math.random()) | ||
userLiked: new Array(...(new Array(5))).map(() => Math.random()), | ||
comments: new Array(...(new Array(5))).map(() => Math.random()) | ||
} | ||
@@ -87,3 +89,4 @@ }) | ||
'qux' | ||
] | ||
], | ||
3 | ||
]) | ||
@@ -114,2 +117,3 @@ | ||
]) | ||
assert.strictEqual(pm.comments, 3) | ||
}) | ||
@@ -148,3 +152,4 @@ | ||
'qux' | ||
] | ||
], | ||
3 | ||
]) | ||
@@ -174,3 +179,4 @@ | ||
'qux' | ||
] | ||
], | ||
3 | ||
]) | ||
@@ -210,3 +216,4 @@ }) | ||
'qux' | ||
] | ||
], | ||
3 | ||
]) | ||
@@ -233,2 +240,3 @@ | ||
}) | ||
assert.strictEqual(obj.comments, 3) | ||
}) | ||
@@ -249,3 +257,4 @@ | ||
likes: 1, | ||
userLiked: 1 | ||
userLiked: 1, | ||
comments: 3 | ||
}) | ||
@@ -263,4 +272,268 @@ | ||
assert.ok(_includes(str, 'likes(1)'), 'likes missing') | ||
assert.ok(_includes(str, 'comments(3)'), 'comments missing') | ||
}) | ||
}) | ||
}) | ||
describe('Pulse Comment model', () => { | ||
testModel({ | ||
model: PulseMessage, | ||
orderedFields: [ | ||
'id', | ||
'mts', | ||
'parent', | ||
'userID', | ||
null, | ||
'title', | ||
'content', | ||
null, | ||
null, | ||
'isPin', | ||
'isPublic', | ||
null, | ||
'tags', | ||
'attachments', | ||
null, | ||
'likes', | ||
'userLiked', | ||
null, | ||
'pulseProfile', | ||
'comments' | ||
] | ||
}) | ||
testModelValidation({ | ||
model: PulseMessage, | ||
validData: { | ||
id: 'foo', | ||
mts: new Array(...(new Array(5))).map(() => Math.random()), | ||
parent: 'parent', | ||
userID: ['foo', 'bar', 'baz', 'qux'], | ||
title: ['foo', 'bar', 'baz', 'qux'], | ||
content: ['foo', 'bar', 'baz', 'qux'], | ||
isPin: new Array(...(new Array(5))).map(() => Math.random()), | ||
isPublic: new Array(...(new Array(5))).map(() => Math.random()), | ||
tags: ['hash', 'tag'], | ||
attachments: ['foo', 'bar', 'baz', 'qux'], | ||
likes: new Array(...(new Array(5))).map(() => Math.random()), | ||
userLiked: new Array(...(new Array(5))).map(() => Math.random()), | ||
comments: new Array(...(new Array(5))).map(() => Math.random()) | ||
} | ||
}) | ||
it('initializes correctly', () => { | ||
const pm = new PulseMessage([ | ||
'foo', | ||
12345, | ||
'parent', | ||
'bar', | ||
null, | ||
'title', | ||
'content', | ||
null, | ||
null, | ||
1, | ||
0, | ||
null, | ||
['#hash', '#tag'], | ||
['foo', 'bar'], | ||
null, | ||
1, | ||
2, | ||
null, | ||
[ | ||
'foo', | ||
12345, | ||
null, | ||
'foo', | ||
null, | ||
'bar.jpg', | ||
'baz', | ||
null, | ||
null, | ||
'qux' | ||
], | ||
0 | ||
]) | ||
assert.strictEqual(pm.id, 'foo') | ||
assert.strictEqual(pm.mts, 12345) | ||
assert.strictEqual(pm.parent, 'parent') | ||
assert.strictEqual(pm.userID, 'bar') | ||
assert.strictEqual(pm.title, 'title') | ||
assert.strictEqual(pm.content, 'content') | ||
assert.strictEqual(pm.isPin, 1) | ||
assert.strictEqual(pm.isPublic, 0) | ||
assert.deepEqual(pm.tags, ['#hash', '#tag']) | ||
assert.deepEqual(pm.attachments, ['foo', 'bar']) | ||
assert.strictEqual(pm.likes, 1) | ||
assert.strictEqual(pm.userLiked, 2) | ||
assert.deepEqual(pm.pulseProfile, [ | ||
'foo', | ||
12345, | ||
null, | ||
'foo', | ||
null, | ||
'bar.jpg', | ||
'baz', | ||
null, | ||
null, | ||
'qux' | ||
]) | ||
assert.strictEqual(pm.comments, 0) | ||
}) | ||
it('serializes correctly', () => { | ||
const pm = new PulseMessage([ | ||
'foo', | ||
12345, | ||
'parent', | ||
'bar', | ||
null, | ||
'title', | ||
'content', | ||
null, | ||
null, | ||
1, | ||
1, | ||
null, | ||
['#hash', '#tag'], | ||
['foo', 'bar'], | ||
null, | ||
1, | ||
2, | ||
null, | ||
[ | ||
'foo', | ||
12345, | ||
null, | ||
'foo', | ||
null, | ||
'bar.jpg', | ||
'baz', | ||
null, | ||
null, | ||
'qux' | ||
], | ||
3 | ||
]) | ||
const arr = pm.serialize() | ||
arr[pm._fields.pulseProfile] = _compact(arr[pm._fields.pulseProfile]) | ||
assert.deepStrictEqual(_compact(arr), [ | ||
'foo', | ||
12345, | ||
'parent', | ||
'bar', | ||
'title', | ||
'content', | ||
1, | ||
1, | ||
['#hash', '#tag'], | ||
['foo', 'bar'], | ||
1, | ||
2, | ||
[ | ||
'foo', | ||
12345, | ||
'foo', | ||
'bar.jpg', | ||
'baz', | ||
'qux' | ||
], | ||
3 | ||
]) | ||
}) | ||
it('unserializes correctly', () => { | ||
const obj = PulseMessage.unserialize([ | ||
'foo', | ||
12345, | ||
'parent', | ||
'bar', | ||
null, | ||
'title', | ||
'content', | ||
null, | ||
null, | ||
1, | ||
1, | ||
null, | ||
['#hash', '#tag'], | ||
['foo', 'bar'], | ||
null, | ||
1, | ||
2, | ||
null, | ||
[ | ||
'foo', | ||
12345, | ||
null, | ||
'foo', | ||
null, | ||
'bar.jpg', | ||
'baz', | ||
null, | ||
null, | ||
'qux' | ||
], | ||
0 | ||
]) | ||
assert.strictEqual(obj.id, 'foo') | ||
assert.strictEqual(obj.mts, 12345) | ||
assert.strictEqual(obj.parent, 'parent') | ||
assert.strictEqual(obj.userID, 'bar') | ||
assert.strictEqual(obj.title, 'title') | ||
assert.strictEqual(obj.content, 'content') | ||
assert.strictEqual(obj.isPin, 1) | ||
assert.strictEqual(obj.isPublic, 1) | ||
assert.deepEqual(obj.tags, ['#hash', '#tag']) | ||
assert.deepEqual(obj.attachments, ['foo', 'bar']) | ||
assert.strictEqual(obj.likes, 1) | ||
assert.strictEqual(obj.userLiked, 2) | ||
assert.deepEqual(obj.pulseProfile, { | ||
id: 'foo', | ||
mtsCreate: 12345, | ||
nickname: 'foo', | ||
picture: 'bar.jpg', | ||
text: 'baz', | ||
twitterHandle: 'qux' | ||
}) | ||
assert.strictEqual(obj.comments, 0) | ||
}) | ||
describe('toString', () => { | ||
it('includes pertinent information', () => { | ||
const pm = new PulseMessage({ | ||
id: 'foo777', | ||
mts: 12345, | ||
parent: 'parent', | ||
userID: 'bar888', | ||
title: 'title', | ||
content: 'content', | ||
isPin: 1, | ||
isPublic: 0, | ||
tags: ['#hash', '#tag'], | ||
attachments: ['foo', 'bar'], | ||
likes: 1, | ||
userLiked: 1, | ||
comments: 3 | ||
}) | ||
const str = pm.toString() | ||
assert.ok(_includes(str, '(foo777)'), 'id missing') | ||
assert.ok(_includes(str, 'bar888'), 'userID missing') | ||
assert.ok(_includes(str, 'parent'), 'parent missing') | ||
assert.ok(_includes(str, 'title'), 'title missing') | ||
assert.ok(_includes(str, 'pinned'), 'pinned missing') | ||
assert.ok(_includes(str, 'not public'), 'not public missing') | ||
assert.ok(_includes(str, 'content'), 'content missing') | ||
assert.ok(_includes(str, '#hash #tag'), 'hash tags missing') | ||
assert.ok(_includes(str, 'foo bar'), 'attachments missing') | ||
assert.ok(_includes(str, 'likes(1)'), 'likes missing') | ||
assert.ok(_includes(str, 'comments(3)'), 'comments missing') | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3405288
9340
154
13