Skip to content

Commit ee89e38

Browse files
committed
Add jsdoc type defs for public API
1 parent eded76c commit ee89e38

File tree

5 files changed

+276
-92
lines changed

5 files changed

+276
-92
lines changed

lib/zookeeper.js

+260-63
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,270 @@ class ZooKeeper extends EventEmitter {
418418
// If the data is NOT a buffer, then the default encoding is 'utf8'.
419419
this.encoding = ((data_as_buffer === true) ? null : 'utf8');
420420
}
421+
422+
/** @returns {number} 1 */
423+
static get ZOO_PERM_READ() {
424+
return NativeZk.ZOO_PERM_READ;
425+
}
426+
427+
/** @returns {number} 2 */
428+
static get ZOO_PERM_WRITE() {
429+
return NativeZk.ZOO_PERM_WRITE;
430+
}
431+
432+
/** @returns {number} 4 */
433+
static get ZOO_PERM_CREATE() {
434+
return NativeZk.ZOO_PERM_CREATE;
435+
}
436+
437+
/** @returns {number} 8 */
438+
static get ZOO_PERM_DELETE() {
439+
return NativeZk.ZOO_PERM_DELETE;
440+
}
441+
442+
/** @returns {number} 16 */
443+
static get ZOO_PERM_ADMIN() {
444+
return NativeZk.ZOO_PERM_ADMIN;
445+
}
446+
447+
/** @returns {number} 31 */
448+
static get ZOO_PERM_ALL() {
449+
return NativeZk.ZOO_PERM_ALL;
450+
}
451+
452+
/** @returns {number} -112 */
453+
static get ZOO_EXPIRED_SESSION_STATE() {
454+
return NativeZk.ZOO_EXPIRED_SESSION_STATE;
455+
}
456+
457+
/** @returns {number} -113 */
458+
static get ZOO_AUTH_FAILED_STATE() {
459+
return NativeZk.ZOO_AUTH_FAILED_STATE;
460+
}
461+
462+
/** @returns {number} 1 */
463+
static get ZOO_CONNECTING_STATE() {
464+
return NativeZk.ZOO_CONNECTING_STATE;
465+
}
466+
467+
/** @returns {number} 2 */
468+
static get ZOO_ASSOCIATING_STATE() {
469+
return NativeZk.ZOO_ASSOCIATING_STATE;
470+
}
471+
472+
/** @returns {number} 3 */
473+
static get ZOO_CONNECTED_STATE() {
474+
return NativeZk.ZOO_CONNECTED_STATE;
475+
}
476+
477+
/** @returns {number} 1 */
478+
static get ZOO_LOG_LEVEL_ERROR() {
479+
return NativeZk.ZOO_LOG_LEVEL_ERROR;
480+
}
481+
482+
/** @returns {number} 2 */
483+
static get ZOO_LOG_LEVEL_WARN() {
484+
return NativeZk.ZOO_LOG_LEVEL_WARN;
485+
}
486+
487+
/** @returns {number} 3 */
488+
static get ZOO_LOG_LEVEL_INFO() {
489+
return NativeZk.ZOO_LOG_LEVEL_INFO;
490+
}
491+
492+
/** @returns {number} 4 */
493+
static get ZOO_LOG_LEVEL_DEBUG() {
494+
return NativeZk.ZOO_LOG_LEVEL_DEBUG;
495+
}
496+
497+
/** @returns {number} 1 */
498+
static get ZOO_EPHEMERAL() {
499+
return NativeZk.ZOO_EPHEMERAL;
500+
}
501+
502+
/** @returns {number} 2 */
503+
static get ZOO_SEQUENCE() {
504+
return NativeZk.ZOO_SEQUENCE;
505+
}
506+
507+
/** @returns {number} 0 */
508+
static get ZOK() {
509+
return NativeZk.ZOK;
510+
}
511+
512+
/** @returns {number} -1 */
513+
static get ZSYSTEMERROR() {
514+
return NativeZk.ZSYSTEMERROR;
515+
}
516+
517+
/** @returns {number} -2 */
518+
static get ZRUNTIMEINCONSISTENCY() {
519+
return NativeZk.ZRUNTIMEINCONSISTENCY;
520+
}
521+
522+
/** @returns {number} -3 */
523+
static get ZDATAINCONSISTENCY() {
524+
return NativeZk.ZDATAINCONSISTENCY;
525+
}
526+
527+
/** @returns {number} -4 */
528+
static get ZCONNECTIONLOSS() {
529+
return NativeZk.ZCONNECTIONLOSS;
530+
}
531+
532+
/** @returns {number} -5 */
533+
static get ZMARSHALLINGERROR() {
534+
return NativeZk.ZMARSHALLINGERROR;
535+
}
536+
537+
/** @returns {number} -6 */
538+
static get ZUNIMPLEMENTED() {
539+
return NativeZk.ZUNIMPLEMENTED;
540+
}
541+
542+
/** @returns {number} -7 */
543+
static get ZOPERATIONTIMEOUT() {
544+
return NativeZk.ZOPERATIONTIMEOUT;
545+
}
546+
547+
/** @returns {number} -8 */
548+
static get ZBADARGUMENTS() {
549+
return NativeZk.ZBADARGUMENTS;
550+
}
551+
552+
/** @returns {number} -9 */
553+
static get ZINVALIDSTATE() {
554+
return NativeZk.ZINVALIDSTATE;
555+
}
556+
557+
/** @returns {number} -100 */
558+
static get ZAPIERROR() {
559+
return NativeZk.ZAPIERROR;
560+
}
561+
562+
/** @returns {number} -101 */
563+
static get ZNONODE() {
564+
return NativeZk.ZNONODE;
565+
}
566+
567+
/** @returns {number} -102 */
568+
static get ZNOAUTH() {
569+
return NativeZk.ZNOAUTH;
570+
}
571+
572+
/** @returns {number} -103 */
573+
static get ZBADVERSION() {
574+
return NativeZk.ZBADVERSION;
575+
}
576+
577+
/** @returns {number} -108 */
578+
static get ZNOCHILDRENFOREPHEMERALS() {
579+
return NativeZk.ZNOCHILDRENFOREPHEMERALS;
580+
}
581+
582+
/** @returns {number} -110 */
583+
static get ZNODEEXISTS() {
584+
return NativeZk.ZNODEEXISTS;
585+
}
586+
587+
/** @returns {number} -111 */
588+
static get ZNOTEMPTY() {
589+
return NativeZk.ZNOTEMPTY;
590+
}
591+
592+
/** @returns {number} -112 */
593+
static get ZSESSIONEXPIRED() {
594+
return NativeZk.ZSESSIONEXPIRED;
595+
}
596+
597+
/** @returns {number} -113 */
598+
static get ZINVALIDCALLBACK() {
599+
return NativeZk.ZINVALIDCALLBACK;
600+
}
601+
602+
/** @returns {number} -114 */
603+
static get ZINVALIDACL() {
604+
return NativeZk.ZINVALIDACL;
605+
}
606+
607+
/** @returns {number} -115 */
608+
static get ZAUTHFAILED() {
609+
return NativeZk.ZAUTHFAILED;
610+
}
611+
612+
/** @returns {number} -116 */
613+
static get ZCLOSING() {
614+
return NativeZk.ZCLOSING;
615+
}
616+
617+
/** @returns {number} -117 */
618+
static get ZNOTHING() {
619+
return NativeZk.ZNOTHING;
620+
}
621+
622+
/** @returns {number} -118 */
623+
static get ZSESSIONMOVED() {
624+
return NativeZk.ZSESSIONMOVED;
625+
}
626+
627+
/** @returns {{perms:number, scheme:string, auth:string}} */
628+
static get ZOO_OPEN_ACL_UNSAFE() {
629+
return NativeZk.ZOO_OPEN_ACL_UNSAFE;
630+
}
631+
632+
/** @returns {{perms:number, scheme:string, auth:string}} */
633+
static get ZOO_READ_ACL_UNSAFE() {
634+
return NativeZk.ZOO_READ_ACL_UNSAFE;
635+
}
636+
637+
/** @returns {{perms:number, scheme:string, auth:string}} */
638+
static get ZOO_CREATOR_ALL_ACL() {
639+
return NativeZk.ZOO_CREATOR_ALL_ACL;
640+
}
641+
642+
/** @returns {number} 1 */
643+
static get ZOO_CREATED_EVENT() {
644+
return NativeZk.ZOO_CREATED_EVENT;
645+
}
646+
647+
/** @returns {number} 2 */
648+
static get ZOO_DELETED_EVENT() {
649+
return NativeZk.ZOO_DELETED_EVENT;
650+
}
651+
652+
/** @returns {number} 3 */
653+
static get ZOO_CHANGED_EVENT() {
654+
return NativeZk.ZOO_CHANGED_EVENT;
655+
}
656+
657+
/** @returns {number} 4 */
658+
static get ZOO_CHILD_EVENT() {
659+
return NativeZk.ZOO_CHILD_EVENT;
660+
}
661+
662+
/** @returns {number} -1 */
663+
static get ZOO_SESSION_EVENT() {
664+
return NativeZk.ZOO_SESSION_EVENT;
665+
}
666+
667+
/** @returns {number} -2 */
668+
static get ZOO_NOTWATCHING_EVENT() {
669+
return NativeZk.ZOO_NOTWATCHING_EVENT;
670+
}
671+
672+
/** @returns {number} 1 */
673+
static get ZOOKEEPER_WRITE() {
674+
return NativeZk.ZOOKEEPER_WRITE;
675+
}
676+
677+
/** @returns {number} 2 */
678+
static get ZOOKEEPER_READ() {
679+
return NativeZk.ZOOKEEPER_READ;
680+
}
421681
}
422682

