Skip to content

Commit 9bb61bc

Browse files
authored
Merge pull request #196 from DavidVujic/jsdoc_types
jsDoc type definitions
2 parents 0425d2f + 08139aa commit 9bb61bc

File tree

3 files changed

+149
-34
lines changed

3 files changed

+149
-34
lines changed

lib/typedefs.js

+104
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,107 @@
55
* @property {string} scheme
66
* @property {string} auth
77
*/
8+
9+
/**
10+
* stat
11+
* @typedef {Object} stat
12+
* @property {number} czxid
13+
* @property {number} mzxid
14+
* @property {number} ctime
15+
* @property {number} mtime
16+
* @property {number} version
17+
* @property {number} cversion
18+
* @property {number} aversion
19+
* @property {string} ephemeralOwner
20+
* @property {number} dataLength
21+
* @property {number} numChildren
22+
* @property {number} pzxid
23+
*/
24+
25+
/**
26+
* Mkdir callback
27+
* @typedef {callback} mkdirCb
28+
* @param {Error} error
29+
* @param {boolean} [success]
30+
*/
31+
32+
/**
33+
* Connect callback
34+
* @typedef {callback} connectCb
35+
* @param {Error} error
36+
* @param {ZooKeeper} client
37+
*/
38+
39+
/**
40+
* Path callback
41+
* @typedef {callback} pathCb
42+
* @param {number} rc
43+
* @param {number} error
44+
* @param {string} path
45+
*/
46+
47+
/**
48+
* Stat callback
49+
* @typedef {callback} statCb
50+
* @param {number} rc
51+
* @param {number} error
52+
* @param {stat} stat
53+
*/
54+
55+
/**
56+
* Data callback
57+
* @typedef {callback} dataCb
58+
* @param {number} rc
59+
* @param {number} error
60+
* @param {stat} stat
61+
* @param {string|Buffer} data
62+
*/
63+
64+
/**
65+
* Child callback
66+
* @typedef {callback} childCb
67+
* @param {number} rc
68+
* @param {number} error
69+
* @param {Array.<string>} children
70+
*/
71+
72+
/**
73+
* Child2 callback
74+
* @typedef {callback} child2Cb
75+
* @param {number} rc
76+
* @param {number} error
77+
* @param {Array.<string>} children
78+
* @param {stat} stat
79+
*/
80+
81+
/**
82+
* Value callback
83+
* @typedef {callback} valueCb
84+
* @param {number} rc
85+
* @param {number} error
86+
* @param {*} value
87+
*/
88+
89+
/**
90+
* Void callback
91+
* @typedef {callback} voidCb
92+
* @param {number} rc
93+
* @param {number} error
94+
*/
95+
96+
/**
97+
* Watch callback
98+
* @typedef {callback} watchCb
99+
* @param {number} type
100+
* @param {number} state
101+
* @param {string} path
102+
*/
103+
104+
/**
105+
* ACL callback
106+
* @typedef {callback} aclCb
107+
* @param {number} rc
108+
* @param {number} error
109+
* @param {acl} acl
110+
* @param {stat} stat
111+
*/

lib/zk_promise.js

