fix: make the config less restrictive (#329)

This commit is contained in:
Jacob Heun
2019-02-25 12:19:37 +01:00
committed by GitHub
parent dfe8f632f7
commit 5f92acd5bb
2 changed files with 9 additions and 22 deletions

View File

@ -42,7 +42,6 @@
"debug": "^4.1.0", "debug": "^4.1.0",
"err-code": "^1.1.2", "err-code": "^1.1.2",
"fsm-event": "^2.1.0", "fsm-event": "^2.1.0",
"kind-of": "^6.0.2",
"libp2p-connection-manager": "~0.0.2", "libp2p-connection-manager": "~0.0.2",
"libp2p-floodsub": "~0.15.7", "libp2p-floodsub": "~0.15.7",
"libp2p-ping": "~0.8.5", "libp2p-ping": "~0.8.5",

View File

@ -1,29 +1,17 @@
'use strict' 'use strict'
const { struct, superstruct } = require('superstruct') const { struct, superstruct } = require('superstruct')
const kind = require('kind-of')
const { optional, list } = struct const { optional, list } = struct
const transports = ['tcp', 'utp', 'webrtcstar', 'webrtcdirect', 'websockets', 'websocketstar']
// Define custom types // Define custom types
const s = superstruct({ const s = superstruct()
types: { const transport = s.union([
tcp: v => kind(v) === 'tcp', s.interface({
utp: v => kind(v) === 'utp', createListener: 'function',
webrtcstar: v => kind(v) === 'webrtcstar', dial: 'function'
webrtcdirect: v => kind(v) === 'webrtcdirect', }),
websockets: v => kind(v) === 'websockets', 'function'
websocketstar: v => kind(v) === 'websocketstar', ])
transport: value => {
const [error] = list([s.union([ ...transports, 'function' ])]).validate(value)
if (error) return error.message
return value.length > 0
? true
: 'You need to provide at least one transport.'
}
}
})
const optionsSchema = s( const optionsSchema = s(
{ {
@ -41,7 +29,7 @@ const optionsSchema = s(
peerDiscovery: optional(list([s('object|function')])), peerDiscovery: optional(list([s('object|function')])),
peerRouting: optional(list(['object'])), peerRouting: optional(list(['object'])),
streamMuxer: optional(list([s('object|function')])), streamMuxer: optional(list([s('object|function')])),
transport: 'transport' transport: list([transport])
}), }),
config: s({ config: s({
peerDiscovery: 'object?', peerDiscovery: 'object?',