Skip to content

Commit f3ccb85

Browse files
Type last (#250)
* fix fetch in javascript client#249 * Apply docs changes * review type Co-authored-by: Francesca-Bit <francesca@terminusdb.com> Co-authored-by: Francesca-Bit <Francesca-Bit@users.noreply.github.com>
1 parent 55d90a7 commit f3ccb85

File tree

7 files changed

+705
-346
lines changed

7 files changed

+705
-346
lines changed

docs/api/typedef.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ the DELETE document interface query parameters
146146
| --- | --- | --- |
147147
| label | <code>string</code> | "Textual DB Name" |
148148
| [comment] | <code>string</code> | "Text description of DB" |
149-
| [public] | <code>boolean</code> | |
149+
| [public] | <code>boolean</code> | - |
150150
| [schema] | <code>boolean</code> | if set to true, a schema graph will be created |
151151

152152

docs/api/woql.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,9 @@ WOQL.delete_quad("Person", "rdf:type", "sys:Class", "schema")
447447
```
448448

449449
## add_triple
450-
##### WOQL.add\_triple(subject, predicate, object) ⇒ <code>object</code>
450+
##### WOQL.add\_triple(subject, predicate, object) ⇒ <code>WOQLQuery</code>
451451
Adds triples according to the the pattern [subject,predicate,object]
452452

453-
**Returns**: <code>object</code> - WOQLQuery
454453

455454
| Param | Type | Description |
456455
| --- | --- | --- |
@@ -460,10 +459,9 @@ Adds triples according to the the pattern [subject,predicate,object]
460459

461460

462461
## add_quad
463-
##### WOQL.add\_quad(subject, predicate, object, graphRef-) ⇒ <code>object</code>
462+
##### WOQL.add\_quad(subject, predicate, object, graphRef-) ⇒ <code>WOQLQuery</code>
464463
Adds quads according to the pattern [S,P,O,G]
465464

466-
**Returns**: <code>object</code> - WOQLQuery
467465

468466
| Param | Type | Description |
469467
| --- | --- | --- |
@@ -1521,8 +1519,7 @@ Update a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Ob
15211519

15221520
## value
15231521
##### WOQL.value(subject, predicate, objValue) ⇒ <code>WOQLQuery</code>
1524-
Creates a pattern matching rule for a quad [Subject, Predicate, Object, Graph] or for a
1525-
triple [Subject, Predicate, Object]
1522+
Creates a pattern matching rule for a triple [Subject, Predicate, Object]
15261523
add extra information about the type of the value object
15271524

15281525
**Returns**: <code>WOQLQuery</code> - A WOQLQuery which contains the a quad or a triple Statement
@@ -1536,8 +1533,7 @@ add extra information about the type of the value object
15361533

15371534
## link
15381535
##### WOQL.link(subject, predicate, object) ⇒ <code>WOQLQuery</code>
1539-
Creates a pattern matching rule for a quad [Subject, Predicate, Object, Graph] or for a
1540-
triple [Subject, Predicate, Object]
1536+
Creates a pattern matching rule for a triple [Subject, Predicate, Object]
15411537

15421538
**Returns**: <code>WOQLQuery</code> - A WOQLQuery which contains the a quad or a triple Statement
15431539

lib/dispatchRequest.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ function formatAuthHeader(auth_obj) {
4646
return `${authType[auth_obj.type]} ${auth_key}`;
4747
}
4848

49+
function checkPayload(payload, options, compress) {
50+
if (!payload || typeof payload !== 'object') return false;
51+
const jsonStringPost = JSON.stringify(payload);
52+
if (jsonStringPost && jsonStringPost.length > 1024 && compress) {
53+
// eslint-disable-next-line no-param-reassign
54+
options.headers['Content-Encoding'] = 'gzip';
55+
return pako.gzip(jsonStringPost);
56+
}
57+
return false;
58+
}
59+
4960
/**
5061
* @file Dispatch Request
5162
* @license Apache Version 2
@@ -195,16 +206,11 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null, c
195206
// eslint-disable-next-line no-fallthrough
196207
}
197208
default: {
198-
let compressedContentPost = null;
199209
options.headers = options.headers ? options.headers : {};
200210
options.headers['Content-Type'] = 'application/json; charset=utf-8';
201-
const jsonStringPost = JSON.stringify(payload);
202-
if (jsonStringPost.length > 1024 && compress) {
203-
options.headers['Content-Encoding'] = 'gzip';
204-
compressedContentPost = pako.gzip(jsonStringPost);
205-
}
211+
const compressedContentPost = checkPayload(payload, options, compress);
206212
return axiosInstance
207-
.post(url, compressedContentPost || payload, options)
213+
.post(url, compressedContentPost || payload || {}, options)
208214
.then((response) => (getDataVersion ? getResultWithDataVersion(response) : response.data))
209215
.catch((err) => {
210216
throw ErrorMessage.apiErrorFormatted(url, options, err);

lib/query/woqlBuilder.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,9 @@ WOQLQuery.prototype.all = function (Subj, Pred, Obj, Graph) {
6363
return this.star(Graph, Subj, Pred, Obj);
6464
};
6565

66-
/* WOQLQuery.prototype.lib = function () {
67-
return new WOQLLibrary();
68-
}; */
69-
7066
/**
7167
* @param {string} s
7268
* @returns {object}
73-
* @example
7469
*/
7570

7671
WOQLQuery.prototype.string = function (s) {
@@ -80,7 +75,6 @@ WOQLQuery.prototype.string = function (s) {
8075
/**
8176
* @param {boolean} tf
8277
* @returns {object}
83-
* @example
8478
*/
8579

8680
WOQLQuery.prototype.boolean = function (tf) {
@@ -92,7 +86,6 @@ WOQLQuery.prototype.boolean = function (tf) {
9286
* @param {any} s
9387
* @param {string} t
9488
* @returns {object}
95-
* @example
9689
*/
9790
WOQLQuery.prototype.literal = function (s, t) {
9891
t = t.indexOf(':') === -1 ? `xsd:${t}` : t;
@@ -102,7 +95,6 @@ WOQLQuery.prototype.literal = function (s, t) {
10295
/**
10396
* @param {string} s
10497
* @returns {object}
105-
* @example
10698
*/
10799

108100
WOQLQuery.prototype.iri = function (s) {
@@ -162,13 +154,15 @@ WOQLQuery.prototype.update_quad = function (subject, predicate, new_object, grap
162154
};
163155

164156
/**
165-
* Removes all triples from a graph
166-
* @param {string} [g] - optional graph resource identifier
157+
* Deletes all triples in the passed graph (defaults to instance/main)
158+
* @param {typedef.GraphRef} [graphRef] - Resource String identifying the graph from
159+
* which all triples will be removed
160+
* @returns {WOQLQuery} - A WOQLQuery which contains the deletion expression
167161
*/
168162

169-
WOQLQuery.prototype.nuke = function (g) {
170-
if (g) {
171-
return this.quad('v:A', 'v:B', 'v:C', g).delete_quad('v:A', 'v:B', 'v:C', g);
163+
WOQLQuery.prototype.nuke = function (graphRef) {
164+
if (graphRef) {
165+
return this.quad('v:A', 'v:B', 'v:C', graphRef).delete_quad('v:A', 'v:B', 'v:C', graphRef);
172166
}
173167
return this.triple('v:A', 'v:B', 'v:C').delete_triple('v:A', 'v:B', 'v:C');
174168
};
@@ -198,12 +192,13 @@ WOQLQuery.prototype.node = function (node, type) {
198192
return this;
199193
};
200194

195+
// do not remove
201196
/**
202-
* set the graph type schema or instance
203-
* for the query we point at the instance graph so you use this only
204-
* if you would like to query the schema graph
197+
* Sets the graph resource ID that will be used for subsequent chained function calls
198+
* @param {typedef.GraphRef} [graphRef] Resource String identifying the graph which will
199+
* be used for subsequent chained schema calls
200+
* @returns {WOQLQuery} A WOQLQuery which contains the partial Graph pattern matching expression
205201
*/
206-
// do not remove
207202
WOQLQuery.prototype.graph = function (g) {
208203
return this._set_context({
209204
graph: g,

0 commit comments

Comments
 (0)