Skip to content

Commit 66072e4

Browse files
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents 507e80e + 48162bb commit 66072e4

13 files changed

+10577
-90
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jspm_packages
3535

3636

3737
# npm package lock
38-
package-lock.json
38+
#package-lock.json
3939
yarn.lock
4040

4141
others

dist/terminus-client.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/terminus-client.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/connectionCapabilities.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ ConnectionCapabilities.prototype.capabilitiesPermit = function (action, dbid, se
9292

9393
if (action === CONST.CREATE_DATABASE) {
9494
rec = this.getServerRecord(server);
95-
} else {
96-
if(dbid) rec = this.getDBRecord(dbid);
97-
else console.log("no dbid", server, dbid);
98-
}
95+
} else if (dbid) rec = this.getDBRecord(dbid);
96+
else console.log('no dbid', server, dbid);
9997
if (rec) {
10098
const auths = rec['terminus:authority'];
10199
if (auths && auths.indexOf(`terminus:${action}`) !== -1) return true;
@@ -110,7 +108,7 @@ ConnectionCapabilities.prototype.getServerRecord = function (srvr) {
110108
const url = (srvr || this.connectionConfig.server);
111109
const connectionObj = this.connection[url] || {};
112110
const okeys = Object.keys(connectionObj);
113-
111+
114112
for (const oid of okeys) {
115113
if (this.connection[url][oid]['@type'] === 'terminus:Server') {
116114
return this.connection[url][oid];
@@ -159,7 +157,7 @@ ConnectionCapabilities.prototype.removeDB = function (dbid, srvr) {
159157

160158
const url = srvr || this.connectionConfig.server;
161159
const dbidCap = this.dbCapabilityID(dbid);
162-
if(dbidCap && this.connection[url] && this.connection[url][dbidCap]){
160+
if (dbidCap && this.connection[url] && this.connection[url][dbidCap]) {
163161
delete this.connection[url][dbidCap];
164162
}
165163
};

lib/dispatchRequest.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ Access-Control-Allow-Methods GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
99
Access-Control-Allow-Origin: http://localhost:3000 // WILD CARD WILL NOT WORK WHEN POSTING
1010
*/
1111

12-
function btoaImplementation (str){
13-
try {
14-
return btoa(str);
15-
} catch(err) {
16-
//console.log('in buffer')
17-
return Buffer.from(str).toString('base64')
18-
}
19-
};
12+
function btoaImplementation(str) {
13+
try {
14+
return btoa(str);
15+
} catch (err) {
16+
// console.log('in buffer')
17+
return Buffer.from(str).toString('base64');
18+
}
19+
}
2020

2121
function DispatchRequest(url, action, payload) {
2222
const options = {
@@ -26,17 +26,17 @@ function DispatchRequest(url, action, payload) {
2626
// url:url,
2727
// no-referrer, *client
2828
};
29-
if(payload && payload['terminus:user_key']){
30-
options.headers = {'Authorization': 'Basic ' + btoaImplementation(":" + payload['terminus:user_key'])};
31-
delete(payload['terminus:user_key']);
29+
if (payload && payload['terminus:user_key']) {
30+
options.headers = { Authorization: `Basic ${btoaImplementation(`:${payload['terminus:user_key']}`)}` };
31+
delete (payload['terminus:user_key']);
3232
}
3333

3434
switch (action) {
3535
case CONST.DELETE_DATABASE:
3636
case CONST.DELETE_DOCUMENT:
37-
if (payload){
37+
if (payload) {
3838
const ext = UTILS.URIEncodePayload(payload);
39-
if(ext) url += "?" + ext;
39+
if (ext) url += `?${ext}`;
4040
}
4141
return axios.delete(url, options)
4242
.then(response => response.data)
@@ -53,8 +53,8 @@ function DispatchRequest(url, action, payload) {
5353
return axios.post(url, JSON.stringify(payload), options)
5454
.then(response => response.data)
5555
.catch((err) => {
56-
var e = new Error(ErrorMessage.getAPIErrorMessage(url, options, err));
57-
if(err.response && err.response.data) e.data = err.response.data;
56+
const e = new Error(ErrorMessage.getAPIErrorMessage(url, options, err));
57+
if (err.response && err.response.data) e.data = err.response.data;
5858
throw e;
5959
});
6060
case CONST.GET_SCHEMA:
@@ -63,9 +63,9 @@ function DispatchRequest(url, action, payload) {
6363
case CONST.WOQL_SELECT:
6464
case CONST.GET_DOCUMENT:
6565
default:
66-
if (payload){
66+
if (payload) {
6767
const ext = UTILS.URIEncodePayload(payload);
68-
if(ext) url += "?" + ext;
68+
if (ext) url += `?${ext}`;
6969
}
7070
return axios.get(url, options)
7171
.then((response => response.data))

lib/errorMessage.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ function getErrorAsMessage(url, api, err) {
1414
return str;
1515
}
1616

17-
function formatErrorMessage(msg){
18-
if(typeof msg == "object"){
19-
var nmsg = "";
20-
for(var key in msg){
21-
nmsg += key + " " + msg[key] + " ";
17+
function formatErrorMessage(msg) {
18+
if (typeof msg === 'object') {
19+
let nmsg = '';
20+
for (const key of Object.keys(msg)) {
21+
nmsg += `${key} ${msg[key]} `;
2222
}
2323
return nmsg;
2424
}

lib/frameHelper.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ FrameHelper.genBNID = function () {
5757
};
5858

5959
FrameHelper.getShorthand = function (link) {
60-
if(typeof link == "object" && link.length) link = link[0];
60+
if (typeof link === 'object' && link.length) link = link[0];
6161
if (link && typeof link === 'string') {
6262
for (const pref of Object.keys(this.standard_urls)) {
6363
const full = this.standard_urls[pref];
@@ -104,28 +104,28 @@ FrameHelper.unshorten = function (url) {
104104
return url;
105105
};
106106

107-
//Valid URLs are those that start with http:// or https://
107+
// Valid URLs are those that start with http:// or https://
108108
FrameHelper.validURL = function (str) {
109-
if(str && str.substring(0, 7) == 'http://' || str.substring(0, 8) == 'https://') return true;
109+
if (str && (str.substring(0, 7) === 'http://' || str.substring(0, 8) === 'https://')) return true;
110110
return false;
111111
};
112112

113113

114114
FrameHelper.labelFromURL = function (url) {
115115
let nurl = this.urlFragment(url);
116116
nurl = (nurl || url);
117-
if(nurl.lastIndexOf("/") < nurl.length-1){
118-
nurl = nurl.substring(nurl.lastIndexOf("/") + 1);
117+
if (nurl.lastIndexOf('/') < nurl.length - 1) {
118+
nurl = nurl.substring(nurl.lastIndexOf('/') + 1);
119119
}
120-
nurl = nurl.replace("_", " ");
120+
nurl = nurl.replace('_', ' ');
121121
return nurl.charAt(0).toUpperCase() + nurl.slice(1);
122122
};
123123

124124
FrameHelper.urlFragment = function (url) {
125125
url = (typeof url !== 'string') ? window.location.href : url;
126126
let bits = url.split('#');
127127
if (bits.length <= 1) {
128-
if(!this.validURL(url)){
128+
if (!this.validURL(url)) {
129129
bits = url.split(':');
130130
}
131131
}
@@ -250,10 +250,9 @@ FrameHelper.parseXsdDate = function (val) {
250250
let parsed;
251251
if (year && Math.abs(year) < 10000) {
252252
let month = val.substring(year.length + 1, year.length + 3);
253-
if (month) { month = parseInt(month)}
254-
else return false;
253+
if (month) { month = parseInt(month, 10); } else return false;
255254
let day = val.substring(year.length + 4);
256-
if (day) day = parseInt(day);
255+
if (day) day = parseInt(day, 10);
257256
else return false;
258257
parsed = {
259258
year,
@@ -308,8 +307,7 @@ FrameHelper.xsdFromParsed = function (parsed, ty) {
308307
let ret;
309308
if (ty === 'xsd:gYear') {
310309
ret = (xparsed.year ? xparsed.year : false);
311-
}
312-
else if (ty === 'xsd:time') {
310+
} else if (ty === 'xsd:time') {
313311
return (xparsed.hour && xparsed.minute && xparsed.second) ? `${xparsed.hour}:${xparsed.minute}:${xparsed.second}` : false;
314312
} else if (ty === 'xsd:date') {
315313
return (xparsed.year && xparsed.month && xparsed.day) ? `${xparsed.year}-${xparsed.month}-${xparsed.day}` : false;

lib/objectFrame.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,8 @@ DataFrame.prototype.isProperty = function () {
764764
DataFrame.prototype.getTypeShorthand = function () {
765765
if (this.isDocument()) return 'document';
766766
if (this.isChoice()) return 'choice';
767-
var sh = FrameHelper.getShorthand(this.getType());
768-
return (sh ? sh : this.getType());
767+
const sh = FrameHelper.getShorthand(this.getType());
768+
return (sh || this.getType());
769769
};
770770

771771
DataFrame.prototype.get = function () {
@@ -879,7 +879,7 @@ ClassFrame.prototype.clone = function (newid, other) {
879879

880880
ClassFrame.prototype.getClassChoices = function () {
881881
const choices = [];
882-
if(this.frame.operands){
882+
if (this.frame.operands) {
883883
for (let i = 0; i < this.frame.operands.length; i += 1) {
884884
for (let j = 0; j < this.frame.operands[i].length; j += 1) {
885885
const domcls = this.frame.operands[i][j].domain;

lib/terminusIDParser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ IDParser.prototype.parseDocumentURL = function (str) {
9595
}
9696
if (this.parseDBID(dbURL) === false) return false;
9797
}
98-
if(str.substring(0, 4) === "doc:") str = str.substring(4);
98+
if (str.substring(0, 4) === 'doc:') str = str.substring(4);
9999
// check if the document's name hasn't space or '/'
100100
if (this.validIDString(str)) {
101101
this.doc = str;
@@ -139,9 +139,9 @@ IDParser.prototype.parseClassFrameURL = function (str) {
139139
return this.parseDBID(str);
140140
};
141141

142-
//Valid URLs are those that start with http:// or https://
142+
// Valid URLs are those that start with http:// or https://
143143
IDParser.prototype.validURL = function (str) {
144-
if(str.substring(0, 7) == "http://" || str.substring(0, 8) == "https://") return true;
144+
if (str.substring(0, 7) === 'http://' || str.substring(0, 8) === 'https://') return true;
145145
return false;
146146
};
147147

@@ -154,7 +154,7 @@ IDParser.prototype.validPrefixedURL = function (str, context) {
154154
return false;
155155
};
156156

157-
IDParser.prototype.validIDString = function (str) {
157+
IDParser.prototype.validIDString = function (str) {
158158
if (typeof str !== 'string') return false;
159159
if (str.indexOf(':') !== -1 || str.indexOf(' ') !== -1 || str.indexOf('/') !== -1) return false;
160160
return true;

lib/woqlClient.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ WOQLClient.prototype.connect = function (curl, key) {
5151
if (key) {
5252
this.connection.setClientKey(serverURL, key);
5353
}
54-
//unset the current server setting until successful connect
54+
// unset the current server setting until successful connect
5555
this.connectionConfig.server = false;
5656
const self = this;
5757
return this.dispatch(serverURL, CONST.CONNECT).then((response) => {
@@ -109,18 +109,24 @@ WOQLClient.prototype.createDatabase = function (dburl, details, key) {
109109

110110
/**
111111
* Delete a Database
112-
* @param {string} dburl it is a terminusDB Url or a terminusDB Id
113-
* @param {object} opts no options are currently supported for this function
112+
* @param {String} dburl it is a terminusDB Url or a terminusDB Id
113+
* @param {String} key an optional API key
114114
* @return {Promise}
115115
*
116116
* if dburl is omitted, the current server and database will be used
117117
*/
118-
WOQLClient.prototype.deleteDatabase = function (dburl, opts) {
118+
WOQLClient.prototype.deleteDatabase = function (dburl, key) {
119119
if (dburl && !this.connectionConfig.setDB(dburl)) {
120120
return Promise.reject(
121121
new URIError(ErrorMessage.getInvalidURIMessage(dburl, 'Delete Database'))
122122
);
123123
}
124+
const opts = {};
125+
126+
if (key) {
127+
opts.key = key;
128+
}
129+
124130
const self = this;
125131
return this.dispatch(`${this.connectionConfig.dbURL()}`, CONST.DELETE_DATABASE, opts).then(
126132
(response) => {
@@ -146,7 +152,7 @@ WOQLClient.prototype.getSchema = function (schurl, opts) {
146152
new URIError(ErrorMessage.getInvalidURIMessage(schurl, 'Get Schema'))
147153
);
148154
}
149-
//consoleco.log('schemaURL', this.connectionConfig.schemaURL());
155+
// consoleco.log('schemaURL', this.connectionConfig.schemaURL());
150156
return this.dispatch(this.connectionConfig.schemaURL(), CONST.GET_SCHEMA, opts);
151157
};
152158

@@ -238,7 +244,7 @@ WOQLClient.prototype.updateDocument = function (docurl, doc, opts) {
238244
return Promise.reject(
239245
new URIError(ErrorMessage.getInvalidURIMessage(docurl, 'Update Document'))
240246
);
241-
}
247+
}
242248
if (doc && doc['@id']
243249
&& !this.connectionConfig.setDocument(doc['@id'], doc['@context'])
244250
) {
@@ -342,8 +348,8 @@ WOQLClient.prototype.addOptionsToWOQL = function (woql, opts) {
342348
WOQLClient.prototype.addOptionsToDocument = function (doc, opts) {
343349
const pdoc = {};
344350
pdoc['@context'] = doc['@context'];
345-
if(pdoc['@context'] && doc['@id']){ //add blank node prefix as document base url
346-
pdoc['@context']["_"] = doc['@id'] + "/"
351+
if (pdoc['@context'] && doc['@id']) { // add blank node prefix as document base url
352+
pdoc['@context']._ = `${doc['@id']}/`;
347353
}
348354
if (opts && opts['terminus:encoding'] && opts['terminus:encoding'] === 'terminus:turtle') {
349355
pdoc['terminus:turtle'] = doc;
@@ -370,8 +376,7 @@ WOQLClient.prototype.addKeyToPayload = function (payload, url) {
370376
delete payload.key;
371377
} else if (this.connection.getClientKey()) {
372378
payload['terminus:user_key'] = this.connection.getClientKey();
373-
}
374-
else if (this.connection.getClientKey(url)) {
379+
} else if (this.connection.getClientKey(url)) {
375380
payload['terminus:user_key'] = this.connection.getClientKey(url);
376381
}
377382
return payload;
@@ -399,13 +404,13 @@ WOQLClient.prototype.dispatchFetch = function (url, action, payload) {
399404
redirect: 'follow', // manual, *follow, error
400405
referrer: 'client', // no-referrer, *client
401406
};
402-
var hdrs = {};
407+
let hdrs = {};
403408
if (this.connectionConfig.platformEndpoint()) {
404409
api.credentials = 'include'; // include, *same-origin, omit
405410
}
406-
if(payload && payload['terminus:user_key']){
407-
hdrs = {'Authorization': 'Basic ' + btoa(":" + payload['terminus:user_key'])};
408-
delete(payload['terminus:user_key']);
411+
if (payload && payload['terminus:user_key']) {
412+
hdrs = { Authorization: `Basic ${btoa(`:${payload['terminus:user_key']}`)}` };
413+
delete (payload['terminus:user_key']);
409414
}
410415
// read only API calls - use GET
411416
switch (action) {
@@ -435,7 +440,7 @@ WOQLClient.prototype.dispatchFetch = function (url, action, payload) {
435440
if (Object.keys(payload).length > 0) url += `?${UTILS.URIEncodePayload(payload)}`;
436441
}
437442
const self = this;
438-
if(Object.keys(hdrs).length > 0){
443+
if (Object.keys(hdrs).length > 0) {
439444
api.headers = new Headers(hdrs);
440445
}
441446
return fetch(url, api).then((response) => {

0 commit comments

Comments
 (0)