Skip to content

Commit dd4481c

Browse files
committed
merge canary
2 parents a6f9968 + d400095 commit dd4481c

File tree

7 files changed

+89
-14
lines changed

7 files changed

+89
-14
lines changed

.ci/publish_canary.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ always-auth=true
66
email=robin@datachemist.com" > $TRAVIS_BUILD_DIR/.npmrc
77
curl -XDELETE https://api.bintray.com/packages/terminusdb/npm-canary/terminusdb:terminusdb-client -u "rrooij:$BINTRAY_API_TOKEN"
88
npm publish --access=public
9+
curl -T "dist/terminusdb-client.min.js" -u"rrooij:$BINTRAY_CURL_API_KEY" "https://api.bintray.com/content/terminusdb/terminusdb/terminusdb-client/canary/canary/terminusdb-client.min.js?publish=1&override=1"
10+
curl -T "dist/terminusdb-client.min.js.map" -u"rrooij:$BINTRAY_CURL_API_KEY" "https://api.bintray.com/content/terminusdb/terminusdb/terminusdb-client/canary/canary/terminusdb-client.min.js.map?publish=1&override=1"

.ci/publish_rc.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ always-auth=true
66
email=robin@datachemist.com" > $TRAVIS_BUILD_DIR/.npmrc
77
curl -XDELETE https://api.bintray.com/packages/terminusdb/npm-rc/terminusdb:terminusdb-client -u "rrooij:$BINTRAY_API_TOKEN"
88
npm publish --access=public
9+
curl -T "dist/terminusdb-client.min.js" -u"rrooij:$BINTRAY_CURL_API_KEY" "https://api.bintray.com/content/terminusdb/terminusdb/terminusdb-client/rc/rc/terminusdb-client.min.js?publish=1&override=1"
10+
curl -T "dist/terminusdb-client.min.js.map" -u"rrooij:$BINTRAY_CURL_API_KEY" "https://api.bintray.com/content/terminusdb/terminusdb/terminusdb-client/rc/rc/terminusdb-client.min.js.map?publish=1&override=1"

lib/connectionConfig.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ ConnectionConfig.prototype.triplesURL = function(type, gid) {
285285
return s
286286
}
287287

288+
/**
289+
* Generate URL for add / get csv api endpoint
290+
*/
291+
ConnectionConfig.prototype.csvURL = function(type, gid) {
292+
var s = this.branchBase('csv')
293+
const graphId = gid || 'main'
294+
const gType = type || 'instance'
295+
s += `/${gType}/${graphId}`
296+
return s
297+
}
298+
288299
/**
289300
* Generate URL for woql query api endpoint
290301
*/

lib/const.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ module.exports = Object.freeze({
3434
REBASE: 'rebase',
3535
RESET: 'reset',
3636
BRANCH: 'branch',
37+
ADD_CSV: 'add_csv',
38+
GET_CSV: 'get_csv',
39+
UPDATE_CSV: 'update_csv'
3740
})

lib/dispatchRequest.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
3636
// url:url,
3737
// no-referrer, *client
3838
}
39-
40-
if (!url.startsWith("https://127.0.0.1")
41-
&& typeof window !== 'undefined') {
39+
// Only allow self signed certs on 127.0.0.1
40+
// and on node
41+
if (url.startsWith("https://127.0.0.1")
42+
&& typeof window === 'undefined') {
4243
const https = require('https')
4344
const agent = new https.Agent({
44-
rejectUnauthorized: true
45+
rejectUnauthorized: false
4546
})
4647
options.httpsAgent = agent
4748
}
@@ -83,6 +84,7 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
8384
case CONST.READ_DATABASE:
8485
case CONST.READ_ORGANIZATION:
8586
case CONST.CONNECT:
87+
case CONST.GET_CSV:
8688
case CONST.CLASS_FRAME:
8789
if (payload) {
8890
const ext = UTILS.URIEncodePayload(payload)
@@ -93,11 +95,23 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
9395
.then(response => response.data)
9496
.catch(err => {
9597
let e = new Error(ErrorMessage.getAPIErrorMessage(url, options, err))
98+
console.log(err)
9699
if (err.response && err.response.data) {
97100
e.data = err.response.data
98101
}
99102
throw e
100103
})
104+
case CONST.ADD_CSV:
105+
options.headers = options.headers ? options.headers : {}
106+
options.headers['Content-Type'] = 'multipart/form-data'
107+
return axiosInstance
108+
.put(url, payload, options)
109+
.then(response => response.data)
110+
.catch(err => {
111+
const e = new Error(ErrorMessage.getAPIErrorMessage(url, options, err))
112+
if (err.response && err.response.data) e.data = err.response.data
113+
throw e
114+
})
101115
case CONST.INSERT_TRIPLES:
102116
options.headers = options.headers ? options.headers : {}
103117
options.headers['Content-Type'] = 'application/json'
@@ -108,7 +122,7 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
108122
const e = new Error(ErrorMessage.getAPIErrorMessage(url, options, err))
109123
if (err.response && err.response.data) e.data = err.response.data
110124
throw e
111-
})
125+
})
112126
default:
113127
options.headers = options.headers ? options.headers : {}
114128
options.headers['Content-Type'] = 'application/json'

