Skip to content

Commit 4229d93

Browse files
Merge pull request #192 from terminusdb/diff_options
Adding options to diff endpoint
2 parents 3b374b6 + a442e84 commit 4229d93

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

docs/api/woqlclient.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ async funtion callGetUserOrganizations(){
11231123
```
11241124
11251125
## getDiff
1126-
##### woqlClient.getDiff(before, after) ⇒ <code>Promise</code>
1126+
##### woqlClient.getDiff(before, after, options) ⇒ <code>Promise</code>
11271127
Get the patch of difference between two documents.
11281128
11291129
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
@@ -1132,6 +1132,7 @@ Get the patch of difference between two documents.
11321132
| --- | --- | --- |
11331133
| before | <code>object</code> | The current state of JSON document |
11341134
| after | <code>object</code> | The updated state of JSON document |
1135+
| options | <code>object</code> | [{}] - Options to send to the diff endpoint |
11351136
11361137
**Example**
11371138
```javascript
@@ -1142,7 +1143,7 @@ const diff = await client.getDiff(
11421143
```
11431144
11441145
## getVersionObjectDiff
1145-
##### woqlClient.getVersionObjectDiff(id, beforeVersion, after) ⇒ <code>Promise</code>
1146+
##### woqlClient.getVersionObjectDiff(id, beforeVersion, after, options) ⇒ <code>Promise</code>
11461147
Get the patch of difference between two documents.
11471148
11481149
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
@@ -1152,6 +1153,7 @@ Get the patch of difference between two documents.
11521153
| id | <code>string</code> | The object id to be diffed |
11531154
| beforeVersion | <code>string</code> | The version from which to compare the object |
11541155
| after | <code>object</code> | The updated state of JSON document |
1156+
| options | <code>object</code> | [{}] - Options to send to the diff endpoint |
11551157
11561158
**Example**
11571159
```javascript
@@ -1163,7 +1165,7 @@ const diff = await client.getVersionObjectDiff(
11631165
```
11641166
11651167
## getVersionDiff
1166-
##### woqlClient.getVersionDiff(id, beforeVersion, afterVersion) ⇒ <code>Promise</code>
1168+
##### woqlClient.getVersionDiff(id, beforeVersion, afterVersion, options) ⇒ <code>Promise</code>
11671169
Get the patch of difference between two documents.
11681170
11691171
**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
@@ -1173,6 +1175,7 @@ Get the patch of difference between two documents.
11731175
| id | <code>string</code> | The object id to be diffed |
11741176
| beforeVersion | <code>string</code> | The version from which to compare the object |
11751177
| afterVersion | <code>string</code> | The version to which to compare the object |
1178+
| options | <code>object</code> | [{}] - Options to send to the diff endpoint |
11761179
11771180
**Example**
11781181
```javascript

lib/woqlClient.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,23 +1468,25 @@ WOQLClient.prototype.userOrganizations = function (orgList) {
14681468
* Get the patch of difference between two documents.
14691469
* @param {object} before - The current state of JSON document
14701470
* @param {object} after - The updated state of JSON document
1471+
* @param {object} options [{}] - Options to send to the diff endpoint
14711472
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
14721473
* @example
14731474
* const diff = await client.getDiff(
14741475
* { "@id": "Person/Jane", "@type": "Person", name: "Jane" },
14751476
* { "@id": "Person/Jane", "@type": "Person", name: "Janine" }
14761477
* );
14771478
*/
1478-
WOQLClient.prototype.getDiff = function (before, after) {
1479+
WOQLClient.prototype.getDiff = function (before, after, options) {
14791480
if (typeof before !== 'object' || typeof after !== 'object') {
14801481
const errmsg = '"before" or "after" parameter error - you must specify a valid before or after json document';
14811482

14821483
return Promise.reject(
14831484
new Error(ErrorMessage.getInvalidParameterMessage(CONST.GET_DIFF, errmsg)),
14841485
);
14851486
}
1487+
const opt = (typeof options === 'undefined') ? {} : options;
1488+
const payload = { before, after, ...opt };
14861489

1487-
const payload = { before, after };
14881490
return this.dispatch(
14891491
CONST.POST,
14901492
`${this.connectionConfig.apiURL()}diff`,
@@ -1497,6 +1499,7 @@ WOQLClient.prototype.getDiff = function (before, after) {
14971499
* @param {string} id - The object id to be diffed
14981500
* @param {string} beforeVersion - The version from which to compare the object
14991501
* @param {object} after - The updated state of JSON document
1502+
* @param {object} options [{}] - Options to send to the diff endpoint
15001503
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
15011504
* @example
15021505
* const diff = await client.getVersionObjectDiff(
@@ -1505,16 +1508,18 @@ WOQLClient.prototype.getDiff = function (before, after) {
15051508
* { "@id": "Person/Jane", "@type": "Person", name: "Janine" }
15061509
* );
15071510
*/
1508-
WOQLClient.prototype.getVersionObjectDiff = function (id, beforeVersion, after) {
1511+
WOQLClient.prototype.getVersionObjectDiff = function (id, beforeVersion, after, options) {
15091512
if (typeof id !== 'string' || typeof beforeVersion !== 'string' || typeof after !== 'object') {
15101513
const errmsg = '"id", "beforeVersion" or "after" parameter error - you must specify a valid after json document and valid id and version';
15111514

15121515
return Promise.reject(
15131516
new Error(ErrorMessage.getInvalidParameterMessage(CONST.GET_DIFF, errmsg)),
15141517
);
15151518
}
1516-
1517-
const payload = { document_id: id, before_data_version: beforeVersion, after };
1519+
const opt = (typeof options === 'undefined') ? {} : options;
1520+
const payload = {
1521+
document_id: id, before_data_version: beforeVersion, after, ...opt,
1522+
};
15181523
return this.dispatch(
15191524
CONST.POST,
15201525
this.connectionConfig.diffURL(),
@@ -1527,6 +1532,7 @@ WOQLClient.prototype.getVersionObjectDiff = function (id, beforeVersion, after)
15271532
* @param {string} id - The object id to be diffed
15281533
* @param {string} beforeVersion - The version from which to compare the object
15291534
* @param {string} afterVersion - The version to which to compare the object
1535+
* @param {object} options [{}] - Options to send to the diff endpoint
15301536
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
15311537
* @example
15321538
* const diff = await client.getVersionDiff(
@@ -1535,19 +1541,20 @@ WOQLClient.prototype.getVersionObjectDiff = function (id, beforeVersion, after)
15351541
* "branch:73rqpooz65kbsheuno5dsayh71x7wf4"
15361542
* );
15371543
*/
1538-
WOQLClient.prototype.getVersionDiff = function (id, beforeVersion, afterVersion) {
1544+
WOQLClient.prototype.getVersionDiff = function (id, beforeVersion, afterVersion, options) {
15391545
if (typeof id !== 'string' || typeof beforeVersion !== 'string' || typeof afterVersion !== 'string') {
15401546
const errmsg = '"id", "beforeVersion" or "after" parameter error - you must specify a valid after json document and valid id and version';
15411547

15421548
return Promise.reject(
15431549
new Error(ErrorMessage.getInvalidParameterMessage(CONST.GET_DIFF, errmsg)),
15441550
);
15451551
}
1546-
1552+
const opt = (typeof options === 'undefined') ? {} : options;
15471553
const payload = {
15481554
document_id: id,
15491555
before_data_version: beforeVersion,
15501556
after_data_version: afterVersion,
1557+
...opt,
15511558
};
15521559
return this.dispatch(
15531560
CONST.POST,

0 commit comments

Comments
 (0)