-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (50 loc) · 1.32 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
//
// Imports
//
const Client = require('./lib');
const plugins = require('./plugins');
//
// Plugins
//
const Plugins = {
gracefulShutdown: plugins.GracefulShutdown,
connectionRetry: plugins.ConnectionRetry,
duplex: plugins.Duplex,
dlx: plugins.DLX,
encoding: plugins.Encoding,
rpc: plugins.RPC,
confirm: plugins.Confirm,
retry: plugins.Retry
};
const resolvePlugins = (plugins) => plugins
.filter(Boolean)
.map((plugin) => {
if (typeof plugin === 'string') {
return new Plugins[plugin]();
} else return plugin;
});
//
// Exports
//
module.exports.connect = (url, options) => Client.start(url, {
logger: console,
plugins: resolvePlugins([
'gracefulShutdown',
'connectionRetry',
'duplex',
'encoding',
'rpc',
'confirm',
'retry'
]),
...options
});
module.exports.Client = function(url, { plugins = [], ...options } = {}) {
return Client(url, { plugins: resolvePlugins(plugins), ...options });
};
module.exports.Client.start = function(url, { plugins = [], ...options } = {}) {
return Client.start(url, { plugins: resolvePlugins(plugins), ...options });
};
module.exports.constants = require('./lib/constants');
module.exports.errors = require('./lib/errors');
module.exports.plugins = plugins;