@sap/cds 7.0.1 → 7.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@
4
4
  - The format is based on [Keep a Changelog](http://keepachangelog.com/).
5
5
  - This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## Version 7.0.2 - 2023-07-06
8
+
9
+ ### Fixed
10
+
11
+ - Glitch in `cds.deploy` if no change was applied
12
+ - Detection of `.cdsrc-private.json` during startup
13
+ - Respect capabilities annotation for draft events
14
+ - `cds compile --to serviceinfo` returns correct service paths again
15
+
7
16
  ## Version 7.0.1 - 2023-07-03
8
17
 
9
18
  ### Fixed
@@ -72,6 +72,9 @@ module.exports = function cds_compile_for_lean_drafts(csn) {
72
72
  if (draft['@readonly']) draft['@readonly'] = undefined
73
73
  if (draft['@insertonly']) draft['@insertonly'] = undefined
74
74
  if (draft['@restrict']) draft['@restrict'] = undefined
75
+ if ('@Capabilities.DeleteRestrictions.Deletable' in draft) draft['@Capabilities.DeleteRestrictions.Deletable'] = undefined
76
+ if ('@Capabilities.InsertRestrictions.Insertable' in draft) draft['@Capabilities.InsertRestrictions.Insertable'] = undefined
77
+ if ('@Capabilities.UpdateRestrictions.Updatable' in draft) draft['@Capabilities.UpdateRestrictions.Updatable'] = undefined
75
78
 
76
79
  // Recursively add drafts for compositions
77
80
  for (const each in draft.elements) {
@@ -35,15 +35,31 @@ module.exports = (model, options={}) => {
35
35
  }
36
36
  }
37
37
  function _makeNode(service) {
38
+ const path = _effectiveNodePath(service)
38
39
  return {
39
40
  name: service.name,
40
- urlPath: _url4 (cds.service.path4(service)),
41
+ urlPath: _url4 (path),
41
42
  destination: 'srv-api', // the name to register in xs-app.json
42
43
  runtime: 'Node.js',
43
44
  location: service.$location
44
45
  }
45
46
  }
46
47
 
48
+ // TODO use a function from cds.service... instead
49
+ function _effectiveNodePath(service) {
50
+ if (service['@path']?.[0] === '/') { // absolute path given
51
+ return service['@path']
52
+ }
53
+ const { ProtocolAdapter } = cds.service.protocols
54
+ const prots = ProtocolAdapter.protocols4(service)
55
+ const prot = prots.find(p => p.kind.startsWith('odata')) || prots[0] // prefer odata for compat. reasons
56
+ if (prot.path && prot.path.startsWith('/')) {
57
+ return prot.path
58
+ }
59
+ const rootPath = cds.env.requires.middlewares ? ProtocolAdapter.protocols[prot.kind]?.path || '' : ''
60
+ return join(rootPath, prot.path || cds.service.path4(service))
61
+ }
62
+
47
63
  // the URL path that is *likely* effective at runtime
48
64
  function _url4 (p) {
49
65
  return normalize (p.replace(/^\/+/, '') + '/') //> /foo/bar -> foo/bar/
@@ -15,7 +15,7 @@ module.exports = exports = function cds_deploy (model,options,csvs) {
15
15
  DEBUG = cds.debug('deploy')
16
16
  return {
17
17
  /** @param {import('@sap/cds/lib/srv/srv-api')} db */
18
- async to(db, o = options || cds.options || {}) {
18
+ async to(db, o = options || {}) {
19
19
 
20
20
  const TRACE = cds.debug('trace')
21
21
  TRACE?.time('cds.deploy db ')
@@ -90,8 +90,8 @@ exports.create = async function cds_deploy_create (db, csn=db.model, o) {
90
90
  } else {
91
91
  await db.run(`UPDATE cds_model SET csn = ?`, after)
92
92
  }
93
- db.options.schema_evolution = 'auto' // for updating package.json
94
93
  }
94
+ o.schema_evolution = 'auto' // for INSERT_from4 below
95
95
  // cds deploy --model-only > fills in table cds_model above
96
96
  if (o['model-only']) return o.dry && console.log(after)
97
97
  // cds deploy -- with auto schema evolution > upgrade by applying delta to former model
@@ -253,9 +253,6 @@ exports.resources = async function cds_deploy_resources (csn, opts) {
253
253
  const folders = await cds_deploy_resources.folders(csn, opts)
254
254
  const found={}, ts = process.env.CDS_TYPESCRIPT
255
255
  for (let folder of folders) {
256
- // fetching init.js files
257
- const init_js = ts && isfile(folder,'init.ts') || isfile(folder,'init.js')
258
- if (init_js) found[init_js] = '*'
259
256
  // fetching .csv and .json files
260
257
  for (let each of ['data','csv']) {
261
258
  const subdir = isdir(folder,each); if (!subdir) continue
@@ -281,6 +278,9 @@ exports.resources = async function cds_deploy_resources (csn, opts) {
281
278
  }
282
279
  }
283
280
  }
281
+ // fetching init.js files -> Note: after .csv files to have that on top, when processing in .reverse order
282
+ const init_js = ts && isfile(folder,'init.ts') || isfile(folder,'init.js')
283
+ if (init_js) found[init_js] = '*'
284
284
  }
285
285
  return found
286
286
  }
@@ -341,7 +341,7 @@ const _queries4 = (db,csn) => !db.cqn2sql ? q => q : q => {
341
341
 
342
342
 
343
343
  const INSERT_from4 = (db,o) => {
344
- const schevo = db.options?.schema_evolution === 'auto' || cds.env.requires.db?.schema_evolution === 'auto' || o?.schema_evolution === 'auto'
344
+ const schevo = o?.schema_evolution === 'auto' || db.options.schema_evolution === 'auto'
345
345
  const INSERT_into = (schevo ? UPSERT : INSERT).into
346
346
  return (file) => ({
347
347
  '.json': { into (entity, json) {
@@ -113,14 +113,14 @@ class Config {
113
113
  ...( global._plugins||[] ).map (root => ({
114
114
  path: root, file: 'package.json', mapper: x => x.cds
115
115
  })),
116
- { path: user_home, file: '.cdsrc.json' },
117
- { path: home, file: '.cdsrc-private.json' },
118
- { path: home, file: '.cdsrc.json' },
116
+ { path: user_home, file: '.cdsrc.json', mapper: x => x.cds||x },
117
+ { path: home, file: '.cdsrc.json', mapper: x => x.cds||x },
119
118
  { path: home, file: 'package.json', mapper: _package_json },
119
+ { path: home, file: '.cdsrc-private.json', mapper: x => x.cds||x },
120
120
  ]
121
121
  function _package_json (pkg) { // fill cds.extends from .extends
122
122
  let cds = pkg.cds
123
- if (pkg.extends) (cds||(cds={})).extends = pkg.extends
123
+ if (pkg.extends) (cds??={}).extends = pkg.extends
124
124
  return cds
125
125
  }
126
126
  }
@@ -434,7 +434,7 @@ class Config {
434
434
  function _add_static_profiles (_home, profiles) {
435
435
  for (let src of ['package.json', '.cdsrc.json']) try {
436
436
  const conf = require(path.join(_home,src))
437
- const cds = src === '.cdsrc.json' ? conf : conf.cds
437
+ const cds = src === 'package.json' ? conf.cds : conf.cds||conf
438
438
  if (cds?.profiles) return profiles.push(...cds.profiles)
439
439
  if (cds?.profile) return profiles.push(cds.profile)
440
440
  } catch (e) { if (e.code !== 'MODULE_NOT_FOUND') throw e }
@@ -856,10 +856,13 @@ function expandStarStar(target, recursion = new Map()) {
856
856
 
857
857
  async function onNew(req) {
858
858
  LOG.debug('new draft')
859
+ if (req.target.actives['@Capabilities.InsertRestrictions.Insertable'] === false || req.target.actives['@readonly'])
860
+ req.reject(405)
859
861
  const isDirectAccess = typeof req.query.INSERT.into === 'string' || req.query.INSERT.into.ref?.length === 1
860
862
  // Only allowed for pseudo draft roots (entities with this action)
861
863
  if (isDirectAccess && !req.target.actives['@Common.DraftRoot.ActivationAction'])
862
864
  req.reject(403, 'DRAFT_MODIFICATION_ONLY_VIA_ROOT')
865
+
863
866
  let DraftUUID
864
867
  if (isDirectAccess) DraftUUID = cds.utils.uuid()
865
868
  else {
@@ -929,6 +932,12 @@ async function onEdit(req) {
929
932
  if (req.query.SELECT.from.ref.length > 1 || draftParams.IsActiveEntity !== true) {
930
933
  req.reject(400, 'Action "draftEdit" can only be called on the root active entity')
931
934
  }
935
+ if (
936
+ req.target['@Capabilities.UpdateRestrictions.Updatable'] === false ||
937
+ req.target['@insertonly'] ||
938
+ req.target['@readonly']
939
+ )
940
+ req.reject(405)
932
941
  const targetWhere = req.query.SELECT.from.ref[0].where
933
942
 
934
943
  if (draftParams.IsActiveEntity !== true) req.reject(400)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds",
3
- "version": "7.0.1",
3
+ "version": "7.0.2",
4
4
  "description": "SAP Cloud Application Programming Model - CDS for Node.js",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "keywords": [