@resolveio/client-lib-core 15.0.5 → 15.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/util/common.helper.mjs +41 -27
- package/fesm2015/resolveio-client-lib-core.mjs +40 -26
- package/fesm2015/resolveio-client-lib-core.mjs.map +1 -1
- package/fesm2020/resolveio-client-lib-core.mjs +40 -26
- package/fesm2020/resolveio-client-lib-core.mjs.map +1 -1
- package/lib/util/common.helper.d.ts +1 -1
- package/package.json +1 -1
|
@@ -463,49 +463,63 @@ function toDataURL(url, callback) {
|
|
|
463
463
|
xhr.responseType = 'blob';
|
|
464
464
|
xhr.send();
|
|
465
465
|
}
|
|
466
|
-
function deepDiffDetails(
|
|
467
|
-
let
|
|
468
|
-
let
|
|
466
|
+
function deepDiffDetails(object1, object2) {
|
|
467
|
+
let obj1 = deepCopy(object1);
|
|
468
|
+
let obj2 = deepCopy(object2);
|
|
469
|
+
let diff = detailedDiff(obj1, obj2);
|
|
470
|
+
let diffString = '\n';
|
|
469
471
|
const formatValue = (value) => {
|
|
470
|
-
if (
|
|
472
|
+
if (value instanceof Date) {
|
|
471
473
|
return moment(value).format('llll');
|
|
472
474
|
}
|
|
473
|
-
|
|
475
|
+
else if (typeof value === 'object' && value !== null) {
|
|
476
|
+
Object.keys(value).filter(a => a.startsWith('_id') || a.startsWith('id_')).forEach(key => {
|
|
477
|
+
delete value[key];
|
|
478
|
+
});
|
|
479
|
+
return JSON.stringify(value); // Pretty print objects
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
return typeof value === 'string' ? `"${value}"` : String(value);
|
|
483
|
+
}
|
|
474
484
|
};
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
485
|
+
const customArrayDiff = (arr1, arr2) => {
|
|
486
|
+
let arrayDiffResults = [];
|
|
487
|
+
const maxLength = Math.max(arr1.length, arr2.length);
|
|
488
|
+
for (let i = 0; i < maxLength; i++) {
|
|
489
|
+
if (arr1[i] && !arr2[i]) {
|
|
490
|
+
arrayDiffResults.push(`Removed at index ${i}: ${formatValue(arr1[i])}`);
|
|
480
491
|
}
|
|
481
|
-
|
|
482
|
-
|
|
492
|
+
else if (!arr1[i] && arr2[i]) {
|
|
493
|
+
arrayDiffResults.push(`Added at index ${i}: ${formatValue(arr2[i])}`);
|
|
494
|
+
}
|
|
495
|
+
else if (arr1[i] && arr2[i] && JSON.stringify(arr1[i]) !== JSON.stringify(arr2[i])) {
|
|
496
|
+
arrayDiffResults.push(`Changed at index ${i}: {${formatObjectDiff(arr1[i], arr2[i])}}`);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return arrayDiffResults.join(', ');
|
|
483
500
|
};
|
|
484
501
|
const formatObjectDiff = (obj1, obj2) => {
|
|
485
502
|
if (obj1 === null || obj2 === null || typeof obj1 !== 'object' || typeof obj2 !== 'object') {
|
|
486
503
|
return `from: ${formatValue(obj1)} to: ${formatValue(obj2)}`;
|
|
487
504
|
}
|
|
488
|
-
if (Array.isArray(obj1)
|
|
489
|
-
return
|
|
505
|
+
if (Array.isArray(obj1) || Array.isArray(obj2)) {
|
|
506
|
+
return customArrayDiff(Array.isArray(obj1) ? obj1 : [], Array.isArray(obj2) ? obj2 : []);
|
|
490
507
|
}
|
|
491
|
-
return Object.keys({ ...obj1, ...obj2 }).map(key => {
|
|
492
|
-
const obj1Val = obj1[key]
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
496
|
-
return `${toTitleCase(key)}: from: ${formatValue(obj1Val)} to: ${formatValue(obj2Val)}`;
|
|
508
|
+
return Object.keys({ ...obj1, ...obj2 }).filter(a => !a.startsWith('_id') && !a.startsWith('id_')).map(key => {
|
|
509
|
+
const obj1Val = obj1 ? obj1[key] : undefined;
|
|
510
|
+
const obj2Val = obj2 ? obj2[key] : undefined;
|
|
511
|
+
return `${toTitleCase(key)}: ${formatObjectDiff(obj1Val, obj2Val)}`;
|
|
497
512
|
}).join(', ');
|
|
498
513
|
};
|
|
514
|
+
// Handle each diff type
|
|
499
515
|
['added', 'deleted', 'updated'].forEach(diffType => {
|
|
500
516
|
if (Object.keys(diff[diffType]).length > 0) {
|
|
501
|
-
diffString += `${toTitleCase(diffType)}:\n`;
|
|
502
517
|
const updates = Object.keys(diff[diffType])
|
|
503
|
-
.
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
})
|
|
518
|
+
.filter(key => diffType === 'added' ? true : (diffType === 'deleted' ? !diff['added'][key] : !diff['added'][key] && !diff['deleted'][key]))
|
|
519
|
+
.filter(key => !key.startsWith('_id') && !key.startsWith('id_'))
|
|
520
|
+
.map(key => `\n${toTitleCase(key)}: ${formatObjectDiff(obj1[key], obj2[key])}`)
|
|
507
521
|
.join(',\n');
|
|
508
|
-
diffString += updates ? `${updates}
|
|
522
|
+
diffString += updates ? `${updates}` : '';
|
|
509
523
|
}
|
|
510
524
|
});
|
|
511
525
|
return diffString;
|