+25-14
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class ZooKeeperPromise extends ZooKeeper {
2121
* @param path {string}
2222
* @param data {(string|Buffer)}
2323
* @param flags {number}
24-
* @returns {ZkPromise}
24+
* @fulfill {string}
25+
* @returns {Promise.<string>}
2526
*/
2627
create(path, data, flags) {
2728
return this.promisify(super.a_create, [path, data, flags]);
@@ -30,7 +31,8 @@ class ZooKeeperPromise extends ZooKeeper {
3031
/**
3132
* @param path {string}
3233
* @param watch {function}
33-
* @returns {ZkPromise}
34+
* @fulfill {stat}
35+
* @returns {Promise.<stat>}
3436
*/
3537
exists(path, watch) {
3638
return this.promisify(super.a_exists, [path, watch]);
@@ -39,7 +41,8 @@ class ZooKeeperPromise extends ZooKeeper {
3941
/**
4042
* @param path {string}
4143
* @param watchCb {function}
42-
* @returns {ZkPromise}
44+
* @fulfill {stat}
45+
* @returns {Promise.<stat>}
4346
*/
4447
w_exists(path, watchCb) {
4548
return this.promisify(super.aw_exists, [path, watchCb]);
@@ -48,7 +51,8 @@ class ZooKeeperPromise extends ZooKeeper {
4851
/**
4952
* @param path {string}
5053
* @param watch {boolean}
51-
* @returns {ZkPromise}
54+
* @fulfill {string|Buffer}
55+
* @returns {Promise.<string|Buffer>}
5256
*/
5357
get(path, watch) {
5458
return this.promisify(super.a_get, [path, watch]);
@@ -57,7 +61,8 @@ class ZooKeeperPromise extends ZooKeeper {
5761
/**
5862
* @param path {string}
5963
* @param watchCb {function}
60-
* @returns {ZkPromise}
64+
* @fulfill {string|Buffer}
65+
* @returns {Promise.<string|Buffer>}
6166
*/
6267
w_get(path, watchCb) {
6368
return this.promisify(super.aw_get, [path, watchCb]);
@@ -66,7 +71,8 @@ class ZooKeeperPromise extends ZooKeeper {
6671
/**
6772
* @param path {string}
6873
* @param watch {boolean}
69-
* @returns {ZkPromise}
74+
* @fulfill {Array.<string>}
75+
* @returns {Promise.<Array.<string>>}
7076
*/
7177
get_children(path, watch) {
7278
return this.promisify(super.a_get_children, [path, watch]);
@@ -75,7 +81,8 @@ class ZooKeeperPromise extends ZooKeeper {
7581
/**
7682
* @param path {string}
7783
* @param watchCb {function}
78-
* @returns {ZkPromise}
84+
* @fulfill {Array.<string>}
85+
* @returns {Promise.<Array.<string>>}
7986
*/
8087
w_get_children(path, watchCb) {
8188
return this.promisify(super.aw_get_children, [path, watchCb]);
@@ -84,7 +91,8 @@ class ZooKeeperPromise extends ZooKeeper {
8491
/**
8592
* @param path {string}
8693
* @param watch {boolean}
87-
* @returns {ZkPromise}
94+
* @fulfill {childrenWithStat}
95+
* @returns {Promise.<Array.<string>>,<stat>}
8896
*/
8997
get_children2(path, watch) {
9098
return this.promisify(super.a_get_children2, [path, watch]);
@@ -93,7 +101,8 @@ class ZooKeeperPromise extends ZooKeeper {
93101
/**
94102
* @param path {string}
95103
* @param watchCb {function}
96-
* @returns {ZkPromise}
104+
* @fulfill {childrenWithStat}
105+
* @returns {Promise.<Array.<string>>,<stat>}
97106
*/
98107
w_get_children2(path, watchCb) {
99108
return this.promisify(super.aw_get_children2, [path, watchCb]);
@@ -103,7 +112,8 @@ class ZooKeeperPromise extends ZooKeeper {
103112
* @param path {string}
104113
* @param data {(string|Buffer)}
105114
* @param version {number} an int32 value
106-
* @returns {ZkPromise}
115+
* @fulfill {stat}
116+
* @returns {Promise.<stat>}
107117
*/
108118
set(path, data, version) {
109119
return this.promisify(super.a_set, [path, data, version]);
@@ -112,7 +122,7 @@ class ZooKeeperPromise extends ZooKeeper {
112122
/**
113123
* @param path {string}
114124
* @param version {number} an int32 value
115-
* @returns {ZkPromise}
125+
* @returns {Promise}
116126
*/
117127
// eslint-disable-next-line no-underscore-dangle
118128
delete_(path, version) {
@@ -122,7 +132,8 @@ class ZooKeeperPromise extends ZooKeeper {
122132

123133
/**
124134
* @param path {string}
125-
* @returns {ZkPromise}
135+
* @fulfill {acl}
136+
* @returns {Promise.<acl>}
126137
*/
127138
get_acl(path) {
128139
return this.promisify(super.a_get_acl, [path]);
@@ -132,15 +143,15 @@ class ZooKeeperPromise extends ZooKeeper {
132143
* @param path {string}
133144
* @param version {number} an int32 value
134145
* @param acl {acl}
135-
* @returns {ZkPromise}
146+
* @returns {Promise}
136147
*/
137148
set_acl(path, version, acl) {
138149
return this.promisify(super.a_set_acl, [path, version, acl]);
139150
}
140151

141152
/**
142153
* @param path {string}
143-
* @returns {ZkPromise}
154+
* @returns {Promise}
144155
*/
145156
sync(path) {
146157
return this.promisify(super.a_sync, [path]);

lib/zookeeper.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const create = (con, p, cb) => {
4343
* does not support ./file or /dir/../file
4444
* @param con {ZooKeeper}
4545
* @param p {string}
46-
* @param callback {function}
46+
* @param callback {mkdirCb}
4747
*/
4848
const mkdirp = (con, p, callback) => {
4949
const dirs = normalize(p).split('/').slice(1); // remove empty string at the start.
@@ -130,7 +130,7 @@ class ZooKeeper extends EventEmitter {
130130

131131
/**
132132
* @param options {object|function}
133-
* @param cb {function}
133+
* @param cb {connectCb}
134134
*/
135135
connect(options, cb) {
136136
let callback;
@@ -168,7 +168,7 @@ class ZooKeeper extends EventEmitter {
168168
* @param path {string}
169169
* @param data {string|Buffer}
170170
* @param flags {number} an int32 value
171-
* @param pathCb {function}
171+
* @param pathCb {pathCb}
172172
* @returns {*}
173173
*/
174174
a_create(path, data, flags, pathCb) {
@@ -179,7 +179,7 @@ class ZooKeeper extends EventEmitter {
179179
/**
180180
* @param path {string}
181181
* @param watch {boolean}
182-
* @param statCb {function}
182+
* @param statCb {statCb}
183183
* @returns {*}
184184
*/
185185
a_exists(path, watch, statCb) {
@@ -189,8 +189,8 @@ class ZooKeeper extends EventEmitter {
189189

190190
/**
191191
* @param path {string}
192-
* @param watchCb {function}
193-
* @param statCb {function}
192+
* @param watchCb {watchCb}
193+
* @param statCb {statCb}
194194
* @returns {*}
195195
*/
196196
aw_exists(path, watchCb, statCb) {
@@ -201,7 +201,7 @@ class ZooKeeper extends EventEmitter {
201201
/**
202202
* @param path {string}
203203
* @param watch {bool}
204-
* @param dataCb {function}
204+
* @param dataCb {dataCb}
205205
* @returns {*}
206206
*/
207207
a_get(path, watch, dataCb) {
@@ -216,8 +216,8 @@ class ZooKeeper extends EventEmitter {
216216

217217
/**
218218
* @param path {string}
219-
* @param watchCb {function}
220-
* @param dataCb {function}
219+
* @param watchCb {watchCb}
220+
* @param dataCb {dataCb}
221221
* @returns {*}
222222
*/
223223
aw_get(path, watchCb, dataCb) {
@@ -233,7 +233,7 @@ class ZooKeeper extends EventEmitter {
233233
/**
234234
* @param path {string}
235235
* @param watch {boolean}
236-
* @param childCb {function}
236+
* @param childCb {childCb}
237237
* @returns {*}
238238
*/
239239
a_get_children(path, watch, childCb) {
@@ -243,8 +243,8 @@ class ZooKeeper extends EventEmitter {
243243

244244
/**
245245
* @param path {string}
246-
* @param watchCb {function}
247-
* @param childCb {function}
246+
* @param watchCb {watchCb}
247+
* @param childCb {childCb}
248248
* @returns {*}
249249
*/
250250
aw_get_children(path, watchCb, childCb) {
@@ -255,7 +255,7 @@ class ZooKeeper extends EventEmitter {
255255
/**
256256
* @param path {string}
257257
* @param watch {boolean}
258-
* @param childCb {function}
258+
* @param childCb {child2Cb}
259259
* @returns {*}
260260
*/
261261
a_get_children2(path, watch, childCb) {
@@ -265,8 +265,8 @@ class ZooKeeper extends EventEmitter {
265265

266266
/**
267267
* @param path {string}
268-
* @param watchCb {function}
269-
* @param childCb {function}
268+
* @param watchCb {watchCb}
269+
* @param childCb {child2Cb}
270270
* @returns {*}
271271
*/
272272
aw_get_children2(path, watchCb, childCb) {
@@ -278,7 +278,7 @@ class ZooKeeper extends EventEmitter {
278278
* @param path {string}
279279
* @param data {string|Buffer}
280280
* @param version {number} an int32 value
281-
* @param statCb {function}
281+
* @param statCb {statCb}
282282
* @returns {*}
283283
*/
284284
a_set(path, data, version, statCb) {
@@ -289,7 +289,7 @@ class ZooKeeper extends EventEmitter {
289289
/**
290290
* @param path {string}
291291
* @param version {number} an int32 value
292-
* @param voidCb {function}
292+
* @param voidCb {voidCb}
293293
* @returns {*}
294294
*/
295295
// eslint-disable-next-line no-underscore-dangle
@@ -301,7 +301,7 @@ class ZooKeeper extends EventEmitter {
301301

302302
/**
303303
* @param path {string}
304-
* @param aclCb {function}
304+
* @param aclCb {aclCb}
305305
* @returns {*}
306306
*/
307307
a_get_acl(path, aclCb) {
@@ -313,7 +313,7 @@ class ZooKeeper extends EventEmitter {
313313
* @param path {string}
314314
* @param version {number} an int32 value
315315
* @param acl {acl}
316-
* @param voidCb {function}
316+
* @param voidCb {voidCb}
317317
* @returns {*}
318318
*/
319319
a_set_acl(path, version, acl, voidCb) {
@@ -333,7 +333,7 @@ class ZooKeeper extends EventEmitter {
333333

334334
/**
335335
* @param path {string}
336-
* @param cb {function}
336+
* @param cb {mkdirCb}
337337
*/
338338
mkdirp(path, cb) {
339339
this.log(`Calling mkdirp with ${util.inspect([path, cb])}`);

0 commit comments

Comments
 (0)