Skip to content

Commit 2b8e84f

Browse files
Adding version stuff
1 parent 10d51fe commit 2b8e84f

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

lib/woqlClient.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,67 @@ WOQLClient.prototype.getDiff = function (before, after) {
14751475
).then((response) => response);
14761476
};
14771477

1478+
1479+
/**
1480+
* Get the patch of difference between two documents.
1481+
* @param {string} id - The object id to be diffed
1482+
* @param {string} beforeVersion - The version from which to compare the object
1483+
* @param {object} after - The updated state of JSON document
1484+
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
1485+
* @example
1486+
* const diff = await client.getVersionObjectDiff(
1487+
* "Person/Jane",
1488+
* "branch:a73ssscfx0kke7z76083cgswszdxy6l",
1489+
* { "@id": "Person/Jane", "@type": "Person", name: "Janine" }
1490+
* );
1491+
*/
1492+
WOQLClient.prototype.getVersionObjectDiff = function (id, beforeVersion, after) {
1493+
if (typeof id !== 'string' || typeof beforeVersion !== 'string' || typeof after !== 'object') {
1494+
const errmsg = '"id", "beforeVersion" or "after" parameter error - you must specify a valid after json document and valid id and version';
1495+
1496+
return Promise.reject(
1497+
new Error(ErrorMessage.getInvalidParameterMessage(CONST.GET_DIFF, errmsg)),
1498+
);
1499+
}
1500+
1501+
const payload = { document_id : id, before_data_version : beforeVersion, after: after};
1502+
return this.dispatch(
1503+
CONST.POST,
1504+
this.branchBase('diff'),
1505+
payload,
1506+
).then((response) => response);
1507+
};
1508+
1509+
/**
1510+
* Get the patch of difference between two documents.
1511+
* @param {string} id - The object id to be diffed
1512+
* @param {string} beforeVersion - The version from which to compare the object
1513+
* @param {object} afterVersion - The version to which to compare the object
1514+
* @returns {Promise} A promise that returns the call response object, or an Error if rejected.
1515+
* @example
1516+
* const diff = await client.getVersionDiff(
1517+
* "Person/Jane",
1518+
* "branch:a73ssscfx0kke7z76083cgswszdxy6l",
1519+
* "branch:73rqpooz65kbsheuno5dsayh71x7wf4"
1520+
* );
1521+
*/
1522+
WOQLClient.prototype.getVersionDiff = function (id, beforeVersion, afterVersion) {
1523+
if (typeof id !== 'string' || typeof beforeVersion !== 'string' || typeof afterVersion !== 'string') {
1524+
const errmsg = '"id", "beforeVersion" or "after" parameter error - you must specify a valid after json document and valid id and version';
1525+
1526+
return Promise.reject(
1527+
new Error(ErrorMessage.getInvalidParameterMessage(CONST.GET_DIFF, errmsg)),
1528+
);
1529+
}
1530+
1531+
const payload = { document_id : id, before_data_version : beforeVersion, after_data_version: afterVersion};
1532+
return this.dispatch(
1533+
CONST.POST,
1534+
this.branchBase('diff'),
1535+
payload,
1536+
).then((response) => response);
1537+
};
1538+
14781539
/**
14791540
* Patch the difference between two documents.
14801541
* @param {object} before - The current state of JSON document

0 commit comments

Comments
 (0)