Skip to content

Commit d887071

Browse files
committed
fix: Do not require uri if redisClient object provided.
1 parent 2f507c3 commit d887071

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

lib/index.js

+23-11
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@ const adaptors = {
1313

1414
const { SYNC } = core;
1515
const init = options => {
16-
const { uri, deserialize, serialize } = options;
16+
const { uri, deserialize, serialize, redisClient } = options;
1717

18-
if (!uri) {
19-
throw new Error('A `uri` option with the database connection string has to be provided to feathers-sync');
18+
if (!uri && !redisClient) {
19+
throw new Error('A `uri` option with the database connection string, or a `redisClient` object has to be provided to feathers-sync');
2020
}
2121

22+
let adapter;
23+
24+
if (redisClient) {
25+
if (typeof redisClient !== "object") {
26+
throw new Error('`redisClient` option provided to feathers-sync is not an object');
27+
}
28+
29+
adapter = adaptors["redis"];
30+
}
31+
2232
if (deserialize && typeof deserialize !== 'function') {
2333
throw new Error('`deserialize` option provided to feathers-sync is not a function');
2434
}
@@ -27,14 +37,16 @@ const init = options => {
2737
throw new Error('`serialize` option provided to feathers-sync is not a function');
2838
}
2939

30-
const { protocol } = new URL(uri);
31-
const name = protocol.substring(0, protocol.length - 1);
32-
const identifiedProtocolName = Object.keys(adaptors).filter((adaptor) => name.indexOf(adaptor) !== -1 ? adaptor : null);
33-
const adapter = adaptors[identifiedProtocolName];
40+
if (typeof adapter !== "function") {
41+
const { protocol } = new URL(uri);
42+
const name = protocol.substring(0, protocol.length - 1);
43+
const identifiedProtocolName = Object.keys(adaptors).filter((adaptor) => name.indexOf(adaptor) !== -1 ? adaptor : null);
44+
adapter = adaptors[identifiedProtocolName];
3445

35-
if (!adapter) {
36-
throw new Error(`${name} is an invalid adapter (uri ${uri})`);
37-
}
46+
if (typeof adapter !== "function") {
47+
throw new Error(`${name} is an invalid adapter (uri ${uri})`);
48+
}
49+
}
3850

3951
return adapter({
4052
serialize: JSON.stringify,
@@ -49,4 +61,4 @@ module.exports = init;
4961
Object.assign(module.exports, adaptors, {
5062
default: init,
5163
SYNC
52-
});
64+
});

0 commit comments

Comments
 (0)