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

Adding element kind #208

Merged
merged 2 commits into from
Oct 24, 2024
Merged

Adding element kind #208

merged 2 commits into from
Oct 24, 2024

Conversation

ThePlenkov
Copy link
Contributor

Kind element - is a valid type

Kind element - is a valid type
@daogrady
Copy link
Contributor

Hi Petr,

thanks for the contribution!
@johannes-vogel @David-Kunz could one of you please confirm that this is valid? Thanks!

Best,
Daniel

@ThePlenkov
Copy link
Contributor Author

it would be great to proceed with this PR too. @daogrady Thanks!

@daogrady
Copy link
Contributor

daogrady commented Oct 2, 2024

Sure, can you please cite a relevant section from CAPire or show a runtime example so I can confirm this is valid?

@ThePlenkov
Copy link
Contributor Author

well, I see your point. Indeed - doesn't seem like documented because it's not used in the compiled file, but if we talk about parsed model - the kind element is there. I don't already remember what was the purpose - but I had to filter out elements based on this kind in my code:

  const model = await cds.load('hana2cds');
  const db = await cds.connect.to('db', {
    model: model as never,
    kind: 'hana',
    credentials: requires?.db?.credentials,
  });

  for (const [entity, definiton] of Object.entries(db.entities)) {

    //define CSV headers
    const headers = Object.values(definiton.elements)
      .filter(
        (e) => (e.kind as kinds) === 'element' && e.type !== 'cds.Association'
      )
      .map((e) => e.name);

so it's a good point which other selector do we need to use.. I already do not remember why e.type !== 'cds.Association' was not enough to distiguish columns from assitiations.. may be need to check again. But this is a fact - that parsed model has kind: element for all the elements. It's just a question - what is the case when elements have something else.. Probably i just don't need to use it all - will check it

@daogrady
Copy link
Contributor

Hi @ThePlenkov ,

were you able to find something pointing to the existence of such a property? If not, I'd like to close this PR for now.

Best,
Daniel

@ThePlenkov
Copy link
Contributor Author

The point is - it is not documented but it is used everywhere in the code , it's 100% one of the core csn types, they just don't render it. Can we ping someone from the compiler module may be to check it?

@daogrady
Copy link
Contributor

When you say "in the code", do you mean "in samples" (like in the bookstore), or "the cds implementation code"? In case of the former, please link any such example so I can confirm it is valid.

@ThePlenkov
Copy link
Contributor Author

No no I mean CDs core code itself. They use it in conditional logic

@daogrady
Copy link
Contributor

daogrady commented Oct 23, 2024

The general policy for things that are not documented in CAPire is, that they are not part of the API and are thus probably not documented on purpose. That goes especially for things that can only be found in the @sap/cds package implementation, as well as things you may find when inspecting runtime artefacts in the debugger.

@David-Kunz could you maybe chime in and clear up whether 'element' (not: 'elements') is a valid value for .kind?

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.

I checked in with a team of the runtime and they confirmed that this change is indeed valid. Thanks for the contribution!

@daogrady daogrady enabled auto-merge (squash) October 24, 2024 10:12
@daogrady daogrady merged commit fc93c8e into cap-js:main Oct 24, 2024
6 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