-
Notifications
You must be signed in to change notification settings - Fork 8
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
[BUG] Missing "drafts" property to register handlers for draft enabled service #34
Comments
Hi Ludwig, thanks for reporting this issue! I will confer with the runtime team and look into this asap. Best, |
Just a quick idea, I believe export class Book extends _._managedAspect(_._cuidAspect(_BookAspect(__.Entity))) {
static drafts: typeof Book
} should be what you are looking for and should retain proper type support, is that correct? |
Yes, that's it. |
Hi Ludwig, just wanted to give you a quick update on this: I have implemented the change in a PoC, but I still need to confer with the runtime team on this, of which many are currently in their well-deserved holiday break. So I have not forgotten this, it just needs to go through some planning, approval, etc. And I didn't want this issue to just become stale. 🙂 Best, |
Hi Daniel, thanks for the update. The other thing I noticed is, that you only add the // model.cds
entity Books : cuid {
title : String;
channels : Composition of many DistributionChannels on channels.book = $self;
entity DistributionChannels : cuid {
channelName : String;
book : Association to Books;
} // service.cds
service CatalogService {
@odata.draft.enabled
entity Books as projection on my.Books;
// will be draft enabled as well
entity DistributionChannels as projection on my.DistributionChannels;
} I experimented a bit with the What do you think? 😊 Regards, |
Hi Ludwig, thanks for poking around and the feedback on your findings!
You are right, this would be the more correct way to do it. I think there is even some
There is a way to propagate annotations down to child entities by using the Best, |
Hi Ludwig, I have conferred with the project's PO on this and we have decided to implement this feature despite requiring some special handling. Best, |
Hi Daniel, I checked the PR and I have few remarks 😊. Singular
|
Hi Ludwig, thank you for your insights! I am not very draft-savvy myself, so your feedback it highly valued to work out the details. 🙂 Draft inheritence on compositionsI am not quite clear on the composition-semantics you are describing:
So in which of the following two examples would you expect the annotation to be propagated to the other entity? @odata.draft.enabled
entity A {}
entity B {
a: Composition of A
} entity A {}
@odata.draft.enabled
entity B {
a: Composition of A
} Singular
|
Hi Daniel If I may chime in on the question regarding which entities should be draft enabled. I believe it is your second example where as a result of the parent entity B being annotated as draft, that child entity A will be draft enabled as well.
And I don’t think this would change how you propagate the annotations but typically we would annotate drafts on a projection of an entity, rather then in the main entity definition (per examples also given by Ludwig a few comments up). Cheers |
Hi Lewin, thanks for weighing in on this! This implies that it's actually kind of complicated to determine if an entity is draft enabled or not. I will try to get a hold of one of the runtime colleagues and see if I can somehow access the elusive Best, |
Hi everyone, being referenced by a draft-enabled entity now causes the referenced entity to become draft-enabled as well. I am still poking around if I have gotten the semantics right, but you are welcome to apply the latest version of the respective feature branch to your model and let me know if something is missing. Best, |
Hi Daniel, I checked the feature branch and saw that you consider both associations and compositions as draft enabled if the parent is draft enabled. Regards, |
Hi Ludwig, thanks again for the feedback! I guess it shows that I have not touched drafts a lot myself. 🙂 Best, |
Hi everyone, draft-enablement is more of a rabbit hole than I had anticipated. I believe I have emulated1 the compiler's behaviour properly. If you find that your model still doesn't contain the appropriate properties, please let me know and maybe even include your model so I can include that in my local test pipeline. Best, Footnotes
|
Hi Daniel, I tested it again, but unfortunately I did not get the required types. Let's take the following db schema and service definition.
entity Books : managed, cuid {
title : String;
publishers : Composition of many Publishers
on publishers.book = $self;
}
entity Publishers : managed, cuid {
name : String;
book : Association to Books;
}
using my.bookshop as my from '../db/data-model';
service CatalogService {
@odata.draft.enabled
entity Books as projection on my.Books;
// also valid and produces also a draft enabled service entity
// entity Books as select * from my.Books;
entity Publishers as projection on my.Publishers;
// also valid and produces also a draft enabled service entity via composition
// entity Publishers as select * from my.Publishers;
} This is a common model/service that can be used with a Fiori Element LR/OP floorplan. With the correct annotations we would be able to edit a At the current PR state I would get the following draft-enabled types
From the service:
The The In summary I would say that the When should a type of a service entity get the
Hope that helps. Regards, |
Hi Ludwig, thank you for the extensive writeup! I missed the case of draft-enablement travelling up through projections as in your projection Cheers, |
Hi Ludwig, I have added the upwards propagation and the model you have provided looks fine with that change. I am currently working through some more models to see if they look as expected. If you have additional models with an added expectation, feel free to add them here, so I can verify that they're also receiving the appropriate draftability. Best, |
Hi Daniel, sorry, I did not have time to look into the changes until now. You still have the One could argue the types from CDS are "unclean" as well, in that regard that e.g. const db = await cds.connect.to("db");
// 'Books' from /db/data-model.cds in namespace 'my.bookshop'
const dbBooks = db.entities["Books"];
// \
// type is 'entity' from @sap/cds/apis/csn.d.ts
// will always print 'undefined' for db entities
console.log(dbBooks.drafts); I personally would welcome it if the Regards, |
Hi Ludwig, don't worry, I was still testing around myself, so no pressure anyway! 🙂 I forgot to address your concerns about the Still, I absolutely see your point that it might be misleading in some cases. So maybe we can approach this in two steps: Best, Footnotes
|
Hi Daniel, sounds good to me 😊👌. Regards, |
Hi,
Currently it is not possible to use the generated types to register handlers specific to draft entities.
Let's say we have following service file:
In the service handler file I would just like to use the following approach to register my handler for the draft entity
Books
.Possible solution
Enhance the generated types for draft enabled service entities in the following way:
This would solve the missing
drafts
property and would allow the handler registration. You would not get type inference in thedata
property unfortunately and a cast would be necessary.I am not sure if both features can be realized at once. But I personally could live with the cast 😊.
Regards,
Ludwig
Details
Versions of CDS tools[^3]:
Version of
cds-typer
[^1]: 0.5.0The text was updated successfully, but these errors were encountered: