@fluxhub/fluxhub-lib 10.0.8 → 10.0.9

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.
@@ -623,6 +623,137 @@
623
623
  return value;
624
624
  }
625
625
 
626
+ var obj_diff = /** @class */ (function () {
627
+ function obj_diff() {
628
+ this.checkType = {
629
+ NUMBER: function (x) { return typeof x === 'number'; },
630
+ BOOLEAN: function (x) { return typeof x === 'boolean'; },
631
+ STRING: function (x) { return typeof x === 'string'; },
632
+ DATE: function (x) { return x instanceof Date; },
633
+ UNDEFINED: function (x) { return typeof x === 'undefined'; },
634
+ NULL: function (x) { return x === null; },
635
+ ARRAY: function (x) { return x instanceof Array; },
636
+ MAP: function (x) { return x instanceof Map; },
637
+ SET: function (x) { return x instanceof Set; },
638
+ ITERABLE_OBJECT: function (x) {
639
+ var type = Object.prototype.toString.call(x);
640
+ return type === '[object Object]';
641
+ }
642
+ };
643
+ this.types = {
644
+ NUMBER: 'NUMBER',
645
+ BOOLEAN: 'BOOLEAN',
646
+ STRING: 'STRING',
647
+ NULL: 'NULL',
648
+ UNDEFINED: 'UNDEFINED',
649
+ DATE: 'DATE',
650
+ ARRAY: 'ARRAY',
651
+ MAP: 'MAP',
652
+ SET: 'SET',
653
+ ITERABLE_OBJECT: 'ITERABLE_OBJECT',
654
+ DEFAULT: 'OBJECT',
655
+ };
656
+ this.iterableTypes = 'ITERABLE_OBJECT__MAP__ARRAY__SET';
657
+ this.noop = function () { };
658
+ this.checkEqualityForComplexTypes = {
659
+ 'DATE': function (dt1, dt2) { return dt1.getTime() === dt2.getTime(); },
660
+ };
661
+ }
662
+ obj_diff.prototype.getType = function (x) {
663
+ var keys = Object.keys(this.checkType);
664
+ var type = this.types.DEFAULT;
665
+ for (var i = 0; i < keys.length; i += 1) {
666
+ if (this.checkType[keys[i]](x)) {
667
+ type = keys[i];
668
+ break;
669
+ }
670
+ }
671
+ return type;
672
+ };
673
+ obj_diff.prototype.isTraversalNeeded = function (type1, type2) {
674
+ return type1 === type2 && this.iterableTypes.indexOf(type1) >= 0;
675
+ };
676
+ obj_diff.prototype.areEqual = function (x, y, type1, type2) {
677
+ if (type1 !== type2) {
678
+ return false;
679
+ }
680
+ return this.checkEqualityForComplexTypes[type1] ? this.checkEqualityForComplexTypes[type1](x, y) : x === y;
681
+ };
682
+ obj_diff.prototype.computeOp = function (x, y, type1, type2) {
683
+ // console.log('type1 ',type1,'type2 ',type2);
684
+ var op = null;
685
+ if (type1 === this.types.UNDEFINED && type2 !== this.types.UNDEFINED) {
686
+ op = 'add';
687
+ }
688
+ else if (type1 !== this.types.UNDEFINED && type2 === this.types.UNDEFINED) {
689
+ op = 'delete';
690
+ }
691
+ else if (!(this.areEqual(x, y, type1, type2))) {
692
+ op = 'update';
693
+ }
694
+ else {
695
+ this.noop();
696
+ }
697
+ return op;
698
+ };
699
+ obj_diff.prototype.getKeys = function (x, y, type) {
700
+ var keys;
701
+ if (type === this.types.ITERABLE_OBJECT) {
702
+ keys = new Set(Object.keys(x).concat(Object.keys(y)));
703
+ }
704
+ else if (type === this.types.ARRAY) {
705
+ keys = x.length > y.length ? new Array(x.length) : new Array(y.length);
706
+ keys = keys.fill(0, 0);
707
+ keys = keys.map(function (el, i) { return i; });
708
+ keys = new Set(keys);
709
+ }
710
+ return keys;
711
+ };
712
+ obj_diff.prototype.makeDiff = function (x, y, op, path, keepOldVal) {
713
+ var diffOb = {
714
+ op: op,
715
+ path: path,
716
+ val: '',
717
+ oldVal: ''
718
+ };
719
+ if (op === 'add' || op === 'update') {
720
+ diffOb.val = y;
721
+ }
722
+ if (keepOldVal && op !== 'add') {
723
+ diffOb.oldVal = x;
724
+ }
725
+ return diffOb;
726
+ };
727
+ obj_diff.prototype.get_diff = function (x, y, keepOldVal, path, diff) {
728
+ if (keepOldVal === void 0) { keepOldVal = false; }
729
+ if (path === void 0) { path = []; }
730
+ if (diff === void 0) { diff = []; }
731
+ var type1 = this.getType(x);
732
+ var type2 = this.getType(y);
733
+ var currPath = path || [];
734
+ var currDiff = diff || [];
735
+ if (this.isTraversalNeeded(type1, type2)) {
736
+ var iterator = this.getKeys(x, y, type1).values();
737
+ var key = iterator.next().value;
738
+ while (key != null) {
739
+ this.get_diff(x[key], y[key], keepOldVal, currPath.concat(key), currDiff);
740
+ key = iterator.next().value;
741
+ }
742
+ }
743
+ else {
744
+ var op = this.computeOp(x, y, type1, type2);
745
+ // console.log('op ',op);
746
+ if (op != null) {
747
+ // console.log()
748
+ currDiff.push(this.makeDiff(x, y, op, path, keepOldVal));
749
+ }
750
+ }
751
+ // console.log('currDiff ',currDiff);
752
+ return currDiff;
753
+ };
754
+ return obj_diff;
755
+ }());
756
+
626
757
  //import { getDiff} from 'recursive-diff';
627
758
  var UtilityService = /** @class */ (function () {
628
759
  function UtilityService(app_s) {
@@ -976,12 +1107,14 @@
976
1107
  if (old_doc === void 0) { old_doc = null; }
977
1108
  if (new_doc === void 0) { new_doc = null; }
978
1109
  var diff1 = [];
979
- /*if (old_doc == null && new_doc == null) return diff1;
980
- let diff = getDiff(old_doc, new_doc, true);
981
- for (let index = 0; index < diff.length; index++) {
982
- if (diff[index].path + "" != "uiid" && diff[index].path + "" != "id")
983
- diff1.push(diff[index]);
984
- }*/
1110
+ if (old_doc == null && new_doc == null)
1111
+ return diff1;
1112
+ var ax = new obj_diff();
1113
+ var diff = ax.get_diff(old_doc, new_doc, true);
1114
+ for (var index = 0; index < diff.length; index++) {
1115
+ if (diff[index].path + "" != "uiid" && diff[index].path + "" != "id")
1116
+ diff1.push(diff[index]);
1117
+ }
985
1118
  return diff1;
986
1119
  };
987
1120
  UtilityService.prototype.insert_log = function (dt, app, k, descri, operazione, link, old_doc, new_doc) {