Comparing version 5.1.0 to 5.2.0
@@ -0,1 +1,4 @@ | ||
#### v 5.2.0 (2022-01-05) | ||
* feat: add a boolean "path exists" function, wrapping the "exists" function. Pull request [291](https://github.com/yfinkelstein/node-zookeeper/pull/291) by @davidvujic | ||
#### v 5.1.0 (2021-12-29) | ||
@@ -2,0 +5,0 @@ * feat: build native addon from the ZooKeeper C client v3.6.3. Pull request [289](https://github.com/yfinkelstein/node-zookeeper/pull/289) by @davidvujic |
@@ -7,2 +7,3 @@ const { getClient, constants } = require('./wrapper'); | ||
const { addTask } = require('./addtask'); | ||
const { verifyTheNodeExistsFeature } = require('./exists'); | ||
@@ -42,2 +43,4 @@ const logger = require('./logger'); | ||
await electLeader(client, '/master'); | ||
await verifyTheNodeExistsFeature(client); | ||
}); | ||
@@ -44,0 +47,0 @@ } |
@@ -500,2 +500,9 @@ /// <reference types="node" /> | ||
* @param {string} path | ||
* @param {boolean} watch | ||
* @fulfill {boolean} | ||
* @returns {Promise.<boolean>} | ||
*/ | ||
pathExists(path: string, watch: boolean): Promise<boolean>; | ||
/** | ||
* @param {string} path | ||
* @param {function} watchCb | ||
@@ -508,2 +515,9 @@ * @fulfill {stat} | ||
* @param {string} path | ||
* @param {function} watchCb | ||
* @fulfill {boolean} | ||
* @returns {Promise.<boolean>} | ||
*/ | ||
w_pathExists(path: string, watchCb: Function): Promise<boolean>; | ||
/** | ||
* @param {string} path | ||
* @param {boolean} watch | ||
@@ -510,0 +524,0 @@ * @fulfill {string|Buffer} |
@@ -7,2 +7,10 @@ // needed to not break the interface | ||
function isTruthy(data) { | ||
if (data) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
/** | ||
@@ -52,2 +60,18 @@ * A promisified version of the ZooKeeper class | ||
* @param {string} path | ||
* @param {boolean} watch | ||
* @fulfill {boolean} | ||
* @returns {Promise.<boolean>} | ||
*/ | ||
async pathExists(path, watch) { | ||
try { | ||
const stat = await this.exists(path, watch); | ||
return isTruthy(stat); | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
/** | ||
* @param {string} path | ||
* @param {function} watchCb | ||
@@ -63,2 +87,18 @@ * @fulfill {stat} | ||
* @param {string} path | ||
* @param {function} watchCb | ||
* @fulfill {boolean} | ||
* @returns {Promise.<boolean>} | ||
*/ | ||
async w_pathExists(path, watchCb) { | ||
try { | ||
const stat = await this.w_exists(path, watchCb); | ||
return isTruthy(stat); | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
/** | ||
* @param {string} path | ||
* @param {boolean} watch | ||
@@ -65,0 +105,0 @@ * @fulfill {string|Buffer} |
{ | ||
"name": "zookeeper", | ||
"description": "apache zookeeper client (zookeeper async API v3.4.x - v3.6.x)", | ||
"version": "5.1.0", | ||
"description": "apache zookeeper client (zookeeper async API v3.4.x - v3.7.x)", | ||
"version": "5.2.0", | ||
"author": "Yuri Finkelstein <yurif2003@yahoo.com>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -106,3 +106,4 @@ # node-zookeeper | ||
* `stat = await exists(path, watch)` | ||
* rejects if node does not exist | ||
* rejects if node does not exist. There's also a `pathExists` as an alternative. | ||
* `trueOrFalseValue = await pathExists(path, watch)` | ||
* `data = await get(path, watch)` | ||
@@ -127,3 +128,4 @@ * `children = await get_children(path, watch)` | ||
* `stat = await w_exists(path, watch_cb)` | ||
* rejects if node does not exist | ||
* rejects if node does not exist. There's also a `w_pathExists` as an alternative. | ||
* `trueOrFalseValue = await w_pathExists(path, watch)` | ||
* `data = await w_get(path, watch_cb)` | ||
@@ -130,0 +132,0 @@ * `children = await w_get_children(path, watch_cb)` |
2507559
87
3712
329