cds-typer
cds-typer copied to clipboard
fix: creates `drafts` property only at entities that are truly draft enabled
Uses a new approach taken from @sap/cds-compiler/lib/transform/draft.js#generateDraft to detect draft enabled entities.
In essence there are only 2 cases when a draft table will be generated for an entity and therefore the .drafts
property of an entity will return a valid CSN entity reference during runtime.
-
Entity A is exposed in a service and has the annotation
@odata.draft.enabled
-
Entity B is used as composition in Entity A or an Entity (C-Z) that is a composition of Entity A
// model.cds entity A { b : Composition of B } entity B { c : Composition of C } entity C { d: Composition of D } entity D { } // service.cds serivce Service { @odata.draft.enabled entity P1 as projection on A; }
-
Service.P1
is draft enabled via annotation -
Service.B
,Service.C
andService.D
are draft enabled via composition relationship -
A
,B
,C
,D
remain as is and won't have access to a.drafts
property
-
Further remarks
- The refactoring uses the
inferred
csn model, because thextended
one does not include the autoexposed entities. - The draft state is no longer propagated top-down, as the model entities must not get the
drafts
properties. Instead, all draft enabled service-entities are collected in an array
Fixes #68