All files / src/cds/expressions cds_table_field.ts

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

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 171x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import {CDSAnnotation, CDSAssociation, CDSComposition, CDSName, CDSType} from ".";
import {Expression, str, seq, star, optPrio, alt} from "../../abap/2_statements/combi";
import {IStatementRunnable} from "../../abap/2_statements/statement_runnable";
 
// A single field or association/composition inside a `define table entity { ... }`
// inline body. Wraps annotations + name + type together so tooling can iterate
// per-field with associated field-level annotations (matches the CDSElement
// shape used for select-list elements).
export class CDSTableField extends Expression {
  public getRunnable(): IStatementRunnable {
    const nullability = optPrio(alt("NOT NULL", "NULL"));
    const field = seq(optPrio(str("KEY")), CDSName, ":", CDSType, nullability);
    const assocOrComp = seq(CDSName, ":", alt(CDSComposition, CDSAssociation));
    return seq(star(CDSAnnotation), alt(field, assocOrComp), ";");
  }
}