Skip to content

Commit 723847c

Browse files
committed
Merge branch 'dev' into canary
2 parents 5dff632 + 05ba853 commit 723847c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3727
-6024
lines changed

docs/api/woql.js.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ Performs a path regular expression match on the graph
10751075
| Param | Type | Description |
10761076
| --- | --- | --- |
10771077
| subject | <code>string</code> | An IRI or variable that refers to an IRI representing the subject, i.e. the starting point of the path |
1078-
| pattern | <code>string</code> | (string) - A path regular expression describing a pattern through multiple edges of the graph Path regular expressions consist of a sequence of predicates and / or a set of alternatives, with quantification operators The characters that are interpreted specially are the following: | representing alternative choices , - representing a sequence of predcitates + - Representing a quantification of 1 or more of the preceding pattern in a sequence {min, max} - Representing at least min examples and at most max examples of the preceding pattern - Representing any predicate () - Parentheses, interpreted in the normal way to group clauses |
1078+
| pattern | <code>string</code> | A regular expression describing a path through multiple edges of the graph. Path regular expressions consist of predicates and special characters including `\|` for alternatives, `,` for sequences, `+` for 1 or more predicates, `{min, max}` for matching a minimum and maximum number of times, `*` for matching anything, and `()` for grouping. |
10791079
| object | <code>string</code> | An IRI or variable that refers to an IRI representing the object, i.e. ending point of the path |
10801080
| resultVarName | <code>string</code> | A variable in which the actual paths traversed will be stored |
10811081

docs/api/woqlClient.js.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ For situations where you want to communicate with a TerminusDB server API, the W
1717

