@sap/cds-dk 8.7.1 → 8.7.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,20 @@ This project adheres to [Semantic Versioning](https://semver.org/).
7
7
 
8
8
  The format is based on [Keep a Changelog](https://keepachangelog.com/).
9
9
 
10
+ ## Version 8.7.2 - 2024-02-14
11
+
12
+ ### Fixed
13
+
14
+ - `cds compile -o` with a file name such as `cds c srv/cat-service.cds -o srv/cat-service.json`.
15
+ - `cds compile` without `-o` doesn't print the file name header for single services any more.
16
+ - `cds add workzone` in combination with multitenancy doesn't throw an error any more.
17
+ - `cds import --from rfc` stores the input file again in `srv/external/<destination>/...` instead of `srv/external/...`.
18
+ - `cds import --name` no longer crashes with a `TypeError`.
19
+ - `cds import --out <filename>` no longer crashes with a `Error: EEXIST`.
20
+ - `BuildError` no longer cuts off its stack.
21
+ - `cds bind -a` doesn't concurrently try to check the Cloud Foundry version or OAuth token.
22
+ - `cds import` now resolves target of association/composition correctly for multiple schema files.
23
+
10
24
  ## Version 8.7.1 - 2024-02-04
11
25
 
12
26
  ### Fixed
@@ -217,7 +217,15 @@ async function compile_all (root='.') {
217
217
  }
218
218
 
219
219
  async function compile (models, options={}) {
220
- options.service ??= 'all'
220
+ const { dest } = options
221
+ if (dest) {
222
+ options.service ??= 'all'
223
+ const ext = path.extname(dest)
224
+ if (ext) {
225
+ options.file ??= path.basename(dest, ext)
226
+ options.dest = path.dirname(dest)
227
+ }
228
+ }
221
229
  if (options.all) return compile_all (models[0])
222
230
 
223
231
  const { inspect } = require('util')
package/bin/import.js CHANGED
@@ -28,7 +28,6 @@ module.exports = Object.assign(_import, {
28
28
 
29
29
  *-o | --out* <filename/dirname>
30
30
  Skips copying to ./srv/external and writes to the specified location.
31
- Dirname is only applicable for importing odata-V4 file with dependencies.
32
31
 
33
32
  *- | --dry*
34
33
  Writes the converted csn to stdout only.
@@ -70,7 +69,7 @@ module.exports = Object.assign(_import, {
70
69
  *-d | --dependencies* <comma-separated list of dependencies>
71
70
  Imports the given list of dependencies along with the main file. Valid for OData V4 only.
72
71
  The dependencies are written to the given dirname(-o option) or ./srv/external.
73
- If the cds files of dependencies are already present in the destination, it will be skipped
72
+ If the cds files of dependencies are already present in the destination, it will be skipped
74
73
  if -f option is not given.
75
74
  NOTE: The dependencies must not have any dependency.
76
75
 
@@ -106,7 +105,7 @@ async function _import(args, options = {}) {
106
105
  const messages = require('../lib/import/message').getMessages();
107
106
  const common = require('../lib/import/common');
108
107
  const cds = require('../lib/index');
109
-
108
+
110
109
  // check if dependencies are provided and import them first
111
110
  if (options.dependencies) {
112
111
  const dependencies = options.dependencies.split(',');
@@ -133,10 +132,11 @@ async function _import(args, options = {}) {
133
132
  input = await common.preProcess(file, options, cwd);
134
133
  }
135
134
 
136
- const fileType = await common.identifyFile(input);
137
- if ((options.isDependency || options.isDependent)
138
- && fileType !== 'edmx') {
139
- throw messages.DEPENDENCY_NOT_SUPPORTED;
135
+ if (input) {
136
+ const fileType = await common.identifyFile(input);
137
+ if ((options.isDependency || options.isDependent) && fileType !== 'edmx') {
138
+ throw messages.DEPENDENCY_NOT_SUPPORTED;
139
+ }
140
140
  }
141
141
 
142
142
  let csn
package/lib/build/util.js CHANGED
@@ -207,7 +207,7 @@ async function getWorkspaces(wsRoot, resolve = false, devDependencies = true) {
207
207
  // read npm workspaces
208
208
  const pkgs = await _execNpmWs(wsRoot)
209
209
  pkgs.forEach(pkg => {
210
- // only create tarball archives for dependencies with version '*'
210
+ // only create tarball archives for dependencies with version '*'
211
211
  if (!resolve || devDependencies && pgkJson.devDependencies?.[pkg] === '*' || pgkJson.dependencies?.[pkg] === '*') {
212
212
  const workspace = _getWorkspace(wsRoot, pkg)
213
213
  if (workspace) {
@@ -240,11 +240,11 @@ function findWorkspaceRoot(currentPath, depth = 0) {
240
240
  }
241
241
 
242
242
  /**
243
- * This JavaScript function filterFeaturePaths is used to filter and categorize file paths
243
+ * This JavaScript function filterFeaturePaths is used to filter and categorize file paths
244
244
  * from a given model into two categories: base and features.
245
245
  * @param {*} model - represents a data model. It's expected to have a $sources property which is an array of file paths.
246
246
  * @param {*} modelPaths - an array of file paths.
247
- * @returns
247
+ * @returns
248
248
  */
249
249
  function filterFeaturePaths(model, modelPaths) {
250
250
  const ftsName = path.dirname(cds.env.features.folders || 'fts/*')
@@ -278,8 +278,8 @@ function filterFeaturePaths(model, modelPaths) {
278
278
  }
279
279
 
280
280
  /**
281
- * Read installed npm workspaces using 'npm ls -ws --json'.
282
- * @returns {Array} list of package paths, or an empty array if either
281
+ * Read installed npm workspaces using 'npm ls -ws --json'.
282
+ * @returns {Array} list of package paths, or an empty array if either
283
283
  * no workspaces are defined or have not been installed.
284
284
  */
285
285
  async function _execNpmWs(wsRoot) {
@@ -331,7 +331,7 @@ function _validateWsDependencies(wsRoot, dependencies, devDependencies) {
331
331
  /**
332
332
  * Returns a flat array of existing files and folders, trailing '/' or '\\' characters have been removed.
333
333
  * @param {Array} modelPaths array of files and folders - optionally nested
334
- * @returns
334
+ * @returns
335
335
  */
336
336
  function _filterModelPaths(modelPaths, filter) {
337
337
  const model = new Set()
@@ -424,7 +424,7 @@ class BuildMessage {
424
424
  * @param {string} message The message text
425
425
  * @param {string} [severity='Error'] Severity: Debug, Info, Warning, Error
426
426
  * @param {any} location Location of the message
427
- *
427
+ *
428
428
  * @memberOf BuildMessage
429
429
  */
430
430
  constructor(message, severity = SEVERITY_ERROR, location) {
@@ -439,9 +439,9 @@ class BuildMessage {
439
439
  }
440
440
 
441
441
  /**
442
- * Class for combined build and compiler errors.
442
+ * Class for combined build and compiler errors.
443
443
  * Additional members:
444
- * messages: vector of detailed build messages
444
+ * messages: array of detailed build messages
445
445
  * @class BuildError
446
446
  * @extends {Error}
447
447
  */
@@ -450,7 +450,6 @@ class BuildError extends Error {
450
450
  super(message)
451
451
  this.name = "BuildError"
452
452
  this.messages = Array.isArray(messages) ? messages : [messages]
453
- this.stack = ""
454
453
  }
455
454
 
456
455
  // for compatibility reasons
@@ -444,13 +444,8 @@ function _findPackageJson(dir, cwd) {
444
444
 
445
445
  async function postProcess(filePath, options, csn, cwd) {
446
446
  const services = _getServiceNames(csn);
447
- let destFilePath;
448
-
449
- if (options.isDependency || options.isDependent) {
450
- destFilePath = path.resolve(cwd, options.out ? path.join(options.out, path.basename(filePath)) : path.join(cds.env.folders.srv, 'external', path.basename(filePath)));
451
- } else {
452
- destFilePath = path.resolve(cwd, options.out ? path.join(path.dirname(options.out), path.basename(filePath)) : path.join(cds.env.folders.srv, 'external', path.basename(filePath)));
453
- }
447
+ const out = options.out || path.join(cds.env.folders.srv, 'external');
448
+ let destFilePath = path.resolve(cwd, path.join(out, path.basename(filePath)));
454
449
 
455
450
  if (options.out) {
456
451
  options.out = _validateAndComputeOutputFilePath(options.out, options.as, destFilePath);
@@ -465,7 +460,7 @@ async function postProcess(filePath, options, csn, cwd) {
465
460
  const kind = options.inputFileKind;
466
461
  let result;
467
462
  try {
468
- result = await _getResult(csn, options.as, options.out || destFilePath.replace(/\.[^.]+$/, ''), options.force, kind, options.isDependent);
463
+ result = await _getResult(csn, options.as, options.out || destFilePath.replace(/\.[^.]+$/, ''), options.force, kind, options.isDependent);
469
464
  } catch (error) {
470
465
  if (options.isDependency && error.message === messages.FILE_MODIFIED) {
471
466
  return console.log(info(`[cds] - skipping import of ${path.basename(filePath)} as it is already imported`));
@@ -476,6 +471,9 @@ async function postProcess(filePath, options, csn, cwd) {
476
471
 
477
472
  const [serviceCsn, csnFile] = result;
478
473
 
474
+ // destFilePath might be wrongly computed and contain the csn file name in the path. Fix it here.
475
+ destFilePath = destFilePath.replace(csnFile, path.dirname(csnFile));
476
+
479
477
  if (!options.dry && !options.no_save) {
480
478
  if (cds.env['project-nature'] === 'java') {
481
479
  await _updateJavaConfig(kind, services, csn, options)
@@ -28,7 +28,7 @@ module.exports = Object.assign(cds_import, {
28
28
  */
29
29
  async function cds_import(filepath, options = { keepNamespace: false }) {
30
30
  // identifies the file and calls the respective api
31
- let fileType = await common.identifyFile(filepath);
31
+ let fileType = filepath && await common.identifyFile(filepath);
32
32
 
33
33
  let csn;
34
34
  switch (fileType) {
@@ -37,6 +37,7 @@ module.exports = class ParserContext {
37
37
  this.primarySchema = "";
38
38
  this.schemaAliasToNamespace = {};
39
39
  this.schemaToSchemaDataIndex = {};
40
+ this.schemaToPrimarySchema = {};
40
41
  this.vocabNamespaceToAlias = {};
41
42
  this.entityToBoundActions = {};
42
43
  this.entityToBoundFunctions = {};
@@ -641,11 +641,11 @@ function _parseAssociationProperty(foreignReference, associationNode, parserCont
641
641
  if (entityTypeMapping.length > 1) {
642
642
  for (let j = 0; j < entityTypeMapping.length; j++) {
643
643
  if (entityTypeMapping[j] === foreignReference) {
644
- associationProperty.target = schemaName + '.' + entityTypeMapping[j];
644
+ associationProperty.target = parserContext.schemaToPrimarySchema[schemaName] + '.' + entityTypeMapping[j];
645
645
  }
646
646
  }
647
647
  } else {
648
- associationProperty.target = schemaName + '.' + entityTypeMapping;
648
+ associationProperty.target = parserContext.schemaToPrimarySchema[schemaName] + '.' + entityTypeMapping;
649
649
  }
650
650
  } else {
651
651
  associationProperty.target = resolvedEntityName;
@@ -1554,6 +1554,7 @@ function _preProcess(edmxAsJson, parserContext, importerContext) {
1554
1554
  parserContext.schemaAliasToNamespace[schemaData.$Alias] = schemaName;
1555
1555
  }
1556
1556
  parserContext.schemaToSchemaDataIndex[schemaName] = indexOfSchema;
1557
+ parserContext.schemaToPrimarySchema[schemaName] = parserContext.primarySchema;
1557
1558
  indexOfSchema++;
1558
1559
  }
1559
1560
  // if mock server use case & traversing primary schema, collect relevant mappings
@@ -24,11 +24,6 @@ module.exports = class MultitenancyTemplate extends require('../../plugin') {
24
24
  return options?.add?.has('mtx') || options?.add?.has('multitenancy') || !!env.requires?.multitenancy || false
25
25
  }
26
26
 
27
- canRun() {
28
- if (cds.requires.workzone) throw `There is no 'cds add multitenancy' support for SAP BTP WorkZone yet.`
29
- return true
30
- }
31
-
32
27
  async run() {
33
28
  const project = readProject()
34
29
  const { isNodejs, isJava, configFile } = project
@@ -19,13 +19,6 @@ module.exports = class extends require('../../plugin') {
19
19
  return !!env.requires?.workzone || cds.cli.options.add.has('workzone-standard')
20
20
  }
21
21
 
22
- canRun() {
23
- if (cds.requires.multitenancy) {
24
- throw `SAP BTP Work Zone, Standard Edition does not support multitenancy yet.`
25
- }
26
- return true
27
- }
28
-
29
22
  async run() {
30
23
  const project = readProject()
31
24
  const { appUIPaths, appPath } = project
package/lib/util/cf.js CHANGED
@@ -44,7 +44,7 @@ module.exports = new class CfUtil {
44
44
  args = args.map(arg => arg.replace(/"/g, '\\"'));
45
45
  const cmdLine = `${CF_COMMAND} "${args.join('" "')}"`;
46
46
  DEBUG?.time(cmdLine);
47
- LOG.debug('>>>', cmdLine);
47
+ DEBUG?.('>>>', cmdLine);
48
48
 
49
49
  try {
50
50
  const result = await execAsync(cmdLine, {
@@ -146,13 +146,21 @@ module.exports = new class CfUtil {
146
146
  }
147
147
  }
148
148
 
149
+ #token
149
150
  async _getCfAuthorization() {
150
- DEBUG?.('getting authorization');
151
- try {
152
- return (await this.cfRun('oauth-token')).stdout;
153
- } catch (err) {
154
- throw err.message;
151
+ if (this.#token) return this.#token
152
+ if (!this._tokenPromise) {
153
+ this._tokenPromise = this.cfRun('oauth-token')
154
+ .then(result => {
155
+ this.#token = result.stdout
156
+ return this.#token
157
+ })
158
+ .catch(err => {
159
+ this._tokenPromise = null
160
+ throw err.message
161
+ })
155
162
  }
163
+ return this._tokenPromise
156
164
  }
157
165
 
158
166
  async getCfTarget() {
@@ -163,7 +171,10 @@ module.exports = new class CfUtil {
163
171
  return target;
164
172
  }
165
173
 
174
+ #checkedVersion = false
166
175
  async _checkCliVersion() {
176
+ if (this.#checkedVersion) return
177
+ this.#checkedVersion = true
167
178
  const result = await this.cfRun('-v');
168
179
  const version = result?.stdout?.match(/version.*(\d+\.\d+\.\d+)/i)
169
180
  if (parseInt(version?.[1]) < CF_CLIENT_MINIMUM_VERSION) {
@@ -358,7 +369,7 @@ Deployment will stop in the near future for Cloud Foundry client versions < ${CF
358
369
  async getOrCreateServiceKey(serviceInstance, serviceKeyName, parameters, { silent = false, create = true } = {}) {
359
370
  const serviceKey = await this._getServiceKey(serviceInstance, serviceKeyName, false);
360
371
  if (serviceKey || !create) {
361
- if (serviceKey && !silent) console.log(`getting service key ${bold(serviceKeyName)}`);
372
+ if (serviceKey && !silent) DEBUG?.(`getting service key ${bold(serviceKeyName)}`);
362
373
  return serviceKey;
363
374
  }
364
375
 
@@ -389,4 +400,4 @@ Deployment will stop in the near future for Cloud Foundry client versions < ${CF
389
400
 
390
401
  throw `Could not create service key ${bold(serviceKeyName)}`;
391
402
  }
392
- }
403
+ }
package/lib/util/write.js CHANGED
@@ -88,7 +88,7 @@ function _write (content, /*to:*/ dest, _many) { // NOSONAR
88
88
  }
89
89
 
90
90
  file = path.resolve (cds.root,file)
91
- // write to the target file, creating parent folders if neccessary
91
+ // write to the target file, creating parent folders if necessary
92
92
  return mkdirp (dirname(file))
93
93
  .then (()=> fs.writeFile (file, typeof content === 'string' ? content : JSON.stringify (content, null, 2)))
94
94
  .then (()=> dest.foreach && dest.foreach(file))
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@sap/cds-dk",
3
- "version": "8.7.1",
3
+ "version": "8.7.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@sap/cds-dk",
9
- "version": "8.7.1",
9
+ "version": "8.7.2",
10
10
  "license": "SEE LICENSE IN LICENSE",
11
11
  "dependencies": {
12
12
  "@cap-js/asyncapi": "^1.0.0",
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "node_modules/@cap-js/db-service": {
46
- "version": "1.17.0",
46
+ "version": "1.17.2",
47
47
  "license": "SEE LICENSE",
48
48
  "optional": true,
49
49
  "dependencies": {
@@ -121,7 +121,7 @@
121
121
  }
122
122
  },
123
123
  "node_modules/@eslint/core": {
124
- "version": "0.10.0",
124
+ "version": "0.11.0",
125
125
  "license": "Apache-2.0",
126
126
  "dependencies": {
127
127
  "@types/json-schema": "^7.0.15"
@@ -152,7 +152,7 @@
152
152
  }
153
153
  },
154
154
  "node_modules/@eslint/js": {
155
- "version": "9.19.0",
155
+ "version": "9.20.0",
156
156
  "license": "MIT",
157
157
  "engines": {
158
158
  "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
@@ -176,6 +176,16 @@
176
176
  "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
177
177
  }
178
178
  },
179
+ "node_modules/@eslint/plugin-kit/node_modules/@eslint/core": {
180
+ "version": "0.10.0",
181
+ "license": "Apache-2.0",
182
+ "dependencies": {
183
+ "@types/json-schema": "^7.0.15"
184
+ },
185
+ "engines": {
186
+ "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
187
+ }
188
+ },
179
189
  "node_modules/@humanfs/core": {
180
190
  "version": "0.19.1",
181
191
  "license": "Apache-2.0",
@@ -228,7 +238,7 @@
228
238
  }
229
239
  },
230
240
  "node_modules/@sap/cds": {
231
- "version": "8.7.0",
241
+ "version": "8.7.2",
232
242
  "license": "SEE LICENSE IN LICENSE",
233
243
  "dependencies": {
234
244
  "@sap/cds-compiler": ">=5.1",
@@ -258,7 +268,7 @@
258
268
  }
259
269
  },
260
270
  "node_modules/@sap/cds-compiler": {
261
- "version": "5.7.2",
271
+ "version": "5.7.4",
262
272
  "license": "SEE LICENSE IN LICENSE",
263
273
  "dependencies": {
264
274
  "antlr4": "4.9.3"
@@ -626,7 +636,7 @@
626
636
  }
627
637
  },
628
638
  "node_modules/call-bind-apply-helpers": {
629
- "version": "1.0.1",
639
+ "version": "1.0.2",
630
640
  "license": "MIT",
631
641
  "dependencies": {
632
642
  "es-errors": "^1.3.0",
@@ -906,15 +916,15 @@
906
916
  }
907
917
  },
908
918
  "node_modules/eslint": {
909
- "version": "9.19.0",
919
+ "version": "9.20.1",
910
920
  "license": "MIT",
911
921
  "dependencies": {
912
922
  "@eslint-community/eslint-utils": "^4.2.0",
913
923
  "@eslint-community/regexpp": "^4.12.1",
914
924
  "@eslint/config-array": "^0.19.0",
915
- "@eslint/core": "^0.10.0",
925
+ "@eslint/core": "^0.11.0",
916
926
  "@eslint/eslintrc": "^3.2.0",
917
- "@eslint/js": "9.19.0",
927
+ "@eslint/js": "9.20.0",
918
928
  "@eslint/plugin-kit": "^0.2.5",
919
929
  "@humanfs/node": "^0.16.6",
920
930
  "@humanwhocodes/module-importer": "^1.0.1",
@@ -1727,7 +1737,7 @@
1727
1737
  }
1728
1738
  },
1729
1739
  "node_modules/object-inspect": {
1730
- "version": "1.13.3",
1740
+ "version": "1.13.4",
1731
1741
  "license": "MIT",
1732
1742
  "engines": {
1733
1743
  "node": ">= 0.4"
@@ -2012,7 +2022,7 @@
2012
2022
  "license": "ISC"
2013
2023
  },
2014
2024
  "node_modules/semver": {
2015
- "version": "7.7.0",
2025
+ "version": "7.7.1",
2016
2026
  "license": "ISC",
2017
2027
  "bin": {
2018
2028
  "semver": "bin/semver.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds-dk",
3
- "version": "8.7.1",
3
+ "version": "8.7.2",
4
4
  "description": "Command line client and development toolkit for the SAP Cloud Application Programming Model",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "keywords": [