Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/api/woqlclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ async funtion callGetUserOrganizations(){
```

## getDiff
##### woqlClient.getDiff(before, after) ⇒ <code>Promise</code>
##### woqlClient.getDiff(before, after, options) ⇒ <code>Promise</code>
Get the patch of difference between two documents.

**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
Expand All @@ -1132,6 +1132,7 @@ Get the patch of difference between two documents.
| --- | --- | --- |
| before | <code>object</code> | The current state of JSON document |
| after | <code>object</code> | The updated state of JSON document |
| options | <code>object</code> | [{}] - Options to send to the diff endpoint |

**Example**
```javascript
Expand All @@ -1142,7 +1143,7 @@ const diff = await client.getDiff(
```

## getVersionObjectDiff
##### woqlClient.getVersionObjectDiff(id, beforeVersion, after) ⇒ <code>Promise</code>
##### woqlClient.getVersionObjectDiff(id, beforeVersion, after, options) ⇒ <code>Promise</code>
Get the patch of difference between two documents.

**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
Expand All @@ -1152,6 +1153,7 @@ Get the patch of difference between two documents.
| id | <code>string</code> | The object id to be diffed |
| beforeVersion | <code>string</code> | The version from which to compare the object |
| after | <code>object</code> | The updated state of JSON document |
| options | <code>object</code> | [{}] - Options to send to the diff endpoint |

**Example**
```javascript
Expand All @@ -1163,7 +1165,7 @@ const diff = await client.getVersionObjectDiff(
```

## getVersionDiff
##### woqlClient.getVersionDiff(id, beforeVersion, afterVersion) ⇒ <code>Promise</code>
##### woqlClient.getVersionDiff(id, beforeVersion, afterVersion, options) ⇒ <code>Promise</code>
Get the patch of difference between two documents.

**Returns**: <code>Promise</code> - A promise that returns the call response object, or an Error if rejected.
Expand All @@ -1173,6 +1175,7 @@ Get the patch of difference between two documents.
| id | <code>string</code> | The object id to be diffed |
| beforeVersion | <code>string</code> | The version from which to compare the object |
| afterVersion | <code>string</code> | The version to which to compare the object |
| options | <code>object</code> | [{}] - Options to send to the diff endpoint |

**Example**
```javascript
Expand Down
21 changes: 14 additions & 7 deletions lib/woqlClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1468,23 +1468,25 @@ WOQLClient.prototype.userOrganizations = function (orgList) {
* Get the patch of difference between two documents.
* @param {object} before - The current state of JSON document
* @param {object} after - The updated state of JSON document
* @param {object} options [{}] - Options to send to the diff endpoint
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
* @example
* const diff = await client.getDiff(
* { "@id": "Person/Jane", "@type": "Person", name: "Jane" },
* { "@id": "Person/Jane", "@type": "Person", name: "Janine" }
* );
*/
WOQLClient.prototype.getDiff = function (before, after) {
WOQLClient.prototype.getDiff = function (before, after, options) {
if (typeof before !== 'object' || typeof after !== 'object') {
const errmsg = '"before" or "after" parameter error - you must specify a valid before or after json document';

return Promise.reject(
new Error(ErrorMessage.getInvalidParameterMessage(CONST.GET_DIFF, errmsg)),
);
}
const opt = (typeof options === 'undefined') ? {} : options;
const payload = { before, after, ...opt };

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

return Promise.reject(
new Error(ErrorMessage.getInvalidParameterMessage(CONST.GET_DIFF, errmsg)),
);
}

const payload = { document_id: id, before_data_version: beforeVersion, after };
const opt = (typeof options === 'undefined') ? {} : options;
const payload = {
document_id: id, before_data_version: beforeVersion, after, ...opt,
};
return this.dispatch(
CONST.POST,
this.connectionConfig.diffURL(),
Expand All @@ -1527,6 +1532,7 @@ WOQLClient.prototype.getVersionObjectDiff = function (id, beforeVersion, after)
* @param {string} id - The object id to be diffed
* @param {string} beforeVersion - The version from which to compare the object
* @param {string} afterVersion - The version to which to compare the object
* @param {object} options [{}] - Options to send to the diff endpoint
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
* @example
* const diff = await client.getVersionDiff(
Expand All @@ -1535,19 +1541,20 @@ WOQLClient.prototype.getVersionObjectDiff = function (id, beforeVersion, after)
* "branch:73rqpooz65kbsheuno5dsayh71x7wf4"
* );
*/
WOQLClient.prototype.getVersionDiff = function (id, beforeVersion, afterVersion) {
WOQLClient.prototype.getVersionDiff = function (id, beforeVersion, afterVersion, options) {
if (typeof id !== 'string' || typeof beforeVersion !== 'string' || typeof afterVersion !== 'string') {
const errmsg = '"id", "beforeVersion" or "after" parameter error - you must specify a valid after json document and valid id and version';

return Promise.reject(
new Error(ErrorMessage.getInvalidParameterMessage(CONST.GET_DIFF, errmsg)),
);
}

const opt = (typeof options === 'undefined') ? {} : options;
const payload = {
document_id: id,
before_data_version: beforeVersion,
after_data_version: afterVersion,
...opt,
};
return this.dispatch(
CONST.POST,
Expand Down