This repository has been archived by the owner on Aug 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
117 lines (102 loc) · 3.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var assert = require('assert')
var crypto = require('crypto')
var format = require('util').format
var inherits = require('util').inherits
var EventEmitter = require('events').EventEmitter
var net = require('net')
var path = require('path')
var ReadableStream = require('readable-stream')
var int53 = require('int53')
var State = require('./state')(inherits)
var ZKErrors = require('./protocol/zk-errors')()
var ACL = require('./acl')(format, crypto)
var ZnodeStat = require('./protocol/znode-stat')(format, int53)
var retry = require('./retry')
var RequestBuffer = require('./request-buffer')()
var createModule = require('./protocol/create')
var noop = function () {}
var nullLogger = {}
Object.keys(console).forEach(function (f) { nullLogger[f] = noop })
function setLogger(logger) {
if (logger) {
var required = Object.keys(console)
assert.ok(
required.every(
function (f) {
return typeof(logger[f] === 'function')
}
),
'logger must implement the global.console interface'
)
return logger
}
else {
return nullLogger
}
}
function ZK(options) {
options = options || {}
var logger = setLogger(options.logger)
var Request = require('./protocol/request')(logger)
var Response = require('./protocol/response')(logger, ZKErrors)
var protocol = {
Auth: require('./protocol/auth')(inherits, Request, Response),
Close: require('./protocol/close')(inherits, Request, Response),
CheckVersion: require('./protocol/check-version')(logger, Request),
Connect: require('./protocol/connect')(logger, inherits, Response, ZKErrors),
Create: createModule(logger, inherits, Request, Response, ACL),
Delete: require('./protocol/delete')(logger, inherits, Request, Response),
Exists: require('./protocol/exists')(logger, inherits, Request, Response, ZKErrors, ZnodeStat),
GetACL: require('./protocol/get-acl')(logger, inherits, Request, Response, ZnodeStat, ACL),
GetChildren: require('./protocol/get-children')(logger, inherits, Request, Response, ZnodeStat),
GetData: require('./protocol/get-data')(logger, inherits, Request, Response, ZnodeStat),
SetACL: require('./protocol/set-acl')(logger, inherits, Request, Response, ZnodeStat, ACL),
SetData: require('./protocol/set-data')(logger, inherits, Request, Response, ZnodeStat),
SetWatches: require('./protocol/set-watches')(logger, inherits, Request, Response),
Sync: require('./protocol/sync')(logger, inherits, Request, Response)
}
var defaults = require('./default-callbacks')(logger, ZKErrors)
protocol.Transaction = require('./protocol/transaction')(logger, assert, inherits, Request, Response, protocol.CheckVersion, protocol.Create, protocol.Delete, protocol.SetData, ZnodeStat, ZKErrors, defaults)
var Ping = require('./protocol/ping')(inherits, Request)
var Watch = require('./protocol/watch')(format)
var Receiver = require('./receiver')(logger, inherits, EventEmitter, State, Watch)
var Watcher = require('./watcher')(logger, Watch)
var Client = require('./client')(
logger,
inherits,
EventEmitter,
net,
ReadableStream,
Receiver
)
var Ensemble = require('./ensemble')(
logger,
inherits,
EventEmitter,
Client,
RequestBuffer,
Ping,
ZKErrors
)
var Session = require('./session')(
logger,
assert,
format,
inherits,
EventEmitter,
path,
ACL,
Ensemble,
Watcher,
protocol,
defaults,
retry,
ZKErrors
)
return new Session(options)
}
ZK.errors = ZKErrors
ZK.ACL = ACL
ZK.retry = retry
ZK.create = createModule.flags
module.exports = ZK