Skip to content

Commit 88ebe8e

Browse files
2 parents 692a167 + 1e5eb56 commit 88ebe8e

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

lib/connectionConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ ConnectionConfig.prototype.graphURL = function(type, gid) {
275275
return this.branchBase('graph') + `/${type}/${gid}`
276276
}
277277

278+
278279
/**
279280
* Generate URL for get / set schema api endpoint
280281
*/

lib/const.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ module.exports = Object.freeze({
3636
BRANCH: 'branch',
3737
ADD_CSV: 'add_csv',
3838
GET_CSV: 'get_csv',
39-
UPDATE_CSV: 'update_csv'
39+
UPDATE_CSV: 'update_csv',
40+
DELETE_CSV: 'delete_csv',
41+
MESSAGE: 'message'
4042
})

lib/dispatchRequest.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
6363
}
6464
switch (action) {
6565
case CONST.DELETE_DATABASE:
66+
case CONST.DELETE_CSV:
6667
case CONST.DELETE_GRAPH:
6768
case CONST.DELETE_USER:
6869
case CONST.DELETE_ORGANIZATION:
@@ -100,6 +101,21 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
100101
}
101102
throw e
102103
})
104+
case CONST.MESSAGE:
105+
if (payload) {
106+
const ext = UTILS.URIEncodePayload(payload)
107+
if (ext) url += `?api:message=${ext}`
108+
}
109+
return axiosInstance
110+
.get(url, options)
111+
.then(response => response.data)
112+
.catch(err => {
113+
let e = new Error(ErrorMessage.getAPIErrorMessage(url, options, err))
114+
if (err.response && err.response.data) {
115+
e.data = err.response.data
116+
}
117+
throw e
118+
})
103119
case CONST.ADD_CSV:
104120
options.headers = options.headers ? options.headers : {}
105121
options.headers['Content-Type'] = 'application/form-data'

lib/woqlClient.js

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ WOQLClient.prototype.insertCSV = function(csv_path, commitMsg, gtype, gid) {
407407
let commit = this.generateCommitInfo(commitMsg)
408408
const formData = new FormData();
409409
csv_path.map((item)=>{
410-
if(typeof(item.name)=="string"){ // file objects
410+
if(typeof(item.name)=="string"){
411411
formData.append(item.name, item)
412412
}
413-
else { // string file paths
413+
else {
414414
let name = new String(item).substring(item.lastIndexOf('/') + 1);
415415
var fr = new File([name], item, {type: "csv/text"});
416416
formData.append(name, fr)
@@ -456,15 +456,53 @@ WOQLClient.prototype.updateCSV = function(csv, commitMsg, gtype, gid) {
456456
*
457457
* @param {string} csvName Name of csv to dump from the specified database to extract
458458
* @param {string} csvDirectory CSV output directory path. (defaults to current directory).
459+
* @param {string} download flag to download csv file
459460
* @param {string} gtype Type of graph (instance|schema|inference)
460461
* @param {string} gid identifier.
461462
* @return {Promise} An API success message
462463
*
463464
*/
464-
WOQLClient.prototype.getCSV = function(csvName, csvDirectory, gtype, gid) {
465-
let options = {}
465+
WOQLClient.prototype.getCSV = function(csvName, download, gtype, gid) {
466+
let options = {}, filePath
466467
options.name=csvName;
467-
return this.dispatch(CONST.GET_CSV, this.connectionConfig.csvURL(gtype, gid), options)
468+
return this.dispatch(CONST.GET_CSV, this.connectionConfig.csvURL(gtype, gid), options).then(results => {
469+
if (download) {
470+
const url=window.URL.createObjectURL(new Blob([results]));
471+
const link=document.createElement('a');
472+
link.href = url;
473+
link.setAttribute('download', csvName);
474+
document.body.appendChild(link);
475+
link.click();
476+
}
477+
return results;
478+
})
479+
}
480+
481+
/**
482+
* Deletes a csv into the specified path
483+
*
484+
* @param {array} csvName is an array of csv file names
485+
* @param {string} gtype type of graph |instance|schema|inference|
486+
* @param {string} gid TerminusDB Graph ID to update, main is the default value
487+
* @return {Promise} An API success message
488+
*/
489+
WOQLClient.prototype.deleteCSV = function(csvName, gtype, gid) {
490+
let options = {}, filePath
491+
options.name=csvName;
492+
return this.dispatch(CONST.DELETE_CSV, this.connectionConfig.csvURL(gtype, gid), options).then(results => {
493+
return results;
494+
})
495+
}
496+
497+
/**
498+
* sends a message to the server
499+
* @param {string} msg - textual string
500+
*/
501+
WOQLClient.prototype.message = function(message) {
502+
const url = this.api() + 'message'
503+
return this.dispatch(CONST.MESSAGE, url, message).then(response => {
504+
return response
505+
})
468506
}
469507

470508

0 commit comments

Comments
 (0)