@sap/cds-dk 6.8.2 → 7.0.0

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 (218) hide show
  1. package/bin/activate.js +15 -7
  2. package/bin/add.js +29 -15
  3. package/bin/bind.js +49 -116
  4. package/bin/build.js +114 -0
  5. package/bin/cds.js +67 -24
  6. package/bin/compile/index.js +2 -2
  7. package/bin/deploy/index.js +46 -39
  8. package/bin/deploy/to-hana.js +11 -8
  9. package/bin/deploy/to-postgres.js +8 -2
  10. package/bin/deploy/to-sqlite.js +0 -1
  11. package/bin/env.js +75 -41
  12. package/bin/eval.js +3 -3
  13. package/bin/extend.js +17 -10
  14. package/bin/help.js +22 -21
  15. package/bin/import.js +10 -7
  16. package/bin/init.js +38 -17
  17. package/bin/login.js +69 -55
  18. package/bin/logout.js +12 -9
  19. package/bin/migrate.js +10 -4
  20. package/bin/pull.js +12 -5
  21. package/bin/push.js +24 -13
  22. package/bin/repl.js +1 -0
  23. package/bin/run.js +25 -0
  24. package/bin/subscribe.js +13 -8
  25. package/bin/unsubscribe.js +15 -8
  26. package/bin/upgrade.js +15 -9
  27. package/bin/util/log.js +24 -0
  28. package/bin/version.js +124 -0
  29. package/bin/watch.js +1 -35
  30. package/bin/watched.js +39 -0
  31. package/lib/bind/KubernetesApiAccessor.js +2 -2
  32. package/lib/bind/bindingManager.js +1 -1
  33. package/lib/bind/bindingUtil.js +0 -9
  34. package/lib/bind/cfKeyProvider.js +10 -72
  35. package/lib/bind/index.js +114 -0
  36. package/lib/bind/kubernetesCredentialsProvider.js +2 -2
  37. package/lib/bind/userCdsrcJsonStorageProvider.js +7 -44
  38. package/lib/build/buildTaskEngine.js +355 -0
  39. package/lib/build/buildTaskFactory.js +284 -0
  40. package/lib/build/buildTaskHandler.js +240 -0
  41. package/lib/build/buildTaskProvider.js +22 -0
  42. package/lib/build/buildTaskProviderFactory.js +182 -0
  43. package/lib/build/constants.js +56 -0
  44. package/lib/build/index.js +21 -0
  45. package/lib/build/provider/buildTaskHandlerEdmx.js +83 -0
  46. package/lib/build/provider/buildTaskHandlerFeatureToggles.js +132 -0
  47. package/lib/build/provider/buildTaskHandlerInternal.js +228 -0
  48. package/lib/build/provider/buildTaskProviderInternal.js +370 -0
  49. package/lib/build/provider/fiori/index.js +167 -0
  50. package/lib/build/provider/hana/2migration.js +179 -0
  51. package/lib/build/provider/hana/index.js +522 -0
  52. package/lib/build/provider/hana/migrationtable.js +472 -0
  53. package/lib/build/provider/hana/template/.hdiconfig-all +163 -0
  54. package/lib/build/provider/hana/template/.hdiconfig-cloud +137 -0
  55. package/lib/build/provider/hana/template/.hdinamespace +4 -0
  56. package/lib/build/provider/hana/template/package.json +12 -0
  57. package/lib/build/provider/hana/template/undeploy.json +5 -0
  58. package/lib/build/provider/java/index.js +93 -0
  59. package/lib/build/provider/java-cf/index.js +1 -0
  60. package/lib/build/provider/mtx/index.js +37 -0
  61. package/lib/build/provider/mtx/resourcesTarBuilder.js +94 -0
  62. package/lib/build/provider/mtx-extension/index.js +131 -0
  63. package/lib/build/provider/mtx-sidecar/index.js +138 -0
  64. package/lib/build/provider/node-cf/index.js +1 -0
  65. package/lib/build/provider/nodejs/index.js +178 -0
  66. package/lib/build/util.js +263 -0
  67. package/lib/cds.js +9 -21
  68. package/lib/client/auth_manager.js +39 -16
  69. package/lib/client/helper/dependency_helper.js +7 -6
  70. package/lib/client/push.js +2 -1
  71. package/lib/client/settings_manager.js +10 -39
  72. package/lib/deploy/to-hana/hana.js +273 -0
  73. package/lib/deploy/to-hana/hdiDeployUtil.js +68 -0
  74. package/lib/deploy/to-hana/mtaUtil.js +171 -0
  75. package/lib/import/asyncapi/importAsyncAPI.js +3 -2
  76. package/lib/import/asyncapi/index.js +5 -2
  77. package/lib/import/asyncapi/parserContext.js +67 -26
  78. package/lib/import/asyncapi/utils.js +34 -3
  79. package/lib/import/common.js +40 -30
  80. package/lib/import/importapi.js +36 -35
  81. package/lib/index.js +12 -17
  82. package/lib/init/constants.js +36 -71
  83. package/lib/init/index.js +18 -52
  84. package/lib/init/template/_merging/registry-mta.js +21 -3
  85. package/lib/init/template/approuter/files/mta.yaml.hbs +29 -29
  86. package/lib/init/template/approuter/files/values.yaml.hbs +5 -5
  87. package/lib/init/template/approuter/files/xs-app.json.hbs +8 -2
  88. package/lib/init/template/approuter/index.js +7 -8
  89. package/lib/init/template/auditlog/files/mta.yaml.hbs +5 -5
  90. package/lib/init/template/auditlog/files/package.json.hbs +13 -13
  91. package/lib/init/template/auditlog/index.js +3 -3
  92. package/lib/init/template/cf-manifest/files/manifest.yml.hbs +22 -22
  93. package/lib/init/template/cf-manifest/files/services-manifest.yml.hbs +3 -3
  94. package/lib/init/template/connectivity/files/mta.yaml.hbs +14 -0
  95. package/lib/init/template/connectivity/files/package.json.hbs +17 -0
  96. package/lib/init/template/connectivity/index.js +21 -4
  97. package/lib/init/template/data/index.js +5 -1
  98. package/lib/init/template/destination/files/mta.yaml.hbs +14 -0
  99. package/lib/init/template/destination/files/package.json.hbs +17 -0
  100. package/lib/init/template/{destinations → destination}/index.js +19 -13
  101. package/lib/init/template/enterprise-messaging/files/event-mesh.json.hbs +3 -3
  102. package/lib/init/template/enterprise-messaging/files/mta.yaml.hbs +5 -5
  103. package/lib/init/template/enterprise-messaging/files/package.json.hbs +9 -9
  104. package/lib/init/template/enterprise-messaging/files/xs-security.json.hbs +19 -0
  105. package/lib/init/template/enterprise-messaging/index.js +27 -6
  106. package/lib/init/template/enterprise-messaging-shared/files/event-mesh.json.hbs +3 -3
  107. package/lib/init/template/enterprise-messaging-shared/files/mta.yaml.hbs +5 -5
  108. package/lib/init/template/enterprise-messaging-shared/files/package.json.hbs +9 -9
  109. package/lib/init/template/enterprise-messaging-shared/index.js +4 -5
  110. package/lib/init/template/extensibility/files/package.json.hbs +10 -10
  111. package/lib/init/template/extensibility/index.js +8 -9
  112. package/lib/init/template/file-based-messaging/files/package.json.hbs +9 -9
  113. package/lib/init/template/file-based-messaging/index.js +3 -4
  114. package/lib/init/template/hana/files/db/package.json +1 -1
  115. package/lib/init/template/hana/files/mta.yaml.hbs +21 -21
  116. package/lib/init/template/hana/files/package.json.hbs +16 -22
  117. package/lib/init/template/hana/files/values.yaml.hbs +1 -1
  118. package/lib/init/template/hana/index.js +5 -15
  119. package/lib/init/template/helm/files/Chart.yaml.hbs +4 -4
  120. package/lib/init/template/helm/files/values.yaml.hbs +6 -6
  121. package/lib/init/template/helm/index.js +5 -10
  122. package/lib/init/template/helm/subcharts/content-deployment/Chart.yaml +2 -0
  123. package/lib/init/template/helm/subcharts/content-deployment/templates/_helpers.tpl +37 -31
  124. package/lib/init/template/helm/subcharts/content-deployment/templates/job.yaml +13 -14
  125. package/lib/init/template/helm/subcharts/content-deployment/templates/secret.yaml +2 -2
  126. package/lib/init/template/helm/subcharts/content-deployment/templates/service-account.yaml +1 -1
  127. package/lib/init/template/helm/subcharts/content-deployment/templates/service-binding.yaml +3 -3
  128. package/lib/init/template/helm/subcharts/content-deployment/values.md +116 -116
  129. package/lib/init/template/helm/subcharts/service-instance/Chart.yaml +2 -0
  130. package/lib/init/template/helm/subcharts/service-instance/templates/_helpers.tpl +9 -9
  131. package/lib/init/template/helm/subcharts/service-instance/templates/serviceinstance.yaml +2 -2
  132. package/lib/init/template/helm/subcharts/service-instance/values.md +15 -15
  133. package/lib/init/template/helm/subcharts/web-application/Chart.yaml +2 -0
  134. package/lib/init/template/helm/subcharts/web-application/templates/NOTES.txt +15 -0
  135. package/lib/init/template/helm/subcharts/web-application/templates/_helpers.tpl +23 -23
  136. package/lib/init/template/helm/subcharts/web-application/templates/api-rule.yaml +4 -4
  137. package/lib/init/template/helm/subcharts/web-application/templates/deployment.yaml +17 -17
  138. package/lib/init/template/helm/subcharts/web-application/templates/network-policy.yaml +24 -3
  139. package/lib/init/template/helm/subcharts/web-application/templates/pod-disruption-budget.yaml +3 -3
  140. package/lib/init/template/helm/subcharts/web-application/templates/secret.yaml +2 -2
  141. package/lib/init/template/helm/subcharts/web-application/templates/service-account.yaml +1 -1
  142. package/lib/init/template/helm/subcharts/web-application/templates/service-binding.yaml +3 -3
  143. package/lib/init/template/helm/subcharts/web-application/templates/service.yaml +3 -3
  144. package/lib/init/template/helm/subcharts/web-application/values.md +141 -123
  145. package/lib/init/template/helm/subcharts/web-application/values.schema.json +7 -0
  146. package/lib/init/template/helm/subcharts/web-application/values.yaml +1 -0
  147. package/lib/init/template/html5-repo/index.js +4 -5
  148. package/lib/init/template/java/index.js +5 -5
  149. package/lib/init/template/kibana-logging/files/mta.yaml.hbs +5 -5
  150. package/lib/init/template/kibana-logging/files/package.json.hbs +9 -9
  151. package/lib/init/template/kibana-logging/index.js +3 -4
  152. package/lib/init/template/lint/index.js +3 -3
  153. package/lib/init/template/mta/files/mta.yaml.hbs +14 -14
  154. package/lib/init/template/mta/files/package.json +5 -0
  155. package/lib/init/template/mta/index.js +12 -13
  156. package/lib/init/template/mtx/index.js +2 -2
  157. package/lib/init/template/multitenancy/files/mta.yaml.hbs +29 -27
  158. package/lib/init/template/multitenancy/files/package.json.hbs +17 -14
  159. package/lib/init/template/multitenancy/files/package.sidecar.json.hbs +7 -7
  160. package/lib/init/template/multitenancy/files/values.yaml.hbs +19 -19
  161. package/lib/init/template/multitenancy/index.js +14 -16
  162. package/lib/init/template/nodejs/files/package.json.hbs +1 -1
  163. package/lib/init/template/nodejs/index.js +5 -8
  164. package/lib/init/template/redis-messaging/files/mta.yaml.hbs +5 -5
  165. package/lib/init/template/redis-messaging/files/package.json.hbs +9 -9
  166. package/lib/init/template/redis-messaging/index.js +4 -5
  167. package/lib/init/template/sample/files/app/_i18n/i18n.properties +43 -0
  168. package/lib/init/template/sample/files/app/_i18n/i18n_de.properties +14 -0
  169. package/lib/init/template/sample/files/app/admin-books/fiori-service.cds +114 -0
  170. package/lib/init/template/sample/files/app/admin-books/webapp/Component.js +8 -0
  171. package/lib/init/template/sample/files/app/admin-books/webapp/i18n/i18n.properties +11 -0
  172. package/lib/init/template/sample/files/app/admin-books/webapp/manifest.json +129 -0
  173. package/lib/init/template/sample/files/app/appconfig/fioriSandboxConfig.json +57 -0
  174. package/lib/init/template/sample/files/app/common.cds +263 -0
  175. package/lib/init/template/sample/files/app/index.html +30 -0
  176. package/lib/init/template/sample/files/app/services.cds +5 -0
  177. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Authors.csv +5 -0
  178. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Books.csv +6 -0
  179. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Books_texts.csv +5 -0
  180. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Genres.csv +16 -0
  181. package/lib/init/template/sample/files/db/schema.cds +31 -0
  182. package/lib/init/template/sample/files/nodejs/admin-service.js +12 -0
  183. package/lib/init/template/sample/files/nodejs/cat-service.js +26 -0
  184. package/lib/init/template/sample/files/srv/admin-service.cds +5 -0
  185. package/lib/init/template/sample/files/srv/cat-service.cds +16 -0
  186. package/lib/init/template/sample/index.js +24 -0
  187. package/lib/init/template/sample-tiny/index.js +39 -0
  188. package/lib/init/template/samples/index.js +5 -56
  189. package/lib/init/template/sqlite/files/package.json.hbs +13 -13
  190. package/lib/init/template/sqlite/index.js +2 -2
  191. package/lib/init/template/templateBase.js +24 -1
  192. package/lib/init/template/toggles/files/package.json.hbs +10 -10
  193. package/lib/init/template/toggles/index.js +3 -3
  194. package/lib/init/template/typer/files/gitignore +1 -0
  195. package/lib/init/template/typer/files/package.json +8 -0
  196. package/lib/init/template/typer/files/xsconfig.json +9 -0
  197. package/lib/init/template/typer/index.js +36 -0
  198. package/lib/init/template/xsuaa/files/mta.yaml.hbs +12 -12
  199. package/lib/init/template/xsuaa/files/package.json.hbs +13 -13
  200. package/lib/init/template/xsuaa/files/values.yaml.hbs +8 -8
  201. package/lib/init/template/xsuaa/index.js +8 -19
  202. package/lib/init/util/merge.js +73 -59
  203. package/lib/init/util/mvn.js +21 -17
  204. package/lib/init/util/projectReader.js +49 -87
  205. package/lib/init/util/xml.js +14 -23
  206. package/lib/util/cfUtil.js +366 -0
  207. package/lib/util/command.js +3 -3
  208. package/lib/util/gitUtil.js +55 -0
  209. package/lib/util/version.js +27 -0
  210. package/npm-shrinkwrap.json +339 -277
  211. package/package.json +6 -6
  212. package/CHANGELOG.md +0 -1453
  213. package/bin/build/all.js +0 -88
  214. package/bin/build/index.js +0 -82
  215. package/lib/compile/index.js +0 -14
  216. /package/lib/init/template/{samples → sample-tiny}/files/nodejs/db/data/my.bookshop-Books.csv +0 -0
  217. /package/lib/init/template/{samples → sample-tiny}/files/nodejs/db/data-model.cds +0 -0
  218. /package/lib/init/template/{samples → sample-tiny}/files/nodejs/srv/cat-service.cds.hbs +0 -0
