@cap-js/change-tracking 1.1.3 → 2.0.0-beta.1

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/README.md +45 -71
  3. package/_i18n/i18n.properties +12 -20
  4. package/_i18n/i18n_ar.properties +3 -3
  5. package/_i18n/i18n_bg.properties +3 -3
  6. package/_i18n/i18n_cs.properties +3 -3
  7. package/_i18n/i18n_da.properties +3 -3
  8. package/_i18n/i18n_de.properties +3 -3
  9. package/_i18n/i18n_el.properties +3 -3
  10. package/_i18n/i18n_en.properties +3 -3
  11. package/_i18n/i18n_en_US_saptrc.properties +3 -32
  12. package/_i18n/i18n_es.properties +3 -3
  13. package/_i18n/i18n_es_MX.properties +3 -3
  14. package/_i18n/i18n_fi.properties +3 -3
  15. package/_i18n/i18n_fr.properties +3 -3
  16. package/_i18n/i18n_he.properties +3 -3
  17. package/_i18n/i18n_hr.properties +3 -3
  18. package/_i18n/i18n_hu.properties +3 -3
  19. package/_i18n/i18n_it.properties +3 -3
  20. package/_i18n/i18n_ja.properties +3 -3
  21. package/_i18n/i18n_kk.properties +3 -3
  22. package/_i18n/i18n_ko.properties +3 -3
  23. package/_i18n/i18n_ms.properties +3 -3
  24. package/_i18n/i18n_nl.properties +3 -3
  25. package/_i18n/i18n_no.properties +3 -3
  26. package/_i18n/i18n_pl.properties +3 -3
  27. package/_i18n/i18n_pt.properties +3 -3
  28. package/_i18n/i18n_ro.properties +3 -3
  29. package/_i18n/i18n_ru.properties +3 -3
  30. package/_i18n/i18n_sh.properties +3 -3
  31. package/_i18n/i18n_sk.properties +3 -3
  32. package/_i18n/i18n_sl.properties +3 -3
  33. package/_i18n/i18n_sv.properties +3 -3
  34. package/_i18n/i18n_th.properties +3 -3
  35. package/_i18n/i18n_tr.properties +3 -3
  36. package/_i18n/i18n_uk.properties +3 -3
  37. package/_i18n/i18n_vi.properties +3 -3
  38. package/_i18n/i18n_zh_CN.properties +3 -3
  39. package/_i18n/i18n_zh_TW.properties +3 -3
  40. package/cds-plugin.js +17 -260
  41. package/index.cds +199 -75
  42. package/lib/TriggerCQN2SQL.js +42 -0
  43. package/lib/h2/java-codegen.js +843 -0
  44. package/lib/h2/register.js +27 -0
  45. package/lib/h2/triggers.js +42 -0
  46. package/lib/hana/composition.js +250 -0
  47. package/lib/hana/register.js +28 -0
  48. package/lib/hana/sql-expressions.js +224 -0
  49. package/lib/hana/triggers.js +254 -0
  50. package/lib/localization.js +59 -115
  51. package/lib/model-enhancer.js +266 -0
  52. package/lib/postgres/composition.js +191 -0
  53. package/lib/postgres/register.js +44 -0
  54. package/lib/postgres/sql-expressions.js +271 -0
  55. package/lib/postgres/triggers.js +115 -0
  56. package/lib/skipHandlers.js +34 -0
  57. package/lib/sqlite/composition.js +235 -0
  58. package/lib/sqlite/register.js +28 -0
  59. package/lib/sqlite/sql-expressions.js +238 -0
  60. package/lib/sqlite/triggers.js +164 -0
  61. package/lib/utils/change-tracking.js +394 -0
  62. package/lib/utils/composition-helpers.js +67 -0
  63. package/lib/utils/entity-collector.js +297 -0
  64. package/lib/utils/session-variables.js +278 -0
  65. package/lib/utils/trigger-utils.js +94 -0
  66. package/package.json +57 -39
  67. package/lib/change-log.js +0 -575
  68. package/lib/entity-helper.js +0 -216
  69. package/lib/format-options.js +0 -66
  70. package/lib/template-processor.js +0 -115
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Entiti Perkhidmatan
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Cipta
43
+ Changes.modification.create=Cipta
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=Kemas kini
45
+ Changes.modification.update=Kemas kini
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Padam
47
+ Changes.modification.delete=Padam
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=Diubah pada
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Service-entiteit
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Cre\u00EBren
43
+ Changes.modification.create=Cre\u00EBren
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=Actualiseren
45
+ Changes.modification.update=Actualiseren
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Verwijderen
47
+ Changes.modification.delete=Verwijderen
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=Gewijzigd om
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Tjenesteentitet
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Opprett
43
+ Changes.modification.create=Opprett
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=Oppdater
45
+ Changes.modification.update=Oppdater
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Slett
47
+ Changes.modification.delete=Slett
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=Endret kl.
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Encja us\u0142ugi
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Utw\u00F3rz
43
+ Changes.modification.create=Utw\u00F3rz
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=Aktualizuj
45
+ Changes.modification.update=Aktualizuj
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Usu\u0144
47
+ Changes.modification.delete=Usu\u0144
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=Zmieniono o
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Entidade de servi\u00E7o
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Criar
43
+ Changes.modification.create=Criar
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=Atualizar
45
+ Changes.modification.update=Atualizar
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Excluir
47
+ Changes.modification.delete=Excluir
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=Modificado em
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Entitate serviciu
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Creare
43
+ Changes.modification.create=Creare
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=Actualizare
45
+ Changes.modification.update=Actualizare
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=\u0218tergere
47
+ Changes.modification.delete=\u0218tergere
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=Modificat la
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=\u0421\u0443\u0449\u043D\u043E\u0441\u0442\u044C \u0441\
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=\u0421\u043E\u0437\u0434\u0430\u0442\u044C
43
+ Changes.modification.create=\u0421\u043E\u0437\u0434\u0430\u0442\u044C
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=\u041E\u0431\u043D\u043E\u0432\u0438\u0442\u044C
45
+ Changes.modification.update=\u041E\u0431\u043D\u043E\u0432\u0438\u0442\u044C
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=\u0423\u0434\u0430\u043B\u0438\u0442\u044C
47
+ Changes.modification.delete=\u0423\u0434\u0430\u043B\u0438\u0442\u044C
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=\u0412\u0440\u0435\u043C\u044F \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u044F
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Entitet usluga
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Kreiraj
43
+ Changes.modification.create=Kreiraj
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=A\u017Euriraj
45
+ Changes.modification.update=A\u017Euriraj
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Izbri\u0161i
47
+ Changes.modification.delete=Izbri\u0161i
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=Promenjeno
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Servisn\u00E1 entita
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Vytvori\u0165
43
+ Changes.modification.create=Vytvori\u0165
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=Aktualiz\u00E1cia
45
+ Changes.modification.update=Aktualiz\u00E1cia
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Odstr\u00E1ni\u0165
47
+ Changes.modification.delete=Odstr\u00E1ni\u0165
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=Zmenen\u00E9 o
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Entiteta storitve
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Ustvari
43
+ Changes.modification.create=Ustvari
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=Posodobi
45
+ Changes.modification.update=Posodobi
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Izbri\u0161i
47
+ Changes.modification.delete=Izbri\u0161i
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=Spremenjeno ob
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Tj\u00E4nstentitet
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Skapa
43
+ Changes.modification.create=Skapa
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=Uppdatera
45
+ Changes.modification.update=Uppdatera
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Radera
47
+ Changes.modification.delete=Radera
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=\u00C4ndring kl.
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=\u0E40\u0E2D\u0E19\u0E17\u0E34\u0E15\u0E35\u0E49\u0E01\u
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=\u0E2A\u0E23\u0E49\u0E32\u0E07
43
+ Changes.modification.create=\u0E2A\u0E23\u0E49\u0E32\u0E07
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=\u0E2D\u0E31\u0E1E\u0E40\u0E14\u0E17
45
+ Changes.modification.update=\u0E2D\u0E31\u0E1E\u0E40\u0E14\u0E17
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=\u0E25\u0E1A
47
+ Changes.modification.delete=\u0E25\u0E1A
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=\u0E40\u0E1B\u0E25\u0E35\u0E48\u0E22\u0E19\u0E41\u0E1B\u0E25\u0E07\u0E40\u0E21\u0E37\u0E48\u0E2D
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Servis birimi
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Olu\u015Ftur
43
+ Changes.modification.create=Olu\u015Ftur
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=G\u00FCncelle
45
+ Changes.modification.update=G\u00FCncelle
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Sil
47
+ Changes.modification.delete=Sil
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=De\u011Fi\u015Fiklik saati
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=\u0421\u0443\u0442\u043D\u0456\u0441\u0442\u044C \u0441\
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=\u0421\u0442\u0432\u043E\u0440\u0438\u0442\u0438
43
+ Changes.modification.create=\u0421\u0442\u0432\u043E\u0440\u0438\u0442\u0438
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=\u041E\u043D\u043E\u0432\u0438\u0442\u0438
45
+ Changes.modification.update=\u041E\u043D\u043E\u0432\u0438\u0442\u0438
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=\u0412\u0438\u0434\u0430\u043B\u0438\u0442\u0438
47
+ Changes.modification.delete=\u0412\u0438\u0434\u0430\u043B\u0438\u0442\u0438
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=\u0427\u0430\u0441 \u0437\u043C\u0456\u043D\u0438
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=Th\u1EF1c th\u1EC3 d\u1ECBch v\u1EE5
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=Ta\u0323o
43
+ Changes.modification.create=Ta\u0323o
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=C\u00E2\u0323p nh\u00E2\u0323t
45
+ Changes.modification.update=C\u00E2\u0323p nh\u00E2\u0323t
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=Xo\u0301a
47
+ Changes.modification.delete=Xo\u0301a
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=Thay \u0111\u00F4\u0309i lu\u0301c
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=\u670D\u52A1\u5B9E\u4F53
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=\u521B\u5EFA
43
+ Changes.modification.create=\u521B\u5EFA
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=\u66F4\u65B0
45
+ Changes.modification.update=\u66F4\u65B0
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=\u5220\u9664
47
+ Changes.modification.delete=\u5220\u9664
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=\u66F4\u6539\u65F6\u95F4
50
50
  #XFLD: Field label
