All files / src/cds/expressions cds_define_hierarchy.ts

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

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 36 371x 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 1x  
import {CDSAnnotation, CDSAs, CDSCondition, CDSInteger, CDSName, CDSParametersSelect, CDSPrefixedName, CDSWithParameters} from ".";
import {Expression, opt, optPrio, 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), optPrio("KEY"), CDSPrefixedName, optPrio(CDSAs));
    const sortDirection = altPrio("ASCENDING", "DESCENDING");
    const siblingsOrderField = seq(CDSPrefixedName, optPrio(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("DEPTH", CDSInteger)),
      opt(seq("MULTIPLE", "PARENTS", altPrio("NOT ALLOWED", "ALLOWED"))),
      opt(seq("ORPHANS", altPrio("IGNORE", "ROOT"))),
      opt(seq("CYCLES", "BREAKUP")),
      opt(seq("CACHE", altPrio("FORCE", "NONE", "EMPTY", "OFF"))),
    );
 
    return seq(
      star(CDSAnnotation),
      "DEFINE", "HIERARCHY", CDSName,
      opt(CDSWithParameters),
      "AS", "PARENT", "CHILD", "HIERARCHY", "(", hierarchyBody, ")",
      "{", seq(field, star(seq(",", field))), "}",
      opt(";"),
    );
  }
}