Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
1b159425d4 Bump the production-dependencies group with 3 updates
Bumps the production-dependencies group with 3 updates: [@cap-js/hana](https://cap.cloud.sap/), [@sap-cloud-sdk/http-client](https://github.com/SAP/cloud-sdk-js) and [@sap-cloud-sdk/resilience](https://github.com/SAP/cloud-sdk-js).


Updates `@cap-js/hana` from 2.1.1 to 2.1.2

Updates `@sap-cloud-sdk/http-client` from 4.0.2 to 4.1.0
- [Release notes](https://github.com/SAP/cloud-sdk-js/releases)
- [Changelog](https://github.com/SAP/cloud-sdk-js/blob/main/CHANGELOG.md)
- [Commits](https://github.com/SAP/cloud-sdk-js/compare/v4.0.2...v4.1.0)

Updates `@sap-cloud-sdk/resilience` from 4.0.2 to 4.1.0
- [Release notes](https://github.com/SAP/cloud-sdk-js/releases)
- [Changelog](https://github.com/SAP/cloud-sdk-js/blob/main/CHANGELOG.md)
- [Commits](https://github.com/SAP/cloud-sdk-js/compare/v4.0.2...v4.1.0)

---
updated-dependencies:
- dependency-name: "@cap-js/hana"
  dependency-version: 2.1.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: production-dependencies
- dependency-name: "@sap-cloud-sdk/http-client"
  dependency-version: 4.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: production-dependencies
- dependency-name: "@sap-cloud-sdk/resilience"
  dependency-version: 4.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: production-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-28 16:00:06 +00:00
8 changed files with 33 additions and 207 deletions

View File

@@ -1,30 +0,0 @@
## Experimental Dynamic Constraints
This example demonstrates how to use dynamic constraints in a CAP application. It includes a service definition and a test setup to validate the constraints.
### Prerequisites
You've setup the [_cap/samples_](https://github.com/sap-samples/cloud-cap-samples) like so:
```sh
git clone -q https://github.com/sap-samples/cloud-cap-samples cap/samples
cd cap/samples
npm install
```
### Testing
Test like that in `cds.repl` from _cap/samples_ root:
```sh
cds repl --run bookshop/test/dynamic-constraints
````
```javascript
await AdminService.create ('Books', {})
await AdminService.create ('Books', { title:' ', author_ID:150 })
await AdminService.create ('Books', { title:'x' })
await cds.validate (Books.constraints, 201)
await cds.validate (Books.constraints)
```

View File

@@ -1,17 +0,0 @@
//
// Quick and dirty implementation for cds.validate()
// using db-level constraints.
//
const cds = require('@sap/cds'); require('./validate.js')
cds.on('served', ()=> {
const { AdminService } = cds.services
AdminService.after (['CREATE','UPDATE'], (result,req) => cds.validate (req.subject, result))
})
Object.defineProperties (cds.entity.prototype, {
constraints: { get() { return cds.model.definitions[this.name+'.constraints'] }},
fields: { get() { return cds.model.definitions[this.name+'.field.control'] }},
})

View File

@@ -1,7 +0,0 @@
namespace AdminService; //> for cds.entities
using { AdminService } from '../../../srv/admin-service';
annotate AdminService with @requires: false;
extend AdminService.Authors with columns {
null as books // to simulate the exclusion of books
}

View File

@@ -1,10 +0,0 @@
namespace sap.capire.bookshop;
using from './admin-service';
view Books.field.control as select from Books { ID,
genre.name == 'Drama' ? 'readonly' :
null as price
}
extend Books with {
fc : Association to Books.field.control on fc.ID = $self.ID
}

View File

@@ -1,76 +0,0 @@
using { AdminService, sap.capire.bookshop as my } from './admin-service';
extend service AdminService with {
// entity Books.drafts as projection on AdminService.Books;
// @cds.api.ignore view Books.drafts.constraints as select from AdminService.Books.drafts mixin {
// before: Association to my.Books on before.ID = $self.ID;
// base: Association to my.Books on base.ID = $self.ID;
// } into { ID, // FIXME: compiler should resolve Books without AdminService prefix
// case
// when title is null then 'is missing'
// when trim(title)='' then 'must not be empty'
// end as title,
// ...
// }
/**
* Validation constraints for Books
*/
@cds.api.ignore view Books.constraints as select from AdminService.Books mixin {
base: Association to my.Books on base.ID = $self.ID;
} into { ID, // FIXME: compiler should resolve Books without AdminService prefix
// two-step mandatory check
case
when title is null then 'is missing'
when trim(title)='' then 'must not be empty'
end as title,
// the above is equivalent to:
// title is null ? 'is missing' : trim(title)='' ? 'must not be empty' :
// range check
stock < 0 ? 'must not be negative' :
null as stock,
// range check
price < 0 ? 'must not be negative' :
null as price,
// assert target check
genre.ID is not null and not exists genre ? 'does not exist' :
null as genre,
// multiple constraints: mandatory + assert target + special
author.ID is null ? 'is missing' : // FIXME: 1) // TODO: 2)
not exists author ? 'Author does not exist: ' || author.ID :
count(base.author.books.ID) -1 > 1 ? author.name || ' already wrote too many books' : // TODO: 3)
null as author,
} group by ID;
// 1) FIXME: expected author.ID to refer to foreign key,
// apparently that is not the case -> move one line up
// and run test to see the erroneous impact.
// 2) TODO: we should allow to write author is null instead of author.ID is null
// 3) TODO: we should support count(author.books)
/**
* Validation constraints for Authors
*/
view Authors.constraints as select from AdminService.Authors { ID, // FIXME: compiler should resolve Authors without AdminService prefix
// two-step mandatory check
name = null ? 'is missing' : trim(name)='' ? 'must not be empty' :
null as name,
// constraint related to two fields
dateOfDeath < dateOfBirth ? 'we can''t die before we are born' : null as _born_before_death,
$self._born_before_death as dateOfBirth,
$self._born_before_death as dateOfDeath,
}
}

View File

@@ -1,34 +0,0 @@
const cds = require('@sap/cds')
const $super = { validate: cds.validate, skip(){} }
/**
* Quick and dirty implementation for cds.validate() using db-level constraints.
*/
cds.validate = function (x, pk, ...columns) {
// Delegate to base impl of cds.validate() for standard input validation
if (!_is_constraints(x)) return $super.skip (...arguments)
// Support subject refs to base entities as arguments
if (x?.ref) [ x, pk ] = [ x.ref +'.constraints', pk.ID||pk ]
// Run the constraints check query
const constraints = typeof x === 'string' ? cds.model.definitions[x] || cds.error `No such constraints view: ${x}` : x
return SELECT.from (constraints, pk, columns.length && columns)
// Collect and throw errors, if any
.then (rows => (rows.map ? rows : [rows]).map (checks => {
const failed = {}; for (let c in checks) {
if (c in constraints.keys) continue
if (c[0] == '_') continue
if (checks[c]) failed[c] = checks[c]
}
if (Object.keys(failed).length) throw cds.error `Invalid input: ${failed}`
return checks
}))
}
// Helpers
const _is_constraints = x => x.ref || x.is_entity || typeof x === 'string'

View File

@@ -52,7 +52,7 @@ module.exports = { DataService }
/** @returns {cds.Service} */
function findDataSource(dataSourceName, entityName) {
for (let srv of cds.service.providers) { // all connected services
for (let srv of Object.values(cds.services)) { // all connected services
if (!srv.name) continue // FIXME intermediate/pending in cds.services ?
if (dataSourceName === srv.name || entityName.startsWith(srv.name+'.')) {
log._debug && log.debug(`using ${srv.name} as data source`)

64
package-lock.json generated
View File

@@ -103,9 +103,9 @@
}
},
"node_modules/@cap-js/hana": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@cap-js/hana/-/hana-2.1.1.tgz",
"integrity": "sha512-4N/ByOd1N++7IEVwoSKyIqEXEzuAJE1qhpWhr3JM4LPoeCpvlv+Eki/YLIvCB06O7/PO8d2569Emjml/TwaJhQ==",
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@cap-js/hana/-/hana-2.1.2.tgz",
"integrity": "sha512-QlcBoQt7ChoJUyBEoGWrIeGsBzX5B4lCx0HS4YAnS++14qb14I2xyKwWkdb+D+p42Rh5pIK1cE6xisUhdyr7nQ==",
"license": "Apache-2.0",
"dependencies": {
"@cap-js/db-service": "^2.1.1",
@@ -201,51 +201,51 @@
}
},
"node_modules/@sap-cloud-sdk/connectivity": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/@sap-cloud-sdk/connectivity/-/connectivity-4.0.2.tgz",
"integrity": "sha512-20ok60K1PLezyngU3Zcp2Hx3R2rlPYNeebD+IcFhzHklJGhkJGWOBiWxSlCLhyi1hGmYIr5SIlXHe/6AvHC69Q==",
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/@sap-cloud-sdk/connectivity/-/connectivity-4.1.0.tgz",
"integrity": "sha512-NUxa7H0MA50bRIbmrO26zjNFfoT38qzrNuDGbhRwmo7IilZ9tgPrtNsDcFW9bnBPjtVwwASJX0bUXhG16nhNDQ==",
"license": "Apache-2.0",
"dependencies": {
"@sap-cloud-sdk/resilience": "^4.0.2",
"@sap-cloud-sdk/util": "^4.0.2",
"@sap/xsenv": "^5.5.0",
"@sap/xssec": "^4.4.0",
"@sap-cloud-sdk/resilience": "^4.1.0",
"@sap-cloud-sdk/util": "^4.1.0",
"@sap/xsenv": "^5.6.1",
"@sap/xssec": "^4.9.0",
"async-retry": "^1.3.3",
"axios": "^1.8.3",
"axios": "^1.10.0",
"jsonwebtoken": "^9.0.2"
}
},
"node_modules/@sap-cloud-sdk/http-client": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/@sap-cloud-sdk/http-client/-/http-client-4.0.2.tgz",
"integrity": "sha512-sfmJ9Ejo+nWW5dikDR8Sa2X5+L/UHcSuaZ+axnelp/+nb+3T2iuO5439lF7BdMNKztUUIYyyjcjmcE+4a8ucDw==",
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/@sap-cloud-sdk/http-client/-/http-client-4.1.0.tgz",
"integrity": "sha512-eg2TjRnz8w1OpSC8Lylyg2NqDjigu4I3PnADHjQ8GNzyKkrCzgvf1QlO49UAg/3HXM58gZMKy7zdlSZ4uOJ/6w==",
"license": "Apache-2.0",
"dependencies": {
"@sap-cloud-sdk/connectivity": "^4.0.2",
"@sap-cloud-sdk/resilience": "^4.0.2",
"@sap-cloud-sdk/util": "^4.0.2",
"axios": "^1.8.3"
"@sap-cloud-sdk/connectivity": "^4.1.0",
"@sap-cloud-sdk/resilience": "^4.1.0",
"@sap-cloud-sdk/util": "^4.1.0",
"axios": "^1.10.0"
}
},
"node_modules/@sap-cloud-sdk/resilience": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/@sap-cloud-sdk/resilience/-/resilience-4.0.2.tgz",
"integrity": "sha512-xksI18EiEmtTPR1gbbnAlJ9mhV700ZIJDhITURLRM6n7u9Tv5JehAVjRa8zxMB/jxrbU+/NiNqxlXa7/cJyybA==",
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/@sap-cloud-sdk/resilience/-/resilience-4.1.0.tgz",
"integrity": "sha512-liFJPtsX/npbDPJWZrc7GmOvsEOviryx5gijE3F3gfRUFSAP8UcqGrrvYA+ifREW3ZAeQ7ur74PInN5WHTKajw==",
"license": "Apache-2.0",
"dependencies": {
"@sap-cloud-sdk/util": "^4.0.2",
"@sap-cloud-sdk/util": "^4.1.0",
"async-retry": "^1.3.3",
"axios": "^1.8.3",
"opossum": "^8.4.0"
"axios": "^1.10.0",
"opossum": "^9.0.0"
}
},
"node_modules/@sap-cloud-sdk/util": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/@sap-cloud-sdk/util/-/util-4.0.2.tgz",
"integrity": "sha512-HhBXWFkDnmpexTDT2Hwx5F39vmAg/q83HCxyOUZSiEZHfOWAflUAYO+oX4mniCkve51eGDQcn82kJeGl+jY9kg==",
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/@sap-cloud-sdk/util/-/util-4.1.0.tgz",
"integrity": "sha512-4OI7lYd2GHQDPysEwFvCKbZ0m40VA0C47rnxWvd6ExzkfT/cKzryesB4jA3vwvgRO14q8MKoG3RcR+9ZPzaeSw==",
"license": "Apache-2.0",
"dependencies": {
"axios": "^1.8.3",
"axios": "^1.10.0",
"chalk": "^4.1.0",
"logform": "^2.7.0",
"voca": "^1.4.1",
@@ -1771,12 +1771,12 @@
}
},
"node_modules/opossum": {
"version": "8.5.0",
"resolved": "https://registry.npmjs.org/opossum/-/opossum-8.5.0.tgz",
"integrity": "sha512-LZNvs+p9/ZbG4oN6unnjh4hTxkB0dyHKI2p7azVt8w+//GKDpfHss6WR7KebbpzGEssYwtSd8Mvwxqcmxg10NA==",
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/opossum/-/opossum-9.0.0.tgz",
"integrity": "sha512-K76U0QkxOfUZamneQuzz+AP0fyfTJcCplZ2oZL93nxeupuJbN4s6uFNbmVCt4eWqqGqRnnowdFuBicJ1fLMVxw==",
"license": "Apache-2.0",
"engines": {
"node": "^24 || ^22 || ^21 || ^20 || ^18 || ^16"
"node": "^24 || ^22 || ^20"
}
},
"node_modules/parseurl": {