@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.
@@ -463,49 +463,63 @@ function toDataURL(url, callback) {
463
463
  xhr.responseType = 'blob';
464
464
  xhr.send();
465
465
  }
466
- function deepDiffDetails(obj1, obj2) {
467
- let diff = detailedDiff(obj2, obj1);
468
- let diffString = '';
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 (moment.isDate(value) || moment(value, moment.ISO_8601, true).isValid()) {
472
+ if (value instanceof Date) {
471
473
  return moment(value).format('llll');
472
474
  }
473
- return typeof value === 'string' ? `"${value}"` : String(value);
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 formatArrayDiff = (arr1, arr2) => {
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)}}`;
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
- return arr2Item !== undefined ? `from: ${formatValue(item)} to: ${formatValue(arr2Item)}` : `removed: ${formatValue(item)}`;
482
- }).join(', ');
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) && Array.isArray(obj2)) {
489
- return formatArrayDiff(obj1, obj2);
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], obj2Val = obj2[key];
493
- if (typeof obj1Val === 'object' && obj1Val !== null && obj2Val !== null) {
494
- return `${toTitleCase(key)}: {${formatObjectDiff(obj1Val, obj2Val)}}`;
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
- .map(key => {
504
- const currentValue = diffType === 'deleted' ? obj1[key] : obj2[key];
505
- return `${toTitleCase(key)}: {${formatObjectDiff(diff[diffType][key], currentValue)}}`;
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}\n` : '';
522
+ diffString += updates ? `${updates}` : '';
509
523
  }
510
524
  });
511
525
  return diffString;