@sap/cds-dk 6.5.2 → 6.6.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 (122) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/bin/activate.js +7 -0
  3. package/bin/add.js +1 -2
  4. package/bin/build/all.js +14 -9
  5. package/bin/cds.js +11 -8
  6. package/bin/compile/index.js +13 -3
  7. package/bin/env.js +16 -25
  8. package/bin/extend.js +8 -0
  9. package/bin/init.js +0 -3
  10. package/bin/login.js +3 -7
  11. package/bin/logout.js +2 -7
  12. package/bin/watch.js +4 -5
  13. package/lib/client/activate.js +1 -1
  14. package/lib/client/helper/errors.js +2 -1
  15. package/lib/client/params.js +4 -3
  16. package/lib/client/pull.js +31 -5
  17. package/lib/client/push.js +3 -3
  18. package/lib/client/settings_manager.js +6 -6
  19. package/lib/client/subscription.js +1 -1
  20. package/lib/compile/asyncapi/channels.js +22 -0
  21. package/lib/compile/asyncapi/components/messageTraits/index.js +89 -0
  22. package/lib/compile/asyncapi/components/messages/index.js +150 -0
  23. package/lib/compile/asyncapi/components/schemas/annotations.js +13 -0
  24. package/lib/compile/asyncapi/components/schemas/array.js +8 -0
  25. package/lib/compile/asyncapi/components/schemas/cache.js +14 -0
  26. package/lib/compile/asyncapi/components/schemas/definition.js +187 -0
  27. package/lib/compile/asyncapi/components/schemas/enum.js +16 -0
  28. package/lib/compile/asyncapi/components/schemas/examples.js +10 -0
  29. package/lib/compile/asyncapi/components/schemas/index.js +14 -0
  30. package/lib/compile/asyncapi/components/schemas/localized.js +29 -0
  31. package/lib/compile/asyncapi/components/schemas/primitiveElement.js +41 -0
  32. package/lib/compile/asyncapi/components/schemas/ref.js +45 -0
  33. package/lib/compile/asyncapi/components/schemas/utils.js +108 -0
  34. package/lib/compile/asyncapi/index.js +226 -0
  35. package/lib/compile/asyncapi/message.js +13 -0
  36. package/lib/compile/asyncapi/utils.js +27 -0
  37. package/lib/compile/index.js +1 -0
  38. package/lib/compile/openapi/csdl2openapi.js +40 -18
  39. package/lib/import/message.js +3 -1
  40. package/lib/import/odata/metadataconverter/MetadataConverter.js +1 -1
  41. package/lib/import/odata/v2parser.js +131 -50
  42. package/lib/import/odata/v4parser.js +160 -68
  43. package/lib/import/openapi/importOpenAPI.js +14 -14
  44. package/lib/init/constants.js +1 -1
  45. package/lib/init/index.js +11 -21
  46. package/lib/init/template/_merging/registry-mta.js +15 -26
  47. package/lib/init/template/approuter/files/package.json +2 -2
  48. package/lib/init/template/approuter/index.js +6 -12
  49. package/lib/init/template/auditlog/files/auditlog.yaml +4 -1
  50. package/lib/init/template/auditlog/index.js +23 -8
  51. package/lib/init/template/cf-manifest/index.js +4 -14
  52. package/lib/init/template/connectivity/files/connectivity-proxy-info.yaml +2 -6
  53. package/lib/init/template/connectivity/files/values.yaml.hbs +5 -8
  54. package/lib/init/template/connectivity/index.js +2 -9
  55. package/lib/init/template/data/index.js +0 -4
  56. package/lib/init/template/destinations/files/destination.yaml +4 -1
  57. package/lib/init/template/destinations/index.js +25 -10
  58. package/lib/init/template/enterprise-messaging/files/event-mesh.yaml +4 -1
  59. package/lib/init/template/enterprise-messaging/files/values.yaml +1 -2
  60. package/lib/init/template/enterprise-messaging/index.js +28 -20
  61. package/lib/init/template/extensibility/index.js +23 -31
  62. package/lib/init/template/hana/files/hana.yaml +4 -1
  63. package/lib/init/template/hana/index.js +44 -24
  64. package/lib/init/template/helm/chart/templates/_helpers.tpl +12 -0
  65. package/lib/init/template/helm/chart/values.root.schema.json +40 -0
  66. package/lib/init/template/helm/chart/values.schema.json +32 -69
  67. package/lib/init/template/helm/index.js +26 -16
  68. package/lib/init/template/helm/subcharts/content-deployment/templates/_helpers.tpl +13 -26
  69. package/lib/init/template/helm/subcharts/content-deployment/templates/job.yaml +3 -3
  70. package/lib/init/template/helm/subcharts/content-deployment/templates/service-account.yaml +2 -0
  71. package/lib/init/template/helm/subcharts/content-deployment/templates/service-binding.yaml +3 -3
  72. package/lib/init/template/helm/subcharts/content-deployment/templating.md +37 -0
  73. package/lib/init/template/helm/subcharts/content-deployment/values.md +182 -185
  74. package/lib/init/template/helm/subcharts/content-deployment/values.schema.json +18 -22
  75. package/lib/init/template/helm/subcharts/content-deployment/values.yaml +2 -0
  76. package/lib/init/template/helm/subcharts/service-instance/Chart.yaml +5 -0
  77. package/lib/init/template/helm/subcharts/service-instance/templates/_helpers.tpl +65 -0
  78. package/lib/init/template/helm/subcharts/service-instance/templates/serviceinstance.yaml +23 -0
  79. package/lib/init/template/helm/subcharts/service-instance/templating.md +18 -0
  80. package/lib/init/template/helm/subcharts/service-instance/values-lint.yaml +2 -0
  81. package/lib/init/template/helm/subcharts/service-instance/values.md +186 -0
  82. package/lib/init/template/helm/subcharts/service-instance/values.schema.json +102 -0
  83. package/lib/init/template/helm/subcharts/service-instance/values.yaml +15 -0
  84. package/lib/init/template/html5-repo/files/html5-apps-repo-host.yaml +4 -1
  85. package/lib/init/template/html5-repo/index.js +30 -21
  86. package/lib/init/template/java/index.js +2 -5
  87. package/lib/init/template/kibana-logging/index.js +7 -10
  88. package/lib/init/template/lint/index.js +2 -3
  89. package/lib/init/template/mta/files/mta.yaml.hbs +4 -2
  90. package/lib/init/template/mta/index.js +7 -11
  91. package/lib/init/template/mtx/index.js +0 -5
  92. package/lib/init/template/multitenancy/files/java/package.json +16 -7
  93. package/lib/init/template/multitenancy/files/mta.yaml.hbs +11 -3
  94. package/lib/init/template/multitenancy/files/saas-registry-secret.yaml +9 -0
  95. package/lib/init/template/multitenancy/files/saas-registry.yaml +4 -17
  96. package/lib/init/template/multitenancy/files/service-manager.yaml +4 -1
  97. package/lib/init/template/multitenancy/files/values.yaml.hbs +15 -3
  98. package/lib/init/template/multitenancy/index.js +56 -31
  99. package/lib/init/template/nodejs/index.js +4 -7
  100. package/lib/init/template/notebook/index.js +1 -3
  101. package/lib/init/template/pipeline/index.js +2 -5
  102. package/lib/init/template/samples/index.js +6 -11
  103. package/lib/init/template/templateBase.js +10 -17
  104. package/lib/init/template/toggles/index.js +2 -6
  105. package/lib/init/template/xsuaa/files/values.yaml.hbs +0 -1
  106. package/lib/init/template/xsuaa/files/xsuaa.yaml +4 -1
  107. package/lib/init/template/xsuaa/index.js +27 -23
  108. package/lib/init/types.d.ts +0 -81
  109. package/lib/init/util/merge.js +23 -25
  110. package/lib/init/util/projectReader.js +27 -24
  111. package/lib/lint/Linter.js +31 -13
  112. package/lib/watch/livereload-server.js +21 -14
  113. package/lib/watch/node-watch.js +51 -49
  114. package/npm-shrinkwrap.json +551 -458
  115. package/package.json +2 -2
  116. package/readme.md +5 -0
  117. package/lib/init/template/connectivity/files/connectivity-binding.yaml +0 -9
  118. package/lib/init/template/connectivity/files/connectivity.yaml +0 -1
  119. package/lib/init/template/multitenancy/files/xsuaa.yaml +0 -1
  120. /package/lib/init/template/hana/files/{chart.yaml → hana-deployer.yaml} +0 -0
  121. /package/lib/init/template/html5-repo/files/{chart.yaml → html5-apps-deployer.yaml} +0 -0
  122. /package/lib/init/template/multitenancy/files/{chart.yaml → sidecar.yaml} +0 -0
