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

Generate Static Name Property #82

Merged
merged 6 commits into from
Oct 10, 2023
Merged

Generate Static Name Property #82

merged 6 commits into from
Oct 10, 2023

Conversation

daogrady
Copy link
Contributor

@daogrady daogrady commented Oct 2, 2023

Generated classes (both for singular and plural) will now contain a static .name property which contains the fully qualified name of the entity it was generated from.

namespace 'sap.bookshop';

entity Books {}

⬇️ (more or less)

// sap/bookshop/.index.ts
class Book {
  static name = 'sap.bookshop.Books'
}

class Books extends Array<Book> {
  static name = 'sap.bookshop.Books'
}

This allows the class and its transpiled form to be used as parameter for CDS functions that expect CSN definitions. Those will look for a .name property and use that as lookup key in the compiled CSN.

This PR is therefore a step towards using the transpiled index.js files in a TypeScript context.

Note that .name is actually a reserved name, so we have to forcefully inject it into the generated classes. This does not seem to be an issue, but should be kept an eye on.

@daogrady daogrady changed the title Static name property Generate Static Name Property Oct 2, 2023
@daogrady daogrady marked this pull request as ready for review October 10, 2023 07:04
@daogrady daogrady enabled auto-merge (squash) October 10, 2023 11:53
@daogrady daogrady merged commit 7fb36f5 into main Oct 10, 2023
7 checks passed
@daogrady daogrady deleted the feat/static-name-property branch October 10, 2023 11:56
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.

1 participant