block-sequence-mongo
Advanced tools
Comparing version 1.0.2 to 1.1.0
# Change Log | ||
## [1.1.0] | ||
### Changed | ||
- Erroring when sequence exceeds Number.MAX_SAFE_INT | ||
## [1.0.2] | ||
@@ -4,0 +8,0 @@ ### Changed |
35
index.js
@@ -5,5 +5,7 @@ var debug = require('debug')('block-sequence:mongo') | ||
var async = require('async') | ||
var bigInt = require('big-integer') | ||
module.exports = function init(config, cb) { | ||
if (Number.MAX_SAFE_INTEGER === undefined) Number.MAX_SAFE_INTEGER = 9007199254740991 | ||
if (arguments.length === 1) return init({}, arguments[0]) | ||
@@ -31,7 +33,10 @@ if (!config.url) return cb(new Error('url is required')) | ||
if (err) return cb(err) | ||
cb(null, _.chain({}) | ||
.defaultsDeep(result.value) | ||
.omit(['_id']) | ||
.value() | ||
) | ||
deserialize(result.value, function(err, sequence) { | ||
if (err) return cb(err) | ||
cb(null, _.chain({}) | ||
.defaultsDeep(sequence) | ||
.omit(['_id']) | ||
.value() | ||
) | ||
}) | ||
} | ||
@@ -53,8 +58,10 @@ ) | ||
if (err) return cb(err) | ||
var sequence = result.value | ||
cb(null, _.chain({ next: sequence.value - size + 1, remaining: size }) | ||
.defaultsDeep(sequence) | ||
.omit(['_id', 'value']) | ||
.value() | ||
) | ||
deserialize(result.value, function(err, sequence) { | ||
if (err) return cb(err) | ||
cb(null, _.chain({ next: sequence.value - size + 1, remaining: size }) | ||
.defaultsDeep(sequence) | ||
.omit(['_id', 'value']) | ||
.value() | ||
) | ||
}) | ||
} | ||
@@ -71,2 +78,8 @@ ) | ||
function deserialize(sequence, cb) { | ||
var value = bigInt(sequence.value) | ||
if (value.greater(Number.MAX_SAFE_INTEGER)) return cb(new Error('Sequence value exceeds Number.MAX_SAFE_INTEGER')) | ||
cb(null, sequence) | ||
} | ||
function close(cb) { | ||
@@ -73,0 +86,0 @@ db.close(cb) |
{ | ||
"name": "block-sequence-mongo", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "A mongo implementation of block-sequence", | ||
@@ -24,3 +24,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"block-sequence-compliance-tests": "^1.2.0", | ||
"block-sequence-compliance-tests": "^2.0.1", | ||
"codeclimate-test-reporter": "^0.4.0", | ||
@@ -36,2 +36,3 @@ "eslint": "^3.12.2", | ||
"async": "^2.1.4", | ||
"big-integer": "^1.6.17", | ||
"debug": "^2.6.0", | ||
@@ -38,0 +39,0 @@ "lodash": "^4.17.4", |
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
8550
102
6
+ Addedbig-integer@^1.6.17
+ Addedbig-integer@1.6.52(transitive)