@@ -1106,4 +1106,71 @@ WOQLClient.prototype.getBranches = function(dbId){
11061106 } )
11071107}
11081108
1109+ /**
1110+ * Get the patch of difference between two documents.
1111+ * @param {object } before - The current state of JSON document
1112+ * @param {object } after - The updated state of JSON document
1113+ * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
1114+ * @example
1115+ * const diff = await client.getDiff(
1116+ * { "@id ": "Person/Jane", "@type": "Person", name: "Jane" },
1117+ * { "@id ": "Person/Jane", "@type": "Person", name: "Janine" }
1118+ * );
1119+ */
1120+ WOQLClient . prototype . getDiff = function ( before , after ) {
1121+
1122+ if ( typeof before !== "object" || typeof after !== "object" ) {
1123+
1124+ const errmsg = `"before" or "after" parameter error - you must specify a valid before or after json document` ;
1125+
1126+ return Promise . reject (
1127+ new Error ( ErrorMessage . getInvalidParameterMessage ( CONST . GET_DIFF , errmsg ) ) ,
1128+ )
1129+ }
1130+
1131+ const payload = { before, after } ;
1132+ return this . dispatch (
1133+ CONST . POST ,
1134+ this . connectionConfig . apiURL ( ) + "diff" ,
1135+ payload
1136+ ) . then ( response => {
1137+ return response ;
1138+ } ) ;
1139+ } ;
1140+
1141+ /**
1142+ * Patch the difference between two documents.
1143+ * @param {object } before - The current state of JSON document
1144+ * @param {object } patch - The patch object
1145+ * @returns {Promise } A promise that returns the call response object, or an Error if rejected.
1146+ * @example
1147+ * let diffPatch = await client.getDiff(
1148+ * { "@id ": "Person/Jane", "@type": "Person", name: "Jane" },
1149+ * { "@id ": "Person/Jane", "@type": "Person", name: "Janine" }
1150+ * );
1151+ *
1152+ * let patch = await client.patch( { "@id ": "Person/Jane", "@type": "Person", name: "Jane" }, diffPatch);
1153+ */
1154+ WOQLClient . prototype . patch = function ( before , patch ) {
1155+
1156+ if ( typeof before !== "object" || typeof patch !== "object" ) {
1157+
1158+ const errmsg = `"before" or "patch" parameter error - you must specify a valid before or patch json document` ;
1159+
1160+ return Promise . reject (
1161+ new Error ( ErrorMessage . getInvalidParameterMessage ( CONST . PATCH , errmsg ) ) ,
1162+ )
1163+ }
1164+ const payload = { before, patch } ;
1165+
1166+ return this . dispatch (
1167+ CONST . POST ,
1168+ this . connectionConfig . apiURL ( ) + 'patch' ,
1169+ payload
1170+ ) . then ( response => {
1171+ return response
1172+ } )
1173+
1174+ }
1175+
11091176module . exports = WOQLClient
0 commit comments