@@ -70,13 +70,16 @@ class Linter {
70
70
  // Determine if case "local" or "global" and resolve plugin accordingly
71
71
  await this._getConfigFileAndSetProjectPath(args);
72
72
 
73
- const overwriteRules = checks.hasEslintConfigContent(this.configContents, "rules");
74
- if (overwriteRules) {
75
- await this._overwriteRuleSeverities();
76
- }
73
+ if (this.pluginPath) {
74
+ const overwriteRules = checks.hasEslintConfigContent(this.configContents, "rules");
75
+ // Overwrite rules severities
76
+ if (overwriteRules) {
77
+ await this._overwriteRuleSeverities();
78
+ }
77
79
 
78
- // Limit to CDS file extensions
79
- this._addExtensions();
80
+ // Limit to CDS file extensions
81
+ this._addExtensions();
82
+ }
80
83
 
81
84
  // Run ESLint with collected options
82
85
  try {
@@ -213,7 +216,18 @@ class Linter {
213
216
  }
214
217
  }
215
218
  } catch (err) {
216
- console.log(err);
219
+ // Report identically to ESLint CLI
220
+ if (typeof err.messageTemplate === "string") {
221
+ try {
222
+ const eslintBase = `${require.resolve('eslint').split('eslint')[0]}/eslint`;
223
+ const template = require(path.join(eslintBase, `messages/${err.messageTemplate}.js`));
224
+ console.log(template(err.messageData || {}));
225
+ exit(1)
226
+ } catch {
227
+ // Ignore template error then fallback to use `error.stack`.
228
+ }
229
+ console.log(err.stack);
230
+ }
217
231
  exit(1)
218
232
  }
