Skip to content

Commit 5f92acd

Browse files
authored
fix: make the config less restrictive (#329)
1 parent dfe8f63 commit 5f92acd

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"debug": "^4.1.0",
4343
"err-code": "^1.1.2",
4444
"fsm-event": "^2.1.0",
45-
"kind-of": "^6.0.2",
4645
"libp2p-connection-manager": "~0.0.2",
4746
"libp2p-floodsub": "~0.15.7",
4847
"libp2p-ping": "~0.8.5",

src/config.js

+9-21
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
'use strict'
22

33
const { struct, superstruct } = require('superstruct')
4-
const kind = require('kind-of')
54
const { optional, list } = struct
65

7-
const transports = ['tcp', 'utp', 'webrtcstar', 'webrtcdirect', 'websockets', 'websocketstar']
86
// Define custom types
9-
const s = superstruct({
10-
types: {
11-
tcp: v => kind(v) === 'tcp',
12-
utp: v => kind(v) === 'utp',
13-
webrtcstar: v => kind(v) === 'webrtcstar',
14-
webrtcdirect: v => kind(v) === 'webrtcdirect',
15-
websockets: v => kind(v) === 'websockets',
16-
websocketstar: v => kind(v) === 'websocketstar',
17-
transport: value => {
18-
const [error] = list([s.union([ ...transports, 'function' ])]).validate(value)
19-
if (error) return error.message
20-
21-
return value.length > 0
22-
? true
23-
: 'You need to provide at least one transport.'
24-
}
25-
}
26-
})
7+
const s = superstruct()
8+
const transport = s.union([
9+
s.interface({
10+
createListener: 'function',
11+
dial: 'function'
12+
}),
13+
'function'
14+
])
2715

2816
const optionsSchema = s(
2917
{
@@ -41,7 +29,7 @@ const optionsSchema = s(
4129
peerDiscovery: optional(list([s('object|function')])),
4230
peerRouting: optional(list(['object'])),
4331
streamMuxer: optional(list([s('object|function')])),
44-
transport: 'transport'
32+
transport: list([transport])
4533
}),
4634
config: s({
4735
peerDiscovery: 'object?',

0 commit comments

Comments
 (0)