@sap/cds-dk 4.8.2 → 4.9.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 (83) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/bin/activate.js +8 -7
  3. package/bin/bind.js +12 -12
  4. package/bin/build/all.js +3 -5
  5. package/bin/build/index.js +1 -1
  6. package/bin/cds.js +1 -1
  7. package/bin/deploy/index.js +7 -1
  8. package/bin/deploy/to-hana.js +5 -4
  9. package/bin/deploy/to-sqlite.js +2 -1
  10. package/bin/extend.js +5 -5
  11. package/bin/help.js +1 -0
  12. package/bin/import.js +45 -31
  13. package/bin/login.js +5 -6
  14. package/bin/logout.js +2 -2
  15. package/bin/parse.js +19 -0
  16. package/lib/bind/bindingUtil.js +41 -49
  17. package/lib/bind/cfKeyProvider.js +9 -17
  18. package/lib/bind/userCdsrcJsonStorageProvider.js +1 -0
  19. package/lib/client/activate.js +3 -2
  20. package/lib/client/extend.js +5 -6
  21. package/lib/client/helper/fs_helper.js +8 -8
  22. package/lib/client/settings_manager.js +12 -9
  23. package/lib/compile/openapi/csdl2openapi.js +213 -165
  24. package/lib/compile/openapi/index.js +1 -2
  25. package/lib/compile/to-xsuaa.js +1 -1
  26. package/lib/import/index.js +22 -15
  27. package/lib/import/message.js +3 -1
  28. package/lib/import/utils/MetadataConverter.js +1 -1
  29. package/lib/import/v2parser.js +112 -56
  30. package/lib/import/v4parser.js +149 -98
  31. package/lib/init/constants.js +6 -2
  32. package/lib/init/index.js +3 -2
  33. package/lib/init/template/_merging/existences.js +80 -4
  34. package/lib/init/template/approuter/files/cds.cdsrc.json +7 -0
  35. package/lib/init/template/approuter/files/cds.cdsrc.json.hbs +9 -0
  36. package/lib/init/template/approuter/files/cds.package.json +9 -0
  37. package/lib/init/template/approuter/files/cds.package.json.hbs +11 -0
  38. package/lib/init/template/approuter/files/index.html +1 -0
  39. package/lib/init/template/approuter/files/mta.yaml.hbs +35 -21
  40. package/lib/init/template/approuter/files/package.json +3 -0
  41. package/lib/init/template/approuter/files/xs-app.json.hbs +19 -0
  42. package/lib/init/template/approuter/index.js +47 -18
  43. package/lib/init/template/auditlog/index.js +5 -5
  44. package/lib/init/template/hana/files/java/cdsrc.json.hbs +7 -0
  45. package/lib/init/template/hana/files/java/{package.json → db/package.json} +0 -0
  46. package/lib/init/template/hana/files/java/profile.cdsrc.json.hbs +12 -0
  47. package/lib/init/template/hana/files/mta.yaml.hbs +10 -17
  48. package/lib/init/template/hana/files/nodejs/cds.package.json.hbs +9 -0
  49. package/lib/init/template/hana/files/nodejs/cds.profile.package.json.hbs +14 -0
  50. package/lib/init/template/hana/files/nodejs/dependencies.package.json +1 -1
  51. package/lib/init/template/hana/index.js +60 -86
  52. package/lib/init/template/java/index.js +5 -2
  53. package/lib/init/template/kibana-logging/files/cds.package.json +7 -0
  54. package/lib/init/template/kibana-logging/files/cds.profile.package.json.hbs +9 -0
  55. package/lib/init/template/kibana-logging/files/mta.yaml.hbs +13 -0
  56. package/lib/init/template/kibana-logging/index.js +64 -0
  57. package/lib/init/template/mta/files/mta.yaml.hbs +3 -8
  58. package/lib/init/template/mta/index.js +8 -2
  59. package/lib/init/template/mtx/files/cds.package.json +0 -12
  60. package/lib/init/template/mtx/files/cds.package.json.hbs +14 -0
  61. package/lib/init/template/mtx/files/java/.cdsrc.json +17 -0
  62. package/lib/init/template/mtx/files/java/package.json +43 -0
  63. package/lib/init/template/mtx/files/java/server.js +30 -0
  64. package/lib/init/template/mtx/files/mta.yaml.hbs +6 -6
  65. package/lib/init/template/mtx/index.js +41 -22
  66. package/lib/init/template/templateBase.js +4 -1
  67. package/lib/init/template/xsuaa/files/cds.cdsrc.json +7 -0
  68. package/lib/init/template/xsuaa/files/cds.cdsrc.json.hbs +9 -0
  69. package/lib/init/template/xsuaa/files/cds.package.json +1 -1
  70. package/lib/init/template/xsuaa/files/cds.package.json.hbs +11 -0
  71. package/lib/init/template/xsuaa/files/mta.yaml.hbs +2 -2
  72. package/lib/init/template/xsuaa/index.js +43 -27
  73. package/lib/init/types.d.ts +43 -19
  74. package/lib/init/util/fsUtil.js +15 -4
  75. package/lib/init/util/projectReader.js +21 -18
  76. package/lib/init/util/templateUtil.js +78 -28
  77. package/lib/util/exec.js +2 -2
  78. package/lib/watch/livereload-server.js +3 -0
  79. package/lib/watch/node-watch.js +8 -1
  80. package/npm-shrinkwrap.json +170 -148
  81. package/package.json +3 -3
  82. package/lib/init/template/approuter/files/xs-app.json +0 -8
  83. package/lib/init/template/nodejs/files/.vscode/settings.json +0 -7
