@@ -4,30 +4,34 @@ const { struct, superstruct } = require('superstruct')
4
4
const { optional, list } = struct
5
5
6
6
// Define custom types
7
- const s = superstruct ( )
8
- const transport = s . union ( [
9
- s . interface ( {
10
- createListener : 'function' ,
11
- dial : 'function'
12
- } ) ,
13
- 'function'
14
- ] )
7
+ const s = superstruct ( {
8
+ types : {
9
+ transport : value => {
10
+ if ( value . length === 0 ) return 'ERROR_EMPTY'
11
+ value . forEach ( i => {
12
+ if ( ! i . dial ) return 'ERR_NOT_A_TRANSPORT'
13
+ } )
14
+ return true
15
+ } ,
16
+ protector : value => {
17
+ if ( ! value . protect ) return 'ERR_NOT_A_PROTECTOR'
18
+ return true
19
+ }
20
+ }
21
+ } )
22
+
15
23
const modulesSchema = s ( {
16
24
connEncryption : optional ( list ( [ s ( 'object|function' ) ] ) ) ,
17
25
// this is hacky to simulate optional because interface doesnt work correctly with it
18
26
// change to optional when fixed upstream
19
- connProtector : s . union ( [ 'undefined' , s . interface ( { protect : 'function' } ) ] ) ,
27
+ connProtector : s ( 'undefined|protector' ) ,
20
28
contentRouting : optional ( list ( [ 'object' ] ) ) ,
21
29
dht : optional ( s ( 'null|function|object' ) ) ,
22
30
pubsub : optional ( s ( 'null|function|object' ) ) ,
23
31
peerDiscovery : optional ( list ( [ s ( 'object|function' ) ] ) ) ,
24
32
peerRouting : optional ( list ( [ 'object' ] ) ) ,
25
33
streamMuxer : optional ( list ( [ s ( 'object|function' ) ] ) ) ,
26
- transport : s . intersection ( [ [ transport ] , s . interface ( {
27
- length ( v ) {
28
- return v > 0 ? true : 'ERROR_EMPTY'
29
- }
30
- } ) ] )
34
+ transport : 'transport'
31
35
} )
32
36
33
37
const configSchema = s ( {
0 commit comments