Skip to content

Commit b01bdc9

Browse files
Merge pull request #269 from terminusdb/fix_integration
fix issues #267 #260 #87 add patchResource and review typescript types generation
2 parents 8a7259a + e68f8ec commit b01bdc9

File tree

9 files changed

+306
-80
lines changed

9 files changed

+306
-80
lines changed

docs/api/woql.md

-6
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,6 @@ Use the document inteface to import documents
351351
| query | <code>WOQLQuery</code> | The query which will be executed to produce the results |
352352
| fileResource | <code>string</code> | an file resource local to the server |
353353

354-
**Example**
355-
```javascript
356-
let [s, p, o] = vars("Subject", "Predicate", "Object")
357-
WOQL.put(WOQL.as("s", s).as("p", p).as("o", o), WOQL.all())
358-
.file({file:"/app/local_files/dump.csv"})
359-
```
360354

361355
## as
362356
##### WOQL.as(source, target, [type]) ⇒ <code>WOQLQuery</code>

docs/api/woqlclient.md

+96-23
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,28 @@ const json = [{ "@type" : "Class",
744744
"name" : "xsd:string",
745745
"perimeter" : { "@type" : "List",
746746
"@class" : "Coordinate" } }]
747-
client.addDocument(json,{"graph_type":"schema"},"mydb","add new schema")
747+
client.addDocument(json,{"graph_type":"schema"},"mydb","add new schema documents")
748+
749+
//if we would like to override the entire schema
750+
const json = [
751+
{"@base": "terminusdb:///data/",
752+
"@schema": "terminusdb:///schema#",
753+
"@type": "@context"
754+
},
755+
{
756+
"@id": "Person",
757+
"@key": {
758+
"@type": "Random"
759+
},
760+
"@type": "Class",
761+
"name": {
762+
"@class": "xsd:string",
763+
"@type": "Optional"
764+
}
765+
}]
748766

767+
// client.addDocument(json,{"graph_type":"schema","full_replace:true"},
768+
"mydb","update the all schema");
749769

750770
// Here we will pass true to show how to get dataVersion
751771

@@ -1184,6 +1204,81 @@ async funtion callGetUserOrganizations(){
11841204
}
11851205
```
11861206
1207+
## patch
1208+
##### woqlClient.patch(before, patch) ⇒ <code>Promise</code>
1209+
Apply a patch object to another object
1210+
1211+
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
1212+
1213+
| Param | Type | Description |
1214+
| --- | --- | --- |
1215+
| before | <code>object</code> | The current state of JSON document |
1216+
| patch | <code>object</code> | The patch object |
1217+
1218+
**Example**
1219+
```javascript
1220+
client.patch(
1221+
{ "@id" : "Person/Jane", "@type" : "Person", "name" : "Jane"},
1222+
{ "name" : { "@op" : "ValueSwap", "@before" : "Jane", "@after": "Janine" }}
1223+
).then(patchResult=>{
1224+
console.log(patchResult)
1225+
})
1226+
//result example
1227+
//{ "@id" : "Person/Jane", "@type" : "Person", "name" : "Jannet"}
1228+
```
1229+
1230+
## patchResource
1231+
##### woqlClient.patchResource(patch, message) ⇒ <code>Promise</code>
1232+
Apply a patch object to the current resource
1233+
1234+
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
1235+
1236+
| Param | Type | Description |
1237+
| --- | --- | --- |
1238+
| patch | <code>array</code> | The patch object |
1239+
| message | <code>string</code> | The commit message |
1240+
1241+
**Example**
1242+
```javascript
1243+
const patch = [
1244+
{
1245+
"@id": "Obj/id1",
1246+
"name": {
1247+
"@op": "SwapValue",
1248+
"@before": "foo",
1249+
"@after": "bar"
1250+
}
1251+
},
1252+
{
1253+
"@id": "Obj/id2",
1254+
"name": {
1255+
"@op": "SwapValue",
1256+
"@before": "foo",
1257+
"@after": "bar"
1258+
}
1259+
}
1260+
]
1261+
client.db("mydb")
1262+
client.checkout("mybranch")
1263+
client.patchResource(patch,"apply patch to mybranch").then(patchResult=>{
1264+
console.log(patchResult)
1265+
})
1266+
// result example
1267+
// ["Obj/id1",
1268+
// "Obj/id2"]
1269+
// or conflict error 409
1270+
// {
1271+
// "@type": "api:PatchError",
1272+
// "api:status": "api:conflict",
1273+
// "api:witnesses": [
1274+
// {
1275+
// "@op": "InsertConflict",
1276+
// "@id_already_exists": "Person/Jane"
1277+
// }
1278+
//]
1279+
//}
1280+
```
1281+
11871282
## getJSONDiff
11881283
##### woqlClient.getJSONDiff(before, after, [options]) ⇒ <code>Promise</code>
11891284
Get the patch of difference between two documents.
@@ -1293,28 +1388,6 @@ client.apply("main","mybranch","merge main").then(result=>{
12931388
})
12941389
```
12951390
1296-
## patch
1297-
##### woqlClient.patch(before, patch) ⇒ <code>Promise</code>
1298-
Patch the difference between two documents.
1299-
1300-
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
1301-
1302-
| Param | Type | Description |
1303-
| --- | --- | --- |
1304-
| before | <code>object</code> | The current state of JSON document |
1305-
| patch | <code>object</code> | The patch object |
1306-
1307-
**Example**
1308-
```javascript
1309-
let diffPatch = await client.getJSONDiff(
1310-
{ "@id": "Person/Jane", "@type": "Person", name: "Jane" },
1311-
{ "@id": "Person/Jane", "@type": "Person", name: "Janine" }
1312-
);
1313-
1314-
let patch = await client.patch( { "@id": "Person/Jane", "@type": "Person", name: "Jane" },
1315-
diffPatch);
1316-
```
1317-
13181391
## sendCustomRequest
13191392
##### woqlClient.sendCustomRequest(requestType, customRequestURL, [payload]) ⇒ <code>Promise</code>
13201393
Call a custom Api endpoit

