Skip to content

Commit 418b7d2

Browse files
committed
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents 88538d7 + 62be8a1 commit 418b7d2

File tree

10 files changed

+262
-70
lines changed

10 files changed

+262
-70
lines changed

lib/const.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ module.exports = Object.freeze({
3939
UPDATE_CSV: 'update_csv',
4040
DELETE_CSV: 'delete_csv',
4141
MESSAGE: 'message',
42+
ACTION: 'action',
4243
INFO: 'info'
4344
})

lib/dispatchRequest.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
8686
case CONST.READ_ORGANIZATION:
8787
case CONST.CONNECT:
8888
case CONST.GET_CSV:
89+
case CONST.MESSAGE:
8990
case CONST.INFO:
9091
if (payload) {
9192
const ext = UTILS.URIEncodePayload(payload)
@@ -101,35 +102,10 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null) {
101102
}
102103
throw e
103104
})
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-
})
119105
case CONST.ADD_CSV:
120-
options.headers = options.headers ? options.headers : {}
121-
options.headers['Content-Type'] = 'application/form-data'
122-
return axiosInstance
123-
.put(url, payload, options)
124-
.then(response => response.data)
125-
.catch(err => {
126-
const e = new Error(ErrorMessage.getAPIErrorMessage(url, options, err))
127-
if (err.response && err.response.data) e.data = err.response.data
128-
throw e
129-
})
130106
case CONST.INSERT_TRIPLES:
131107
options.headers = options.headers ? options.headers : {}
132-
options.headers['Content-Type'] = 'application/json'
108+
options.headers['Content-Type'] = 'application/form-data'
133109
return axiosInstance
134110
.put(url, payload, options)
135111
.then(response => response.data)

lib/query/woqlBuilder.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ WOQLQuery.prototype.iri = function(s) {
5151
}
5252
}
5353

54-
WOQLQuery.prototype.update_triple = function(subject, predicate, new_object) {
54+
WOQLQuery.prototype.update_triple = function(subject, predicate, new_object, old_object) {
55+
old_object = old_object || "v:AnyObject"
5556
return this.and(
5657
new WOQLQuery().opt(
57-
new WOQLQuery().triple(subject, predicate, "v:AnyObject")
58-
.delete_triple(subject, predicate, "v:AnyObject")
58+
new WOQLQuery().triple(subject, predicate, old_object)
59+
.delete_triple(subject, predicate, old_object)
5960
.not().triple(subject, predicate, new_object)
6061
),
6162
new WOQLQuery().add_triple(subject, predicate, new_object)

lib/query/woqlCore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ WOQLQuery.prototype.cleanPredicate = function(p) {
262262
return this.expandVariable(pred)
263263
}
264264

265-
WOQLQuery.prototype.wellKnownPredicate = function(p) {
265+
WOQLQuery.prototype.wellKnownPredicate = function(p, noxsd) {
266266
if (this.vocab && this.vocab[p]){
267267
let full = this.vocab[p]
268268
let start = full.substring(0, 3)

lib/utils.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ Utils.compareIDs = function(ida, idb) {
115115
return false
116116
}
117117

118+
119+
118120
/**
119121
* Shortens a URL to its compressed format - returns the full URL if not possible
120122
*/
@@ -145,6 +147,68 @@ Utils.unshorten = function(url) {
145147
return url
146148
}
147149

150+
151+
/* shortens a jsonld document to its prefixed form */
152+
Utils.json_shorten = function(jsonld, prefixes) {
153+
const shorten_json_val = (val, prefixes) => {
154+
if(Array.isArray(val)){
155+
let nvals = []
156+
for(var i = 0; i<val.length; i++){
157+
nvals.push(shorten_json_val(val[i], prefixes))
158+
}
159+
return nvals
160+
}
161+
else if(typeof val == "object"){
162+
return this.json_shorten(val, prefixes)
163+
}
164+
else if(typeof val == "string"){
165+
return this.shorten(val, prefixes)
166+
}
167+
else {
168+
return val
169+
}
170+
}
171+
prefixes = prefixes || jsonld["@context"]
172+
let nujson = {}
173+
for(var key in jsonld){
174+
let nkey = (key[0] == "@" ? key : this.shorten(key, prefixes))
175+
let nval = shorten_json_val(jsonld[key], prefixes)
176+
nujson[nkey] = nval
177+
}
178+
return nujson
179+
}
180+
181+
/* Unshortens a jsonld document to its full form */
182+
Utils.json_unshorten = function(jsonld, prefixes) {
183+
const unshorten_json_val = (val, prefixes) => {
184+
if(Array.isArray(val)){
185+
let nvals = []
186+
for(var i = 0; i<val.length; i++){
187+
nvals.push(unshorten_json_val(val[i], prefixes))
188+
}
189+
return nvals
190+
}
191+
else if(typeof val == "object"){
192+
return this.json_unshorten(val, prefixes)
193+
}
194+
else if(typeof val == "string"){
195+
return this.unshorten(val, prefixes)
196+
}
197+
else {
198+
return val
199+
}
200+
}
201+
prefixes = prefixes || jsonld["@context"]
202+
let nujson = {}
203+
for(var key in jsonld){
204+
let nkey = (key[0] == "@" ? key : this.unshorten(key, prefixes))
205+
let nval = unshorten_json_val(jsonld[key], prefixes)
206+
nujson[nkey] = nval
207+
}
208+
return nujson
209+
}
210+
211+
148212
/**
149213
* Tests a string to see if it is a valid URL -
150214
* Valid URLs are those that start with http:// or https://

lib/viewer/documentFrame.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const ObjectFrame = require("./objectFrame");
22
const FrameConfig = require("./frameConfig");
33
const FrameHelper = require("../utils");
4+
const WOQL = require("../woql");
45

56
/**
67
* @file Document Frame

lib/viewer/frameRule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ FramePattern.prototype.getRendererType = function (frame) {
502502
if (frame.isObject()) return 'object';
503503
if (frame.isData()) return 'data';
504504
if (frame.renderer_type) return frame.renderer_type;
505-
console.log(new Error(`frame configuration passed non-renderer type ${frame.constructor.name}`));
505+
console.log(frame, new Error(`frame configuration passed non-renderer type ${frame.constructor.name}`));
506506
return false;
507507
};
508508

0 commit comments

Comments
 (0)