@@ -8,25 +8,31 @@ import advanced_security.javascript.frameworks.cap.RemoteFlowSources
8
8
9
9
/**
10
10
* 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`.
12
12
*
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)
15
27
* ```
16
28
*/
17
- /* TODO: Does the `cds` object imported with `"@sap/cds/lib"` also have shortcut to `cds.db`? */
18
29
class CdsFacade extends API:: Node {
19
30
string importPath ;
20
31
21
32
CdsFacade ( ) {
22
33
importPath = [ "@sap/cds" , "@sap/cds/lib" ] and
23
34
this = API:: moduleImport ( importPath )
24
35
}
25
-
26
- /**
27
- * Holds if this CDS facade object is imported via path `"@sap/cds/lib"`.
28
- */
29
- predicate isFromCdsLib ( ) { importPath = "@sap/cds/lib" }
30
36
}
31
37
32
38
/**
@@ -41,23 +47,6 @@ class CdsEntitiesCall extends DataFlow::CallNode {
41
47
string getNamespace ( ) { result = this .getArgument ( 0 ) .getStringValue ( ) }
42
48
}
43
49
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
-
61
50
/**
62
51
* A call to `serve` on a CDS facade.
63
52
*/
@@ -275,13 +264,26 @@ abstract class CdsDbService extends ServiceInstance {
275
264
override UserDefinedApplicationService getDefinition ( ) { none ( ) }
276
265
}
277
266
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 |
281
273
this = cds .getMember ( "db" ) .asSource ( ) or
282
274
this = cds .asSource ( )
283
275
)
284
276
}
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" ) }
285
287
}
286
288
287
289
class DbServiceInstanceFromCdsConnectTo extends ServiceInstanceFromCdsConnectTo , CdsDbService {
@@ -760,11 +762,7 @@ class EntityReferenceFromDbOrCdsEntities extends EntityReferenceFromEntities {
760
762
this .getEntities ( ) .( MethodCallNode ) .getArgument ( 0 ) .getStringValue ( ) + "." + entityName
761
763
}
762
764
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 ( ) }
768
766
}
769
767
770
768
class EntityReferenceFromCqlClause extends EntityReference , ExprNode {
0 commit comments