@cap-js/db-service 1.0.1 → 1.1.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.
@@ -1,50 +1,92 @@
1
1
  'use strict'
2
2
 
3
+ // REVISIT: define following unknown types
4
+
5
+ /**
6
+ * @typedef {unknown} $refLink
7
+ */
8
+
9
+ /**
10
+ * @typedef {unknown} parent
11
+ */
12
+
13
+ /**
14
+ * @typedef {unknown} where
15
+ */
16
+
17
+ /**
18
+ * @typedef {unknown} children
19
+ */
20
+
21
+ /**
22
+ * @typedef {unknown} queryArtifact
23
+ */
24
+
25
+ /**
26
+ * @typedef {string} alias
27
+ */
28
+
29
+ /**
30
+ * @typedef {Map<alias,Root>} _roots
31
+ */
32
+
33
+ /**
34
+ * @typedef {Object.<string, unknown>} sources
35
+ */
36
+
3
37
  /**
4
38
  * A class representing a Node in the join tree.
5
- *
6
- * @property {$refLink} - A reference link to this node.
7
- * @property {parent} - The parent Node of this node.
8
- * @property {where} - An optional condition to be applied to this node.
9
- * @property {children} - A Map of children nodes belonging to this node.
10
39
  */
11
40
  class Node {
41
+ /**
42
+ * @param {$refLink} $refLink
43
+ * @param {parent} parent
44
+ * @param {where} where
45
+ */
12
46
  constructor($refLink, parent, where = null) {
47
+ /** @type {$refLink} - A reference link to this node. */
13
48
  this.$refLink = $refLink
49
+ /** @type {parent} - The parent Node of this node. */
14
50
  this.parent = parent
51
+ /** @type {where} - An optional condition to be applied to this node. */
15
52
  this.where = where
53
+ /** @type {children} - A Map of children nodes belonging to this node. */
16
54
  this.children = new Map()
17
55
  }
18
56
  }
19
57
 
20
58
  /**
21
59
  * A class representing the root of the join tree.
22
- *
23
- * @property {queryArtifact} - The artifact used to make the query.
24
- * @property {alias} - The alias of the artifact.
25
- * @property {parent} - The parent Node of this root, null for the root Node.
26
- * @property {children} - A Map of children nodes belonging to this root.
27
60
  */
28
61
  class Root {
62
+ /**
63
+ * @param {[alias, queryArtifact]} querySource
64
+ */
29
65
  constructor(querySource) {
30
66
  const [alias, queryArtifact] = querySource
67
+ /** @type {queryArtifact} - The artifact used to make the query. */
31
68
  this.queryArtifact = queryArtifact
69
+ /** @type {alias} - The alias of the artifact. */
32
70
  this.alias = alias
71
+ /** @type {parent} - The parent Node of this root, null for the root Node. */
33
72
  this.parent = null
73
+ /** @type {children} - A Map of children nodes belonging to this root. */
34
74
  this.children = new Map()
35
75
  }
36
76
  }
37
77
 
38
78
  /**
39
79
  * A class representing a Join Tree.
40
- *
41
- * @property {_roots} - A Map of root nodes.
42
- * @property {isInitial} - A boolean indicating if the join tree is in its initial state.
43
- * @property {_queryAliases} - A Map of query aliases, which is used during the association to join translation.
44
80
  */
45
81
  class JoinTree {
82
+ /**
83
+ *
84
+ * @param {sources} sources
85
+ */
46
86
  constructor(sources) {
87
+ /** @type {_roots} - A Map of root nodes. */
47
88
  this._roots = new Map()
89
+ /** @type {boolean} - A boolean indicating if the join tree is in its initial state. */
48
90
  this.isInitial = true
49
91
  /**
50
92
  * A map that holds query aliases which are used during the
@@ -53,6 +95,7 @@ class JoinTree {
53
95
  *
54
96
  * The table aliases are treated case insensitive. The index of each
55
97
  * table alias entry, is the capitalized version of the alias.
98
+ * @type {Map<string, string>}
56
99
  */
57
100
  this._queryAliases = new Map()
58
101
  Object.entries(sources).forEach(entry => {
@@ -82,6 +125,7 @@ class JoinTree {
82
125
  * Calculates and adds the next available table alias to the alias map.
83
126
  *
84
127
  * @param {string} alias - The original alias name.
128
+ * @param {unknown[]} outerQueries - An array of outer queries.
85
129
  * @returns {string} - The next unambiguous table alias.
86
130
  */
87
131
  addNextAvailableTableAlias(alias, outerQueries) {
@@ -107,7 +151,7 @@ class JoinTree {
107
151
  * For each step, it checks whether it has been seen before. If so, it resets the $refLink to point to the already merged $refLink.
108
152
  * If not, it creates a new Node and ensures proper aliasing and foreign key access.
109
153
  *
110
- * @param {Object} col - The column object to be merged into the existing join tree. This object should have the properties $refLinks and ref.
154
+ * @param {object} col - The column object to be merged into the existing join tree. This object should have the properties $refLinks and ref.
111
155
  * @returns {boolean} - Always returns true, indicating the column has been successfully merged into the join tree.
112
156
  */
113
157
  mergeColumn(col) {
@@ -145,8 +189,9 @@ class JoinTree {
145
189
  }
146
190
  const child = new Node($refLink, node, where)
147
191
  if (child.$refLink.definition.isAssociation) {
148
- if (child.where) {
149
- // always join relevant
192
+ if (child.where || col.inline) {
193
+ // filter is always join relevant
194
+ // if the column ends up in an `inline` -> each assoc step is join relevant
150
195
  child.$refLink.onlyForeignKeyAccess = false
151
196
  } else {
152
197
  child.$refLink.onlyForeignKeyAccess = true
package/package.json CHANGED
@@ -1,14 +1,22 @@
1
1
  {
2
2
  "name": "@cap-js/db-service",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "CDS base database service",
5
- "homepage": "https://cap.cloud.sap/",
5
+ "homepage": "https://github.com/cap-js/cds-dbs/tree/main/db-service#cds-base-database-service",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/cap-js/cds-dbs"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/cap-js/cds-dbs/issues"
12
+ },
6
13
  "keywords": [
7
14
  "CAP",
8
15
  "CDS"
9
16
  ],
10
17
  "author": "SAP SE (https://www.sap.com)",
11
18
  "main": "index.js",
19
+ "types": "./dist/index.d.ts",
12
20
  "files": [
13
21
  "lib",
14
22
  "CHANGELOG.md"
@@ -19,12 +27,16 @@
19
27
  },
20
28
  "scripts": {
21
29
  "prettier": "npx prettier --write .",
22
- "test": "npx jest --silent",
30
+ "test": "npm run build && npx jest --silent",
31
+ "build": "tsc && find lib/ -type f -name '*.d.ts' -exec cp '{}' 'dist/{}' ';' && cp ts.eslintrc.cjs dist/.eslintrc.cjs && npx eslint ./dist --ext .d.ts",
23
32
  "lint": "npx eslint . && npx prettier --check . "
24
33
  },
25
- "dependencies": {},
26
34
  "peerDependencies": {
27
- "@sap/cds": ">=7"
35
+ "@sap/cds": ">=7.1.1"
28
36
  },
29
- "license": "SEE LICENSE"
37
+ "license": "SEE LICENSE",
38
+ "devDependencies": {
39
+ "@typescript-eslint/eslint-plugin": "^6.2.0",
40
+ "typescript": "^5.1.6"
41
+ }
30
42
  }