Skip to content

Commit 475b3aa

Browse files
committed
added getDatabases
1 parent dee1a29 commit 475b3aa

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

lib/woqlClient.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const { default: axios } = require('axios')
3434
* {user:"myemail@something.com", organization:'mycloudTeam'})
3535
*
3636
* client.setApiKey(MY_ACCESS_TOKEN)
37+
* //to get the list of all the team and databases
38+
* client.getDatabases(result=>{
39+
* console.log(result)
40+
*
41+
* })
3742
* async function getSchema() {
3843
* client.db("test")
3944
* client.checkout("dev")
@@ -109,23 +114,41 @@ WOQLClient.prototype.api = function() {
109114
}
110115

111116
/**
112-
* Gets/Sets the client’s internal organization context value
117+
* Gets/Sets the client’s internal organization context value, if you change the organization name the
118+
* databases list will be set to empty
113119
* @param {string | boolean} [orgId] the organization id to set the context to
114120
* @returns {string | boolean}
115121
* @example
116122
* client.organization("admin")
117123
*/
118124
WOQLClient.prototype.organization = function(orgId) {
119125
if (typeof orgId !== 'undefined') {
120-
this.connectionConfig.setOrganization(orgId)
121-
const orgObj = this.userOrganizations().find(element => element['name'] === orgId)
122-
const dbs = orgObj ? orgObj.databases : []
123-
//change the database list
124-
this.databases(dbs)
126+
this.connectionConfig.setOrganization(orgId)
127+
//we have to reset the databases list
128+
this.databases([])
125129
}
126130
return this.connectionConfig.organization()
127131
}
128132

133+
/**
134+
* Gets the organization's databases list
135+
* @returns {string | boolean}
136+
* @example
137+
* client.getDatabases()
138+
*/
139+
WOQLClient.prototype.getDatabases = async function(){
140+
// return response
141+
if(!this.connectionConfig.organization()){
142+
throw new Error(`You need to set the organization name`);
143+
}
144+
//when we will have the end point to get the databases only for the current organization
145+
//we'll change this call
146+
await this.getUserOrganizations();
147+
const dbs = this.userOrganizations().find(element => element['name'] === this.connectionConfig.organization())
148+
this.databases(dbs)
149+
return dbs
150+
}
151+
129152
/**
130153
* Gets the current user object as returned by the connect capabilities response
131154
* user has fields: [id, name, notes, author]
@@ -821,22 +844,6 @@ WOQLClient.prototype.prepareRevisionControlArgs = function(rc_args) {
821844

822845

823846

824-
/***
825-
* Server Version API
826-
* Note: the below endpoints are not part of the terminusdb desktop package
827-
* they belong to the server package version of the DB which is under construction.
828-
* Until that package is released all of the below endpoints should be considered
829-
* as unreliable and subject to change - they are provided complete with the desktop
830-
* version to show users what is coming and to allow people to use them at their own risk
831-
* Any use of them should be considered unsupported and at your own risk
832-
* get all the database information from the remote server
833-
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
834-
*/
835-
836-
WOQLClient.prototype.getDatabase = function() {
837-
return this.dispatch(CONST.GET, this.connectionConfig.dbURL())
838-
}
839-
840847
/**
841848
* update the database details
842849
* @param {object} dbDoc - an object that describe the database details
@@ -1075,17 +1082,15 @@ WOQLClient.prototype.getBranches = function(dbId){
10751082

10761083
}
10771084

1078-
//this method is not documented
1079-
/*
1085+
1086+
1087+
/**
10801088
* get the organizations and the database related
10811089
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
10821090
* @example
1083-
* const client = new TerminusDB.WOQLClient()
10841091
* client.getUserOrganizations().then(result=>{
10851092
* console.log(result)
10861093
* })
1087-
* //get back the datatabases for the current organization
1088-
* const organizationDatabases = client.databases()
10891094
*/
10901095
WOQLClient.prototype.getUserOrganizations = function(){
10911096
// return response
@@ -1095,9 +1100,6 @@ WOQLClient.prototype.getBranches = function(dbId){
10951100
).then(response => {
10961101
const orgList = Array.isArray(response) ? response : []
10971102
this.userOrganizations(orgList)
1098-
if (orgList.length>0 && this.connectionConfig.organization()){
1099-
this.organization(this.connectionConfig.organization())
1100-
}
11011103
return orgList
11021104
})
11031105
}

0 commit comments

Comments
 (0)