Comparing version 1.1.0 to 1.2.0
@@ -151,2 +151,17 @@ "use strict"; | ||
/** | ||
* Return BigInt or undefined if parse failed. | ||
*/ | ||
function safeBigInt(value) { | ||
if (value === undefined || value === null || value === "") { | ||
return undefined; | ||
} | ||
try { | ||
return BigInt(value); | ||
} catch (err) { | ||
return undefined; | ||
} | ||
} | ||
/** | ||
* Common options | ||
@@ -560,5 +575,5 @@ */ | ||
function hasIndexChanged(index, prevIndex) { | ||
if (typeof index !== "string" || !index) return false; | ||
if (typeof prevIndex !== "string" || !prevIndex) return true; | ||
return index !== prevIndex; | ||
if (typeof index !== "bigint" || index <= 0) return false; | ||
if (typeof prevIndex !== "bigint") return true; | ||
return index > prevIndex; | ||
} | ||
@@ -604,2 +619,3 @@ | ||
exports.parseDuration = parseDuration; | ||
exports.safeBigInt = safeBigInt; | ||
exports.setTimeoutContext = setTimeoutContext; | ||
@@ -606,0 +622,0 @@ exports.createServiceCheck = createServiceCheck; |
@@ -21,3 +21,3 @@ const events = require("events"); | ||
options.wait = options.wait || "30s"; | ||
options.index = options.index || "0"; | ||
options.index = utils.safeBigInt(options.index || "0"); | ||
@@ -154,11 +154,19 @@ if ( | ||
const newIndex = res.headers["x-consul-index"]; | ||
const newIndex = utils.safeBigInt(res.headers["x-consul-index"]); | ||
if (newIndex === undefined) { | ||
return this._err(errors.Validation("Watch not supported"), res); | ||
} | ||
if (newIndex === 0n) { | ||
return this._err( | ||
errors.Consul("Consul returned zero index value"), | ||
res | ||
); | ||
} | ||
if (utils.hasIndexChanged(newIndex, this._options.index)) { | ||
this._options.index = newIndex; | ||
const prevIndex = this._options.index; | ||
const reset = prevIndex !== undefined && newIndex < prevIndex; | ||
if (reset || utils.hasIndexChanged(newIndex, prevIndex)) { | ||
this._options.index = reset ? 0n : newIndex; | ||
this.emit("change", data, res); | ||
@@ -165,0 +173,0 @@ } |
{ | ||
"name": "consul", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Consul client", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
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
107814
2234