cap-js / cds-typer

CDS type generator for JavaScript
Apache License 2.0
29 stars 10 forks source link

feat: add static property `elements` to entity classes #345

Closed stockbal closed 1 month ago

stockbal commented 1 month ago

Enables proper access to all entity elements of the underlying LinkedDefinition.

e.g.

entity Books : cuid {
  title : String;
  stock : Integer;
}

new property elements allows access to all defined elements of the entity and access the underlying LinkedDefinition of those elements.

import { Book } from "#cds-models/my/bookshop";
import cds from "@sap/cds";

if (Book.elements.ID instanceof cds.builtin.classes.UUID) console.log("ID is of type UUID");
if (Book.elements.stock instanceof cds.builtin.classes.Integer) console.log("stock is of type Integer");