fix: avoid using superstruct interface

This commit is contained in:
Jacob Heun 2019-08-20 15:01:40 +02:00
parent b0f124b5ff
commit aa95ab9928

View File

@ -4,30 +4,34 @@ const { struct, superstruct } = require('superstruct')
const { optional, list } = struct const { optional, list } = struct
// Define custom types // Define custom types
const s = superstruct() const s = superstruct({
const transport = s.union([ types: {
s.interface({ transport: value => {
createListener: 'function', if (value.length === 0) return 'ERROR_EMPTY'
dial: 'function' value.forEach(i => {
}), if (!i.dial) return 'ERR_NOT_A_TRANSPORT'
'function' })
]) return true
},
protector: value => {
if (!value.protect) return 'ERR_NOT_A_PROTECTOR'
return true
}
}
})
const modulesSchema = s({ const modulesSchema = s({
connEncryption: optional(list([s('object|function')])), connEncryption: optional(list([s('object|function')])),
// this is hacky to simulate optional because interface doesnt work correctly with it // this is hacky to simulate optional because interface doesnt work correctly with it
// change to optional when fixed upstream // change to optional when fixed upstream
connProtector: s.union(['undefined', s.interface({ protect: 'function' })]), connProtector: s('undefined|protector'),
contentRouting: optional(list(['object'])), contentRouting: optional(list(['object'])),
dht: optional(s('null|function|object')), dht: optional(s('null|function|object')),
pubsub: optional(s('null|function|object')), pubsub: optional(s('null|function|object')),
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: s.intersection([[transport], s.interface({ transport: 'transport'
length (v) {
return v > 0 ? true : 'ERROR_EMPTY'
}
})])
}) })
const configSchema = s({ const configSchema = s({