@@ -13,12 +13,22 @@ const adaptors = {
13
13
14
14
const { SYNC } = core ;
15
15
const init = options => {
16
- const { uri, deserialize, serialize } = options ;
16
+ const { uri, deserialize, serialize, redisClient } = options ;
17
17
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' ) ;
20
20
}
21
21
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
+
22
32
if ( deserialize && typeof deserialize !== 'function' ) {
23
33
throw new Error ( '`deserialize` option provided to feathers-sync is not a function' ) ;
24
34
}
@@ -27,14 +37,16 @@ const init = options => {
27
37
throw new Error ( '`serialize` option provided to feathers-sync is not a function' ) ;
28
38
}
29
39
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 ] ;
34
45
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
+ }
38
50
39
51
return adapter ( {
40
52
serialize : JSON . stringify ,
@@ -49,4 +61,4 @@ module.exports = init;
49
61
Object . assign ( module . exports , adaptors , {
50
62
default : init ,
51
63
SYNC
52
- } ) ;
64
+ } ) ;
0 commit comments