Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function recursiveObjectExtraction(node: YAMLNode | undefined, object: PlainObject, validationContext: ValidationContext, source: ProjectSource): any {
// ATTENTION: Typings of the yaml ast parser are wrong
if (!node) {
return object;
}
switch (node.kind) {
case Kind.MAP:
const mapNode = node as YamlMap;
mapNode.mappings.forEach(val => {
object[val.key.value] = recursiveObjectExtraction(val.value, {}, validationContext, source);
});
return object;
case Kind.MAPPING:
throw new Error('Should never be reached since a mapping can not exist without a map.');
case Kind.SCALAR:
const scalarNode = node as YAMLScalar;
// check whether string or number scalar
if (scalarNode.doubleQuoted || scalarNode.singleQuoted || isNaN(Number(scalarNode.value))) {
return scalarNode.value;
} else {
return Number(scalarNode.value);
}
case Kind.SEQ:
const seqNode = node as YAMLSequence;
return seqNode.items.map(val => recursiveObjectExtraction(val, {}, validationContext, source));
case Kind.INCLUDE_REF:
validationContext.addMessage(ValidationMessage.error(`Include references are not supported`, new MessageLocation(source, node.startPosition, node.endPosition)));
return undefined;
case Kind.ANCHOR_REF:
validationContext.addMessage(ValidationMessage.error(`Anchor references are not supported`, new MessageLocation(source, node.startPosition, node.endPosition)));
return undefined;
}
}
//Autocompletion on root nodes
//Case 1 covered
if(parentNodeList.length === 0){
return Object.keys(this.kuberSchema["rootNodes"]).map(x => ({
label: x
}));
}
//Autocompletion on scalar nodes
//Case 2 Covered
if(parentList.length === 1 && (node && (node.value && node.value.kind === Kind.SCALAR) || node.kind === Kind.SCALAR)){
return this.autoCompleteScalarResults(nodesToSearch);
}
let possibleChildren = [];
while(nodesToSearch.length > 0){
let currNodePath = nodesToSearch.shift();
let depth = currNodePath.length - 1;
let currNode = currNodePath[depth];
//Autocompletion on deep child nodes
if(currNodePath.length === parentList.length){
possibleChildren.push(currNode);
}
if(currNode["items"] && currNode["items"]["properties"]){
if(currNode["items"]["properties"][parentList[currNodePath.length]]){
//For Kedge and normal schemas
if(api_obj === parentList[0]){
nodesToSearch.push([this.schema.properties[api_obj]]);
}
rootNodeList.push(api_obj);
}
}
if(parentNodeList.length === 0){
let rootNodes = Array.from(new Set(rootNodeList));
return callback([],[], rootNodes);
}
//Return early when we found a scalar node at the root level i.e. key: value <- here
if(returnEarlyForScalar && parentList.length === 1 && (node && (node.value && node.value.kind === Kind.SCALAR) || node.kind === Kind.SCALAR)){
return callback([], nodesToSearch, []);
}
let possibleChildren = [];
while(nodesToSearch.length > 0){
let currNodePath = nodesToSearch.shift();
let depth = currNodePath.length - 1;
let currNode = currNodePath[depth];
if(currNodePath.length === parentList.length){
possibleChildren.push(currNode);
}
//This is when its an array
if(currNode["items"] && currNode["items"]["properties"]){
if(currNode["items"]["properties"][parentList[currNodePath.length]]){