diff --git a/README.md b/README.md index 2a20fdbe..3f2245a2 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Have a look at the code in the [examples](./examples) folder: with __master__, _ * `init(options)` * `connect(options, connect_cb)` * `close()` -* `path = await create(path, data, flags)` +* `path = await create(path, data, flags, ttl)` * `mkdirp(path, callback(Error))` * `stat = await exists(path, watch)` * `data = await get(path, watch)` @@ -126,6 +126,7 @@ Have a look at the code in the [examples](./examples) folder: with __master__, _ * `connect(options, connect_cb)` * `close()` * `a_create(path, data, flags, path_cb)` +* `a_createTtl(path, data, flags, path_cb)` * `mkdirp(path, callback(Error))` * `a_exists(path, watch, stat_cb)` * `a_get(path, watch, data_cb)` @@ -164,9 +165,17 @@ Have a look at the code in the [examples](./examples) folder: with __master__, _ * options : object. valid keys: { connect, timeout, debug_level, host_order_deterministic, data_as_buffer} * path : string * data : string or Buffer -* flags : int32 -* version : int32 +* flags : int32. Supported: + - `ZOO_PERSISTENT` + - `ZOO_EPHEMERAL` + - `ZOO_PERSISTENT_SEQUENTIAL` + - `ZOO_EPHEMERAL_SEQUENTIAL` + - `ZOO_CONTAINER` + - `ZOO_PERSISTENT_WITH_TTL` + - `ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL` +* version : int32. Pass 'null' or don't pas any to skip version checking. * watch : boolean +* ttl: int32. Must be postive if any of the TTL modes is used; not positive or unspecified otherwise. * scheme : authorisation scheme (digest, auth) * auth : authorisation credentials (username:password) * acl : acls list (same as output parameter, look below) - read only diff --git a/lib/constants.js b/lib/constants.js index 8463767e..9489e0bf 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -46,12 +46,30 @@ module.exports.ZOO_LOG_LEVEL_INFO = NativeZk.ZOO_LOG_LEVEL_INFO; /** @type {number} 4 */ module.exports.ZOO_LOG_LEVEL_DEBUG = NativeZk.ZOO_LOG_LEVEL_DEBUG; +/** @type {number} 0 */ +module.exports.ZOO_PERSISTENT = NativeZk.ZOO_PERSISTENT; + /** @type {number} 1 */ module.exports.ZOO_EPHEMERAL = NativeZk.ZOO_EPHEMERAL; /** @type {number} 2 */ module.exports.ZOO_SEQUENCE = NativeZk.ZOO_SEQUENCE; +/** @type {number} 2 */ +module.exports.ZOO_PERSISTENT_SEQUENTIAL = NativeZk.ZOO_PERSISTENT_SEQUENTIAL; + +/** @type {number} 3 */ +module.exports.ZOO_EPHEMERAL_SEQUENTIAL = NativeZk.ZOO_EPHEMERAL_SEQUENTIAL; + +/** @type {number} 4 */ +module.exports.ZOO_CONTAINER = NativeZk.ZOO_CONTAINER; + +/** @type {number} 5 */ +module.exports.ZOO_PERSISTENT_WITH_TTL = NativeZk.ZOO_PERSISTENT_WITH_TTL; + +/** @type {number} 6 */ +module.exports.ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL = NativeZk.ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL; + /** @type {number} 0 */ module.exports.ZOK = NativeZk.ZOK; diff --git a/lib/typedeclarations.d.ts b/lib/typedeclarations.d.ts index a70c6eaf..148e0ce0 100644 --- a/lib/typedeclarations.d.ts +++ b/lib/typedeclarations.d.ts @@ -357,8 +357,14 @@ declare module "zookeeperConstants" { export var ZOO_LOG_LEVEL_WARN: number; export var ZOO_LOG_LEVEL_INFO: number; export var ZOO_LOG_LEVEL_DEBUG: number; + export var ZOO_PERSISTENT: number; export var ZOO_EPHEMERAL: number; + export var ZOO_PERSISTENT_SEQUENTIAL: number; + export var ZOO_EPHEMERAL_SEQUENTIAL: number; export var ZOO_SEQUENCE: number; + export var ZOO_CONTAINER: number; + export var ZOO_PERSISTENT_WITH_TTL: number; + export var ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL: number; export var ZOK: number; export var ZSYSTEMERROR: number; export var ZRUNTIMEINCONSISTENCY: number; diff --git a/lib/zk_promise.js b/lib/zk_promise.js index a69fb234..19f8931f 100644 --- a/lib/zk_promise.js +++ b/lib/zk_promise.js @@ -24,11 +24,14 @@ class ZooKeeperPromise extends ZooKeeper { * @param {string} path * @param {(string|Buffer)} data * @param {number} flags + * @param {number} ttl, + * Must be positive integer if using any TTL mode; + * not-positive integer or null/undefined otherwise * @fulfill {string} * @returns {Promise.} */ - create(path, data, flags) { - return this.promisify(super.a_create, [path, data, flags]); + create(path, data, flags, ttl) { + return this.promisify(super.a_createTtl, [path, data, flags, ttl]); } /** diff --git a/lib/zookeeper.js b/lib/zookeeper.js index 675e6967..16f1a566 100644 --- a/lib/zookeeper.js +++ b/lib/zookeeper.js @@ -175,8 +175,27 @@ class ZooKeeper extends EventEmitter { * @returns {*} */ a_create(path, data, flags, pathCb) { - this.log(`Calling a_create with ${util.inspect([path, data, flags, pathCb])}`); - return this.native.a_create(path, data, flags, pathCb); + this.log(`Calling a_create with ${util.inspect([path, data, flags, -1, pathCb])}`); + return this.native.a_create(path, data, flags, -1, pathCb); + } + + /** + * @param {string} path + * @param {string|Buffer} data + * @param {number} flags - an int32 value + * @param {number} ttl + * Must be positive integer if using any TTL mode; + * not-positive integer or null/undefined otherwise + * @param {pathCb} pathCb + * @returns {*} + */ + a_createTtl(path, data, flags, ttl, pathCb) { + if (flags < 0) { + pathCb(new Error('Unsupported flags used. Are you on Windows? Then you\'re stuck to client version 3.4 and can\'t use container/ttl nodes.')); + } + const realTtl = ttl || -1; + this.log(`Calling a_create with ${util.inspect([path, data, flags, realTtl, pathCb])}`); + return this.native.a_create(path, data, flags, realTtl, pathCb); } /** diff --git a/prebuilds/darwin-x64/node.abi72.node b/prebuilds/darwin-x64/node.abi72.node deleted file mode 100755 index ab9e3f98..00000000 Binary files a/prebuilds/darwin-x64/node.abi72.node and /dev/null differ diff --git a/prebuilds/darwin-x64/node.abi83.node b/prebuilds/darwin-x64/node.abi83.node deleted file mode 100755 index e373939d..00000000 Binary files a/prebuilds/darwin-x64/node.abi83.node and /dev/null differ diff --git a/prebuilds/win32-x64/node.abi72.node b/prebuilds/win32-x64/node.abi72.node deleted file mode 100644 index a2eff3d7..00000000 Binary files a/prebuilds/win32-x64/node.abi72.node and /dev/null differ diff --git a/prebuilds/win32-x64/node.abi83.node b/prebuilds/win32-x64/node.abi83.node deleted file mode 100644 index 9b6673c5..00000000 Binary files a/prebuilds/win32-x64/node.abi83.node and /dev/null differ diff --git a/src/node-zk.cpp b/src/node-zk.cpp index 8d7c5139..e3cda570 100644 --- a/src/node-zk.cpp +++ b/src/node-zk.cpp @@ -172,7 +172,6 @@ class ZooKeeper: public Nan::ObjectWrap { Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("auth"), LOCAL_STRING(""), static_cast(ReadOnly | DontDelete)); Nan::DefineOwnProperty(constructor, LOCAL_STRING("ZOO_CREATOR_ALL_ACL"), acl_creator, static_cast(ReadOnly | DontDelete)); - NODE_DEFINE_CONSTANT(constructor, ZOO_CREATED_EVENT); NODE_DEFINE_CONSTANT(constructor, ZOO_DELETED_EVENT); NODE_DEFINE_CONSTANT(constructor, ZOO_CHANGED_EVENT); @@ -190,8 +189,14 @@ class ZooKeeper: public Nan::ObjectWrap { NODE_DEFINE_CONSTANT(constructor, ZOOKEEPER_WRITE); NODE_DEFINE_CONSTANT(constructor, ZOOKEEPER_READ); + NODE_DEFINE_CONSTANT(constructor, ZOO_PERSISTENT); NODE_DEFINE_CONSTANT(constructor, ZOO_EPHEMERAL); NODE_DEFINE_CONSTANT(constructor, ZOO_SEQUENCE); + NODE_DEFINE_CONSTANT(constructor, ZOO_PERSISTENT_SEQUENTIAL); + NODE_DEFINE_CONSTANT(constructor, ZOO_EPHEMERAL_SEQUENTIAL); + NODE_DEFINE_CONSTANT(constructor, ZOO_CONTAINER); + NODE_DEFINE_CONSTANT(constructor, ZOO_PERSISTENT_WITH_TTL); + NODE_DEFINE_CONSTANT(constructor, ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL); NODE_DEFINE_CONSTANT(constructor, ZOO_CREATED_EVENT); NODE_DEFINE_CONSTANT(constructor, ZOO_DELETED_EVENT); @@ -637,17 +642,18 @@ class ZooKeeper: public Nan::ObjectWrap { } static void ACreate(const Nan::FunctionCallbackInfo& info) { - A_METHOD_PROLOG(4); + A_METHOD_PROLOG(5); Nan::Utf8String _path (toString(info[0])); uint32_t flags = toUint(info[2]); + int32_t ttl = toInt(info[3]); if (Buffer::HasInstance(info[1])) { // buffer Local _data = toLocalObj(info[1]); - METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); + METHOD_EPILOG(zoo_acreate_ttl(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), &ZOO_OPEN_ACL_UNSAFE, flags, ttl, string_completion, cb)); } else { // other Nan::Utf8String _data (toString(info[1])); - METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, *_data, _data.length(), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb)); + METHOD_EPILOG(zoo_acreate_ttl(zk->zhandle, *_path, *_data, _data.length(), &ZOO_OPEN_ACL_UNSAFE, flags, ttl, string_completion, cb)); } }