@@ -6,12 +6,12 @@ const UTILS = require("./utils")
6
6
/**
7
7
* @file Connection Capabilities
8
8
* @license Apache Version 2
9
+ * @constructor
9
10
* @description Object which helps manage the capabilities available for a given TerminusDB connection
10
11
* Creates an entry in the connection registry for the server
11
12
* and all the databases that the client has access to
12
13
* maps the input authorties to a per-db array for internal storage and easy
13
14
* access control checks
14
- * @param {String } key API key
15
15
*/
16
16
function ConnectionCapabilities ( ) {
17
17
this . clear ( )
@@ -30,39 +30,66 @@ ConnectionCapabilities.prototype.clear = function() {
30
30
31
31
/**
32
32
* @param {object } capabilities the JSON object returned by the connect API call
33
- * it is a system:User object with a system:role predicate which points at an array of roles
33
+ * @returns { object } it is a system:User object with a system:role predicate which points at an array of roles
34
34
*/
35
- ConnectionCapabilities . prototype . setCapabilities = function ( connectjson ) {
35
+ ConnectionCapabilities . prototype . setCapabilities = function ( capabilities ) {
36
36
this . clear ( )
37
37
this . databases = false
38
- if ( connectjson [ '@context' ] ) this . _load_connection_context ( connectjson [ '@context' ] )
39
- this . user = this . _extract_user_info ( connectjson )
38
+ if ( capabilities [ '@context' ] ) this . _load_connection_context ( capabilities [ '@context' ] )
39
+ this . user = this . _extract_user_info ( capabilities )
40
40
this . _extract_database_organizations ( ) //find the organization which owns the db
41
41
return this . user
42
42
}
43
43
44
- ConnectionCapabilities . prototype . get_user = function ( ) {
44
+ /*
45
+ * @returns {object }
46
+ */
47
+ //ConnectionCapabilities.prototype.get_user = function() {
48
+ ConnectionCapabilities . prototype . getUserObj = function ( ) {
49
+ //console.log("___USER___OBJ",this.user)
45
50
return this . user
46
51
}
47
-
52
+ //getDatabases
53
+ /*
54
+ * @returns {string|boolean }
55
+ */
48
56
ConnectionCapabilities . prototype . author = function ( ) {
49
57
if ( this . user && this . user . author ) return this . user . author
50
58
return false
51
59
}
52
60
53
- ConnectionCapabilities . prototype . get_databases = function ( ) {
61
+
62
+ /**
63
+ * @description get the database details list for the get capabilities call
64
+ * @returns {array }
65
+ */
66
+ //KEVIN
67
+ //ConnectionCapabilities.prototype.get_databases = function() {
68
+ ConnectionCapabilities . prototype . getDatabaseList = function ( ) {
54
69
if ( ! this . databases ) this . databases = this . _databases_from_dbdocs ( )
55
70
return this . databases
56
71
}
57
-
58
- ConnectionCapabilities . prototype . set_databases = function ( newdbs ) {
59
- this . databases = newdbs
72
+ /**
73
+ * @description set the newDBList form the get capabilities result
74
+ * @param {array } newDBList
75
+ */
76
+ //KEVIN
77
+ ConnectionCapabilities . prototype . setDatabaseList = function ( newDBList ) {
78
+ //ConnectionCapabilities.prototype.set_databases = function(newDBList) {
79
+ this . databases = newDBList
60
80
}
61
81
62
- ConnectionCapabilities . prototype . get_database = function ( dbid , orgid ) {
82
+ /**
83
+ * @description Gets the database's details
84
+ * @param {?string } dbId
85
+ * @param {?string } orgId
86
+ * @returns {object }
87
+ */
88
+ //ConnectionCapabilities.prototype.get_database = function(dbId, orgId) {
89
+ ConnectionCapabilities . prototype . getDatabaseObj = function ( dbId , orgId ) {
63
90
if ( ! this . databases ) this . databases = this . _databases_from_dbdocs ( )
64
91
for ( var i = 0 ; i < this . databases . length ; i ++ ) {
65
- if ( this . databases [ i ] . id == dbid && this . databases [ i ] . organization == orgid ) {
92
+ if ( this . databases [ i ] . id === dbId && this . databases [ i ] . organization === orgId ) {
66
93
return this . databases [ i ]
67
94
}
68
95
}
@@ -139,7 +166,7 @@ ConnectionCapabilities.prototype.actions_permitted = function(actions, resnames)
139
166
}
140
167
141
168
ConnectionCapabilities . prototype . buildContextsFromPrefixes = function ( ) {
142
- let dbs = this . get_databases ( )
169
+ let dbs = this . getDatabaseList ( )
143
170
for ( var i = 0 ; i < dbs . length ; i ++ ) {
144
171
dbs [ i ] . jsonld_context = _jsonld_context_from_prefixes ( dbs [ i ] . prefix_pairs )
145
172
}
@@ -171,7 +198,7 @@ ConnectionCapabilities.prototype.getContextForOutboundQuery = function(woql, dbi
171
198
else {
172
199
if ( this . _is_system_db ( dbid ) ) ob = this . getSystemContext ( )
173
200
else {
174
- let dbrec = this . get_database ( dbid , orgid )
201
+ let dbrec = this . getDatabaseObj ( dbid , orgid )
175
202
let jcon = ( dbrec && dbrec . jsonld_context ? dbrec . jsonld_context : this . jsonld_context )
176
203
for ( var k in jcon ) {
177
204
//if (k != 'doc') ob[k] = jcon[k]
0 commit comments