1818
**Example**
1919
```js
20-
const client = new TerminusClient.Client(SERVER_URL)
20+
const client = new TerminusClient.WOQLClient(SERVER_URL)
2121
await client.connect(params)
2222
client.db("test")
2323
client.checkout("dev")
@@ -45,7 +45,7 @@ or the promise will be rejected.
4545

4646
**Example**
4747
```js
48-
client.connect({key="mykey",user="admin"})
48+
client.connect({key:"mykey",user:"admin"})
4949
```
5050

5151
### Create Database

docsify

Whitespace-only changes.

lib/connectionConfig.js

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,12 @@ function ConnectionConfig(serverUrl, params) {
4242
this.refid = false
4343
/** @type {string | boolean} */
4444
this.connection_error = false
45-
45+
//I can set serverURL only in constructor
4646
let surl = this.parseServerURL(serverUrl)
47-
if (surl) {
48-
//I can set serverURL only in constructor
49-
this.server = surl
50-
if (params) this.update(params)
51-
} else {
52-
//better throw an error
53-
//fail fast designer
54-
this.setError(`Invalid Server URL: ${serverUrl}`)
55-
}
47+
48+
this.server = surl
49+
if (params) this.update(params)
50+
5651
}
5752

5853
/**
@@ -77,8 +72,10 @@ ConnectionConfig.prototype.copy = function() {
7772
*/
7873
ConnectionConfig.prototype.update = function(params) {
7974
if (!params) return
80-
const orgID = params.organization || params.user
75+
const orgID = params.organization || params.user
76+
//console.log("orgID",orgID,params)
8177
this.setOrganization(orgID)
78+
if (typeof params.credential !== 'undefined')this.setTokenParameter(params.credential)
8279
if (typeof params.db !== 'undefined') this.setDB(params.db)
8380
if (typeof params.jwt !== 'undefined') this.setRemoteBasicAuth(params.jwt, params.jwt_user)
8481
if (typeof params.key !== 'undefined') this.setLocalBasicAuth(params.key, params.user)
@@ -87,6 +84,10 @@ ConnectionConfig.prototype.update = function(params) {
8784
if (typeof params.repo !== 'undefined') this.setRepo(params.repo)
8885
}
8986

87+
ConnectionConfig.prototype.setTokenParameter = function(param){
88+
this.tokenParameter = param
89+
}
90+
9091
/**
9192
* Simple gets to retrieve current connection status
9293
* Gets the current server url
@@ -96,6 +97,15 @@ ConnectionConfig.prototype.serverURL = function() {
9697
return this.server
9798
}
9899

100+
/**
101+
* Simple gets to retrieve current connection status
102+
* Gets the current server url
103+
* @returns {string}
104+
*/
105+
ConnectionConfig.prototype.author = function() {
106+
return this.author
107+
}
108+
99109
/**
100110
* Gets the server connection url
101111
* @returns {string}
@@ -109,6 +119,7 @@ ConnectionConfig.prototype.apiURL = function() {
109119
* @returns {string | boolean}
110120
*/
111121
ConnectionConfig.prototype.db = function() {
122+
if(!this.dbid) throw new Error('Invalid database name');
112123
return this.dbid
113124
}
114125

@@ -191,7 +202,7 @@ ConnectionConfig.prototype.parseServerURL = function(str) {
191202
}
192203
//throw an error this is the
193204
//return false
194-
return ''
205+
throw new Error(`Invalid Server URL: ${str}`);
195206
}
196207

197208
/**
@@ -272,13 +283,14 @@ ConnectionConfig.prototype.setRemoteBasicAuth = function(remoteKey, remoteUserID
272283
* set the local database connection credential
273284
* @param {string} [userKey] - basic auth api key
274285
* @param {string} [userId] - user id
286+
* @param {string} [type] - basic - jwt - token
275287
*/
276-
ConnectionConfig.prototype.setLocalBasicAuth = function(userKey, userId = 'admin') {
288+
ConnectionConfig.prototype.setLocalBasicAuth = function(userKey, userId = 'admin', type= 'basic') {
277289
if (!userKey) {
278290
this.local_auth = undefined
279291
} else {
280292
const uid = userId
281-
this.local_auth = {type: 'basic', user: uid, key: userKey}
293+
this.local_auth = {type:type, user: uid, key: userKey}
282294
}
283295
}
284296

@@ -347,7 +359,7 @@ ConnectionConfig.prototype.organizationURL = function(orgId, action) {
347359
* @returns {string}
348360
*/
349361
ConnectionConfig.prototype.rolesURL = function() {
350-
return `${this.apiURL()}roles`
362+
return `${this.apiURL()}role`
351363
}
352364

353365
/**
@@ -404,13 +416,14 @@ ConnectionConfig.prototype.queryURL = function() {
404416
return this.branchBase('woql')
405417
}
406418

419+
407420
/**
408-
* Generate URL for class frame api endpoint
421+
* get the url to update the organization role in the system database
422+
* don't change the end point (this is a terminus db server end point)
409423
* @returns {string}
410424
*/
411-
ConnectionConfig.prototype.classFrameURL = function() {
412-
if (this.db() == this.system_db) return this.dbBase('frame')
413-
return this.branchBase('frame')
425+
ConnectionConfig.prototype.updateOrganizationRoleURL = function() {
426+
return `${this.apiURL()}update_role`
414427
}
415428

416429
/**
@@ -531,6 +544,10 @@ ConnectionConfig.prototype.dbBase = function(action) {
531544
return `${this.apiURL()}${action}/${this.dbURLFragment()}`
532545
}
533546

547+
//https://127.0.0.1:6363/api/document/admin/cloud-profiles/local/branch/main?graph_type=instance
548+
//instance
549+
550+
534551
/**
535552
* Generate base branch url consisting of server/action/organization/dbid/branchid
536553
* @param {typedef.ActionType} action
@@ -563,7 +580,11 @@ ConnectionConfig.prototype.branchBase = function(action) {
563580
return b
564581
}
565582
//_commits branch is magic - stores all commits for repo
566-
if (this.branch() == '_commits') {
583+
584+
/*
585+
*https://127.0.0.1:6363/api/db/admin/profiles01/local/_commits
586+
*/
587+
if (this.branch() === '_commits') {
567588
return b + `/${this.branch()}`
568589
} else if (this.ref()) {
569590
return b + `/commit/${this.ref()}`
@@ -583,4 +604,32 @@ ConnectionConfig.prototype.dbURLFragment = function() {
583604
return this.organization() + '/' + this.db()
584605
}
585606

607+
/**
608+
* Generate url portion consisting of organization/dbid
609+
* (unless dbid = system dbname in which case there is no organization)
610+
* @property {typedef.DocParamsPost|Object} params
611+
*/
612+
613+
ConnectionConfig.prototype.documentURL = function(params){
614+
const paramsStr=this.queryParameter(params)
615+
if (this.db() === this.system_db){
616+
return this.dbBase('document')+paramsStr
617+
}
618+
return this.branchBase('document')+paramsStr
619+
}
620+
621+
ConnectionConfig.prototype.queryParameter = function(params){
622+
if(params && typeof params!=='object')return ''
623+
let queryString = Object.keys(params).map((key) => {
624+
return key + '=' + encodeURIComponent(params[key])
625+
}).join('&');
626+
627+
return `?${queryString}`;
628+
}
629+
630+
ConnectionConfig.prototype.jsonSchemaURL = function(params){
631+
const paramsStr=this.queryParameter(params)
632+
return this.branchBase('schema')+paramsStr
633+
}
634+
586635
module.exports = ConnectionConfig

lib/const.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
*/
66

77
module.exports = Object.freeze({
8+
POST:'POST',
9+
GET:'GET',
10+
DELETE:'DELETE',
11+
PUT:'PUT',
812
SQUASH_BRANCH: 'SQUASH_BRANCH',
913
UPDATE_SCHEMA: 'UPDATE_SCHEMA',
1014
CONNECT: 'connect',
1115
CREATE_DATABASE: 'create_database',
1216
READ_DATABASE: 'read_database',
1317
UPDATE_DATABASE: 'update_database',
14-
DELETE_DATABASE: 'delete_database',
1518
CREATE_USER: 'create_user',
1619
READ_USER: 'read_user',
1720
UPDATE_USER: 'update_user',
18-
DELETE_USER: 'delete_user',
1921
CREATE_ORGANIZATION: 'create_organization',
2022
READ_ORGANIZATION: 'read_organization',
2123
UPDATE_ORGANIZATION: 'update_organization',
22-
DELETE_ORGANIZATION: 'delete_organization',
2324
GET_ROLES: 'get_roles',
2425
UPDATE_ROLES: 'update_roles',
2526
CREATE_GRAPH: 'create_graph',
26-
DELETE_GRAPH: 'delete_graph',
2727
GET_TRIPLES: 'get_triples',
2828
INSERT_TRIPLES: 'insert_triples',
2929
UPDATE_TRIPLES: 'update_triples',
@@ -39,12 +39,10 @@ module.exports = Object.freeze({
3939
REBASE: 'rebase',
4040
RESET: 'reset',
4141
BRANCH: 'branch',
42-
DELETE_BRANCH: 'delete_branch',
4342
RESET_BRANCH: 'reset_branch',
4443
ADD_CSV: 'add_csv',
4544
GET_CSV: 'get_csv',
4645
UPDATE_CSV: 'update_csv',
47-
DELETE_CSV: 'delete_csv',
4846
MESSAGE: 'message',
4947
ACTION: 'action',
5048
INFO: 'info',

lib/dispatchRequest.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ function btoaImplementation(str) {
2323
* @param {string} action API action
2424
* @param {object} payload data to be transmitted to endpoint
2525
* @param {string} key optional basic auth string to be passed
26-
* @param {string} reqUID the unique reqID
26+
* @param {object} customHeaders the unique reqID
2727
*/
28-
function DispatchRequest(url, action, payload, local_auth, remote_auth = null, reqUID = null) {
28+
function DispatchRequest(url, action, payload, local_auth, remote_auth = null, customHeaders = null) {
2929
/*
3030
*CORS is only required when trying to fetch data from a browser,
3131
*as browsers by default will block requests to different origins
@@ -34,6 +34,7 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null, r
3434
mode: 'cors', // no-cors, cors, *same-origin
3535
redirect: 'follow', // manual, *follow, error
3636
referrer: 'client',
37+
headers:{}
3738
// url:url,
3839
// no-referrer, *client
3940
}
@@ -51,35 +52,32 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null, r
5152
* I can call the local database using the local authorization key or
5253
* a jwt token
5354
*/
54-
if (local_auth && local_auth.type == 'basic') {
55+
if (local_auth && local_auth.type === 'basic') {
5556
let encoded = btoaImplementation(local_auth.user + ':' + local_auth.key)
5657
options.headers = {Authorization: `Basic ${encoded}`}
57-
} else if (local_auth && local_auth.type == 'jwt') {
58+
} else if (local_auth && local_auth.type === 'jwt') {
5859
options.headers = {Authorization: `Bearer ${local_auth.key}`}
60+
} else if (local_auth && local_auth.type === 'cloud') {
61+
5962
}
6063
/*
6164
* pass the Authorization information of another
6265
* terminusdb server to the local terminusdb
6366
*/
64-
if (remote_auth && remote_auth.type == 'jwt') {
65-
if (!options.headers) options.headers = {}
67+
if (remote_auth && remote_auth.type == 'jwt') {
6668
options.headers['Authorization-Remote'] = `Bearer ${remote_auth.key}`
6769
} else if (remote_auth && remote_auth.type == 'basic') {
6870
let rencoded = btoaImplementation(remote_auth.user + ':' + remote_auth.key)
69-
if (!options.headers) options.headers = {}
7071
options.headers['Authorization-Remote'] = `Basic ${rencoded}`
7172
}
7273

73-
if (reqUID) {
74-
options.headers['ReqUID'] = reqUID
74+
if (customHeaders && typeof customHeaders === "object" ) {
75+
Object.keys(customHeaders).map((key) => {
76+
options.headers[key] = customHeaders[key]
77+
})
7578
}
7679
switch (action) {
77-
case CONST.DELETE_DATABASE:
78-
case CONST.DELETE_CSV:
79-
case CONST.DELETE_GRAPH:
80-
case CONST.DELETE_USER:
81-
case CONST.DELETE_BRANCH:
82-
case CONST.DELETE_ORGANIZATION:
80+
case CONST.DELETE:
8381
if (payload) {
8482
options.headers = options.headers ? options.headers : {}
8583
options.headers['Content-Type'] = 'application/json'
@@ -93,15 +91,7 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null, r
9391
if (err.response && err.response.data) e.data = err.response.data
9492
throw e
9593
})
96-
case CONST.GET_TRIPLES:
97-
case CONST.READ_USER:
98-
case CONST.READ_DATABASE:
99-
case CONST.READ_ORGANIZATION:
100-
case CONST.CONNECT:
101-
case CONST.GET_CSV:
102-
case CONST.MESSAGE:
103-
case CONST.INFO:
104-
case CONST.GET_ROLES:
94+
case CONST.GET:
10595
if (payload) {
10696
const ext = UTILS.URIEncodePayload(payload)
10797
if (ext) url += `?${ext}`
@@ -128,6 +118,17 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null, r
128118
if (err.response && err.response.data) e.data = err.response.data
129119
throw e
130120
})
121+
case CONST.PUT:
122+
options.headers = options.headers ? options.headers : {}
123+
options.headers['Content-Type'] = 'application/json'
124+
return axiosInstance
125+
.put(url, payload, options)
126+
.then(response => response.data)
127+
.catch(err => {
128+
const e = new Error(ErrorMessage.getAPIErrorMessage(url, options, err))
129+
if (err.response && err.response.data) e.data = err.response.data
130+
throw e
131+
})
131132
default:
132133
options.headers = options.headers ? options.headers : {}
133134
options.headers['Content-Type'] = 'application/json'

0 commit comments

Comments
 (0)