@@ -6,12 +6,12 @@ const UTILS = require("./utils")
66/**
77 * @file Connection Capabilities
88 * @license Apache Version 2
9+ * @constructor
910 * @description Object which helps manage the capabilities available for a given TerminusDB connection
1011 * Creates an entry in the connection registry for the server
1112 * and all the databases that the client has access to
1213 * maps the input authorties to a per-db array for internal storage and easy
1314 * access control checks
14- * @param {String } key API key
1515 */
1616function ConnectionCapabilities ( ) {
1717 this . clear ( )
@@ -30,39 +30,66 @@ ConnectionCapabilities.prototype.clear = function() {
3030
3131/**
3232 * @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
3434 */
35- ConnectionCapabilities . prototype . setCapabilities = function ( connectjson ) {
35+ ConnectionCapabilities . prototype . setCapabilities = function ( capabilities ) {
3636 this . clear ( )
3737 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 )
4040 this . _extract_database_organizations ( ) //find the organization which owns the db
4141 return this . user
4242}
4343
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)
4550 return this . user
4651}
47-
52+ //getDatabases
53+ /*
54+ * @returns {string|boolean }
55+ */
4856ConnectionCapabilities . prototype . author = function ( ) {
4957 if ( this . user && this . user . author ) return this . user . author
5058 return false
5159}
5260
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 ( ) {
5469 if ( ! this . databases ) this . databases = this . _databases_from_dbdocs ( )
5570 return this . databases
5671}
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
6080}
6181
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 ) {
6390 if ( ! this . databases ) this . databases = this . _databases_from_dbdocs ( )
6491 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 ) {
6693 return this . databases [ i ]
6794 }
6895 }
@@ -139,7 +166,7 @@ ConnectionCapabilities.prototype.actions_permitted = function(actions, resnames)
139166}
140167
141168ConnectionCapabilities . prototype . buildContextsFromPrefixes = function ( ) {
142- let dbs = this . get_databases ( )
169+ let dbs = this . getDatabaseList ( )
143170 for ( var i = 0 ; i < dbs . length ; i ++ ) {
144171 dbs [ i ] . jsonld_context = _jsonld_context_from_prefixes ( dbs [ i ] . prefix_pairs )
145172 }
@@ -171,7 +198,7 @@ ConnectionCapabilities.prototype.getContextForOutboundQuery = function(woql, dbi
171198 else {
172199 if ( this . _is_system_db ( dbid ) ) ob = this . getSystemContext ( )
173200 else {
174- let dbrec = this . get_database ( dbid , orgid )
201+ let dbrec = this . getDatabaseObj ( dbid , orgid )
175202 let jcon = ( dbrec && dbrec . jsonld_context ? dbrec . jsonld_context : this . jsonld_context )
176203 for ( var k in jcon ) {
177204 //if (k != 'doc') ob[k] = jcon[k]
0 commit comments