@resolveio/client-lib-core 15.0.6 → 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,45 +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
+ }
484
+ };
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])}`);
491
+ }
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(', ');
474
500
  };
475
501
  const formatObjectDiff = (obj1, obj2) => {
476
502
  if (obj1 === null || obj2 === null || typeof obj1 !== 'object' || typeof obj2 !== 'object') {
477
503
  return `from: ${formatValue(obj1)} to: ${formatValue(obj2)}`;
478
504
  }
479
505
  if (Array.isArray(obj1) || Array.isArray(obj2)) {
480
- const arr1 = Array.isArray(obj1) ? obj1 : [];
481
- const arr2 = Array.isArray(obj2) ? obj2 : [];
482
- const maxLength = Math.max(arr1.length, arr2.length);
483
- const arrayDiff = [];
484
- for (let i = 0; i < maxLength; i++) {
485
- arrayDiff.push(formatObjectDiff(arr1[i], arr2[i]));
486
- }
487
- return `[${arrayDiff.join(', ')}]`;
506
+ return customArrayDiff(Array.isArray(obj1) ? obj1 : [], Array.isArray(obj2) ? obj2 : []);
488
507
  }
489
- return Object.keys({ ...obj1, ...obj2 }).map(key => {
508
+ return Object.keys({ ...obj1, ...obj2 }).filter(a => !a.startsWith('_id') && !a.startsWith('id_')).map(key => {
490
509
  const obj1Val = obj1 ? obj1[key] : undefined;
491
510
  const obj2Val = obj2 ? obj2[key] : undefined;
492
511
  return `${toTitleCase(key)}: ${formatObjectDiff(obj1Val, obj2Val)}`;
493
512
  }).join(', ');
494
513
  };
514
+ // Handle each diff type
495
515
  ['added', 'deleted', 'updated'].forEach(diffType => {
496
516
  if (Object.keys(diff[diffType]).length > 0) {
497
- diffString += `${toTitleCase(diffType)}:\n`;
498
517
  const updates = Object.keys(diff[diffType])
499
- .map(key => {
500
- const currentValue = diffType === 'deleted' ? obj1[key] : obj2[key];
501
- return `${toTitleCase(key)}: ${formatObjectDiff(diff[diffType][key], currentValue)}`;
502
- })
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])}`)
503
521
  .join(',\n');
504
- diffString += updates ? `${updates}\n` : '';
522
+ diffString += updates ? `${updates}` : '';
505
523
  }
506
524
  });
507
525
  return diffString;