All files / src/cds/expressions cds_define_hierarchy.ts

100% Statements 35/35
100% Branches 1/1
100% Functions 1/1
100% Lines 35/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 361x 1x 1x 1x 1x 1x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 1x  
import {CDSAnnotation, CDSAs, CDSCondition, CDSName, CDSParametersSelect, CDSPrefixedName, CDSWithParameters} from ".";
import {Expression, opt, seq, star, altPrio} from "../../abap/2_statements/combi";
import {IStatementRunnable} from "../../abap/2_statements/statement_runnable";
 
export class CDSDefineHierarchy extends Expression {
  public getRunnable(): IStatementRunnable {
    const field = seq(star(CDSAnnotation), opt("KEY"), CDSPrefixedName, opt(CDSAs));
    const sortDirection = altPrio("ASCENDING", "DESCENDING");
    const siblingsOrderField = seq(CDSPrefixedName, opt(sortDirection));
    const siblingsOrder = seq("SIBLINGS", "ORDER", "BY", siblingsOrderField, star(seq(",", siblingsOrderField)));
 
    const directory = seq("DIRECTORY", CDSName, "FILTER", "BY", CDSCondition);
    const hierarchyBody = seq(
      "SOURCE", CDSName, opt(CDSParametersSelect),
      "CHILD", "TO", "PARENT", "ASSOCIATION", CDSName,
      opt(directory),
      opt(seq("START", "WHERE", CDSCondition)),
      opt(siblingsOrder),
      opt(seq("NODETYPE", CDSName)),
      opt(seq("MULTIPLE", "PARENTS", "ALLOWED")),
      opt(seq("ORPHANS", altPrio("IGNORE", "ROOT"))),
      opt(seq("CYCLES", "BREAKUP")),
      opt(seq("CACHE", altPrio("FORCE", "NONE", "EMPTY"))),
    );
 
    return seq(
      star(CDSAnnotation),
      "DEFINE", "HIERARCHY", CDSName,
      opt(CDSWithParameters),
      "AS", "PARENT", "CHILD", "HIERARCHY", "(", hierarchyBody, ")",
      "{", seq(field, star(seq(",", field))), "}",
      opt(";"),
    );
  }
}