@sap/cds-dk 6.2.3 → 6.3.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 +39 -0
  2. package/bin/bind.js +4 -4
  3. package/bin/deploy/to-h2.js +4 -0
  4. package/bin/deploy/to-sqlite.js +6 -4
  5. package/bin/help.js +1 -1
  6. package/bin/login.js +1 -0
  7. package/bin/push.js +29 -7
  8. package/lib/bind/userCdsrcJsonStorageProvider.js +4 -4
  9. package/lib/client/activate.js +1 -1
  10. package/lib/client/base_command.js +10 -10
  11. package/lib/client/helper/dependency_helper.js +10 -1
  12. package/lib/client/helper/logging.js +6 -2
  13. package/lib/client/pull.js +6 -6
  14. package/lib/client/push.js +33 -14
  15. package/lib/client/settings_manager.js +53 -22
  16. package/lib/compile/openapi/csdl2openapi.js +1 -1
  17. package/lib/compile/to-xsuaa.js +1 -1
  18. package/lib/import/odata/v2parser.js +37 -1
  19. package/lib/import/odata/v4parser.js +101 -23
  20. package/lib/init/constants.js +1 -1
  21. package/lib/init/index.js +23 -45
  22. package/lib/init/template/approuter/index.js +44 -48
  23. package/lib/init/template/auditlog/index.js +14 -10
  24. package/lib/init/template/cf-manifest/index.js +9 -11
  25. package/lib/init/template/connectivity/index.js +10 -10
  26. package/lib/init/template/data/index.js +20 -19
  27. package/lib/init/template/destinations/index.js +14 -9
  28. package/lib/init/template/enterprise-messaging/index.js +14 -9
  29. package/lib/init/template/extensibility/index.js +14 -9
  30. package/lib/init/template/hana/index.js +51 -57
  31. package/lib/init/template/helm/index.js +27 -59
  32. package/lib/init/template/helm/subchart/templates/_helpers.tpl +38 -0
  33. package/lib/init/template/helm/subchart/templates/deployment.yaml +12 -12
  34. package/lib/init/template/helm/subchart/values.md +565 -194
  35. package/lib/init/template/helm/subchart/values.schema.json +163 -8
  36. package/lib/init/template/helm/subchart/values.yaml +17 -1
  37. package/lib/init/template/html5-repo/index.js +15 -11
  38. package/lib/init/template/java/index.js +15 -11
  39. package/lib/init/template/kibana-logging/index.js +30 -31
  40. package/lib/init/template/lint/index.js +17 -18
  41. package/lib/init/template/mta/index.js +18 -40
  42. package/lib/init/template/mtx/index.js +2 -3
  43. package/lib/init/template/multitenancy/index.js +27 -20
  44. package/lib/init/template/nodejs/index.js +18 -20
  45. package/lib/init/template/notebook/index.js +5 -434
  46. package/lib/init/template/pipeline/index.js +10 -10
  47. package/lib/init/template/samples/index.js +7 -16
  48. package/lib/init/template/templateBase.js +17 -18
  49. package/lib/init/template/toggles/files/cdsrc.json +5 -0
  50. package/lib/init/template/toggles/files/cdsrc.json.hbs +7 -0
  51. package/lib/init/template/toggles/index.js +12 -6
  52. package/lib/init/template/xsuaa/index.js +44 -41
  53. package/lib/init/types.d.ts +0 -59
  54. package/lib/init/util/commandUtil.js +6 -7
  55. package/lib/init/util/fsUtil.js +23 -109
  56. package/lib/init/util/merge.js +319 -0
  57. package/lib/init/util/mvnArchetypeUtil.js +6 -5
  58. package/lib/init/util/projectReader.js +125 -300
  59. package/lib/init/util/spinner.js +10 -8
  60. package/lib/init/util/templateUtil.js +25 -368
  61. package/lib/lint/Linter.js +2 -3
  62. package/lib/lint/checks.js +0 -1
  63. package/lib/lint/io.js +18 -34
  64. package/npm-shrinkwrap.json +1132 -1190
  65. package/package.json +3 -3
  66. package/lib/init/template/notebook/cap_magic.py +0 -118
  67. package/lib/init/template/notebook/files/{{{name}}}.ipynb.hbs +0 -90
  68. package/lib/init/template/notebook/files/{{{name}}}.json +0 -102
  69. package/lib/init/template/notebook/notebook.js +0 -394
  70. package/lib/init/util/logger.js +0 -42