219
233
  }
@@ -250,19 +264,23 @@ class Linter {
250
264
  this.pluginPath = require.resolve("@sap/eslint-plugin-cds", {
251
265
  paths: [path.dirname(this.configPath)],
252
266
  });
267
+ this.pluginApi = require(this.pluginPath.replace("index.js", "api"));
253
268
  } catch (err) {
254
- // Do nothing
269
+ // CLI will report (no locally installed plugin)
255
270
  }
256
- this.pluginApi = require(this.pluginPath.replace("index.js", "api"));
257
271
  }
258
272
  }
259
273
  }
260
274
  }
261
275
  if (!this.pluginPath) {
262
- this.pluginPath = require.resolve("@sap/eslint-plugin-cds", {
263
- paths: [this.cdsdkPath],
264
- });
265
- this.pluginApi = require(this.pluginPath.replace("index.js", "api"));
276
+ try {
277
+ this.pluginPath = require.resolve("@sap/eslint-plugin-cds", {
278
+ paths: [this.cdsdkPath],
279
+ });
280
+ this.pluginApi = require(this.pluginPath.replace("index.js", "api"));
281
+ } catch (err) {
282
+ // CLI will report (no globally installed plugin)
283
+ }
266
284
  }
267
285
  // Project path is directory of ESLint config file