lib/woqlClient.js

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ WOQLClient.prototype.resource = function(type, val) {
226226
* @param {object} config - see constructor for structure
227227
* @return {Promise}
228228
* @public
229-
*
229+
*
230230
*/
231231
WOQLClient.prototype.connect = function(config) {
232232
if (config) this.connectionConfig.update(config)
@@ -369,7 +369,7 @@ WOQLClient.prototype.updateTriples = function(gtype, gid, turtle, commit_msg) {
369369

370370

371371
/**
372-
* Appends the passed turtle to the contents of a graph
372+
* Appends the passed turtle to the contents of a graph
373373
*
374374
* @param {string} gtype type of graph |instance|schema|inference|
375375
* @param {string} gid TerminusDB Graph ID to update, main is the default value
@@ -393,6 +393,49 @@ WOQLClient.prototype.insertTriples = function(gtype, gid, turtle, commit_msg) {
393393
)
394394
}
395395

396+
/**
397+
* Adds a csv
398+
*
399+
* @param {string} gtype type of graph |instance|schema|inference|
400+
* @param {string} gid TerminusDB Graph ID to update, main is the default value
401+
* @param {string} csv is an array of csv file names
402+
* @param {string} commit_msg Textual message describing the reason for the update
403+
* @return {Promise}
404+
*/
405+
406+
WOQLClient.prototype.addCSV = function(gtype, gid, csv, commit_msg) {
407+
if (commit_msg && csv) {
408+
let commit = this.generateCommitInfo(commit_msg)
409+
const formData = new FormData();
410+
for(var x = 0; x<csv.length; x++) {
411+
formData.append('file', csv[x])
412+
}
413+
formData.append('payload', JSON.stringify(commit))
414+
return this.dispatch(
415+
CONST.ADD_CSV,
416+
this.connectionConfig.csvURL(gtype, gid),
417+
formData,
418+
)
419+
}
420+
}
421+
422+
423+
/**
424+
* gets loaded csv
425+
*
426+
* @param {string} gtype Type of graph (instance|schema|inference)
427+
* schema get the database schema in owl
428+
* instance get all the database documents data in owl format
429+
* inference get all the constraints schema in owl
430+
*
431+
* @return {Promise}
432+
*
433+
*/
434+
WOQLClient.prototype.getCSV = function(gtype, gid) {
435+
return this.dispatch(CONST.GET_CSV, this.connectionConfig.csvURL(gtype, gid))
436+
}
437+
438+
396439
/**
397440
* Executes a WOQL query on the specified database and returns the results
398441
*
@@ -586,7 +629,7 @@ WOQLClient.prototype._load_db_prefixes = function(dbs) {
586629
ndb.prefix_pairs = {}
587630
}
588631
if(row['Prefix_'+j] && row['Prefix_'+j]['@value'] && row['IRI_'+j]["@value"]){
589-
ndb.prefix_pairs[row['Prefix_'+j]["@value"]] = row['IRI_'+j]["@value"]
632+
ndb.prefix_pairs[row['Prefix_'+j]["@value"]] = row['IRI_'+j]["@value"]
590633
}
591634
}
592635
}
@@ -598,8 +641,8 @@ WOQLClient.prototype._load_db_prefixes = function(dbs) {
598641
/**
599642
* Not yet released - subject to change in parameters
600643
* The class frame API endpoint is not yet sufficiently stable for release
601-
* It should be considered unreliable and subject to change in parameters until
602-
* it has been released
644+
* It should be considered unreliable and subject to change in parameters until
645+
* it has been released
603646
*/
604647

605648
/**
@@ -621,12 +664,12 @@ WOQLClient.prototype.getClassFrame = function(cls) {
621664

622665

623666
/***
624-
* Server Version API
667+
* Server Version API
625668
* Note: the below endpoints are not part of the terminusdb desktop package
626-
* they belong to the server package version of the DB which is under construction.
669+
* they belong to the server package version of the DB which is under construction.
627670
* Until that package is released all of the below endpoints should be considered
628671
* as unreliable and subject to change - they are provided complete with the desktop
629-
* version to show users what is coming and to allow people to use them at their own risk
672+
* version to show users what is coming and to allow people to use them at their own risk
630673
* Any use of them should be considered unsupported and at your own risk
631674
*/
632675

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
},
6767
"repository": {
6868
"type": "git",
69-
"url": "git+https://github.com/terminusdb/terminusdb-client.git"
69+
"url": "git+https://github.com/terminusdb/terminusdb-client-js.git"
7070
},
7171
"keywords": [
7272
"Terminus",

0 commit comments

Comments
 (0)