423683
exports = module.exports = ZooKeeper;
424684

425-
Object.keys(NativeZk).forEach((key) => {
426-
exports[key] = key;
427-
});
428-
429685
/** @deprecated use strings directly */
430686
exports.on_closed = 'close';
431687
/** @deprecated use strings directly */
@@ -442,62 +698,3 @@ exports.on_event_changed = 'changed';
442698
exports.on_event_child = 'child';
443699
/** @deprecated use strings directly */
444700
exports.on_event_notwatching = 'notwatching';
445-
446-
// Other Constants
447-
Object.keys(NativeZk).forEach((key) => {
448-
exports[key] = NativeZk[key];
449-
});
450-
451-
/* Notable Constants:
452-
Permissions:
453-
* ZOO_PERM_READ = 1
454-
* ZOO_PERM_WRITE = 2
455-
* ZOO_PERM_CREATE = 4
456-
* ZOO_PERM_DELETE = 8
457-
* ZOO_PERM_ADMIN = 16
458-
* ZOO_PERM_ALL = 31
459-
460-
States:
461-
* ZOO_EXPIRED_SESSION_STATE = -112
462-
* ZOO_AUTH_FAILED_STATE = -113
463-
* ZOO_CONNECTING_STATE = 1
464-
* ZOO_ASSOCIATING_STATE = 2
465-
* ZOO_CONNECTED_STATE = 3
466-
467-
Log Levels:
468-
* ZOO_LOG_LEVEL_ERROR = 1
469-
* ZOO_LOG_LEVEL_WARN = 2
470-
* ZOO_LOG_LEVEL_INFO = 3
471-
* ZOO_LOG_LEVEL_DEBUG = 4
472-
473-
API Responses:
474-
* ZOK = 0
475-
* ZSYSTEMERROR = -1
476-
* ZRUNTIMEINCONSISTENCY = -2
477-
* ZDATAINCONSISTENCY = -3
478-
* ZCONNECTIONLOSS = -4
479-
* ZMARSHALLINGERROR = -5
480-
* ZUNIMPLEMENTED = -6
481-
* ZOPERATIONTIMEOUT = -7
482-
* ZBADARGUMENTS = -8
483-
* ZINVALIDSTATE = -9
484-
* ZAPIERROR = -100
485-
* ZNONODE = -101
486-
* ZNOAUTH = -102
487-
* ZBADVERSION = -103
488-
* ZNOCHILDRENFOREPHEMERALS = -108
489-
* ZNODEEXISTS = -110
490-
* ZNOTEMPTY = -111
491-
* ZSESSIONEXPIRED = -112
492-
* ZINVALIDCALLBACK = -113
493-
* ZINVALIDACL = -114
494-
* ZAUTHFAILED = -115
495-
* ZCLOSING = -116
496-
* ZNOTHING = -117
497-
* ZSESSIONMOVED = -118
498-
499-
Dunno:
500-
* ZOO_EPHEMERAL = 1
501-
* ZOO_SEQUENCE = 2
502-
503-
*/

tests/helpers/fakes.js

-8
This file was deleted.

tests/zookeeper/exportedconstantstest.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
const test = require('tape');
2-
const proxyquire = require('proxyquire');
3-
const { FakeNativeZooKeeper, path } = require('../helpers/fakes.js');
2+
const NativeZk = require('./../../build/zookeeper.node').ZooKeeper;
3+
const ZooKeeper = require('../../lib/zookeeper.js');
44

5-
FakeNativeZooKeeper.hello = 'world';
6-
7-
const ZooKeeper = proxyquire('../../lib/zookeeper.js', {
8-
[path]: { ZooKeeper: FakeNativeZooKeeper },
9-
});
5+
const keys = Object.keys(NativeZk);
106

117
test('native static constants are exported', (t) => {
12-
t.plan(1);
8+
t.plan(keys.length);
139

14-
t.equal(ZooKeeper.hello, FakeNativeZooKeeper.hello);
10+
keys.forEach((key) => {
11+
t.equal(ZooKeeper[key], NativeZk[key]);
12+
});
1513
});
1614

1715
test('legacy event constants are exported', (t) => {

0 commit comments

Comments
 (0)