Skip to content

Commit aa95ab9

Browse files
committed
fix: avoid using superstruct interface
1 parent b0f124b commit aa95ab9

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/config.js

+18-14
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,34 @@ const { struct, superstruct } = require('superstruct')
44
const { optional, list } = struct
55

66
// 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+
1523
const modulesSchema = s({
1624
connEncryption: optional(list([s('object|function')])),
1725
// this is hacky to simulate optional because interface doesnt work correctly with it
1826
// change to optional when fixed upstream
19-
connProtector: s.union(['undefined', s.interface({ protect: 'function' })]),
27+
connProtector: s('undefined|protector'),
2028
contentRouting: optional(list(['object'])),
2129
dht: optional(s('null|function|object')),
2230
pubsub: optional(s('null|function|object')),
2331
peerDiscovery: optional(list([s('object|function')])),
2432
peerRouting: optional(list(['object'])),
2533
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'
3135
})
3236

3337
const configSchema = s({

0 commit comments

Comments
 (0)