lib/connectionConfig.js

+9
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,15 @@ ConnectionConfig.prototype.pullURL = function () {
513513
return purl;
514514
};
515515

516+
/**
517+
* Generate URL for pull endpoint
518+
* @returns {string}
519+
*/
520+
ConnectionConfig.prototype.patchURL = function () {
521+
const purl = this.branchBase('patch');
522+
return purl;
523+
};
524+
516525
/**
517526
* Generate URL for diff endpoint
518527
* @returns {string}

lib/dispatchRequest.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null, c
172172
}
173173
return axiosInstance
174174
.get(url, options)
175-
.then((response) => (getDataVersion ? getResultWithDataVersion(response) : response.data))
175+
.then((response) => {
176+
const r = getDataVersion ? getResultWithDataVersion(response) : response.data;
177+
return r;
178+
})
176179
.catch((err) => {
177180
throw ErrorMessage.apiErrorFormatted(url, options, err);
178181
});
@@ -216,7 +219,10 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null, c
216219
const compressedContentPost = checkPayload(payload, options, compress);
217220
return axiosInstance
218221
.post(url, compressedContentPost || payload || {}, options)
219-
.then((response) => (getDataVersion ? getResultWithDataVersion(response) : response.data))
222+
.then((response) => {
223+
const r = getDataVersion ? getResultWithDataVersion(response) : response.data;
224+
return r;
225+
})
220226
.catch((err) => {
221227
throw ErrorMessage.apiErrorFormatted(url, options, err);
222228
});

lib/query/woqlQuery.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -786,16 +786,6 @@ WOQLQuery.prototype.as = function (...varList) {
786786
return this;
787787
};
788788

789-
/* WOQLQuery.prototype.file = function (fpath, opts) {
790-
// if (fpath && fpath == 'args') return ['file', 'format']
791-
if (this.cursor['@type']) this.wrapCursorWithAnd();
792-
this.cursor['@type'] = 'QueryResource';
793-
this.cursor.source = { '@type': 'Source', file: fpath };
794-
this.cursor.format = 'csv'; // hard coded for now
795-
if (typeof opts !== 'undefined') this.cursor.options = opts;
796-
return this;
797-
}; */
798-
799789
/**
800790
* Identifies a remote resource by URL and specifies the format of the resource through the options
801791
* @param {object} remoteObj - The URL at which the remote resource can be accessed
@@ -1505,7 +1495,7 @@ WOQLQuery.prototype.order_by = function (...orderedVarlist) {
15051495

15061496
for (let i = 0; i < orderedVarlist.length; i++) {
15071497
let obj;
1508-
if (typeof orderedVarlist[i] === 'string' && orderedVarlist[i] !== '') {
1498+
if ((typeof orderedVarlist[i] === 'string' || orderedVarlist[i] instanceof Var) && orderedVarlist[i] !== '') {
15091499
obj = {
15101500
'@type': 'OrderTemplate',
15111501
variable: this.rawVar(orderedVarlist[i]),
@@ -1548,9 +1538,9 @@ WOQLQuery.prototype.group_by = function (gvarlist, groupedvar, output, groupquer
15481538
this.cursor['@type'] = 'GroupBy';
15491539
this.cursor.group_by = [];
15501540

1551-
if (typeof gvarlist === 'string') gvarlist = [gvarlist];
1541+
if (typeof gvarlist === 'string' || gvarlist instanceof Var) gvarlist = [gvarlist];
15521542
this.cursor.group_by = this.rawVarList(gvarlist);
1553-
if (typeof groupedvar === 'string') groupedvar = [groupedvar];
1543+
if (typeof groupedvar === 'string' || groupedvar instanceof Var) groupedvar = [groupedvar];
15541544
this.cursor.template = this.rawVarList(groupedvar);
15551545
this.cursor.grouped = this.varj(output);
15561546
return this.addSubQuery(groupquery);

lib/woql.js

-4
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,6 @@ WOQL.get = function (asvars, queryResource) {
353353
* @param {WOQLQuery} query - The query which will be executed to produce the results
354354
* @param {string} fileResource - an file resource local to the server
355355
* @returns {WOQLQuery} A WOQLQuery which contains the put expression
356-
* @example
357-
* let [s, p, o] = vars("Subject", "Predicate", "Object")
358-
* WOQL.put(WOQL.as("s", s).as("p", p).as("o", o), WOQL.all())
359-
* .file({file:"/app/local_files/dump.csv"})
360356
*/
361357
WOQL.put = function (varsToExp, query, fileResource) {
362358
return new WOQLQuery().put(varsToExp, query, fileResource);

0 commit comments

Comments
 (0)