const jsondiffpatch = require("jsondiffpatch").create({
// used to match objects when diffing arrays, by default only === operator is used
objectHash: function(obj) {
// this function is used only to when objects are not equal by ref
return obj._id || obj.id || obj.componentKey;
},
// arrays: {
// // default true, detect items moved inside the array (otherwise they will be registered as remove+add)
// detectMove: true,
// // default false, the value of items moved is not included in deltas
// includeValueOnMove: false
// },
textDiff: {
// default 60, minimum string length (left and right sides) to use text diff algorythm: google-diff-match-patch
minLength: Infinity
},
propertyFilter: function(name, context) {
/*
this optional function can be specified to ignore object properties (eg. volatile data)
name: property name, present in either context.left or context.right objects
context: the diff context (has context.left and context.right objects)
*/
return name.slice(0, 1) !== '#x27; && name !== 'revision' && name != 'auditDetails';
}
});
const jsondiffpatchformatters = require("jsondiffpatch");
const before = {
"id": "702a4b04-5c82-43db-a898-8e141eb70426",
"componentType": "Project",
"locale": "fr-BE",
"revision": 12,
"derivedFrom": {},
"annotations": [],
"containedComponents": [
{
"id": "f31f8603-ddf2-4566-a3d6-d6b40c26aaf3",
"componentId": "c57371f0-0695-4053-ade1-75bbe9e8bbea",
"revision": 2,
"componentType": "MetadataDefinition"
},
{
"id": "321fc1ee-9efe-439f-804d-8f7444a6b507",
"componentId": "f8d3adf7-53e9-4fae-afa7-5eafcd99e740",
"revision": 7,
"componentType": "MetadataDefinition"
},
{
"id": "c6668178-34df-48c8-9dcd-4423e9034caa",
"componentId": "c01c8a24-a981-41df-aa05-bfdfd6625a94",
"revision": 9,
"componentType": "MetadataDefinition"
},
{
"id": "3c9b001d-653c-419e-bb93-c11e795147d6",
"componentId": "e32b5107-6c63-43f4-b023-262a01b8df34",
"revision": 2,
"componentType": "MetadataDefinition"
},
{
"id": "c609785a-9eea-4731-b536-8976f273b512",
"componentId": "6ad6a184-4e32-4222-87ee-47f723d0e240",
"revision": 1,
"componentType": "MetadataDefinition"
},
{
"id": "template-d0e108b0-1c68-4c0c-a9b6-83b7662208d6",
"componentId": "d0e108b0-1c68-4c0c-a9b6-83b7662208d6",
"componentType": "Project"
}
],
"propertyMappings": {},
"auditDetails": {
"createdOn": "2021-07-05T23:48:10.914Z",
"createdByUserId": "9f66d112-bd94-43b7-a03d-d47a950357fd",
"modifiedOn": "2021-07-05T23:49:28.443Z",
"modifiedByUserId": "9f66d112-bd94-43b7-a03d-d47a950357fd"
},
"workspaceId": "00000000-0000-0000-0000-000000000000",
"content": {
"title": "Thilina section diff",
"isTemplate": false,
"basedOn": "template-d0e108b0-1c68-4c0c-a9b6-83b7662208d6",
"sections": [
{
"id": "82a8e0a9-cbc9-4a1c-91c6-56aded1e5d12",
"title": "Section 1",
"description": "Zewpev sitez moahura jom ejuwiled zu megevazib dfdfdf dfdfdfdf fdfdfdfdfdfdf dfdfd fdfdfdfdf dfdfdf dfdfdf dfdfdfdfdfdfd",
"content": [],
"subsections": [
{
"id": "382d4e8f-99ab-4038-b811-73eb05a81252",
"title": "section 1.1",
"content": [
"569743f6-f50b-4175-aae5-f81023c36dea"],
"subsections": []
},
{
"id": "bad1f8cc-5188-4a06-a03c-3b7a29afc30e",
"title": "section 1.2",
"content": [],
"subsections": []
},
{
"id": "464c2db4-c625-4c0b-80c8-750aff1fe9af",
"title": "section 1.3",
"content": [],
"subsections": []
}
]
}
],
"metadataSettings": [
{
"componentKey": "c609785a-9eea-4731-b536-8976f273b512",
"isRequired": true,
"value": "1"
},
{
"componentKey": "f31f8603-ddf2-4566-a3d6-d6b40c26aaf3",
"isRequired": false
},
{
"componentKey": "321fc1ee-9efe-439f-804d-8f7444a6b507",
"isRequired": false
},
{
"componentKey": "c6668178-34df-48c8-9dcd-4423e9034caa",
"isRequired": false
},
{
"componentKey": "3c9b001d-653c-419e-bb93-c11e795147d6",
"isRequired": true,
"value": "2"
}
],
"stylesheets": {}
}
};
const after = {
"id": "702a4b04-5c82-43db-a898-8e141eb70426",
"componentType": "Project",
"locale": "fr-BE",
"revision": 16,
"derivedFrom": {},
"annotations": [],
"containedComponents": [
{
"id": "f31f8603-ddf2-4566-a3d6-d6b40c26aaf3",
"componentId": "c57371f0-0695-4053-ade1-75bbe9e8bbea",
"revision": 2,
"componentType": "MetadataDefinition"
},
{
"id": "321fc1ee-9efe-439f-804d-8f7444a6b507",
"componentId": "f8d3adf7-53e9-4fae-afa7-5eafcd99e740",
"revision": 7,
"componentType": "MetadataDefinition"
},
{
"id": "c6668178-34df-48c8-9dcd-4423e9034caa",
"componentId": "c01c8a24-a981-41df-aa05-bfdfd6625a94",
"revision": 9,
"componentType": "MetadataDefinition"
},
{
"id": "3c9b001d-653c-419e-bb93-c11e795147d6",
"componentId": "e32b5107-6c63-43f4-b023-262a01b8df34",
"revision": 2,
"componentType": "MetadataDefinition"
},
{
"id": "c609785a-9eea-4731-b536-8976f273b512",
"componentId": "6ad6a184-4e32-4222-87ee-47f723d0e240",
"revision": 1,
"componentType": "MetadataDefinition"
},
{
"id": "template-d0e108b0-1c68-4c0c-a9b6-83b7662208d6",
"componentId": "d0e108b0-1c68-4c0c-a9b6-83b7662208d6",
"componentType": "Project"
},
{
"id": "569743f6-f50b-4175-aae5-f81023c36dea",
"componentId": "00afe928-fa9c-45ea-b801-6c22506cf093",
"componentType": "Topic"
}
],
"propertyMappings": {},
"auditDetails": {
"createdOn": "2021-07-05T23:48:10.914Z",
"createdByUserId": "9f66d112-bd94-43b7-a03d-d47a950357fd",
"modifiedOn": "2021-07-06T02:02:05.506Z",
"modifiedByUserId": "9f66d112-bd94-43b7-a03d-d47a950357fd"
},
"workspaceId": "00000000-0000-0000-0000-000000000000",
"content": {
"title": "Thilina section diff",
"isTemplate": false,
"basedOn": "template-d0e108b0-1c68-4c0c-a9b6-83b7662208d6",
"sections": [
{
"id": "82a8e0a9-cbc9-4a1c-91c6-56aded1e5d12",
"title": "Section 1",
"description": "aZewpev sitez moahura jom ejuwiled zu cxcxcx dfcvxvcvxcvxcv grfgfgfgfgfgfgfgfgfg",
"content": [
],
"subsections": [
{
"id": "0bd1123c-0ac1-4811-8c7d-c83b9ddff5e7",
"title": "section 1.0",
"content": [],
"subsections": []
},
{
"id": "464c2db4-c625-4c0b-80c8-750aff1fe9af",
"title": "section 1.3 edit",
"content": [],
"subsections": []
},
{
"id": "382d4e8f-99ab-4038-b811-73eb05a81252",
"title": "section 1.1",
"content": [],
"subsections": []
},
{
"id": "bad1f8cc-5188-4a06-a03c-3b7a29afc30e",
"title": "section 1.2",
"content": [
"569743f6-f50b-4175-aae5-f81023c36dea"],
"subsections": []
}
]
}
],
"metadataSettings": [
{
"componentKey": "c609785a-9eea-4731-b536-8976f273b512",
"isRequired": true,
"value": "1"
},
{
"componentKey": "f31f8603-ddf2-4566-a3d6-d6b40c26aaf3",
"isRequired": false
},
{
"componentKey": "321fc1ee-9efe-439f-804d-8f7444a6b507",
"isRequired": false
},
{
"componentKey": "c6668178-34df-48c8-9dcd-4423e9034caa",
"isRequired": false
},
{
"componentKey": "3c9b001d-653c-419e-bb93-c11e795147d6",
"isRequired": true,
"value": "2"
}
],
"stylesheets": {}
}
};
var delta = jsondiffpatch.diff(before, after);
// var output = jsondiffpatchformatters.formatters.jsonpatch.format(delta);