268
286
  this.projectPath = path.dirname(this.configPath);
@@ -1,4 +1,6 @@
1
- const DEBUG = /\b(y|all|cli|livereload)\b/.test(process.env.DEBUG) && console.debug
1
+ const cds = require('../cds')
2
+ const DEBUG = cds.debug('cli|livereload')
3
+
2
4
  const axios = require('axios')
3
5
  const ws = require('ws')
4
6
  const express = require('express')
@@ -19,7 +21,7 @@ module.exports = class LiveReload {
19
21
  const {address,port} = server.address()
20
22
  startWs(server)
21
23
  this.url = await livereloadURL(address, port)
22
- DEBUG && DEBUG(`[cds] - live reload available at ${this.url}`)
24
+ DEBUG?.(`live reload available at ${this.url}`)
23
25
  resolve(this.url)
24
26
  }
25
27
  // start server
@@ -39,13 +41,13 @@ module.exports = class LiveReload {
39
41
  const startWs = (server) => {
40
42
  this.wsServer = new ws.Server({ server })
41
43
  this.wsServer.on('connection', (socket) => {
42
- DEBUG && DEBUG('Client connected')
44
+ DEBUG?.('Client connected')
43
45
  socket.on('message', (msg) => {
44
- DEBUG && DEBUG('Client message', msg)
46
+ DEBUG?.('Client message', msg)
45
47
  const request = JSON.parse(msg)
46
48
 
47
49
  if (request.command === 'hello') {
48
- DEBUG && DEBUG('Client handshake')
50
+ DEBUG?.('Client handshake')
49
51
  const data = JSON.stringify({
50
52
  command: 'hello',
51
53
  protocols: [
@@ -59,16 +61,21 @@ module.exports = class LiveReload {
59
61
  })
60
62
  socket.send(data)
61
63
  } else if (request.command === 'info') {
62
- DEBUG && DEBUG('Server received client data. Not sending response.')
64
+ DEBUG?.('Server received client data. Not sending response.')
63
65
  }
64
66
  })
65
67
  })
66
- this.wsServer.on('close', () => { DEBUG && DEBUG('Socket closed') })
67
- this.wsServer.on('error', (e) => DEBUG && DEBUG(e))
68
+ if (DEBUG) {
69
+ server.on('close', () => DEBUG('⚡️','cds watch - livereload closed'))
70
+ this.wsServer.on('close', () => DEBUG('⚡️','cds watch - web socket closed'))
71
+ this.wsServer.on('error', (e) => DEBUG(e))
72
+ }
68
73
  }
69
- const close = () => { this.wsServer.close(); server.close(); DEBUG && DEBUG('Reload server closed') }
70
- process.once('SIGTERM', close)
71
- process.once('SIGINT', close)
74
+
75
+ process.once('shutdown', ()=>{
76
+ server.close()
77
+ this.wsServer.close()
78
+ })
72
79
  })
73
80
  }
74
81
 
@@ -81,7 +88,7 @@ module.exports = class LiveReload {
81
88
  command: 'reload',
82
89
  path: this.files.length ? this.files[0] : '',
83
90
  })
84
- DEBUG && DEBUG(`[cds] - live reload for ${this.files}. ${this.wsServer.clients.size} ws clients`)
91
+ DEBUG?.(`live reload for ${this.files}. ${this.wsServer.clients.size} ws clients`)
85
92
  broadcast(data, this.wsServer.clients)
86
93
  this.files = []
87
94
  }
