forked from strongloop/strong-mq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (34 loc) · 945 Bytes
/
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
// attempt to lazy-load providers on reference
var assert = require('assert');
var copy = require('underscore').clone;
var parse = require('url').parse;
function urlProvider(url) {
var protocol = parse(url).protocol;
return protocol.split(':')[0];
}
function extractProvider(options) {
var provider;
var url;
if (typeof options == 'string') {
provider = urlProvider(options);
url = options;
options = null;
} else {
provider = options.provider;
url = null;
options = copy(options);
delete options.provider;
}
assert(provider, 'options must specify the provider');
return [provider, url, options];
}
exports.create = function(options) {
var parsed = extractProvider(options || {
provider: 'native'
});
var provider = parsed[0];
var url = parsed[1];
options = parsed[2];
var Connection = require('./lib/adapters/' + provider);
return new Connection(provider, url, options);
};