Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const defineComponent = async (component, state, context) => {
// TODO BRN: If we ever need to retrigger define (redefine) hydrating state here may be an issue
if (!isComponent(component)) {
throw new TypeError(
`defineComponent expected component parameter to be a component. Instead received ${component}`
)
}
component = hydrateComponent(component, state, context)
if (isFunction(component.define)) {
let children = await or(component.define(context), {})
children = filter(isComponent, map(resolve, children))
if (isObject(children)) {
forEach((child) => {
// TODO BRN: Look for children that already have parents. If this is the case then someone has returned a child from define that was defined by another component (possibly passed along as a variable)
child.parent = component
// child = setKey(appendKey(getKey(component), kdx), child)
}, children)
} else {
throw new Error(
`define() method must return either an object or an array. Instead received ${children} from ${component}.`
)
}
component.children = await map(
async (child, key) => defineComponent(child, get(['children', key], state), context),
children
)
}
return component
}
]),
inputTypes
)
const coreInputs = mapObjIndexed((value) => resolve(value), pick(keys(coreInputTypes), inputs))
const schema = validate({ ...coreInputTypes }, 'RAML10')
const validation = schema({ ...coreInputs })
if (!validation.valid) {
let errorMessages = []
const typeName = chalk.white(`"${Type.props.name}"`)
const header = chalk.redBright.bold(`\ninputType error(s) in Type ${typeName}:\n`)
errorMessages = append(header, errorMessages)
forEach((error) => {
const value = chalk.cyanBright(`"${error.value}"`)
const key = `${chalk.yellowBright(error.key)}`
const suppliedInputType = typeof error.value
const msg = ` - inputType ${key} has invalid \`${suppliedInputType}\` value of ${value} according to the rule: ${chalk.yellowBright(
error.rule
)} ${chalk.yellowBright(error.attr)}.\n`
errorMessages = append(msg, errorMessages)
}, prop('errors', validation))
const message = errorMessages.join('')
throw Error(message)
}
// set defaults if any...
forEachObjIndexed((coreInputType, key) => {
if (!coreInputs[key] && !coreInputType.required && coreInputType.default !== undefined) {
coreInputs[key] = coreInputType.default
function doFlatten(subRoutes, basePath) {
forEach((valueO, keyO) => {
const key = resolve(keyO)
const value = resolve(valueO)
if (key.startsWith('/')) {
doFlatten(value, joinPath(basePath, key))
} else {
if (key.toLowerCase() === 'routes') {
return doFlatten(value, basePath)
} else if (
!['any', 'delete', 'get', 'head', 'options', 'patch', 'post', 'put'].includes(
key.toLowerCase()
)
) {
throw new Error(
`Configuration key "${key}" was interpreted as an HTTP method because it does not start with a slash, but it is not a valid method.`
)
}
const objectToGraph = (object) => {
const graph = new Graph(object.options).setGraph(object.value)
forEach((node) => {
graph.setNode(node.v, node.value)
if (node.parent) {
graph.setParent(node.v, node.parent)
}
}, object.nodes)
forEach((edge) => {
graph.setEdge({ v: edge.v, w: edge.w, name: edge.name }, edge.value)
}, object.edges)
return graph
}
const reduceWalkee = (accum, component, keys, iteratee, recur) => {
let result = iteratee(accum, component, keys)
const children = resolve(component.children)
if (isObject(children)) {
forEach((child, childKdx) => {
const newKeys = concat(keys, [childKdx])
result = recur(result, resolve(child), newKeys, iteratee)
}, children)
}
return result
}
const objectToGraph = (object) => {
const graph = new Graph(object.options).setGraph(object.value)
forEach((node) => {
graph.setNode(node.v, node.value)
if (node.parent) {
graph.setParent(node.v, node.parent)
}
}, object.nodes)
forEach((edge) => {
graph.setEdge({ v: edge.v, w: edge.w, name: edge.name }, edge.value)
}, object.edges)
return graph
}
obj.data
) {
if (isArray(obj.data)) {
printArray(compact(obj.data), subLog, level + 1)
} else {
printObj(compact(obj.data), subLog, level)
}
if (obj.children && level <= 1) {
if (isArray(obj.children)) {
printArray(compact(obj.children), subLog)
} else {
printObj(compact(obj.children), subLog)
}
}
} else {
forEach((val, key) => {
if (isArray(val)) {
printArray(val, subLog, level + 1)
} else if (isObject(val)) {
log(`${key}:`)
printObj(val, subLog, level + 1)
} else {
log(`${key}: ${val}`)
}
}, obj)
}
}
const walkee = (accum, component, keys, iteratee, recur) => {
let result = accum
const children = resolve(component.children)
if (isObject(children)) {
forEach((child, childKdx) => {
const newKeys = concat(keys, [childKdx])
result = recur(result, resolve(child), newKeys, iteratee)
}, children)
}
return iteratee(result, component, keys)
}