@@ -40,11 +40,11 @@ ChangeLog.serviceEntity=\u670D\u52D9\u5BE6\u9AD4
40
40
  ## Change Log Modifications##
41
41
  ########################################
42
42
  #XFLD: Field label
43
- ChangeLog.modification.create=\u5EFA\u7ACB
43
+ Changes.modification.create=\u5EFA\u7ACB
44
44
  #XFLD: Field label
45
- ChangeLog.modification.update=\u66F4\u65B0
45
+ Changes.modification.update=\u66F4\u65B0
46
46
  #XFLD: Field label
47
- ChangeLog.modification.delete=\u522A\u9664
47
+ Changes.modification.delete=\u522A\u9664
48
48
  #XFLD: Field label
49
49
  ChangeLog.createdAt=\u66F4\u6539\u6642\u9593
50
50
  #XFLD: Field label
package/cds-plugin.js CHANGED
@@ -1,260 +1,17 @@
1
- const cds = require('@sap/cds')
2
- const DEBUG = cds.debug('changelog')
3
-
4
- const isRoot = 'change-tracking-isRootEntity'
5
- const hasParent = 'change-tracking-parentEntity'
6
-
7
- const isChangeTracked = (entity) => {
8
- if (entity.query?.SET?.op === 'union') return false // REVISIT: should that be an error or warning?
9
- if (entity['@changelog']) return true
10
- if (Object.values(entity.elements).some(e => e['@changelog'])) return true
11
- }
12
-
13
- // Add the appropriate Side Effects attribute to the custom action
14
- const addSideEffects = (actions, flag, element) => {
15
- if (!flag && (element === undefined || element === null)) {
16
- return
17
- }
18
-
19
- for (const se of Object.values(actions)) {
20
- const target = flag ? 'TargetProperties' : 'TargetEntities'
21
- const sideEffectAttr = se[`@Common.SideEffects.${target}`]
22
- const property = flag ? 'changes' : { '=': `${element}.changes` }
23
- if (sideEffectAttr?.length >= 0) {
24
- sideEffectAttr.findIndex(
25
- (item) =>
26
- (item['='] ? item['='] : item) ===
27
- (property['='] ? property['='] : property)
28
- ) === -1 && sideEffectAttr.push(property)
29
- } else {
30
- se[`@Common.SideEffects.${target}`] = [property]
31
- }
32
- }
33
- }
34
-
35
- function setChangeTrackingIsRootEntity (entity, csn, val = true) {
36
- if (csn.definitions?.[entity.name]) {
37
- csn.definitions[entity.name][isRoot] = val
38
- }
39
- }
40
-
41
- function checkAndSetRootEntity (parentEntity, entity, csn) {
42
- if (entity[isRoot] === false) {
43
- return entity
44
- }
45
- if (parentEntity) {
46
- return compositionRoot(parentEntity, csn)
47
- } else {
48
- setChangeTrackingIsRootEntity(entity, csn)
49
- return { ...csn.definitions?.[entity.name], name: entity.name }
50
- }
51
- }
52
-
53
- function processEntities (m) {
54
- for (let name in m.definitions) {
55
- compositionRoot({ ...m.definitions[name], name }, m)
56
- }
57
- }
58
-
59
- function compositionRoot (entity, csn) {
60
- if (!entity || entity.kind !== 'entity') {
61
- return
62
- }
63
- const parentEntity = compositionParent(entity, csn)
64
- return checkAndSetRootEntity(parentEntity, entity, csn)
65
- }
66
-
67
- function compositionParent (entity, csn) {
68
- if (!entity || entity.kind !== 'entity') {
69
- return
70
- }
71
- const parentAssociation = compositionParentAssociation(entity, csn)
72
- return parentAssociation ?? null
73
- }
74
-
75
- function compositionParentAssociation (entity, csn) {
76
- if (!entity || entity.kind !== 'entity') {
77
- return
78
- }
79
- const elements = entity.elements ?? {}
80
-
81
- // Add the change-tracking-isRootEntity attribute of the child entity
82
- processCompositionElements(entity, csn, elements)
83
-
84
- const hasChildFlag = entity[isRoot] !== false
85
- const hasParentEntity = entity[hasParent]
86
-
87
- if (hasChildFlag || !hasParentEntity) {
88
- // Find parent association of the entity
89
- const parentAssociation = findParentAssociation(entity, csn, elements)
90
- if (parentAssociation) {
91
- const parentAssociationTarget = elements[parentAssociation]?.target
92
- if (hasChildFlag) setChangeTrackingIsRootEntity(entity, csn, false)
93
- return {
94
- ...csn.definitions?.[parentAssociationTarget],
95
- name: parentAssociationTarget
96
- }
97
- } else return
98
- }
99
- return { ...csn.definitions?.[entity.name], name: entity.name }
100
- }
101
-
102
- function processCompositionElements (entity, csn, elements) {
103
- for (const name in elements) {
104
- const element = elements[name]
105
- const target = element?.target
106
- const definition = csn.definitions?.[target]
107
- if (
108
- element.type !== 'cds.Composition' ||
109
- target === entity.name ||
110
- !definition ||
111
- definition[isRoot] === false
112
- ) {
113
- continue
114
- }
115
- setChangeTrackingIsRootEntity({ ...definition, name: target }, csn, false)
116
- }
117
- }
118
-
119
- function findParentAssociation (entity, csn, elements) {
120
- return Object.keys(elements).find((name) => {
121
- const element = elements[name]
122
- const target = element?.target
123
- if (element.type === 'cds.Association' && target !== entity.name) {
124
- const parentDefinition = csn.definitions?.[target] ?? {}
125
- const parentElements = parentDefinition?.elements ?? {}
126
- return !!Object.keys(parentElements).find((parentEntityName) => {
127
- const parentElement = parentElements?.[parentEntityName] ?? {}
128
- if (parentElement.type === 'cds.Composition') {
129
- const isCompositionEntity = parentElement.target === entity.name
130
- // add parent information in the current entity
131
- if (isCompositionEntity) {
132
- csn.definitions[entity.name][hasParent] = {
133
- associationName: name,
134
- entityName: target
135
- }
136
- }
137
- return isCompositionEntity
138
- }
139
- })
140
- }
141
- })
142
- }
143
-
144
-
145
-
146
- /**
147
- * Returns an expression for the key of the given entity, which we can use as the right-hand-side of an ON condition.
148
- */
149
- function entityKey4 (entity) {
150
- const xpr = []
151
- for (let k in entity.elements) {
152
- const e = entity.elements[k]; if (!e.key) continue
153
- if (xpr.length) xpr.push('||')
154
- if (e.type === 'cds.Association') xpr.push({ ref: [k, e.keys?.[0]?.ref?.[0]] })
155
- else xpr.push({ ref:[k] })
156
- }
157
- return xpr
158
- }
159
-
160
-
161
- // Unfold @changelog annotations in loaded model
162
- function enhanceModel (m) {
163
-
164
- const _enhanced = 'sap.changelog.enhanced'
165
- if (m.meta?.[_enhanced]) return // already enhanced
166
-
167
- // Get definitions from Dummy entity in our models
168
- const { 'sap.changelog.aspect': aspect } = m.definitions; if (!aspect) return // some other model
169
- const { '@UI.Facets': [facet], elements: { changes } } = aspect
170
- if (changes.on.length > 2) changes.on.pop() // remove ID -> filled in below
171
-
172
- processEntities(m) // REVISIT: why is that required ?!?
173
-
174
- for (let name in m.definitions) {
175
-
176
- const entity = m.definitions[name]
177
- if (entity.kind === 'entity' && !entity['@cds.autoexposed'] && isChangeTracked(entity)) {
178
-
179
- if (!entity['@changelog.disable_assoc']) {
180
-
181
- // Add association to ChangeView...
182
- const keys = entityKey4(entity); if (!keys.length) continue // If no key attribute is defined for the entity, the logic to add association to ChangeView should be skipped.
183
- const assoc = new cds.builtin.classes.Association({ ...changes, on: [ ...changes.on, ...keys ] })
184
-
185
- // --------------------------------------------------------------------
186
- // PARKED: Add auto-exposed projection on ChangeView to service if applicable
187
- // const namespace = name.match(/^(.*)\.[^.]+$/)[1]
188
- // const service = m.definitions[namespace]
189
- // if (service) {
190
- // const projection = {from:{ref:[assoc.target]}}
191
- // m.definitions[assoc.target = namespace + '.' + Changes] = {
192
- // '@cds.autoexposed':true, kind:'entity', projection
193
- // }
194
- // DEBUG?.(`\n
195
- // extend service ${namespace} with {
196
- // entity ${Changes} as projection on ${projection.from.ref[0]};
197
- // }
198
- // `.replace(/ {10}/g,''))
199
- // }
200
- // --------------------------------------------------------------------
201
-
202
- DEBUG?.(`\n
203
- extend ${name} with {
204
- changes : Association to many ${assoc.target} on ${ assoc.on.map(x => x.ref?.join('.') || x).join(' ') };
205
- }
206
- `.replace(/ {8}/g,''))
207
- const query = entity.projection || entity.query?.SELECT
208
- if (query) (query.columns ??= ['*']).push({ as: 'changes', cast: assoc })
209
- else if (entity.elements) entity.elements.changes = assoc
210
-
211
- // Add UI.Facet for Change History List
212
- if (!entity['@changelog.disable_facet'])
213
- entity['@UI.Facets']?.push(facet)
214
- }
215
-
216
- if (entity.actions) {
217
- const hasParentInfo = entity[hasParent]
218
- const entityName = hasParentInfo?.entityName
219
- const parentEntity = entityName ? m.definitions[entityName] : null
220
- const isParentRootAndHasFacets = parentEntity?.[isRoot] && parentEntity?.['@UI.Facets']
221
- if (entity[isRoot] && entity['@UI.Facets']) {
222
- // Add side effects for root entity
223
- addSideEffects(entity.actions, true)
224
- } else if (isParentRootAndHasFacets) {
225
- // Add side effects for child entity
226
- addSideEffects(entity.actions, false, hasParentInfo?.associationName)
227
- }
228
- }
229
- }
230
- }
231
- (m.meta ??= {})[_enhanced] = true
232
- }
233
-
234
- // Add generic change tracking handlers
235
- function addGenericHandlers() {
236
- const { track_changes, _afterReadChangeView } = require("./lib/change-log")
237
- for (const srv of cds.services) {
238
- if (srv instanceof cds.ApplicationService) {
239
- let any = false
240
- for (const entity of Object.values(srv.entities)) {
241
- if (isChangeTracked(entity)) {
242
- cds.db.before("CREATE", entity, track_changes)
243
- cds.db.before("UPDATE", entity, track_changes)
244
- cds.db.before("DELETE", entity, track_changes)
245
- any = true
246
- }
247
- }
248
- if (any && srv.entities.ChangeView) {
249
- srv.after("READ", srv.entities.ChangeView, _afterReadChangeView)
250
- }
251
- }
252
- }
253
- }
254
-
255
-
256
- // Register plugin hooks
257
- cds.on('compile.for.runtime', csn => { DEBUG?.('on','compile.for.runtime'); enhanceModel(csn) })
258
- cds.on('compile.to.edmx', csn => { DEBUG?.('on','compile.to.edmx'); enhanceModel(csn) })
259
- cds.on('compile.to.dbx', csn => { DEBUG?.('on','compile.to.dbx'); enhanceModel(csn) })
260
- cds.on('served', addGenericHandlers)
1
+ const cds = require('@sap/cds');
2
+
3
+ const { enhanceModel } = require('./lib/model-enhancer.js');
4
+ const { registerSessionVariableHandlers } = require('./lib/skipHandlers.js');
5
+ const { deploySQLiteTriggers } = require('./lib/sqlite/register.js');
6
+ const { registerPostgresCompilerHook, deployPostgresLabels } = require('./lib/postgres/register.js');
7
+ const { registerH2CompilerHook } = require('./lib/h2/register.js');
8
+ const { registerHDICompilerHook } = require('./lib/hana/register.js');
9
+
10
+ cds.on('loaded', enhanceModel);
11
+ cds.on('listening', registerSessionVariableHandlers);
12
+ cds.once('served', deploySQLiteTriggers);
13
+ cds.once('served', deployPostgresLabels);
14
+
15
+ registerH2CompilerHook();
16
+ registerPostgresCompilerHook();
17
+ registerHDICompilerHook();