@@ -34,6 +34,11 @@ const { default: axios } = require('axios')
34
34
* {user:"myemail@something.com", organization:'mycloudTeam' })
35
35
*
36
36
* 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
+ * })
37
42
* async function getSchema() {
38
43
* client.db("test")
39
44
* client.checkout("dev")
@@ -109,23 +114,41 @@ WOQLClient.prototype.api = function() {
109
114
}
110
115
111
116
/**
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
113
119
* @param {string | boolean } [orgId] the organization id to set the context to
114
120
* @returns {string | boolean }
115
121
* @example
116
122
* client.organization("admin")
117
123
*/
118
124
WOQLClient . prototype . organization = function ( orgId ) {
119
125
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 ( [ ] )
125
129
}
126
130
return this . connectionConfig . organization ( )
127
131
}
128
132
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
+
129
152
/**
130
153
* Gets the current user object as returned by the connect capabilities response
131
154
* user has fields: [id, name, notes, author]
@@ -821,22 +844,6 @@ WOQLClient.prototype.prepareRevisionControlArgs = function(rc_args) {
821
844
822
845
823
846
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
-
840
847
/**
841
848
* update the database details
842
849
* @param {object } dbDoc - an object that describe the database details
@@ -1075,17 +1082,15 @@ WOQLClient.prototype.getBranches = function(dbId){
1075
1082
1076
1083
}
1077
1084
1078
- //this method is not documented
1079
- /*
1085
+
1086
+
1087
+ /**
1080
1088
* get the organizations and the database related
1081
1089
* @returns {Promise } A promise that returns the call response object, or an Error if rejected.
1082
1090
* @example
1083
- * const client = new TerminusDB.WOQLClient()
1084
1091
* client.getUserOrganizations().then(result=>{
1085
1092
* console.log(result)
1086
1093
* })
1087
- * //get back the datatabases for the current organization
1088
- * const organizationDatabases = client.databases()
1089
1094
*/
1090
1095
WOQLClient . prototype . getUserOrganizations = function ( ) {
1091
1096
// return response
@@ -1095,9 +1100,6 @@ WOQLClient.prototype.getBranches = function(dbId){
1095
1100
) . then ( response => {
1096
1101
const orgList = Array . isArray ( response ) ? response : [ ]
1097
1102
this . userOrganizations ( orgList )
1098
- if ( orgList . length > 0 && this . connectionConfig . organization ( ) ) {
1099
- this . organization ( this . connectionConfig . organization ( ) )
1100
- }
1101
1103
return orgList
1102
1104
} )
1103
1105
}
0 commit comments