@@ -0,0 +1,179 @@
1
+ const path = require('path')
2
+ const parser = require('./migrationtable')
3
+ const { BuildError, hasOptionValue } = require('../../util')
4
+ const { LOG_MODULE_NAMES } = require('../../constants')
5
+ const cds = require('../../../cds'), { compiler: cdsc } = cds
6
+ const cdscVersion = `-- generated by cds-compiler version ${cdsc.version()}`
7
+ const { getArtifactCdsPersistenceName } = cdsc
8
+ let logger = cds.log(LOG_MODULE_NAMES)
9
+ const ANNO_PERSISTENCE_JOURNAL = '@cds.persistence.journal'
10
+
11
+ module.exports = async (model, lastDevVersion, srcPath, options = {}) => {
12
+ if (options.logger) {
13
+ logger = options.logger
14
+ }
15
+
16
+ const journalFileNames = _getJournalFileNames(model)
17
+ const { definitions, deletions, migrations, afterImage } = _toHdiMigration(model, lastDevVersion, journalFileNames, options)
18
+ const definitionResult = []
19
+
20
+ for (const { name, suffix, sql } of definitions) {
21
+ let definitionEntry = { name, suffix, content: sql }
22
+
23
+ if (suffix === '.hdbtable') {
24
+ if (journalFileNames.has(name)) {
25
+ const migration = migrations.find(migration => migration.name === name)
26
+ definitionEntry = await _2migrationtable(srcPath, migration || _emptyMigration(name), sql)
27
+ }
28
+ }
29
+ if (definitionEntry) {
30
+ definitionResult.push(definitionEntry)
31
+ }
32
+ }
33
+ return { definitions: definitionResult, deletions, afterImage: _filterJournalArtifacts(afterImage) }
34
+ }
35
+
36
+ function _toHdiMigration(model, lastDevVersion, journalFileNames, options) {
37
+ const result = cdsc.to.hdi.migration(cds.minify(model), options, lastDevVersion);
38
+ if (logger._debug) {
39
+ logger.debug('cdsc.to.hdi.migration returned')
40
+ for (const { name, suffix, sql } of result.definitions) {
41
+ if (suffix === '.hdbtable' || suffix === '.hdbmigrationtable') {
42
+ if (journalFileNames.has(name)) {
43
+ const migration = result.migrations.find(migration => migration.name === name)
44
+ logger.debug(`
45
+ File ${name + '.hdbmigrationtable'} - ${migration ? migration.changeset.length : 0} new changes
46
+ ${sql}
47
+ ${migration ? migration.changeset.map(change => change.sql).join('\n') : 'Empty changeset'}
48
+ `)
49
+ }
50
+ }
51
+ }
52
+ }
53
+ return result
54
+ }
55
+
56
+ /**
57
+ * Returns an object providing access to the .hdbmigrationtable file content and its corresponding filename.
58
+ *
59
+ * @param {String} srcPath Fully qualified path of the directory containing .hdbmigrationtable files
60
+ * @param {String} migration the migration descriptor
61
+ * @param {String} tableSql SQL TABLE definition
62
+ * @returns {Object} Providing access to 'content' and 'fileName'.
63
+ */
64
+ async function _2migrationtable(srcPath, migration, tableSql) {
65
+ let migrationTableModel = null
66
+ const file = path.join(srcPath, migration.name + migration.suffix)
67
+ try {
68
+ migrationTableModel = await parser.read(file)
69
+ } catch (e) {
70
+ // abort build in order to ensure consistent afterImage model state / hdbmigrationtable file state
71
+ throw new BuildError(`${path.relative(process.cwd(), file)}: ${e.message}`)
72
+ }
73
+
74
+ if (migrationTableModel) {
75
+ // adding new changeset if change exist, ignore otherwise
76
+ const migrationEntry = _getNewMigrationEntry(migration.changeset, migrationTableModel.versionNumber)
77
+ if (migrationEntry) {
78
+ const versionNumber = migrationTableModel.versionNumber + 1
79
+ const migrationCount = migrationTableModel.migrations.entries.length
80
+ const migrations = `${migrationEntry.content}${migrationCount > 0 ? '\n' : ''}${migrationTableModel.migrations.toString()}${migrationCount > 0 ? '\n' : ''}`
81
+ return {
82
+ name: migration.name,
83
+ suffix: migration.suffix,
84
+ content: `== version=${versionNumber}\n${tableSql}\n\n${migrations}`,
85
+ changed: true,
86
+ dropColumns: migrationEntry.dropColumns
87
+ }
88
+ } else {
89
+ // existing migration file version
90
+ return { name: migration.name, suffix: migration.suffix, content: migrationTableModel.toString(), changed: false }
91
+ }
92
+ }
93
+ // initial migration file version
94
+ return { name: migration.name, suffix: migration.suffix, content: `== version=1\n${tableSql}\n`, changed: true }
95
+ }
96
+
97
+ function _getNewMigrationEntry(changeset, currentVersion) {
98
+ if (changeset && changeset.length > 0) {
99
+ const dropColumns = changeset.some(e => e.drop)
100
+ const manualChange = changeset.some(e => !e.sql)
101
+ const enableDrop = cds.env.hana?.journal?.['enable-drop']
102
+ const content = changeset.reduce((acc, e) => {
103
+ if (!acc) {
104
+ acc = `== migration=${currentVersion + 1}\n`
105
+ acc += `${cdscVersion}\n`
106
+
107
+ if (dropColumns && enableDrop !== true) {
108
+ acc += `>>>>> Manual resolution required - DROP statements causing data loss are disabled by default.
109
+ >>>>> You may either:
110
+ >>>>> uncomment statements to allow incompatible changes, or
111
+ >>>>> refactor statements, e.g. replace DROP/ADD by single RENAME statement
112
+ >>>>> After manual resolution delete all lines starting with >>>>>\n`
113
+ } else if (manualChange) {
114
+ acc += `>>>>> Manual resolution required - insert ALTER statement(s) as described below.
115
+ >>>>> After manual resolution delete all lines starting with >>>>>\n`
116
+ }
117
+ }
118
+ if (e.sql) {
119
+ if (e.drop && enableDrop !== true) {
120
+ acc += `${e.sql.replace(/^/gm, '-- ')}\n`;
121
+ } else {
122
+ acc += `${e.sql}\n`
123
+ }
124
+ } else {
125
+ acc +=
126
+ `>>>>> Insert ALTER statement for: ${e.description}\n`
127
+ }
128
+ return acc
129
+ }, null)
130
+ return { dropColumns, content }
131
+ }
132
+ return null
133
+ }
134
+
135
+ function _emptyMigration(name) {
136
+ return { name, suffix: ".hdbmigrationtable", changeset: [] }
137
+ }
138
+
139
+ function _getJournalFileNames(model) {
140
+ const journalNames = new Set(cds.reflect(model).all(item => {
141
+ if (item.kind === 'entity' && item[ANNO_PERSISTENCE_JOURNAL] === true) {
142
+ if (item['@cds.persistence.skip'] === true || item['@cds.persistence.exists'] === true) {
143
+ logger.warn(`[hdbmigrationtable] annotation @cds.persistence.journal skipped for entity '${item.name}' as persistence exists`)
144
+ }
145
+ return true
146
+ }
147
+ return false
148
+ }).map(entity => getArtifactCdsPersistenceName(entity.name, 'quoted', model, 'hana')))
149
+
150
+ logger._debug && logger.debug(`\n[hdbmigrationtable] found ${journalNames.size} model entities annotated with '@cds.persistence.journal`)
151
+ logger._debug && logger.debug(`[hdbmigrationtable] ${[...journalNames].join(', ')}\n`)
152
+
153
+ return journalNames
154
+ }
155
+
156
+ // delete all entities that are not relevant
157
+ function _filterJournalArtifacts(csn) {
158
+ if (!csn) {
159
+ return
160
+ }
161
+ const dict = csn.definitions
162
+ for (const name in dict) {
163
+ if (!_isPersistedAsJournalTable(dict[name])) {
164
+ delete dict[name]
165
+ }
166
+ }
167
+ // mark CSN as modified by cds build
168
+ csn.meta.build = `CDS Build v${cds.version}`
169
+ return csn;
170
+ }
171
+
172
+ // see cds-compiler/lib/model/csnUtils.js#isPersistedAsTable
173
+ function _isPersistedAsJournalTable(artifact) {
174
+ return artifact.kind === 'entity' && hasOptionValue(artifact['@cds.persistence.journal'], true) &&
175
+ !artifact.abstract &&
176
+ !hasOptionValue(artifact['@cds.persistence.skip'], true) &&
177
+ !hasOptionValue(artifact['@cds.persistence.exists'], true) &&
178
+ (!artifact.query && !artifact.projection || hasOptionValue(artifact['@cds.persistence.table'], true))
179
+ }