From 2fa29b4921405348ae29999af54a11f11e54fc21 Mon Sep 17 00:00:00 2001 From: David Vujic Date: Thu, 4 Jul 2024 16:47:06 +0200 Subject: [PATCH] fix: ACL type defs (#346) * dev(examples): add ACL runnable example * fix(typedefs): ACL type * docs(ACL): typo in permissions key * bump version to 6.2.1 with changelog --- CHANGELOG.md | 5 +++++ README.md | 2 +- examples/acl.js | 39 +++++++++++++++++++++++++++++++++++++++ lib/typedeclarations.d.ts | 10 +++++++--- lib/typedefs.js | 11 ++++++++--- package.json | 2 +- 6 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 examples/acl.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 6099f4a6..9a4159ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +#### v 6.2.1 (2024-07-04) +* fix: ACL type, should be an array of objects. Also, fix typo in permissions key. + + Pull request [346](https://github.com/yfinkelstein/node-zookeeper/pull/346) by @davidvujic + #### v 6.2.0 (2024-05-25) * fix: build error in Node.js 22 caused by removed V8 AccessControl property diff --git a/README.md b/README.md index 51fe0d3d..f8d2bcf4 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ Have a look at the code in the [examples](./examples) folder: with __master__, _ * int numChildren // number of children of this node * long pzxid // last modified children * acl is an array of acls objects, single acl object has following key - * int perms // permisions + * int perm // permisions * string scheme // authorisation scheme (digest, auth) * string auth // authorisation credentials (username:hashed_password) * zookeeper is the ZooKeeper instance on which connect was called diff --git a/examples/acl.js b/examples/acl.js new file mode 100644 index 00000000..6dcc82d8 --- /dev/null +++ b/examples/acl.js @@ -0,0 +1,39 @@ +const { getClient, constants } = require('./wrapper'); + +const logger = require('./logger'); +const notifier = require('./notifier'); + +notifier.on('connect', (message) => logger.log('connect', message)); +notifier.on('createNode', (message) => logger.log('createNode', message)); + +async function init() { + const client = getClient(); + + client.on('connect', async () => { + const path = '/acl-testing'; + const data = ''; + const flags = constants.ZOO_EPHEMERAL; + const version = 0; + + await client.create(path, data, flags); + + const before = await client.get_acl(path); + + const updatedAcl = [{ + perm: constants.ZOO_PERM_READ, + scheme: 'world', + auth: 'anyone', + }]; + + await client.set_acl(path, version, updatedAcl); + + const after = await client.get_acl(path); + + logger.log('before:', before[0]); + logger.log('after:', after[0]); + }); +} + +if (require.main === module) { + init().catch(logger.error); +} diff --git a/lib/typedeclarations.d.ts b/lib/typedeclarations.d.ts index 60200cc2..e4bfccc9 100644 --- a/lib/typedeclarations.d.ts +++ b/lib/typedeclarations.d.ts @@ -624,13 +624,17 @@ declare module "index" { const ZooKeeper: typeof import("zookeeper"); } /** - * ACL + * ACL object */ -type acl = { - perms: number; +type aclObject = { + perm: number; scheme: string; auth: string; }; +/** + * ACL + */ +type acl = Array; /** * stat */ diff --git a/lib/typedefs.js b/lib/typedefs.js index 1374f42d..6ff92741 100644 --- a/lib/typedefs.js +++ b/lib/typedefs.js @@ -1,11 +1,16 @@ /** - * ACL - * @typedef {Object} acl - * @property {number} perms + * ACL object + * @typedef {Object} aclObject + * @property {number} perm * @property {string} scheme * @property {string} auth */ +/** + * ACL + * @typedef {Array.} acl + */ + /** * stat * @typedef {Object} stat diff --git a/package.json b/package.json index 91ea0170..3d2dd89c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "zookeeper", "description": "apache zookeeper client (zookeeper async API v3.5.x - v3.8.x)", - "version": "6.2.0", + "version": "6.2.1", "author": "Yuri Finkelstein ", "license": "MIT", "contributors": [