Skip to content

Commit 301ca43

Browse files
Adding options to diff endpoint
1 parent 57c3048 commit 301ca43

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/woqlClient.js

Lines changed: 12 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+
let 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,16 @@ 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+
let opt = (typeof options === 'undefined') ? {} : options
1520+
const payload = { document_id: id, before_data_version: beforeVersion, after, ...opt};
15181521
return this.dispatch(
15191522
CONST.POST,
15201523
this.connectionConfig.diffURL(),
@@ -1527,6 +1530,7 @@ WOQLClient.prototype.getVersionObjectDiff = function (id, beforeVersion, after)
15271530
* @param {string} id - The object id to be diffed
15281531
* @param {string} beforeVersion - The version from which to compare the object
15291532
* @param {string} afterVersion - The version to which to compare the object
1533+
* @param {object} options [{}] - Options to send to the diff endpoint
15301534
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
15311535
* @example
15321536
* const diff = await client.getVersionDiff(
@@ -1535,19 +1539,20 @@ WOQLClient.prototype.getVersionObjectDiff = function (id, beforeVersion, after)
15351539
* "branch:73rqpooz65kbsheuno5dsayh71x7wf4"
15361540
* );
15371541
*/
1538-
WOQLClient.prototype.getVersionDiff = function (id, beforeVersion, afterVersion) {
1542+
WOQLClient.prototype.getVersionDiff = function (id, beforeVersion, afterVersion, options) {
15391543
if (typeof id !== 'string' || typeof beforeVersion !== 'string' || typeof afterVersion !== 'string') {
15401544
const errmsg = '"id", "beforeVersion" or "after" parameter error - you must specify a valid after json document and valid id and version';
15411545

15421546
return Promise.reject(
15431547
new Error(ErrorMessage.getInvalidParameterMessage(CONST.GET_DIFF, errmsg)),
15441548
);
15451549
}
1546-
1550+
let opt = (typeof options === 'undefined') ? {} : options
15471551
const payload = {
15481552
document_id: id,
15491553
before_data_version: beforeVersion,
15501554
after_data_version: afterVersion,
1555+
...opt
15511556
};
15521557
return this.dispatch(
15531558
CONST.POST,

0 commit comments

Comments
 (0)