@@ -93,8 +100,8 @@ module.exports = class LiveReload {
93
100
 
94
101
  function broadcast(data, sockets) {
95
102
  sockets.forEach(socket => {
96
- DEBUG && DEBUG(`Sending ${data}`)
97
- socket.send(data, err=> DEBUG && DEBUG(err))
103
+ DEBUG?.(`Sending ${data}`)
104
+ socket.send(data, err=> DEBUG?.(err))
98
105
  })
99
106
  }
100
107
 
@@ -1,4 +1,5 @@
1
- const DEBUG = /\b(y|all|cli|watch)\b/.test(process.env.DEBUG) && console.debug
1
+ const cds = require ('../cds')
2
+ const DEBUG = cds.debug('cli|watch')
2
3
 
3
4
  module.exports = ({ cwd, script, ext, includes=RegExp(), ignore=RegExp(), env={}, delay=200, options={} })=>{
4
5
 
@@ -8,19 +9,19 @@ module.exports = ({ cwd, script, ext, includes=RegExp(), ignore=RegExp(), env={}
8
9
  const EventEmitter = require('events')
9
10
  const emitter = new EventEmitter
10
11
 
11
- const killAndExit = (sig) => {
12
- DEBUG && DEBUG('\nreceived signal:', sig)
13
- _kill (child, process.exit)
12
+ process.on('SIGINT', ()=>console.log()) //> newline after ^C
13
+ process.on('SIGINT', _shutdown)
14
+ process.on('SIGTERM', _shutdown)
15
+ function _shutdown (signal,n) {
16
+ DEBUG?.('⚡️', signal, n, 'received by cds watch')
17
+ process.emit('shutdown')
14
18
  }
15
- process.on('SIGTERM', killAndExit)
16
- process.on('SIGINT', killAndExit)
17
19
 
18
20
  // Re-starting child process...
19
21
  const { fork } = require('child_process')
20
22
  const restart = _coalesceEvents(delay, (events) => {
21
- DEBUG && DEBUG('>> Events:', events)
23
+ DEBUG?.('Restart', {events})
22
24
  _kill (child, () => {
23
- DEBUG && console.trace('Restart')
24
25
  const execArgv = [...process.execArgv]
25
26
  events.forEach(evt => {
26
27
  if (evt.type && evt.type.startsWith('--')) execArgv.push(evt.type)
@@ -38,38 +39,46 @@ module.exports = ({ cwd, script, ext, includes=RegExp(), ignore=RegExp(), env={}
38
39
  if (msg === 'restart') return restart()
39
40
  emitter.emit('message', msg)
40
41
  })
42
+ // child.channel.unref()
43
+ // child.unref()
44
+ // child.on('exit', process.exit)
41
45
  })
42
46
 
43
47
  })
44
48
 
45
49
  restart()
50
+ process.on('shutdown', ()=> _kill(child))
46
51
 
47
52
  // Watching for touched files...
48
53
  const watch = require('node-watch')
49
54
  const include = RegExp(`\\.(${ext.replace(/,/g,'|')})$|${includes.source}`)
50
55
  const filter = f => !ignore.test(f) && include.test(f)
51
- watch (cwd||process.cwd(),{ recursive:true, filter, delay:0 }, restart)
56
+ const watcher = watch (cwd||process.cwd(),{ recursive:true, filter, delay:0 })
57
+ if (DEBUG) watcher.on('close', ()=> DEBUG('⚡️', 'cds watch - file watcher closed'))
58
+ watcher.on('change', restart)
59
+ process.on('shutdown', ()=> watcher.close())
52
60
 
53
61
  // Live commands...
54
- const readline = require('readline')
55
- readline.createInterface(process.stdin).on('line', (input) => {
62
+ const readline = require('readline').createInterface(process.stdin).on('line', (input) => {
56
63
  if (input === '') restart()
57
64
  else if (input === 'restart' || input === 'rs' || input.match(/^y$/i)) restart()
58
65
  else if (input === 'debug' || input === 'dbg') restart('--inspect')
59
66
  else if (input === 'break' || input === 'brk') restart('--inspect-brk')
60
67
  else if (input === 'debug-brk') restart('--inspect-brk')
61
68
  else if (input === 'ps') ps(child,env)
62
- else if (input === 'bye' || input.match(/^n$/i)) { _kill (child, () => process.exit()) }
69
+ else if (input === 'bye' || input.match(/^n$/i)) { _kill (child) }
63
70
  else console.log ('?\n')
64
71
  })
72
+ if (DEBUG) readline.on('close', ()=> DEBUG('⚡️', 'cds watch - readline closed'))
73
+ process.on('shutdown', ()=> readline.close())
65
74
 
66
75
  emitter.restart = restart
67
- emitter.stop = () => _kill(child, () => false)
76
+ emitter.stop = () => _kill(child)
68
77
  emitter.setEnv = (name, value) => {
69
78
  if (typeof value === "undefined") {
70
79
  delete env[name]
71
80
  } else {
72
- env[name]
81
+ env[name] // REVISIT: no value assigned ???
73
82
  }
74
83
  }
75
84
  return emitter
@@ -85,58 +94,51 @@ const ps = (child,env) => console.log (`\x1b[32m
85
94
  // reduces mutiple node-watch events in a time frame into a bulk
86
95
  function _coalesceEvents(delay, fn) {
87
96
  let timer, cache = []
88
- function handle() {
89
- fn(cache)
90
- timer = null
91
- cache = []
92
- }
93
97
  return function(type, name) { // node-watch callback signature
94
- cache.push({type, name})
95
- if (!timer) {
96
- timer = setTimeout(handle, delay);
97
- }
98
+ if (type) cache.push({type, name})
99
+ if (!timer) timer = setTimeout(() => {
100
+ fn(cache)
101
+ timer = null
102
+ cache = []
103
+ }, delay).unref();
98
104
  }
99
105
  }
100
106
 
101
107
  /*
102
108
  * Ensures the given child process gets killed in different environments
103
109
  */
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(); }
110
+ function _kill (child, cb=()=>{}) {
111
+ if (!child) return cb()
112
+ if (child[_pending]) return // safeguard against repeated calls for the same process
113
+ child[_pending] = true
114
+ const _done = () => { delete child[_pending]; return cb(); }
109
115
 
110
- const waitTime = parseInt(process.env.CDS_WATCH_KILL_DELAY) || 500
116
+ const waitTime = parseInt(process.env.CDS_WATCH_KILL_DELAY) || 2222
111
117
  // On Windows, child_process.kill() abruptly kills the process (https://nodejs.org/api/child_process.html#subprocesskillsignal)
112
118
  // Server has cleanup code to run, so send a custom message and give it a bit time.
113
119
  if (process.platform === 'win32') {
114
- proc.send({ close: true }, () => {}) // see @sap/cds/bin/serve.js
120
+ child.send({ close: true }, () => {}) // see @sap/cds/bin/serve.js
115
121
  setTimeout(()=> {
116
- proc.kill()
117
- DEBUG && DEBUG('Killed process', proc.pid)
118
- fn()
119
- }, waitTime)
122
+ child.kill()
123
+ DEBUG?.('Killed process', child.pid)
124
+ _done()
125
+ }, waitTime).unref()
120
126
  return
121
127
  }
122
128
 
129
+ // fallback for misbehaving processes: SIGKILL it after some time
130
+ const forced = setTimeout(()=> {
131
+ DEBUG?.('⚡️', 'cds watch - killing child forcefully!')
132
+ child.kill('SIGKILL')
133
+ }, waitTime).unref()
134
+
123
135
  // 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()
136
+ child.on('exit',() => { clearTimeout(forced)
137
+ DEBUG?.('⚡️', 'cds watch - child exited', child.pid)
138
+ _done()
139
+ })
131
140
 
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)
141
+ child.kill()
140
142
  }
141
143
 
142
144
  const _pending = Symbol.for('sap.cds.watch.pendingKill')