private navigateToPath()

in packages/@aws-c2a/engine/lib/rules/rule-processor.ts [136:161]


  private navigateToPath(entity: ScopeNode, path?: string[]): ScopeNode[] {
    if(entity === undefined) return [];
    if(!path || path.length === 0) return [entity];

    if(isScopeVertex(entity)) {
      const traverse = (conditions: any): VertexScopeNode[] =>
        this.graph.v(entity.vertex).outAny(conditions).run().map(vertexToScopeNode);
      const newPropertyScopeNodes = traverse({_label: 'hasProperties'});
      const nestedPropertyScopeNodes = traverse({_label: 'value', ...path[0] === propertyPathWildcard ? {} : {key: path[0]}});
      const exposesValuesScopeNodes = traverse({_label: 'exposesValues', key: path[0]});

      return [
        ...flatMap(newPropertyScopeNodes, v => this.navigateToPath(v, path)),
        ...flatMap(nestedPropertyScopeNodes, v => this.navigateToPath(v, path.slice(1))),
        ...flatMap(exposesValuesScopeNodes, v => this.navigateToPath(v, path.slice(1))),
        ...[entity.vertex[path[0]]].filter(fn.isDefined).map(scalarToScopeNode) ?? [],
      ];
    } else if(isScopeValue(entity)){
      const value = entity.value;
      if(value === null || value == undefined) return [];
      if(typeof value === 'object'){
        return this.navigateToPath((value as Record<string, any>)[path[0]], path.slice(1));
      }
    }
    return [];
  }