@@ -39,29 +39,21 @@ class CFKeyProvider {
39
39
  return result.data;
40
40
  }
41
41
 
42
- extract(string, pattern, defaultValue) {
43
- const array = string.split(/[\n\r]+/);
44
- for (let line of array) {
45
- const match = line.match(pattern);
46
- if (match) {
47
- return match[1];
48
- }
49
- }
50
-
51
- if (typeof defaultValue === 'undefined') {
52
- throw Error(`Pattern not found: ${pattern}`);
53
- } else {
54
- return defaultValue;
42
+ extract(string, pattern, errorMsg) {
43
+ const match = string.match(pattern);
44
+ if (!match || !match[1]) {
45
+ throw new Error(errorMsg);
55
46
  }
47
+ return match[1];
56
48
  }
57
49
 
58
50
  async getCfTargetFromCli() {
59
51
  const result = await this._cfRead('target');
60
52
  return {
61
- apiEndpoint: this.extract(result, /^api endpoint:\s+(.*)$/i),
62
- user: this.extract(result, /^user:\s+(.*)$/i),
63
- org: this.extract(result, /^org:\s+(.*)$/i),
64
- space: this.extract(result, /^space:\s+(.*)$/i),
53
+ apiEndpoint: this.extract(result, /api endpoint\s*:\s*(.*)/i, `CF API endpoint is missing. Use 'cf login' to login.`),
54
+ user: this.extract(result, /user\s*:\s*(.*)/i, `CF user is missing. Use 'cf login' to login.`),
55
+ org: this.extract(result, /org\s*:\s*(.*)/i, `CF org is missing. Use 'cf target -o <ORG> to specify.`),
56
+ space: this.extract(result, /space\s*:\s*(.*)/i, `CF space is missing. Use 'cf target -s <SPACE>' to specify.`),
65
57
  };
66
58
  }
67
59
 
@@ -2,6 +2,7 @@ const os = require('os');
2
2
  const path = require('path');
3
3
  const readline = require('readline');
4
4
 
5
+ // TODO transition to fs → need to mock fs and fse in test (cf. MTX client)
5
6
  const { fse } = require('@sap/cds-foss');
6
7
  const { highlight } = require('../util/term');
7
8
 
@@ -1,6 +1,6 @@
1
+ const fs = require('fs').promises;
1
2
  const path = require('path');
2
3
  const axios = require('axios');
3
- const { fse } = require('@sap/cds-foss');
4
4
 
5
5
  const AuthManager = require('./auth_manager');
6
6
  const BaseCommand = require('./base_command');
@@ -122,6 +122,7 @@ module.exports = class Activate extends BaseCommand {
122
122
  return !(/.*node_modules\/_base\/.*/.test(unixFilename));
123
123
  });
124
124
 
125
+ // FIXME remove async
125
126
  i18nFolders.forEach(async(folder) => {
126
127
  const i18nFiles = collectFiles(projectFolder, folder, entry => {
127
128
  const ext = path.extname(entry);
@@ -131,7 +132,7 @@ module.exports = class Activate extends BaseCommand {
131
132
  });
132
133
 
133
134
  try {
134
- const pkgJson = await fse.readFile(path.join(absoluteFolder, 'package.json'), 'utf-8');
135
+ const pkgJson = await fs.readFile(path.join(absoluteFolder, 'package.json'), 'utf-8');
135
136
  allFiles.set('package.json', pkgJson);
136
137
  } catch(e) {
137
138
  Logger.log('No package.json file found');
@@ -1,5 +1,6 @@
1
- const axios = require('axios');
1
+ const fs = require('fs');
2
2
  const path = require('path');
3
+ const axios = require('axios');
3
4
  const { fse } = require('@sap/cds-foss');
4
5
 
5
6
  const AuthManager = require('./auth_manager');
@@ -24,10 +25,8 @@ module.exports = class Extend extends BaseCommand {
24
25
  static get COMMAND_URL_SUFFIX() { return COMMAND_URL_SUFFIX; }
25
26
 
26
27
  static async storeFiles(content, targetDirectory, filter) {
27
- if (!fse.existsSync(targetDirectory)) {
28
- fse.mkdirpSync(targetDirectory);
29
- }
30
- targetDirectory = fse.realpathSync(targetDirectory)
28
+ fse.mkdirpSync(targetDirectory);
29
+ targetDirectory = fs.realpathSync(targetDirectory)
31
30
  const writtenFiles = new Set();
32
31
  const filesToWrite = new Map();
33
32
  for (const [filename, filecontent] of content) {
@@ -39,7 +38,7 @@ module.exports = class Extend extends BaseCommand {
39
38
  for (const [filepath, content] of [...filesToWrite.entries()]) {
40
39
  const normalizedFilepath = normalizePath(filepath);
41
40
  fse.mkdirpSync(path.dirname(normalizedFilepath));
42
- fse.writeFileSync(normalizedFilepath, content);
41
+ fs.writeFileSync(normalizedFilepath, content);
43
42
  writtenFiles.add(path.relative(process.cwd(), normalizedFilepath));
44
43
  Extend._logWrittenFile(normalizedFilepath);
45
44
  }
@@ -1,10 +1,10 @@
1
+ const fs = require('fs');
1
2
  const path = require('path');
2
- const { fse } = require('@sap/cds-foss');
3
3
 
4
4
  async function collectFileContent(filePaths, root) {
5
5
  const resultMap = new Map();
6
6
  filePaths.forEach((filePath) => {
7
- const fileContent = fse.readFileSync(filePath);
7
+ const fileContent = fs.readFileSync(filePath);
8
8
  resultMap.set(toUnixPath(path.relative(root, filePath)), fileContent.toString('utf-8'));
9
9
  });
10
10
  return resultMap;
@@ -26,20 +26,20 @@ function collectFiles(root, sourceDir, filter) {
26
26
 
27
27
  function _traverseFileSystem(root, sourceDir, files, filter) {
28
28
  let absoluteDir = path.resolve(root, sourceDir);
29
- if (!fse.existsSync(absoluteDir)) {
29
+ if (!fs.existsSync(absoluteDir)) {
30
30
  return;
31
31
  }
32
- absoluteDir = fse.realpathSync(absoluteDir);
33
- if (fse.statSync(absoluteDir)) {
34
- fse.readdirSync(absoluteDir)
32
+ absoluteDir = fs.realpathSync(absoluteDir);
33
+ if (fs.statSync(absoluteDir)) {
34
+ fs.readdirSync(absoluteDir)
35
35
  .map(subDirEntry => path.join(absoluteDir, subDirEntry))
36
36
  .forEach(entry => {
37
- const stats = fse.statSync(entry)
37
+ const stats = fs.statSync(entry)
38
38
  if (stats.isDirectory()) {
39
39
  _traverseFileSystem(root, entry, files, filter);
40
40
  }
41
41
  if (stats.isFile() && (!filter || filter.call(this, entry))) {
42
- const fileContent = fse.readFileSync(entry);
42
+ const fileContent = fs.readFileSync(entry);
43
43
  files.set(toUnixPath(path.relative(root, entry)), fileContent.toString('utf-8'));
44
44
  }
45
45
  });
@@ -1,3 +1,4 @@
1
+ const fs = require('fs');
1
2
  const os = require('os');
2
3
  const path = require('path');
3
4
  const { fse } = require('@sap/cds-foss');
@@ -54,12 +55,14 @@ function other(tokenStorage) {
54
55
  }
55
56
 
56
57
  function getProjectFolder(params) {
57
- const relativePath = params.get('projectFolder') || params.get('directory') || (
58
- params.has('subdomain') && fse.existsSync(params.get('subdomain'))
59
- ? params.get('subdomain')
60
- : '.'
61
- );
62
- return fse.realpathSync(relativePath);
58
+ if (params.has('projectFolder')) {
59
+ const maybeExistentPath = path.resolve(params.get('projectFolder'));
60
+ return maybeExistentPath;
61
+ }
62
+ const existentPath = params.has('subdomain') && fs.existsSync(params.get('subdomain'))
63
+ ? params.get('subdomain')
64
+ : '.';
65
+ return fs.realpathSync(existentPath);
63
66
  }
64
67
 
65
68
  async function getAppUrlAndSubdomainFromSuggestions(params) {
@@ -348,7 +351,7 @@ class SettingsManager {
348
351
  const deletionUrlsAndSubdomains = new Set();
349
352
 
350
353
  Object.entries(settingsByFolder)
351
- .filter(entry => ! fse.pathExistsSync(entry[0]))
354
+ .filter(entry => ! fs.existsSync(entry[0]))
352
355
  .forEach(entry => {
353
356
  delete settingsByFolder[entry[0]];
354
357
  deletionFolders.push(entry[0]);
@@ -433,7 +436,7 @@ class SettingsManager {
433
436
  static async _loadFromFile(projectFolder) {
434
437
  const all = !projectFolder;
435
438
 
436
- if (!fse.existsSync(CONFIG.paths.settings)) {
439
+ if (!fs.existsSync(CONFIG.paths.settings)) {
437
440
  Logger.debug('Settings file absent');
438
441
  return emptyData(all);
439
442
  }
@@ -461,7 +464,7 @@ class SettingsManager {
461
464
  static async _loadAuthFromFile(appUrl, subdomain) {
462
465
  const all = !appUrl;
463
466
 
464
- if (!fse.existsSync(CONFIG.paths.auth)) {
467
+ if (!fs.existsSync(CONFIG.paths.auth)) {
465
468
  Logger.debug('Authentication-data file absent');
466
469
  return emptyData(all);
467
470
  }