@resolveio/client-lib-core 15.0.3 → 15.0.5

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.
@@ -473,22 +473,13 @@ function deepDiffDetails(obj1, obj2) {
473
473
  return typeof value === 'string' ? `"${value}"` : String(value);
474
474
  };
475
475
  const formatArrayDiff = (arr1, arr2) => {
476
- let maxLength = Math.max(arr1.length, arr2.length);
477
- let arrayDiff = [];
478
- for (let i = 0; i < maxLength; i++) {
479
- if (i >= arr1.length) {
480
- arrayDiff.push(`added: ${formatValue(arr2[i])}`);
481
- continue;
476
+ return arr1.map((item, index) => {
477
+ const arr2Item = arr2[index];
478
+ if (typeof item === 'object' && item !== null && arr2Item !== undefined) {
479
+ return `{${formatObjectDiff(item, arr2Item)}}`;
482
480
  }
483
- if (i >= arr2.length) {
484
- arrayDiff.push(`removed: ${formatValue(arr1[i])}`);
485
- continue;
486
- }
487
- if (arr1[i] !== arr2[i]) {
488
- arrayDiff.push(`from: ${formatValue(arr1[i])} to: ${formatValue(arr2[i])}`);
489
- }
490
- }
491
- return `[${arrayDiff.join(', ')}]`;
481
+ return arr2Item !== undefined ? `from: ${formatValue(item)} to: ${formatValue(arr2Item)}` : `removed: ${formatValue(item)}`;
482
+ }).join(', ');
492
483
  };
493
484
  const formatObjectDiff = (obj1, obj2) => {
494
485
  if (obj1 === null || obj2 === null || typeof obj1 !== 'object' || typeof obj2 !== 'object') {
@@ -497,21 +488,26 @@ function deepDiffDetails(obj1, obj2) {
497
488
  if (Array.isArray(obj1) && Array.isArray(obj2)) {
498
489
  return formatArrayDiff(obj1, obj2);
499
490
  }
500
- return Object.keys(obj1).map(key => {
501
- if (typeof obj1[key] === 'object' && obj1[key] !== null && obj2[key] !== null) {
502
- return `${toTitleCase(key)}: {${formatObjectDiff(obj1[key], obj2[key])}}`;
491
+ return Object.keys({ ...obj1, ...obj2 }).map(key => {
492
+ const obj1Val = obj1[key], obj2Val = obj2[key];
493
+ if (typeof obj1Val === 'object' && obj1Val !== null && obj2Val !== null) {
494
+ return `${toTitleCase(key)}: {${formatObjectDiff(obj1Val, obj2Val)}}`;
503
495
  }
504
- return `${toTitleCase(key)}: from: ${formatValue(obj1[key])} to: ${formatValue(obj2[key])}`;
496
+ return `${toTitleCase(key)}: from: ${formatValue(obj1Val)} to: ${formatValue(obj2Val)}`;
505
497
  }).join(', ');
506
498
  };
507
- if (Object.keys(diff.updated).length > 0) {
508
- diffString += 'Updated:\n';
509
- const updates = Object.keys(diff.updated)
510
- .filter(key => key.substr(0, 2) !== 'id' && diff.updated[key] !== obj2[key])
511
- .map(key => `${toTitleCase(key)}: {${formatObjectDiff(diff.updated[key], obj2[key])}}`)
512
- .join(',\n');
513
- diffString += updates ? `${updates}\n` : '';
514
- }
499
+ ['added', 'deleted', 'updated'].forEach(diffType => {
500
+ if (Object.keys(diff[diffType]).length > 0) {
501
+ diffString += `${toTitleCase(diffType)}:\n`;
502
+ const updates = Object.keys(diff[diffType])
503
+ .map(key => {
504
+ const currentValue = diffType === 'deleted' ? obj1[key] : obj2[key];
505
+ return `${toTitleCase(key)}: {${formatObjectDiff(diff[diffType][key], currentValue)}}`;
506
+ })
507
+ .join(',\n');
508
+ diffString += updates ? `${updates}\n` : '';
509
+ }
510
+ });
515
511
  return diffString;
516
512
  }
517
513
  function generateCronStringFromDate(date) {