@@ -5,7 +5,7 @@ const hasParent = 'change-tracking-parentEntity'
5
5
6
6
const isChangeTracked = ( entity ) => (
7
7
( entity [ '@changelog' ]
8
- || entity . elements && Object . values ( entity . elements ) . some ( e => e [ '@changelog' ] ) ) && entity . query ?. SET ?. op !== 'union'
8
+ || entity . elements && Object . values ( entity . elements ) . some ( e => e [ '@changelog' ] ) ) && entity . query ?. SET ?. op !== 'union'
9
9
)
10
10
11
11
// Add the appropriate Side Effects attribute to the custom action
@@ -30,113 +30,113 @@ const addSideEffects = (actions, flag, element) => {
30
30
}
31
31
}
32
32
33
- function setChangeTrackingIsRootEntity ( entity , csn , val = true ) {
33
+ function setChangeTrackingIsRootEntity ( entity , csn , val = true ) {
34
34
if ( csn . definitions ?. [ entity . name ] ) {
35
- csn . definitions [ entity . name ] [ isRoot ] = val ;
35
+ csn . definitions [ entity . name ] [ isRoot ] = val
36
36
}
37
37
}
38
38
39
- function checkAndSetRootEntity ( parentEntity , entity , csn ) {
39
+ function checkAndSetRootEntity ( parentEntity , entity , csn ) {
40
40
if ( entity [ isRoot ] === false ) {
41
- return entity ;
41
+ return entity
42
42
}
43
43
if ( parentEntity ) {
44
- return compositionRoot ( parentEntity , csn ) ;
44
+ return compositionRoot ( parentEntity , csn )
45
45
} else {
46
- setChangeTrackingIsRootEntity ( entity , csn ) ;
47
- return { ...csn . definitions ?. [ entity . name ] , name : entity . name } ;
46
+ setChangeTrackingIsRootEntity ( entity , csn )
47
+ return { ...csn . definitions ?. [ entity . name ] , name : entity . name }
48
48
}
49
49
}
50
50
51
- function processEntities ( m ) {
51
+ function processEntities ( m ) {
52
52
for ( let name in m . definitions ) {
53
- compositionRoot ( { ...m . definitions [ name ] , name} , m )
53
+ compositionRoot ( { ...m . definitions [ name ] , name } , m )
54
54
}
55
55
}
56
56
57
- function compositionRoot ( entity , csn ) {
57
+ function compositionRoot ( entity , csn ) {
58
58
if ( ! entity || entity . kind !== 'entity' ) {
59
- return ;
59
+ return
60
60
}
61
- const parentEntity = compositionParent ( entity , csn ) ;
62
- return checkAndSetRootEntity ( parentEntity , entity , csn ) ;
61
+ const parentEntity = compositionParent ( entity , csn )
62
+ return checkAndSetRootEntity ( parentEntity , entity , csn )
63
63
}
64
64
65
- function compositionParent ( entity , csn ) {
65
+ function compositionParent ( entity , csn ) {
66
66
if ( ! entity || entity . kind !== 'entity' ) {
67
- return ;
67
+ return
68
68
}
69
- const parentAssociation = compositionParentAssociation ( entity , csn ) ;
70
- return parentAssociation ?? null ;
69
+ const parentAssociation = compositionParentAssociation ( entity , csn )
70
+ return parentAssociation ?? null
71
71
}
72
72
73
- function compositionParentAssociation ( entity , csn ) {
73
+ function compositionParentAssociation ( entity , csn ) {
74
74
if ( ! entity || entity . kind !== 'entity' ) {
75
- return ;
75
+ return
76
76
}
77
- const elements = entity . elements ?? { } ;
77
+ const elements = entity . elements ?? { }
78
78
79
79
// Add the change-tracking-isRootEntity attribute of the child entity
80
- processCompositionElements ( entity , csn , elements ) ;
80
+ processCompositionElements ( entity , csn , elements )
81
81
82
- const hasChildFlag = entity [ isRoot ] !== false ;
83
- const hasParentEntity = entity [ hasParent ] ;
82
+ const hasChildFlag = entity [ isRoot ] !== false
83
+ const hasParentEntity = entity [ hasParent ]
84
84
85
85
if ( hasChildFlag || ! hasParentEntity ) {
86
86
// Find parent association of the entity
87
- const parentAssociation = findParentAssociation ( entity , csn , elements ) ;
87
+ const parentAssociation = findParentAssociation ( entity , csn , elements )
88
88
if ( parentAssociation ) {
89
- const parentAssociationTarget = elements [ parentAssociation ] ?. target ;
90
- if ( hasChildFlag ) setChangeTrackingIsRootEntity ( entity , csn , false ) ;
89
+ const parentAssociationTarget = elements [ parentAssociation ] ?. target
90
+ if ( hasChildFlag ) setChangeTrackingIsRootEntity ( entity , csn , false )
91
91
return {
92
92
...csn . definitions ?. [ parentAssociationTarget ] ,
93
93
name : parentAssociationTarget
94
- } ;
95
- } else return ;
94
+ }
95
+ } else return
96
96
}
97
- return { ...csn . definitions ?. [ entity . name ] , name : entity . name } ;
97
+ return { ...csn . definitions ?. [ entity . name ] , name : entity . name }
98
98
}
99
99
100
- function processCompositionElements ( entity , csn , elements ) {
100
+ function processCompositionElements ( entity , csn , elements ) {
101
101
for ( const name in elements ) {
102
- const element = elements [ name ] ;
103
- const target = element ?. target ;
104
- const definition = csn . definitions ?. [ target ] ;
102
+ const element = elements [ name ]
103
+ const target = element ?. target
104
+ const definition = csn . definitions ?. [ target ]
105
105
if (
106
106
element . type !== 'cds.Composition' ||
107
107
target === entity . name ||
108
108
! definition ||
109
109
definition [ isRoot ] === false
110
110
) {
111
- continue ;
111
+ continue
112
112
}
113
- setChangeTrackingIsRootEntity ( { ...definition , name : target } , csn , false ) ;
113
+ setChangeTrackingIsRootEntity ( { ...definition , name : target } , csn , false )
114
114
}
115
115
}
116
116
117
- function findParentAssociation ( entity , csn , elements ) {
117
+ function findParentAssociation ( entity , csn , elements ) {
118
118
return Object . keys ( elements ) . find ( ( name ) => {
119
- const element = elements [ name ] ;
120
- const target = element ?. target ;
119
+ const element = elements [ name ]
120
+ const target = element ?. target
121
121
if ( element . type === 'cds.Association' && target !== entity . name ) {
122
- const parentDefinition = csn . definitions ?. [ target ] ?? { } ;
123
- const parentElements = parentDefinition ?. elements ?? { } ;
122
+ const parentDefinition = csn . definitions ?. [ target ] ?? { }
123
+ const parentElements = parentDefinition ?. elements ?? { }
124
124
return ! ! Object . keys ( parentElements ) . find ( ( parentEntityName ) => {
125
- const parentElement = parentElements ?. [ parentEntityName ] ?? { } ;
125
+ const parentElement = parentElements ?. [ parentEntityName ] ?? { }
126
126
if ( parentElement . type === 'cds.Composition' ) {
127
- const isCompositionEntity = parentElement . target === entity . name ;
127
+ const isCompositionEntity = parentElement . target === entity . name
128
128
// add parent information in the current entity
129
129
if ( isCompositionEntity ) {
130
130
csn . definitions [ entity . name ] [ hasParent ] = {
131
131
associationName : name ,
132
132
entityName : target
133
- } ;
133
+ }
134
134
}
135
- return isCompositionEntity ;
135
+ return isCompositionEntity
136
136
}
137
- } ) ;
137
+ } )
138
138
}
139
- } ) ;
139
+ } )
140
140
}
141
141
142
142
// Unfold @changelog annotations in loaded model
@@ -146,7 +146,7 @@ cds.on('loaded', m => {
146
146
const { 'sap.changelog.aspect' : aspect } = m . definitions ; if ( ! aspect ) return // some other model
147
147
const { '@UI.Facets' : [ facet ] , elements : { changes } } = aspect
148
148
changes . on . pop ( ) // remove ID -> filled in below
149
-
149
+
150
150
// Process entities to define the relation
151
151
processEntities ( m )
152
152
@@ -162,54 +162,53 @@ cds.on('loaded', m => {
162
162
keys . push ( {
163
163
e,
164
164
val : elms [ e ]
165
- } ) ;
165
+ } )
166
166
} else {
167
- keys . push ( e ) ;
167
+ keys . push ( e )
168
168
}
169
169
}
170
170
}
171
171
172
172
// If no key attribute is defined for the entity, the logic to add association to ChangeView should be skipped.
173
- if ( keys . length === 0 ) {
174
- continue ;
173
+ if ( keys . length === 0 ) {
174
+ continue
175
175
}
176
176
177
177
// Add association to ChangeView...
178
- const on = [ ...changes . on ] ;
178
+ const on = [ ...changes . on ]
179
179
keys . forEach ( ( k , i ) => {
180
- i && on . push ( "||" ) ;
180
+ i && on . push ( "||" )
181
181
on . push ( {
182
182
ref : k ?. val ?. type === "cds.Association" ? [ k . e , k . val . keys ?. [ 0 ] ?. ref ?. [ 0 ] ] : [ k ]
183
- } ) ;
184
- } ) ;
183
+ } )
184
+ } )
185
185
const assoc = { ...changes , on }
186
186
const query = entity . projection || entity . query ?. SELECT
187
- if ( ! entity [ '@changelog.disable_assoc' ] )
188
- {
189
- if ( query ) {
190
- ( query . columns ??= [ '*' ] ) . push ( { as : 'changes' , cast : assoc } )
191
- } else {
192
- entity . elements . changes = assoc
193
- }
187
+ if ( ! entity [ '@changelog.disable_assoc' ] ) {
188
+ if ( query ) {
189
+ ( query . columns ??= [ '*' ] ) . push ( { as : 'changes' , cast : assoc } )
190
+ } else {
191
+ entity . elements . changes = assoc
192
+ }
194
193
195
- // Add UI.Facet for Change History List
196
- if ( ! entity [ '@changelog.disable_facet' ] )
197
- entity [ '@UI.Facets' ] ?. push ( facet )
194
+ // Add UI.Facet for Change History List
195
+ if ( ! entity [ '@changelog.disable_facet' ] )
196
+ entity [ '@UI.Facets' ] ?. push ( facet )
198
197
}
199
198
200
199
if ( entity . actions ) {
201
- const hasParentInfo = entity [ hasParent ] ;
202
- const entityName = hasParentInfo ?. entityName ;
203
- const parentEntity = entityName ? m . definitions [ entityName ] : null ;
200
+ const hasParentInfo = entity [ hasParent ]
201
+ const entityName = hasParentInfo ?. entityName
202
+ const parentEntity = entityName ? m . definitions [ entityName ] : null
204
203
205
- const isParentRootAndHasFacets = parentEntity ?. [ isRoot ] && parentEntity ?. [ '@UI.Facets' ] ;
204
+ const isParentRootAndHasFacets = parentEntity ?. [ isRoot ] && parentEntity ?. [ '@UI.Facets' ]
206
205
207
206
if ( entity [ isRoot ] && entity [ '@UI.Facets' ] ) {
208
207
// Add side effects for root entity
209
- addSideEffects ( entity . actions , true ) ;
208
+ addSideEffects ( entity . actions , true )
210
209
} else if ( isParentRootAndHasFacets ) {
211
210
// Add side effects for child entity
212
- addSideEffects ( entity . actions , false , hasParentInfo ?. associationName ) ;
211
+ addSideEffects ( entity . actions , false , hasParentInfo ?. associationName )
213
212
}
214
213
}
215
214
}
0 commit comments