@@ -372,67 +372,14 @@ WOQLClient.prototype.deleteDatabase = function(dbId, orgId, force) {
372
372
this . organization ( orgIdValue )
373
373
let payload = force ? { force : true } : null
374
374
if ( dbId && this . db ( dbId ) ) {
375
- return this . dispatch ( CONST . DATABASE , this . connectionConfig . dbURL ( ) , payload )
375
+ return this . dispatch ( CONST . DELETE , this . connectionConfig . dbURL ( ) , payload )
376
376
}
377
377
let errmsg = `Delete database parameter error - you must specify a valid database id - ${ dbId } is invalid`
378
378
return Promise . reject (
379
- new Error ( ErrorMessage . getInvalidParameterMessage ( CONST . DATABASE , errmsg ) ) ,
379
+ new Error ( ErrorMessage . getInvalidParameterMessage ( CONST . DELETE , errmsg ) ) ,
380
380
)
381
381
}
382
382
383
- /**
384
- * Creates a new named graph within a TerminusDB database
385
- * @param {typedef.GraphType } graphType - type of graph
386
- * @param {string } graphId - id of the graph to be created
387
- * @param {string } commitMsg - a message describing the reason for the change that will be written into the commit log
388
- * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
389
- * @example
390
- * client.createGraph("schema", "alt", "Adding new schema graph")
391
- */
392
- //TO BE REMOVED
393
- WOQLClient . prototype . createGraph = function ( graphType , graphId , commitMsg ) {
394
- if (
395
- graphType &&
396
- [ 'inference' , 'schema' , 'instance' ] . indexOf ( graphType ) !== - 1 &&
397
- graphId &&
398
- commitMsg
399
- ) {
400
- let commit = this . generateCommitInfo ( commitMsg )
401
- return this . dispatch (
402
- CONST . CREATE_GRAPH ,
403
- this . connectionConfig . graphURL ( graphType , graphId ) ,
404
- commit ,
405
- )
406
- }
407
- let errmsg = `Create graph parameter error - you must specify a valid type (inference, instance, schema), graph id and commit message`
408
- return Promise . reject (
409
- new Error ( ErrorMessage . getInvalidParameterMessage ( CONST . CREATE_GRAPH , errmsg ) ) ,
410
- )
411
- }
412
-
413
- /**
414
- * Deletes a graph from a TerminusDB database
415
- * @param {typedef.GraphType } graphType - type of graph
416
- * @param {string } graphId - local id of graph
417
- * @param {string } commitMsg - a message describing the reason for the change that will be written into the commit log
418
- * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
419
- * @example
420
- * client.deleteGraph("schema", "alt", "Deleting alt schema graph")
421
- */
422
- WOQLClient . prototype . deleteGraph = function ( graphType , graphId , commitMsg ) {
423
- if ( graphType && [ 'inference' , 'schema' , 'instance' ] . indexOf ( graphType ) != - 1 && graphId ) {
424
- let commit = this . generateCommitInfo ( commitMsg )
425
- return this . dispatch (
426
- CONST . GRAPH ,
427
- this . connectionConfig . graphURL ( graphType , graphType ) ,
428
- commit ,
429
- )
430
- }
431
- let errmsg = `Delete graph parameter error - you must specify a valid type (inference, instance, schema), graph id and commit message`
432
- return Promise . reject (
433
- new Error ( ErrorMessage . getInvalidParameterMessage ( CONST . GRAPH , errmsg ) ) ,
434
- )
435
- }
436
383
437
384
/**
438
385
* Retrieve the contents of a graph within a TerminusDB as triples, encoded in the turtle (ttl) format
@@ -871,24 +818,34 @@ WOQLClient.prototype.dispatch = function(action, apiUrl, payload) {
871
818
) ,
872
819
) ,
873
820
)
874
- } //I have to do a call to get the jwt token
875
- /*if(this.connectionConfig.tokenParameter){
821
+ }
822
+ //I have to review this I don't want a call everytime
823
+ if ( this . connectionConfig . tokenParameter ) {
876
824
const param = this . connectionConfig . tokenParameter
877
- await axios.post(param.url,param.options).then(result=>result.data).then(data=>{
825
+ axios . post ( param . url , param . options ) . then ( result => result . data ) . then ( data => {
878
826
if ( data . access_token ) {
879
827
console . log ( "ACCESS_TOKEN" , data . access_token )
880
828
this . localAuth ( { "key" :data . access_token , "type" :"jwt" } )
881
829
}
830
+ return DispatchRequest (
831
+ apiUrl ,
832
+ action ,
833
+ payload ,
834
+ this . localAuth ( ) ,
835
+ this . remoteAuth ( ) ,
836
+ this . customHeaders ( ) ,
837
+ )
882
838
} )
883
- }*/
884
- return DispatchRequest (
885
- apiUrl ,
886
- action ,
887
- payload ,
888
- this . localAuth ( ) ,
889
- this . remoteAuth ( ) ,
890
- this . customHeaders ( ) ,
891
- )
839
+ } else {
840
+ return DispatchRequest (
841
+ apiUrl ,
842
+ action ,
843
+ payload ,
844
+ this . localAuth ( ) ,
845
+ this . remoteAuth ( ) ,
846
+ this . customHeaders ( ) ,
847
+ )
848
+ }
892
849
893
850
}
894
851
@@ -1318,34 +1275,37 @@ WOQLClient.prototype.getEnums = function(dbId){
1318
1275
* @param {string } [dbId]
1319
1276
* @returns
1320
1277
*/
1321
- /* WOQLClient.prototype.getClassDocuments = async function(dbId){
1278
+ WOQLClient . prototype . getClassDocuments = function ( dbId ) {
1322
1279
const params = { 'graph_type' :"schema" , "as_list" :true , "type" :"sys:Class" }
1323
- const result = await this.getDocument(params,dbId)
1324
- let documents=[]
1325
- if(result){
1280
+ return this . getDocument ( params , dbId ) . then ( result => {
1281
+ let documents = [ ]
1282
+ if ( result ) {
1326
1283
documents = result . filter ( item => ! item [ '@subdocument' ] && ! item [ '@abstract' ] )
1327
- }
1328
- return documents
1329
- }*/
1284
+ }
1285
+ return documents
1286
+ } )
1287
+ }
1330
1288
1331
1289
/**
1332
1290
*
1333
1291
* @param {* } dbId
1334
1292
* @returns
1335
1293
*/
1336
- /* WOQLClient.prototype.getBranches = async function(dbId){
1294
+ WOQLClient . prototype . getBranches = function ( dbId ) {
1337
1295
const params = { type :'Branch' , 'as_list' :true }
1338
1296
const branch = this . checkout ( )
1339
- const result = await this.getDocument(params,dbId,"_commits")
1297
+ return this . getDocument ( params , dbId , "_commits" ) . then ( result => {
1298
+ const branchesObj = { }
1299
+ if ( result ) {
1300
+ result . forEach ( item => {
1301
+ branchesObj [ item . name ] = item
1302
+ } )
1303
+ }
1304
+ this . checkout ( branch )
1305
+ return branchesObj
1306
+ } )
1340
1307
//reset branch
1341
- const branchesObj = {}
1342
- if(result){
1343
- result.forEach(item=>{
1344
- branchesObj[item.name]=item
1345
- })
1346
- }
1347
- this.checkout(branch)
1348
- return branchesObj
1349
- }*/
1308
+
1309
+ }
1350
1310
1351
1311
module . exports = WOQLClient
0 commit comments