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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 22 deletions

View File

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

View File

@ -1,29 +1,17 @@
'use strict'
const { struct, superstruct } = require('superstruct')
const kind = require('kind-of')
const { optional, list } = struct
const transports = ['tcp', 'utp', 'webrtcstar', 'webrtcdirect', 'websockets', 'websocketstar']
// Define custom types
const s = superstruct({
types: {
tcp: v => kind(v) === 'tcp',
utp: v => kind(v) === 'utp',
webrtcstar: v => kind(v) === 'webrtcstar',
webrtcdirect: v => kind(v) === 'webrtcdirect',
websockets: v => kind(v) === 'websockets',
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 s = superstruct()
const transport = s.union([
s.interface({
createListener: 'function',
dial: 'function'
}),
'function'
])
const optionsSchema = s(
{
@ -41,7 +29,7 @@ const optionsSchema = s(
peerDiscovery: optional(list([s('object|function')])),
peerRouting: optional(list(['object'])),
streamMuxer: optional(list([s('object|function')])),
transport: 'transport'
transport: list([transport])
}),
config: s({
peerDiscovery: 'object?',