Skip to content

Commit cee86f1

Browse files
committed
Add documentation, make CdsDb extend CdsDbService, and remove isFromCdsLib/0
As stated in the new docstring of `CdsFacade`, the same `cds_facade` object can be accessed either via `@sap/cds` or `@sap/cds/lib`. Therefore, there is no distinction to be made between the two. Also, the `CdsDb` and the `GloballyAccessedCdsDbService` aimed to capture the same thing, so delete the latter in favor of the former (it's clearer and more concise).
1 parent d7f5ed4 commit cee86f1

File tree

1 file changed

+32
-34
lines changed
  • javascript/frameworks/cap/lib/advanced_security/javascript/frameworks/cap

1 file changed

+32
-34
lines changed

javascript/frameworks/cap/lib/advanced_security/javascript/frameworks/cap/CDS.qll

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,31 @@ import advanced_security.javascript.frameworks.cap.RemoteFlowSources
88

99
/**
1010
* The CDS facade object that provides useful interfaces to the current CAP application.
11-
* It also acts as a shortcut to `cds.db` when imported via `"@sap/cds"`.
11+
* It also acts as a shortcut to `cds.db`.
1212
*
13-
* ```js
14-
* const cds = require('@sap/cds')
13+
* ``` javascript
14+
* var cds = require("@sap/cds")
15+
* var cds = require("@sap/cds/lib")
16+
* ```
17+
*
18+
* Note that, despite not being recorded in the API documentation, this object can also
19+
* be obtained via a more specific import path `"@sap/cds/lib"`. The `cds_facade` object
20+
* defined this way is identical with the official `"@sap/cds"` down to the memory location
21+
* it is allocated in:
22+
*
23+
* ``` javascript
24+
* var cds = require("@sap/cds");
25+
* var cdslib = require("@sap/cds/lib");
26+
* assert(cds === cdslib)
1527
* ```
1628
*/
17-
/* TODO: Does the `cds` object imported with `"@sap/cds/lib"` also have shortcut to `cds.db`? */
1829
class CdsFacade extends API::Node {
1930
string importPath;
2031

2132
CdsFacade() {
2233
importPath = ["@sap/cds", "@sap/cds/lib"] and
2334
this = API::moduleImport(importPath)
2435
}
25-
26-
/**
27-
* Holds if this CDS facade object is imported via path `"@sap/cds/lib"`.
28-
*/
29-
predicate isFromCdsLib() { importPath = "@sap/cds/lib" }
3036
}
3137

3238
/**
@@ -41,23 +47,6 @@ class CdsEntitiesCall extends DataFlow::CallNode {
4147
string getNamespace() { result = this.getArgument(0).getStringValue() }
4248
}
4349

44-
/**
45-
* The property `db` of on a CDS facade, often accessed as `cds.db`.
46-
*/
47-
class CdsDb extends SourceNode {
48-
CdsDb() { exists(CdsFacade cds | not cds.isFromCdsLib() | this = cds.getMember("db").asSource()) }
49-
50-
MethodCallNode getRunCall() { result = this.getAMemberCall("run") }
51-
52-
MethodCallNode getCreateCall() { result = this.getAMemberCall("create") }
53-
54-
MethodCallNode getUpdateCall() { result = this.getAMemberCall("update") }
55-
56-
MethodCallNode getDeleteCall() { result = this.getAMemberCall("delete") }
57-
58-
MethodCallNode getInsertCall() { result = this.getAMemberCall("insert") }
59-
}
60-
6150
/**
6251
* A call to `serve` on a CDS facade.
6352
*/
@@ -275,13 +264,26 @@ abstract class CdsDbService extends ServiceInstance {
275264
override UserDefinedApplicationService getDefinition() { none() }
276265
}
277266

278-
class GloballyAccessedCdsDbService extends CdsDbService {
279-
GloballyAccessedCdsDbService() {
280-
exists(CdsFacade cds | not cds.isFromCdsLib() |
267+
/**
268+
* The property `db` of on a CDS facade, often accessed as `cds.db`.
269+
*/
270+
class CdsDb extends SourceNode, CdsDbService {
271+
CdsDb() {
272+
exists(CdsFacade cds |
281273
this = cds.getMember("db").asSource() or
282274
this = cds.asSource()
283275
)
284276
}
277+
278+
MethodCallNode getRunCall() { result = this.getAMemberCall("run") }
279+
280+
MethodCallNode getCreateCall() { result = this.getAMemberCall("create") }
281+
282+
MethodCallNode getUpdateCall() { result = this.getAMemberCall("update") }
283+
284+
MethodCallNode getDeleteCall() { result = this.getAMemberCall("delete") }
285+
286+
MethodCallNode getInsertCall() { result = this.getAMemberCall("insert") }
285287
}
286288

287289
class DbServiceInstanceFromCdsConnectTo extends ServiceInstanceFromCdsConnectTo, CdsDbService {
@@ -760,11 +762,7 @@ class EntityReferenceFromDbOrCdsEntities extends EntityReferenceFromEntities {
760762
this.getEntities().(MethodCallNode).getArgument(0).getStringValue() + "." + entityName
761763
}
762764

763-
override UserDefinedApplicationService getServiceDefinition() {
764-
/* TODO: Always get the DB service definition. */
765-
none()
766-
// result.getServiceName() = this.(CdsEntitiesCall).getNamespace()
767-
}
765+
override UserDefinedApplicationService getServiceDefinition() { none() }
768766
}
769767

770768
class EntityReferenceFromCqlClause extends EntityReference, ExprNode {

0 commit comments

Comments
 (0)