Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add static property elements to entity classes #345

Merged

Conversation

stockbal
Copy link
Contributor

@stockbal stockbal commented Oct 4, 2024

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");

Comment on lines 16 to 18
import { entity } from '@sap/cds'

export type ElementsOf<T> = {[name in keyof Required<T>]: entity["elements"][string]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be the same as

import { type } from '@sap/cds'

export type ElementsOf<T> = {[name in keyof Required<T>]: type}

, or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I will make the change

Copy link
Contributor

@daogrady daogrady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for this addition! :)

@daogrady daogrady enabled auto-merge (squash) October 16, 2024 09:48
@daogrady daogrady merged commit bfed040 into cap-js:main Oct 16, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants