@sap/cds-dk 4.9.6 → 6.0.2

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 (143) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/bin/activate.js +4 -4
  3. package/bin/add.js +11 -5
  4. package/bin/bind.js +16 -28
  5. package/bin/build/all.js +2 -2
  6. package/bin/build/index.js +12 -19
  7. package/bin/cds.js +16 -17
  8. package/bin/compile/index.js +12 -3
  9. package/bin/deploy/index.js +14 -14
  10. package/bin/deploy/to-hana.js +4 -4
  11. package/bin/deploy/to-sqlite.js +1 -1
  12. package/bin/env.js +13 -4
  13. package/bin/eval.js +1 -1
  14. package/bin/fix-redirects.js +1 -1
  15. package/bin/import.js +44 -179
  16. package/bin/repl.js +1 -1
  17. package/bin/watch.js +10 -15
  18. package/lib/bind/BindingManager.js +87 -0
  19. package/lib/bind/bindingResolver.js +14 -85
  20. package/lib/bind/bindingUtil.js +18 -11
  21. package/lib/bind/cfKeyProvider.js +58 -29
  22. package/lib/bind/kubernetesCredentialsProvider.js +44 -21
  23. package/lib/bind/userCdsrcJsonStorageProvider.js +12 -18
  24. package/lib/cds.js +13 -0
  25. package/lib/client/base_command.js +3 -2
  26. package/lib/client/extend.js +6 -7
  27. package/lib/client/helper/fs_helper.js +7 -8
  28. package/lib/client/settings_manager.js +14 -10
  29. package/lib/compile/index.js +9 -10
  30. package/lib/compile/openapi/csdl2openapi.js +151 -43
  31. package/lib/compile/openapi/index.js +2 -2
  32. package/lib/compile/to-xsuaa.js +3 -2
  33. package/lib/import/common.js +342 -27
  34. package/lib/import/importapi.js +81 -13
  35. package/lib/import/message.js +4 -4
  36. package/lib/import/odata/index.js +141 -0
  37. package/lib/import/{utils → odata/metadataconverter}/MetadataConverter.js +2 -2
  38. package/lib/import/{utils → odata/metadataconverter}/MetadataConverterFactory.js +1 -1
  39. package/lib/import/{utils → odata/util}/MultiMap.js +0 -0
  40. package/lib/import/{v2parser.js → odata/v2parser.js} +405 -468
  41. package/lib/import/{v4parser.js → odata/v4parser.js} +311 -322
  42. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Aggregation.V1.json +0 -0
  43. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Authorization.V1.json +0 -0
  44. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Capabilities.V1.json +0 -0
  45. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Core.V1.json +0 -0
  46. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Measures.V1.json +0 -0
  47. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Validation.V1.json +0 -0
  48. package/lib/import/openapi/importOpenAPI.js +521 -0
  49. package/lib/import/openapi/index.js +19 -0
  50. package/lib/import/openapi/utilities.js +38 -0
  51. package/lib/index.js +1 -1
  52. package/lib/init/constants.js +7 -2
  53. package/lib/init/index.js +10 -3
  54. package/lib/init/template/_merging/existences.js +79 -19
  55. package/lib/init/template/approuter/files/mta.yaml.hbs +25 -11
  56. package/lib/init/template/approuter/files/package.json +1 -1
  57. package/lib/init/template/approuter/files/xs-app.json.hbs +7 -0
  58. package/lib/init/template/approuter/index.js +61 -54
  59. package/lib/init/template/auditlog/index.js +2 -2
  60. package/lib/init/template/data/index.js +2 -2
  61. package/lib/init/template/hana/files/mta.yaml.hbs +17 -17
  62. package/lib/init/template/hana/index.js +8 -4
  63. package/lib/init/template/helm/index.js +39 -0
  64. package/lib/init/template/helm/update/index.js +28 -0
  65. package/lib/init/template/java/index.js +7 -9
  66. package/lib/init/template/kibana-logging/index.js +5 -6
  67. package/lib/init/template/mta/index.js +4 -4
  68. package/lib/init/template/mtx/files/java/package.json +9 -9
  69. package/lib/init/template/mtx/files/mta.yaml.hbs +0 -7
  70. package/lib/init/template/mtx/files/xs-security.json.hbs +11 -20
  71. package/lib/init/template/mtx/index.js +50 -57
  72. package/lib/init/template/nodejs/files/package.json.hbs +2 -2
  73. package/lib/init/template/notebook/index.js +2 -0
  74. package/lib/init/template/templateBase.js +6 -4
  75. package/lib/init/template/xsuaa/index.js +9 -5
  76. package/lib/init/util/fsUtil.js +25 -10
  77. package/lib/init/util/logger.js +1 -1
  78. package/lib/init/util/mvnArchetypeUtil.js +4 -10
  79. package/lib/init/util/projectReader.js +16 -8
  80. package/lib/init/util/templateUtil.js +30 -34
  81. package/lib/k8s/ChartAdder.js +65 -0
  82. package/lib/k8s/ChartBuilder.js +186 -0
  83. package/lib/k8s/Context.js +71 -0
  84. package/lib/k8s/ImageUtil.js +21 -0
  85. package/lib/k8s/Model.d.ts +53 -0
  86. package/lib/k8s/auditlog/index.js +29 -0
  87. package/lib/k8s/auditlog/templates/auditlog.yaml +1 -0
  88. package/lib/k8s/buildModel.js +70 -0
  89. package/lib/k8s/connectivity/index.js +74 -0
  90. package/lib/k8s/connectivity/templates/connectivity-binding.yaml +9 -0
  91. package/lib/k8s/connectivity/templates/connectivity-proxy-info.yaml +16 -0
  92. package/lib/k8s/connectivity/templates/connectivity.yaml +1 -0
  93. package/lib/k8s/deployment/index.js +81 -0
  94. package/lib/k8s/deployment/subchart/Chart.yaml +6 -0
  95. package/lib/k8s/deployment/subchart/templates/_helpers.tpl +156 -0
  96. package/lib/k8s/deployment/subchart/templates/api-rule.yaml +24 -0
  97. package/lib/k8s/deployment/subchart/templates/deployment.yaml +110 -0
  98. package/lib/k8s/deployment/subchart/templates/network-policy.yaml +16 -0
  99. package/lib/k8s/deployment/subchart/templates/pod-disruption-budget.yaml +11 -0
  100. package/lib/k8s/deployment/subchart/templates/secret.yaml +10 -0
  101. package/lib/k8s/deployment/subchart/templates/service-binding.yaml +27 -0
  102. package/lib/k8s/deployment/subchart/templates/service.yaml +11 -0
  103. package/lib/k8s/deployment/subchart/values-lint.yaml +8 -0
  104. package/lib/k8s/deployment/subchart/values.schema.json +449 -0
  105. package/lib/k8s/deployment/subchart/values.yaml +76 -0
  106. package/lib/k8s/deployment/subchart-override/templates/_web_application_helpers.tpl +81 -0
  107. package/lib/k8s/destinations/index.js +40 -0
  108. package/lib/k8s/destinations/lib.js +16 -0
  109. package/lib/k8s/destinations/templates/destinations.yaml +1 -0
  110. package/lib/k8s/docker/push.js +8 -0
  111. package/lib/k8s/event-mesh/index.js +53 -0
  112. package/lib/k8s/event-mesh/lib.js +9 -0
  113. package/lib/k8s/event-mesh/templates/event-mesh.yaml +1 -0
  114. package/lib/k8s/hana-deployer/index.js +38 -0
  115. package/lib/k8s/hana-deployer/templates/hana-deployer-job.yaml +41 -0
  116. package/lib/k8s/helm/Release.js +80 -0
  117. package/lib/k8s/html5-apps-deployer/index.js +43 -0
  118. package/lib/k8s/html5-apps-deployer/templates/_html5_deployment_helpers.tpl +16 -0
  119. package/lib/k8s/html5-apps-deployer/templates/html5-apps-deployer-job.yaml +53 -0
  120. package/lib/k8s/html5-apps-repo-host/index.js +26 -0
  121. package/lib/k8s/html5-apps-repo-host/lib.js +16 -0
  122. package/lib/k8s/html5-apps-repo-host/templates/html5-apps-repo-host.yaml +1 -0
  123. package/lib/k8s/index.js +153 -0
  124. package/lib/k8s/modules.js +36 -0
  125. package/lib/k8s/multitenancy/index.js +24 -0
  126. package/lib/k8s/multitenancy/lib.js +25 -0
  127. package/lib/k8s/multitenancy/templates/saas-registry.yaml +19 -0
  128. package/lib/k8s/readProject.js +14 -0
  129. package/lib/k8s/resources/helm/chart/templates/NOTES.txt +11 -0
  130. package/lib/k8s/resources/helm/chart/templates/_deployment_helpers.tpl +221 -0
  131. package/lib/k8s/resources/helm/chart/templates/_helpers.tpl +167 -0
  132. package/lib/k8s/resources/helm/chart/templates/_sapcp_helpers.tpl +103 -0
  133. package/lib/k8s/util.js +186 -0
  134. package/lib/k8s/wrapFeature.js +55 -0
  135. package/lib/k8s/xsuaa/index.js +64 -0
  136. package/lib/k8s/xsuaa/lib.js +14 -0
  137. package/lib/k8s/xsuaa/templates/xsuaa.yaml +1 -0
  138. package/lib/util/exec.js +1 -1
  139. package/lib/util/write.js +1 -1
  140. package/lib/watch/node-watch.js +43 -14
  141. package/npm-shrinkwrap.json +914 -2745
  142. package/package.json +5 -5
  143. package/lib/import/index.js +0 -235
@@ -0,0 +1,55 @@
1
+ function wrapFeature(name, impl) {
2
+ return async function (context) {
3
+
4
+ const isRequired = once(async function () {
5
+ const features = await context.get('features');
6
+ const isRequired = impl.isRequired ? (context => impl.isRequired(context)) : (() => false);
7
+
8
+ return features.has(name) || await isRequired(context);
9
+ });
10
+
11
+ const init = once(async function () {
12
+ const enabled = await isRequired();
13
+ if (enabled && impl.init) await impl.init(context);
14
+ return enabled;
15
+ });
16
+
17
+ const handler = {
18
+ get(target, prop) {
19
+ if (typeof impl[prop] !== 'function') return undefined;
20
+
21
+ switch (prop) {
22
+ case 'addToChart':
23
+ return async (builder, values) => {
24
+ if (impl.addToChart && values[name] && values[name].enabled !== false)
25
+ return impl.addToChart(builder, values);
26
+ }
27
+
28
+ default:
29
+ return async (...args) => {
30
+ if (await init()) {
31
+ return impl[prop](...args);
32
+ }
33
+ }
34
+ }
35
+ },
36
+ };
37
+
38
+ return new Proxy(impl, handler);
39
+ }
40
+ }
41
+
42
+ function once(func) {
43
+ let result;
44
+ let called;
45
+
46
+ return function () {
47
+ if (!called) {
48
+ result = func();
49
+ called = true;
50
+ }
51
+ return result;
52
+ }
53
+ }
54
+
55
+ module.exports = wrapFeature;
@@ -0,0 +1,64 @@
1
+ const { renderXsSecurityJson } = require('./lib');
2
+ const wrapFeature = require('../wrapFeature');
3
+
4
+ module.exports = wrapFeature('xsuaa', {
5
+ async getXsuaaRequiresServiceName(context) {
6
+ const env = await context.get('env');
7
+ if (env.requires.auth && env.requires.auth.kind === 'xsuaa') return 'auth';
8
+ else if (env.requires.uaa && env.requires.uaa.kind === 'xsuaa') return 'uaa';
9
+ else undefined;
10
+ },
11
+
12
+ async isRequired(context) {
13
+ return !!await this.getXsuaaRequiresServiceName(context)
14
+ },
15
+
16
+ async init(context) {
17
+ const model = await context.get('model');
18
+ const { services } = model;
19
+ delete services.auth;
20
+ delete services.xsuaa;
21
+ delete services.uaa;
22
+ // remove database bindings as they need a workaround
23
+ delete services.db;
24
+ delete services['db-mt'];
25
+
26
+ this.bindingName = await this.getXsuaaRequiresServiceName(context)
27
+ },
28
+
29
+ async getChartCapabilities(context) {
30
+ const model = await context.get('model');
31
+
32
+ return {
33
+ xsuaa: {
34
+ serviceOfferingName: 'xsuaa',
35
+ servicePlanName: 'application',
36
+ parameters: {
37
+ xsappname: model.app.name
38
+ },
39
+ config: 'xs-security.json'
40
+ }
41
+ }
42
+ },
43
+
44
+ // eslint-disable-next-line no-unused-vars
45
+ async getServiceBindings(context) {
46
+ return {
47
+ [this.bindingName || 'auth']: {
48
+ serviceInstanceName: 'xsuaa'
49
+ }
50
+ }
51
+ },
52
+
53
+ async addToChart(builder, { xsuaa }) {
54
+ await builder.addAllTemplates(__dirname);
55
+
56
+ const { config } = xsuaa;
57
+ if (config) {
58
+ if (!await builder.addChartFile(config, { optional: true })) {
59
+ const xsSecurityJson = await renderXsSecurityJson(builder.rootPath, config);
60
+ await builder.writeChartFile(config, xsSecurityJson);
61
+ }
62
+ }
63
+ }
64
+ });
@@ -0,0 +1,14 @@
1
+ const { exec } = require("../../util/exec");
2
+
3
+ async function renderXsSecurityJson(projectPath) {
4
+ const result = await exec({
5
+ cwd: projectPath,
6
+ stdio: ["inherit", "pipe", "inherit"],
7
+ })`cds compile srv -2 xsuaa`;
8
+ const xsSecurityJson = result.stdout;
9
+ return xsSecurityJson;
10
+ }
11
+
12
+ module.exports = {
13
+ renderXsSecurityJson
14
+ };
@@ -0,0 +1 @@
1
+ {{- include "cap.service-instance" . }}
package/lib/util/exec.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const { spawn, spawnSync } = require('child_process');
2
2
 
3
- const cds = require('@sap/cds/lib');
3
+ const cds = require('../cds');
4
4
  const log = cds.log('exec');
5
5
 
6
6
  function* commandIterator(strs, args) {
package/lib/util/write.js CHANGED
@@ -21,7 +21,7 @@ const USAGE = ()=>{ //NOSONAR
21
21
  .then (write.to ('some/folder'))
22
22
  }
23
23
 
24
- const cds = require ('@sap/cds/lib')
24
+ const cds = require('../cds')
25
25
  const { mkdirp, path, fs:{promises:fs} } = cds.utils, { join, dirname } = path
26
26
 
27
27
 
@@ -9,9 +9,8 @@ module.exports = ({ cwd, script, ext, ignore=RegExp(), env={}, delay=200, option
9
9
  const emitter = new EventEmitter
10
10
 
11
11
  const killAndExit = (sig) => {
12
- DEBUG && DEBUG('Signal:', sig)
13
- emitter.emit('quit')
14
- _kill (child, () => process.exit())
12
+ DEBUG && DEBUG('\nreceived signal:', sig)
13
+ _kill (child, process.exit)
15
14
  }
16
15
  process.on('SIGTERM', killAndExit)
17
16
  process.on('SIGINT', killAndExit)
@@ -21,6 +20,7 @@ module.exports = ({ cwd, script, ext, ignore=RegExp(), env={}, delay=200, option
21
20
  const restart = _coalesceEvents(delay, (events) => {
22
21
  DEBUG && DEBUG('>> Events:', events)
23
22
  _kill (child, () => {
23
+ DEBUG && console.trace('Restart')
24
24
  const execArgv = [...process.execArgv]
25
25
  events.forEach(evt => {
26
26
  if (evt.type && evt.type.startsWith('--')) execArgv.push(evt.type)
@@ -32,7 +32,7 @@ module.exports = ({ cwd, script, ext, ignore=RegExp(), env={}, delay=200, option
32
32
  const updated = events.filter(evt => evt.type && evt.type === 'update').map(evt => evt.name)
33
33
  emitter.emit ('restart', updated)
34
34
  child = fork (script, { cwd, env, stdio:'inherit', execArgv }, (err)=>{
35
- if (err) console.error (err)
35
+ if (err) console.error (err)
36
36
  })
37
37
  child.on('message', msg => {
38
38
  if (msg === 'restart') return restart()
@@ -48,7 +48,7 @@ module.exports = ({ cwd, script, ext, ignore=RegExp(), env={}, delay=200, option
48
48
  const watch = require('node-watch')
49
49
  const include = RegExp(`\\.(${ext.replace(/,/g,'|')})$`)
50
50
  const filter = f => !ignore.test(f) && include.test(f)
51
- watch (process.cwd(),{ recursive:true, filter, delay:0 }, restart)
51
+ watch (cwd||process.cwd(),{ recursive:true, filter, delay:0 }, restart)
52
52
 
53
53
  // Live commands...
54
54
  const readline = require('readline')
@@ -64,8 +64,8 @@ module.exports = ({ cwd, script, ext, ignore=RegExp(), env={}, delay=200, option
64
64
  })
65
65
 
66
66
  emitter.restart = restart
67
- emitter.stop = () => { _kill(child, () => false); child = undefined; }
68
- emitter.setEnv = (name, value) => {
67
+ emitter.stop = () => _kill(child, () => false)
68
+ emitter.setEnv = (name, value) => {
69
69
  if (typeof value === "undefined") {
70
70
  delete env[name]
71
71
  } else {
@@ -98,16 +98,45 @@ function _coalesceEvents(delay, fn) {
98
98
  }
99
99
  }
100
100
 
101
- function _kill (proc, fn=()=>{}) {
102
- if (!proc) return fn()
101
+ /*
102
+ * Ensures the given child process gets killed in different environments
103
+ */
104
+ function _kill (proc, cb=()=>{}) {
105
+ if (!proc) return cb()
106
+ if (proc[_pending]) return // safeguard against repeated calls for the same process
107
+ proc[_pending] = true
108
+ const fn = () => { delete proc[_pending]; return cb(); }
103
109
 
110
+ const waitTime = parseInt(process.env.CDS_WATCH_KILL_DELAY) || 500
104
111
  // On Windows, child_process.kill() abruptly kills the process (https://nodejs.org/api/child_process.html#subprocesskillsignal)
105
112
  // Server has cleanup code to run, so send a custom message and give it a bit time.
106
113
  if (process.platform === 'win32') {
107
- proc.send({ exit: true }, () => {})
108
- const waitTime = parseInt(process.env.CDS_WATCH_KILL_DELAY) || 500
109
- setTimeout(()=> { proc.kill(); fn() }, waitTime)
110
- } else {
111
- proc.kill(); fn()
114
+ proc.send({ close: true }, () => {}) // see @sap/cds/bin/serve.js
115
+ setTimeout(()=> {
116
+ proc.kill()
117
+ DEBUG && DEBUG('Killed process', proc.pid)
118
+ fn()
119
+ }, waitTime)
120
+ return
112
121
  }
122
+
123
+ // first kill normally (using SIGTERM)
124
+ let killed = false
125
+ proc.on('exit',() => {
126
+ if (!killed) { killed = true
127
+ DEBUG && DEBUG('Killed process', proc.pid)
128
+ fn()
129
+ }
130
+ }).kill()
131
+
132
+ // fallback for misbehaving processes: SIGKILL it after some time
133
+ setTimeout(()=> {
134
+ if (!killed) { killed = true
135
+ proc.kill('SIGKILL')
136
+ DEBUG && DEBUG('Killed process (forcefully)', proc.pid)
137
+ fn()
138
+ }
139
+ }, waitTime)
113
140
  }
141
+
142
+ const _pending = Symbol.for('sap.cds.watch.pendingKill')