@cap-js/change-tracking 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,27 @@ All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/).
6
6
 
7
+ ## Version 1.0.5 - 15.01.24
8
+
9
+ ### Fixed
10
+
11
+ - Error on HANA when logging Boolean or Numeric Data
12
+
13
+ ## Version 1.0.4 - 08.01.24
14
+
15
+ ### Added
16
+
17
+ - Side effect annotation now allows automatic refresh after a custom action caused changes
18
+
19
+ ### Changed
20
+
21
+ - Added a check to disable change tracking for views with a UNION
22
+
23
+ ### Fixed
24
+
25
+ - Handling of associations within change tracked entities
26
+ - Handling of change log when custom actions on child entities are called
27
+
7
28
  ## Version 1.0.3 - 10.11.23
8
29
 
9
30
  ### Added
@@ -37,3 +58,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
37
58
  ### Added
38
59
 
39
60
  - Initial release
61
+
package/cds-plugin.js CHANGED
@@ -1,10 +1,28 @@
1
1
  const cds = require('@sap/cds')
2
2
 
3
3
  const isChangeTracked = (entity) => (
4
- entity['@changelog']
5
- || entity.elements && Object.values(entity.elements).some(e => e['@changelog'])
4
+ (entity['@changelog']
5
+ || entity.elements && Object.values(entity.elements).some(e => e['@changelog'])) && entity.query?.SET?.op !== 'union'
6
6
  )
7
7
 
8
+ // Add the appropriate Side Effects attribute to the custom action
9
+ const addSideEffects = (actions, flag, element) => {
10
+ for (const se of Object.values(actions)) {
11
+ const target = flag ? 'TargetProperties' : 'TargetEntities'
12
+ const sideEffectAttr = se[`@Common.SideEffects.${target}`]
13
+ const property = flag ? 'changes' : { '=': `${element}.changes` }
14
+ if (sideEffectAttr?.length >= 0) {
15
+ sideEffectAttr.findIndex(
16
+ (item) =>
17
+ (item['='] ? item['='] : item) ===
18
+ (property['='] ? property['='] : property)
19
+ ) === -1 && sideEffectAttr.push(property)
20
+ } else {
21
+ se[`@Common.SideEffects.${target}`] = [property]
22
+ }
23
+ }
24
+ }
25
+
8
26
 
9
27
  // Unfold @changelog annotations in loaded model
10
28
  cds.on('loaded', m => {
@@ -23,7 +41,9 @@ cds.on('loaded', m => {
23
41
  for (let e in elms) if (elms[e].key) keys.push(e)
24
42
 
25
43
  // Add association to ChangeView...
26
- const on = [...changes.on]; keys.forEach((k, i) => { i && on.push('||'); on.push({ ref: [k] }) })
44
+ const on = [...changes.on]; keys.forEach((k, i) => { i && on.push('||'); on.push({
45
+ ref: k === 'up_' ? [k,'ID'] : [k] // REVISIT: up_ handling is a dirty hack for now
46
+ })})
27
47
  const assoc = { ...changes, on }
28
48
  const query = entity.projection || entity.query?.SELECT
29
49
  if (query) {
@@ -34,6 +54,31 @@ cds.on('loaded', m => {
34
54
 
35
55
  // Add UI.Facet for Change History List
36
56
  entity['@UI.Facets']?.push(facet)
57
+
58
+ // The changehistory list should be refreshed after the custom action is triggered
59
+ if (entity.actions) {
60
+
61
+ // Update the changehistory list on the current entity when the custom action of the entity is triggered
62
+ if (entity['@UI.Facets']) {
63
+ addSideEffects(entity.actions, true)
64
+ }
65
+
66
+ // When the custom action of the child entity is performed, the change history list of the parent entity is updated
67
+ if (entity.elements) {
68
+ //ToDo: Revisit Breaklook with node.js Expert
69
+ breakLoop: for (const [ele, eleValue] of Object.entries(entity.elements)) {
70
+ const parentEntity = m.definitions[eleValue.target]
71
+ if (parentEntity && parentEntity['@UI.Facets'] && eleValue.type === 'cds.Association') {
72
+ for (const value of Object.values(parentEntity.elements)) {
73
+ if (value.target === name) {
74
+ addSideEffects(entity.actions, false, ele)
75
+ break breakLoop
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
37
82
  }
38
83
  }
39
84
  })
package/lib/change-log.js CHANGED
@@ -301,8 +301,8 @@ function _trackedChanges4 (srv, target, diff) {
301
301
  entity: getDBEntity(element.parent).name,
302
302
  serviceEntity: element.parent.name,
303
303
  attribute: element["@odata.foreignKey4"] || key,
304
- valueChangedFrom: from || '',
305
- valueChangedTo: to || '',
304
+ valueChangedFrom: from?? '',
305
+ valueChangedTo: to?? '',
306
306
  valueDataType: element.type,
307
307
  modification: row._op,
308
308
  keys,
@@ -359,7 +359,7 @@ async function track_changes (req) {
359
359
  if (!changes) return
360
360
 
361
361
  await _formatChangeLog(changes, req)
362
- if (isComposition && !isDraftEnabled) {
362
+ if (isComposition) {
363
363
  [ target, entityKey ] = await _prepareChangeLogForComposition(target, entityKey, changes, this)
364
364
  }
365
365
  const dbEntity = getDBEntity(target)
@@ -367,7 +367,11 @@ async function track_changes (req) {
367
367
  entity: dbEntity.name,
368
368
  entityKey: entityKey,
369
369
  serviceEntity: target.name,
370
- changes: changes.filter(c => c.valueChangedFrom || c.valueChangedTo),
370
+ changes: changes.filter(c => c.valueChangedFrom || c.valueChangedTo).map((c) => ({
371
+ ...c,
372
+ valueChangedFrom: `${c.valueChangedFrom ?? ''}`,
373
+ valueChangedTo: `${c.valueChangedTo ?? ''}`,
374
+ })),
371
375
  })
372
376
  }
373
377
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/change-tracking",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "CDS plugin providing out-of-the box support for automatic capturing, storing, and viewing of the change records of modeled entities.",
5
5
  "repository": "cap-js/change-tracking",
6
6
  "author": "SAP SE (https://www.sap.com)",