@cap-js/db-service 2.1.1 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@
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
+ ## [2.2.0](https://github.com/cap-js/cds-dbs/compare/db-service-v2.1.2...db-service-v2.2.0) (2025-06-30)
8
+
9
+
10
+ ### Added
11
+
12
+ * **recurse:** object-page hierarchies ([#1247](https://github.com/cap-js/cds-dbs/issues/1247)) ([6fe81f2](https://github.com/cap-js/cds-dbs/commit/6fe81f27bc1aee0b8edebe3d9251928ebea8474a))
13
+
14
+ ## [2.1.2](https://github.com/cap-js/cds-dbs/compare/db-service-v2.1.1...db-service-v2.1.2) (2025-06-12)
15
+
16
+
17
+ ### Fixed
18
+
19
+ * Hierarchy View support for ancestors/descendants requests ([#1241](https://github.com/cap-js/cds-dbs/issues/1241)) ([1ccb8b7](https://github.com/cap-js/cds-dbs/commit/1ccb8b7ded50f77de1d71d79b0c4b2040ee6a4f1))
20
+
7
21
  ## [2.1.1](https://github.com/cap-js/cds-dbs/compare/db-service-v2.1.0...db-service-v2.1.1) (2025-06-06)
8
22
 
9
23
 
package/lib/cqn2sql.js CHANGED
@@ -282,6 +282,25 @@ class CQN2SQLRenderer {
282
282
  SELECT_recurse(q) {
283
283
  let { from, columns, where, orderBy, recurse, _internal } = q.SELECT
284
284
 
285
+ const keys = []
286
+ const _target = q._target
287
+
288
+ if (_target) {
289
+ for (const _key in _target.keys) {
290
+ const k = _target.keys[_key]
291
+ if (!k.virtual && !k.isAssociation && !k.value) {
292
+ keys.push({ ref: [_key] })
293
+ }
294
+ }
295
+
296
+ // `where` needs to be wrapped to also support `where == ['exists', { SELECT }]` which is not allowed in `START WHERE`
297
+ const clone = q.clone()
298
+ clone.columns(keys)
299
+ clone.SELECT.recurse = undefined
300
+ clone.SELECT.expand = undefined // omits JSON
301
+ where = [{ list: keys }, 'in', clone]
302
+ }
303
+
285
304
  const requiredComputedColumns = { PARENT_ID: true, NODE_ID: true }
286
305
  if (!_internal) requiredComputedColumns.RANK = true
287
306
  const addComputedColumn = (name) => {
@@ -376,11 +395,12 @@ class CQN2SQLRenderer {
376
395
  const expandedByOne = { list: [] } // DistanceTo(...,1)
377
396
  const expandedByZero = { list: [] } // not DistanceTo(...,null)
378
397
  let expandedFilter = []
398
+ // If a root where exists it should always be DistanceFromRoot otherwise when a recurse.where exists with only DistanceTo() calls
379
399
  let distanceType = 'DistanceFromRoot'
380
400
  let distanceVal
381
401
 
382
402
  if (recurse.where) {
383
- distanceType = 'Distance'
403
+ distanceType = where?.length ? 'DistanceFromRoot' : 'Distance'
384
404
  if (recurse.where[0] === 'and') recurse.where = recurse.where.slice(1)
385
405
  expandedFilter = [...recurse.where]
386
406
  collectDistanceTo(expandedFilter)
@@ -463,7 +483,7 @@ class CQN2SQLRenderer {
463
483
  },
464
484
  where: expandedFilter.length ? expandedFilter : undefined,
465
485
  orderBy: [{ ref: ['HIERARCHY_RANK'], sort: 'asc' }],
466
- groupBy: [{ ref: ['NODE_ID'] },{ ref: ['PARENT_ID'] }, { ref: ['HIERARCHY_RANK'] }, { ref: ['HIERARCHY_LEVEL'] }, { ref: ['HIERARCHY_TREE_SIZE'] }, ...columnsOut.filter(c => c.ref)],
486
+ groupBy: [{ ref: ['NODE_ID'] }, { ref: ['PARENT_ID'] }, { ref: ['HIERARCHY_RANK'] }, { ref: ['HIERARCHY_LEVEL'] }, { ref: ['HIERARCHY_TREE_SIZE'] }, ...columnsOut.filter(c => c.ref)],
467
487
  }
468
488
  }
469
489
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/db-service",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "CDS base database service",
5
5
  "homepage": "https://github.com/cap-js/cds-dbs/tree/main/db-service#cds-base-database-service",
6
6
  "repository": {