@@ -1,36 +1,29 @@
1
1
  const path = require('path');
2
-
2
+ const cds = require('../../../cds')
3
+ const { fs, read, write } = cds.utils
3
4
  const commandUtil = require('../../util/commandUtil');
4
5
  const mvnArchetypes = require('../../util/mvnArchetypeUtil');
5
6
  const term = require('../../../util/term');
7
+ const { mergeJSON, mergeYAML } = require('../../util/merge')
8
+ const { copyFiles } = require('../../util/templateUtil')
6
9
  const ProjectReader = require('../../util/projectReader');
7
-
8
- const TemplateBase = require('../templateBase');
9
10
  const versionCompare = require('../../util/versionCompare');
10
11
 
11
12
  const { PROJECT_TYPE, OPTION_JAVA, URLS } = require('../../constants');
12
- const { nullLogger } = require('../../util/logger');
13
+
13
14
  const { srvNode, srvJava, hdbDeployer, serviceManager, hdiContainer, mtxSidecar } = require('../_merging/registry-mta');
14
- const cds = require('../../../cds'), { fs } = cds.utils
15
15
 
16
- module.exports = class HanaTemplate extends TemplateBase {
16
+ module.exports = class HanaTemplate extends require('../templateBase') {
17
17
  constructor(projectPath, generator) {
18
18
  super(projectPath, generator, __dirname);
19
- this.projectReader = new ProjectReader(this);
19
+ this.projectReader = new ProjectReader(projectPath);
20
20
  }
21
21
 
22
- // read env from project
23
- async getEnv() {
24
- const cdsEnvVar = process.env.CDS_ENV;
25
- process.env.CDS_ENV = 'production'
26
- try {
27
- return await super.getEnv();
28
- } finally {
29
- cdsEnvVar ? process.env.CDS_ENV = cdsEnvVar : delete process.env.CDS_ENV
30
- }
22
+ static hasFacet(env) {
23
+ return env.requires?.db?.kind === 'hana'
31
24
  }
32
25
 
33
- async checkEnabled() {
26
+ async canRun() {
34
27
  const cds = require('../../../cds')
35
28
  if (versionCompare(cds.version, '5.9.0') < 0) {
36
29
  cds.error('The added configuration requires @sap/cds 5.9.0 or higher. Please update @sap/cds to the latest version and run \x1b[1mcds add hana\x1b[0m again.')
@@ -38,15 +31,44 @@ module.exports = class HanaTemplate extends TemplateBase {
38
31
  return true
39
32
  }
40
33
 
34
+ async run() {
35
+ const env = await this.getEnv();
36
+
37
+ const hdiConfigPath = path.join(this.projectPath, env.folders.db, 'src', '.hdiconfig');
38
+ const hdiConfigTemplatePath = path.join(__dirname, 'files', 'common', 'src', '.hdiconfig');
39
+ await mergeJSON(hdiConfigPath, hdiConfigTemplatePath);
40
+
41
+ const undeployJSONPath = path.join(this.projectPath, env.folders.db, 'undeploy.json');
42
+ const undeployJSONTemplatePath = path.join(__dirname, 'files', 'common', 'undeploy.json');
43
+ await mergeJSON(undeployJSONPath, undeployJSONTemplatePath);
44
+
45
+ const projectType = await this.getProjectType();
46
+ switch (projectType) {
47
+ case PROJECT_TYPE.java: {
48
+ await copyFiles(path.join(__dirname, 'files', 'java', 'db'), path.join(this.projectPath, env.folders.db), {}, this.options.force);
49
+ await this._updatePomXml();
50
+ await this._updateCdsConfiguration();
51
+ break;
52
+ }
53
+ case PROJECT_TYPE.nodejs: {
54
+ await this._updatePackageJson()
55
+ break;
56
+ }
57
+ default: break;
58
+ }
59
+ await this.runDependentMerging()
60
+ }
61
+
62
+
41
63
  async runDependentMerging() {
42
64
  const projectDescriptor = await this.projectReader.read(this.options)
43
- const { hasMtaDeployment, hasHelmDeployment, isNodejs, isJava, isMultitenant } = projectDescriptor.cap
65
+ const { hasMta, hasHelm, isNodejs, isJava, isMultitenant } = projectDescriptor.cap
44
66
 
45
67
  if (isMultitenant) {
46
68
  await this._updateCdsConfiguration()
47
69
  }
48
70
 
49
- if (hasMtaDeployment) {
71
+ if (hasMta) {
50
72
  const srv = isNodejs ? srvNode : srvJava
51
73
  const db = isMultitenant ? serviceManager : hdiContainer
52
74
  const deletions = isMultitenant ? [{
@@ -86,7 +108,7 @@ module.exports = class HanaTemplate extends TemplateBase {
86
108
 
87
109
  const modules = !isMultitenant ? [srv, hdbDeployer] : [srv]
88
110
 
89
- await this.templateUtil.mergeYAML(
111
+ await mergeYAML(
90
112
  mtaYAMLPath,
91
113
  `${__dirname}/files/mta.yaml.hbs`,
92
114
  projectDescriptor,
@@ -94,8 +116,8 @@ module.exports = class HanaTemplate extends TemplateBase {
94
116
  )
95
117
  }
96
118
 
97
- if (hasHelmDeployment) {
98
- await this.templateUtil.mergeYAML(
119
+ if (hasHelm) {
120
+ await mergeYAML(
99
121
  path.join(this.projectPath, 'chart', 'values.yaml'),
100
122
  path.join(__dirname, 'files', 'values.yaml.hbs'),
101
123
  projectDescriptor, { forceOverwrite: true })
@@ -106,34 +128,6 @@ module.exports = class HanaTemplate extends TemplateBase {
106
128
  }
107
129
  }
108
130
 
109
- async run() {
110
- const env = await this.getEnv();
111
-
112
- const hdiConfigPath = path.join(this.projectPath, env.folders.db, 'src', '.hdiconfig');
113
- const hdiConfigTemplatePath = path.join(__dirname, 'files', 'common', 'src', '.hdiconfig');
114
- await this.templateUtil.mergeJSON(hdiConfigPath, hdiConfigTemplatePath);
115
-
116
- const undeployJSONPath = path.join(this.projectPath, env.folders.db, 'undeploy.json');
117
- const undeployJSONTemplatePath = path.join(__dirname, 'files', 'common', 'undeploy.json');
118
- await this.templateUtil.mergeJSON(undeployJSONPath, undeployJSONTemplatePath);
119
-
120
- const projectType = await this.getProjectType();
121
- switch (projectType) {
122
- case PROJECT_TYPE.java: {
123
- await this.templateUtil.copyFiles(path.join('java', 'db'), path.join(this.projectPath, env.folders.db), {}, this.options.force);
124
- await this._updatePomXml();
125
- await this._updateCdsConfiguration();
126
- break;
127
- }
128
- case PROJECT_TYPE.nodejs: {
129
- await this._updatePackageJson()
130
- break;
131
- }
132
- default: break;
133
- }
134
- await this.runDependentMerging()
135
- }
136
-
137
131
  async _updatePomXml() {
138
132
  // if called during cds init the project generation call to AT will add settings
139
133
  if (!this.options.add.has(OPTION_JAVA)) {
@@ -141,7 +135,7 @@ module.exports = class HanaTemplate extends TemplateBase {
141
135
  try {
142
136
  await commandUtil.spawnCommand('mvn', mvnAddHanaArgs, {
143
137
  cwd: this.projectPath
144
- }, (this.logger.isDebug ? this.logger : nullLogger));
138
+ });
145
139
  } catch (err) {
146
140
  if (err.code === 'ENOENT' && err.path === 'mvn') {
147
141
  throw new Error(`Maven executable 'mvn' not found, follow ${term.info(URLS.MAVEN_INSTALL_HELP)} and install Maven on your machine.`);
@@ -154,12 +148,12 @@ module.exports = class HanaTemplate extends TemplateBase {
154
148
  async _updatePackageJson() {
155
149
  const packageJsonPath = path.join(this.projectPath, 'package.json')
156
150
  const dependenciesTemplatePath = path.join(__dirname, 'files', 'nodejs', 'dependencies.package.json');
157
- await this.templateUtil.mergeJSON(packageJsonPath, dependenciesTemplatePath);
151
+ await mergeJSON(packageJsonPath, dependenciesTemplatePath);
158
152
 
159
- const packageJson = await this.fsUtil.readJSON(packageJsonPath);
160
- if (packageJson.dependencies['@sap/hana-client']) {
153
+ const packageJson = await read(packageJsonPath);
154
+ if ('@sap/hana-client' in packageJson.dependencies) {
161
155
  delete packageJson.dependencies['@sap/hana-client'];
162
- await this.fsUtil.writeJSON(packageJsonPath, packageJson);
156
+ await write(packageJsonPath, packageJson, { spaces: 2 });
163
157
  }
164
158
 
165
159
  await this._updateCdsConfiguration()
@@ -171,13 +165,13 @@ module.exports = class HanaTemplate extends TemplateBase {
171
165
  configPath = configPath ?? path.join(this.projectPath, configFile)
172
166
  const projectDescriptor = await this.projectReader.read(this.options);
173
167
  const { for: forProfile } = projectDescriptor.cap;
174
- let json; try { json = await this.fsUtil.readJSON(configPath) } catch { /* ignore */ }
168
+ let json; try { json = await read(configPath, 'utf8') } catch { /* ignore */ }
175
169
  const _cds = projectType === PROJECT_TYPE.nodejs ? json?.cds : json;
176
170
  const shortcut = typeof _cds?.requires?.db === 'string' || !json ? 'shortcut.' : '';
177
171
  const profile = forProfile ? 'profile.' : '';
178
172
  const cdsTemplateFile = `cds.${shortcut}${profile}json.hbs`
179
173
  const { pLanguage } = projectDescriptor.cap;
180
174
  const cdsTemplatePath = path.join(__dirname, 'files', pLanguage, cdsTemplateFile);
181
- await this.templateUtil.mergeJSON(configPath, cdsTemplatePath, projectDescriptor, { forceOverwrite: true })
175
+ await mergeJSON(configPath, cdsTemplatePath, projectDescriptor, { forceOverwrite: true })
182
176
  }
183
177
  }
@@ -1,54 +1,53 @@
1
- /* eslint-disable no-unused-vars */
2
- /* eslint-disable no-unreachable */
3
1
  const path = require('path');
4
- const TemplateBase = require('../templateBase');
2
+ const { exists, read, copy, rimraf } = require('../../../cds').utils;
5
3
  const ProjectReader = require('../../util/projectReader');
6
- const { fs, rimraf } = require('../../../cds').utils;
7
- const { yaml } = require('@sap/cds-foss')
4
+ const { mergeYAML } = require('../../util/merge')
5
+ //const { yaml } = require('@sap/cds-foss')
8
6
 
9
- module.exports = class HelmTemplate extends TemplateBase {
7
+ module.exports = class HelmTemplate extends require('../templateBase') {
10
8
  constructor(projectPath, generator) {
11
9
  super(projectPath, generator, __dirname);
12
- this.projectReader = new ProjectReader(this);
10
+ this.projectReader = new ProjectReader(projectPath);
13
11
  }
14
12
 
15
- async checkEnabled() {
13
+ static hasFacet(_, projectPath, options) {
14
+ // REVISIT: this works, but could be semantically nicer with a 'shouldRunDependentMerging' or the like
15
+ if (options?.add.has('mta') && !options?.add.has('helm')) return false
16
+ return exists(path.join(projectPath, 'chart', 'values.yaml'))
17
+ }
18
+
19
+ async canRun() {
16
20
  if (this.options.force) {
17
- await rimraf(this.chartPath)
21
+ await rimraf(path.join(this.projectPath, 'chart'))
18
22
  return true;
19
23
  }
20
24
  return true;
21
25
  }
22
26
 
23
- get chartPath() {
24
- return path.join(this.projectPath, 'chart');
25
- }
26
-
27
27
  async run() {
28
28
  const projectDescriptor = await this.projectReader.read(this.options)
29
- const { appName, appDescription, appVersion, isJava } = projectDescriptor.cap
30
29
 
31
- await fs.copy(
30
+ await copy(
32
31
  path.join(__dirname, 'subchart'),
33
32
  path.join(this.projectPath, 'chart', 'charts', 'web-application'),
34
33
  )
35
- await fs.copy(
34
+ await copy(
36
35
  path.join(__dirname, 'chart'),
37
- path.join(this.chartPath),
36
+ path.join(this.projectPath, 'chart')
38
37
  )
39
38
 
40
- const webApplicationChartPath = process.env.WEB_APPLICATION_CHART || path.join(__dirname, 'subchart')
39
+ const webApplicationChartPath = process.env.WEB_APPLICATION_CHART ?? path.join(__dirname, 'subchart')
41
40
  const chartFilePath = path.join(webApplicationChartPath, 'Chart.yaml')
42
- const chartFile = await fs.promises.readFile(chartFilePath, { encoding: 'utf-8' })
43
- const { version } = yaml.parse(chartFile)
41
+ const chartFile = await read(chartFilePath)
42
+ //const { version } = yaml.parse(chartFile)
44
43
 
45
- await this.templateUtil.mergeYAML(
44
+ await mergeYAML(
46
45
  path.join(this.projectPath, 'chart', 'Chart.yaml'),
47
46
  path.join(__dirname, 'files', 'Chart.yaml.hbs'),
48
47
  projectDescriptor, { forceOverwrite: true }
49
48
  )
50
49
 
51
- await this.templateUtil.mergeYAML(
50
+ await mergeYAML(
52
51
  path.join(this.projectPath, 'chart', 'values.yaml'),
53
52
  path.join(__dirname, 'files', 'values.yaml.hbs'),
54
53
  projectDescriptor, { forceOverwrite: true }
@@ -57,43 +56,12 @@ module.exports = class HelmTemplate extends TemplateBase {
57
56
  }
58
57
 
59
58
  async runDependentMerging() {
60
- const projectDescriptor = await this.projectReader.read()
61
- const { hasHana, hasXsuaa, isMultitenant, isExtensible, hasMessaging, hasAuditlog, hasDestination } = projectDescriptor.cap
62
-
63
- if (hasHana) {
64
- const HanaTemplate = require(`../hana`)
65
- const template = new HanaTemplate(this.projectPath, this.generator)
66
- await template.runDependentMerging()
67
- }
68
- if (hasAuditlog) {
69
- const AuditlogTemplate = require(`../auditlog`)
70
- const template = new AuditlogTemplate(this.projectPath, this.generator)
71
- await template.runDependentMerging()
72
- }
73
- if (hasMessaging) {
74
- const EnterpriseMessagingTemplate = require(`../enterprise-messaging`)
75
- const template = new EnterpriseMessagingTemplate(this.projectPath, this.generator)
76
- await template.runDependentMerging()
77
- }
78
- if (hasDestination) {
79
- const DestinationsTemplate = require(`../destinations`)
80
- const template = new DestinationsTemplate(this.projectPath, this.generator)
81
- await template.runDependentMerging()
82
- }
83
- if (hasXsuaa) {
84
- const XsuaaTemplate = require(`../xsuaa`)
85
- const template = new XsuaaTemplate(this.projectPath, this.generator)
86
- await template.runDependentMerging()
87
- }
88
- if (isMultitenant) {
89
- const MultitenancyTemplate = require(`../multitenancy`)
90
- const template = new MultitenancyTemplate(this.projectPath, this.generator)
91
- await template.runDependentMerging()
92
- }
93
- if (isExtensible) {
94
- const ExtensibilityTemplate = require(`../extensibility`)
95
- const template = new ExtensibilityTemplate(this.projectPath, this.generator)
96
- await template.runDependentMerging()
59
+ // Re-applying the dependent merging part of other facets if necessary.
60
+ const dependentFacets = ['hana', 'xsuaa', 'auditlog', 'enterprise-messaging', 'destinations' , 'multitenancy', 'extensibility']
61
+ for (const facet of dependentFacets) {
62
+ const Template = require('../'+facet)
63
+ const template = new Template(this.projectPath, this.generator)
64
+ if (Template.hasFacet(await this.getEnv(), this.projectPath, this.options)) await template.runDependentMerging()
97
65
  }
98
66
  }
99
67
  };
@@ -165,3 +165,41 @@ If release name contains chart name it will be used as service insatnce name.
165
165
  {{- $name }}
166
166
  {{- end }}
167
167
  {{- end }}
168
+
169
+ {{- define "web-application.processEnv" -}}
170
+ {{- $result := dict }}
171
+ {{- $variables := list }}
172
+ {{- range $k, $v := . }}
173
+ {{- $variable := dict }}
174
+ {{- if (kindIs "string" $k) }}
175
+ {{- if eq "APPLICATION_NAME" $k }}
176
+ {{- $_ := set $result "appName" true }}
177
+ {{- end }}
178
+ {{- if eq "APPLICATION_URI" $k }}
179
+ {{- $_ := set $result "appURI" true }}
180
+ {{- end }}
181
+ {{- $_ := set $variable "name" $k -}}
182
+ {{- if (kindIs "map" $v)}}
183
+ {{- $_ := set $variable "valueFrom" $v}}
184
+ {{- else }}
185
+ {{- $_ := set $variable "value" ($v | toString) }}
186
+ {{- end }}
187
+ {{- else }}
188
+ {{- if eq "APPLICATION_NAME" $v.name }}
189
+ {{- $_ := set $result "appName" true }}
190
+ {{- end }}
191
+ {{- if eq "APPLICATION_URI" $v.name }}
192
+ {{- $_ := set $result "appURI" true }}
193
+ {{- end }}
194
+ {{- $_ := set $variable "name" $v.name }}
195
+ {{- if $v.value }}
196
+ {{- $_ := set $variable "value" ($v.value | toString)}}
197
+ {{- else }}
198
+ {{- $_ := set $variable "valueFrom" (omit $v "name")}}
199
+ {{- end }}
200
+ {{- end }}
201
+ {{- $variables = append $variables $variable}}
202
+ {{- end }}
203
+ {{- $_ := set $result "vars" $variables }}
204
+ {{- $result | mustToJson }}
205
+ {{- end }}
@@ -30,18 +30,6 @@ spec:
30
30
  name: {{ $secretName }}
31
31
  {{- end }}
32
32
  env:
33
- {{- range $k, $v := .Values.env }}
34
- - name: {{ $k }}
35
- value: {{ $v | quote }}
36
- {{- end }}
37
- {{- if not .Values.env.APPLICATION_NAME }}
38
- - name: APPLICATION_NAME
39
- value: {{ include "web-application.fullname" . }}
40
- {{- end }}
41
- {{- if not .Values.env.APPLICATION_URI }}
42
- - name: APPLICATION_URI
43
- value: {{ include "web-application.applicationUri" . }}
44
- {{- end }}
45
33
  {{- if .Values.bindings }}
46
34
  - name: SERVICE_BINDING_ROOT
47
35
  value: /bindings
@@ -50,6 +38,18 @@ spec:
50
38
  value: {{ .Values.port | quote }}
51
39
  - name: TMPDIR
52
40
  value: /tmp
41
+ {{- $envVars := (include "web-application.processEnv" .Values.env | fromJson) }}
42
+ {{- if not (eq (len $envVars.vars) 0) }}
43
+ {{- $envVars.vars | toYaml | nindent 8}}
44
+ {{- end }}
45
+ {{- if not $envVars.appName}}
46
+ - name: APPLICATION_NAME
47
+ value: {{ include "web-application.fullname" . }}
48
+ {{- end }}
49
+ {{- if not $envVars.appURI}}
50
+ - name: APPLICATION_URI
51
+ value: {{ include "web-application.applicationUri" . }}
52
+ {{- end }}
53
53
  livenessProbe:
54
54
  {{- if .Values.health_check.liveness.path }}
55
55
  httpGet: