@commercetools/sync-actions 6.0.0 → 6.1.1

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.
@@ -1,21 +1,19 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash.flatten'), require('lodash.isequal'), require('lodash.isnil'), require('diff-match-patch'), require('chalk'), require('lodash.foreach'), require('lodash.uniqwith'), require('lodash.intersection'), require('lodash.without'), require('lodash.sortby')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'lodash.flatten', 'lodash.isequal', 'lodash.isnil', 'diff-match-patch', 'chalk', 'lodash.foreach', 'lodash.uniqwith', 'lodash.intersection', 'lodash.without', 'lodash.sortby'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CommercetoolsSyncActions = {}, global.flatten, global.isEqual, global.isNil, global.dmp, global.chalk, global.forEach, global.uniqWith, global.intersection, global.without, global.sortBy$1));
5
- })(this, (function (exports, flatten, isEqual, isNil, dmp, chalk, forEach, uniqWith, intersection, without, sortBy$1) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash.flatten'), require('lodash.isequal'), require('lodash.isnil'), require('jsondiffpatch/dist/jsondiffpatch.cjs'), require('lodash.foreach'), require('lodash.uniqwith'), require('lodash.intersection'), require('lodash.without'), require('lodash.sortby')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'lodash.flatten', 'lodash.isequal', 'lodash.isnil', 'jsondiffpatch/dist/jsondiffpatch.cjs', 'lodash.foreach', 'lodash.uniqwith', 'lodash.intersection', 'lodash.without', 'lodash.sortby'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CommercetoolsSyncActions = {}, global.flatten, global.isEqual, global.isNil, global.jsondiffpatch_cjs, global.forEach, global.uniqWith, global.intersection, global.without, global.sortBy));
5
+ })(this, (function (exports, flatten, isEqual, isNil, jsondiffpatch_cjs, forEach, uniqWith, intersection, without, sortBy) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
10
10
  var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
11
11
  var isNil__default = /*#__PURE__*/_interopDefaultLegacy(isNil);
12
- var dmp__default = /*#__PURE__*/_interopDefaultLegacy(dmp);
13
- var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
14
12
  var forEach__default = /*#__PURE__*/_interopDefaultLegacy(forEach);
15
13
  var uniqWith__default = /*#__PURE__*/_interopDefaultLegacy(uniqWith);
16
14
  var intersection__default = /*#__PURE__*/_interopDefaultLegacy(intersection);
17
15
  var without__default = /*#__PURE__*/_interopDefaultLegacy(without);
18
- var sortBy__default = /*#__PURE__*/_interopDefaultLegacy(sortBy$1);
16
+ var sortBy__default = /*#__PURE__*/_interopDefaultLegacy(sortBy);
19
17
 
20
18
  function _arrayLikeToArray(r, a) {
21
19
  (null == a || a > r.length) && (a = r.length);
@@ -133,14 +131,14 @@
133
131
  var i = _toPrimitive(t, "string");
134
132
  return "symbol" == typeof i ? i : i + "";
135
133
  }
136
- function _typeof$1(o) {
134
+ function _typeof(o) {
137
135
  "@babel/helpers - typeof";
138
136
 
139
- return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
137
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
140
138
  return typeof o;
141
139
  } : function (o) {
142
140
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
143
- }, _typeof$1(o);
141
+ }, _typeof(o);
144
142
  }
145
143
  function _unsupportedIterableToArray(r, a) {
146
144
  if (r) {
@@ -241,2453 +239,11 @@
241
239
  };
242
240
  }
243
241
 
244
- var _typeof = typeof Symbol === "function" && _typeof$1(Symbol.iterator) === "symbol" ? function (obj) {
245
- return _typeof$1(obj);
246
- } : function (obj) {
247
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof$1(obj);
248
- };
249
- var classCallCheck = function classCallCheck(instance, Constructor) {
250
- if (!(instance instanceof Constructor)) {
251
- throw new TypeError("Cannot call a class as a function");
252
- }
253
- };
254
- var createClass = function () {
255
- function defineProperties(target, props) {
256
- for (var i = 0; i < props.length; i++) {
257
- var descriptor = props[i];
258
- descriptor.enumerable = descriptor.enumerable || false;
259
- descriptor.configurable = true;
260
- if ("value" in descriptor) descriptor.writable = true;
261
- Object.defineProperty(target, descriptor.key, descriptor);
262
- }
263
- }
264
- return function (Constructor, protoProps, staticProps) {
265
- if (protoProps) defineProperties(Constructor.prototype, protoProps);
266
- if (staticProps) defineProperties(Constructor, staticProps);
267
- return Constructor;
268
- };
269
- }();
270
- var get = function get(object, property, receiver) {
271
- if (object === null) object = Function.prototype;
272
- var desc = Object.getOwnPropertyDescriptor(object, property);
273
- if (desc === undefined) {
274
- var parent = Object.getPrototypeOf(object);
275
- if (parent === null) {
276
- return undefined;
277
- } else {
278
- return get(parent, property, receiver);
279
- }
280
- } else if ("value" in desc) {
281
- return desc.value;
282
- } else {
283
- var getter = desc.get;
284
- if (getter === undefined) {
285
- return undefined;
286
- }
287
- return getter.call(receiver);
288
- }
289
- };
290
- var inherits = function inherits(subClass, superClass) {
291
- if (typeof superClass !== "function" && superClass !== null) {
292
- throw new TypeError("Super expression must either be null or a function, not " + _typeof$1(superClass));
293
- }
294
- subClass.prototype = Object.create(superClass && superClass.prototype, {
295
- constructor: {
296
- value: subClass,
297
- enumerable: false,
298
- writable: true,
299
- configurable: true
300
- }
301
- });
302
- if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
303
- };
304
- var possibleConstructorReturn = function possibleConstructorReturn(self, call) {
305
- if (!self) {
306
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
307
- }
308
- return call && (_typeof$1(call) === "object" || typeof call === "function") ? call : self;
309
- };
310
- var slicedToArray = function () {
311
- function sliceIterator(arr, i) {
312
- var _arr = [];
313
- var _n = true;
314
- var _d = false;
315
- var _e = undefined;
316
- try {
317
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
318
- _arr.push(_s.value);
319
- if (i && _arr.length === i) break;
320
- }
321
- } catch (err) {
322
- _d = true;
323
- _e = err;
324
- } finally {
325
- try {
326
- if (!_n && _i["return"]) _i["return"]();
327
- } finally {
328
- if (_d) throw _e;
329
- }
330
- }
331
- return _arr;
332
- }
333
- return function (arr, i) {
334
- if (Array.isArray(arr)) {
335
- return arr;
336
- } else if (Symbol.iterator in Object(arr)) {
337
- return sliceIterator(arr, i);
338
- } else {
339
- throw new TypeError("Invalid attempt to destructure non-iterable instance");
340
- }
341
- };
342
- }();
343
- var toConsumableArray = function toConsumableArray(arr) {
344
- if (Array.isArray(arr)) {
345
- for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
346
- return arr2;
347
- } else {
348
- return Array.from(arr);
349
- }
350
- };
351
- var Processor = function () {
352
- function Processor(options) {
353
- classCallCheck(this, Processor);
354
- this.selfOptions = options || {};
355
- this.pipes = {};
356
- }
357
- createClass(Processor, [{
358
- key: 'options',
359
- value: function options(_options) {
360
- if (_options) {
361
- this.selfOptions = _options;
362
- }
363
- return this.selfOptions;
364
- }
365
- }, {
366
- key: 'pipe',
367
- value: function pipe(name, pipeArg) {
368
- var pipe = pipeArg;
369
- if (typeof name === 'string') {
370
- if (typeof pipe === 'undefined') {
371
- return this.pipes[name];
372
- } else {
373
- this.pipes[name] = pipe;
374
- }
375
- }
376
- if (name && name.name) {
377
- pipe = name;
378
- if (pipe.processor === this) {
379
- return pipe;
380
- }
381
- this.pipes[pipe.name] = pipe;
382
- }
383
- pipe.processor = this;
384
- return pipe;
385
- }
386
- }, {
387
- key: 'process',
388
- value: function process(input, pipe) {
389
- var context = input;
390
- context.options = this.options();
391
- var nextPipe = pipe || input.pipe || 'default';
392
- var lastPipe = void 0;
393
- var lastContext = void 0;
394
- while (nextPipe) {
395
- if (typeof context.nextAfterChildren !== 'undefined') {
396
- // children processed and coming back to parent
397
- context.next = context.nextAfterChildren;
398
- context.nextAfterChildren = null;
399
- }
400
- if (typeof nextPipe === 'string') {
401
- nextPipe = this.pipe(nextPipe);
402
- }
403
- nextPipe.process(context);
404
- lastContext = context;
405
- lastPipe = nextPipe;
406
- nextPipe = null;
407
- if (context) {
408
- if (context.next) {
409
- context = context.next;
410
- nextPipe = lastContext.nextPipe || context.pipe || lastPipe;
411
- }
412
- }
413
- }
414
- return context.hasResult ? context.result : undefined;
415
- }
416
- }]);
417
- return Processor;
418
- }();
419
- var Pipe = function () {
420
- function Pipe(name) {
421
- classCallCheck(this, Pipe);
422
- this.name = name;
423
- this.filters = [];
424
- }
425
- createClass(Pipe, [{
426
- key: 'process',
427
- value: function process(input) {
428
- if (!this.processor) {
429
- throw new Error('add this pipe to a processor before using it');
430
- }
431
- var debug = this.debug;
432
- var length = this.filters.length;
433
- var context = input;
434
- for (var index = 0; index < length; index++) {
435
- var filter = this.filters[index];
436
- if (debug) {
437
- this.log('filter: ' + filter.filterName);
438
- }
439
- filter(context);
440
- if ((typeof context === 'undefined' ? 'undefined' : _typeof(context)) === 'object' && context.exiting) {
441
- context.exiting = false;
442
- break;
443
- }
444
- }
445
- if (!context.next && this.resultCheck) {
446
- this.resultCheck(context);
447
- }
448
- }
449
- }, {
450
- key: 'log',
451
- value: function log(msg) {
452
- console.log('[jsondiffpatch] ' + this.name + ' pipe, ' + msg);
453
- }
454
- }, {
455
- key: 'append',
456
- value: function append() {
457
- var _filters;
458
- (_filters = this.filters).push.apply(_filters, arguments);
459
- return this;
460
- }
461
- }, {
462
- key: 'prepend',
463
- value: function prepend() {
464
- var _filters2;
465
- (_filters2 = this.filters).unshift.apply(_filters2, arguments);
466
- return this;
467
- }
468
- }, {
469
- key: 'indexOf',
470
- value: function indexOf(filterName) {
471
- if (!filterName) {
472
- throw new Error('a filter name is required');
473
- }
474
- for (var index = 0; index < this.filters.length; index++) {
475
- var filter = this.filters[index];
476
- if (filter.filterName === filterName) {
477
- return index;
478
- }
479
- }
480
- throw new Error('filter not found: ' + filterName);
481
- }
482
- }, {
483
- key: 'list',
484
- value: function list() {
485
- return this.filters.map(function (f) {
486
- return f.filterName;
487
- });
488
- }
489
- }, {
490
- key: 'after',
491
- value: function after(filterName) {
492
- var index = this.indexOf(filterName);
493
- var params = Array.prototype.slice.call(arguments, 1);
494
- if (!params.length) {
495
- throw new Error('a filter is required');
496
- }
497
- params.unshift(index + 1, 0);
498
- Array.prototype.splice.apply(this.filters, params);
499
- return this;
500
- }
501
- }, {
502
- key: 'before',
503
- value: function before(filterName) {
504
- var index = this.indexOf(filterName);
505
- var params = Array.prototype.slice.call(arguments, 1);
506
- if (!params.length) {
507
- throw new Error('a filter is required');
508
- }
509
- params.unshift(index, 0);
510
- Array.prototype.splice.apply(this.filters, params);
511
- return this;
512
- }
513
- }, {
514
- key: 'replace',
515
- value: function replace(filterName) {
516
- var index = this.indexOf(filterName);
517
- var params = Array.prototype.slice.call(arguments, 1);
518
- if (!params.length) {
519
- throw new Error('a filter is required');
520
- }
521
- params.unshift(index, 1);
522
- Array.prototype.splice.apply(this.filters, params);
523
- return this;
524
- }
525
- }, {
526
- key: 'remove',
527
- value: function remove(filterName) {
528
- var index = this.indexOf(filterName);
529
- this.filters.splice(index, 1);
530
- return this;
531
- }
532
- }, {
533
- key: 'clear',
534
- value: function clear() {
535
- this.filters.length = 0;
536
- return this;
537
- }
538
- }, {
539
- key: 'shouldHaveResult',
540
- value: function shouldHaveResult(should) {
541
- if (should === false) {
542
- this.resultCheck = null;
543
- return;
544
- }
545
- if (this.resultCheck) {
546
- return;
547
- }
548
- var pipe = this;
549
- this.resultCheck = function (context) {
550
- if (!context.hasResult) {
551
- console.log(context);
552
- var error = new Error(pipe.name + ' failed');
553
- error.noResult = true;
554
- throw error;
555
- }
556
- };
557
- return this;
558
- }
559
- }]);
560
- return Pipe;
561
- }();
562
- var Context = function () {
563
- function Context() {
564
- classCallCheck(this, Context);
565
- }
566
- createClass(Context, [{
567
- key: 'setResult',
568
- value: function setResult(result) {
569
- this.result = result;
570
- this.hasResult = true;
571
- return this;
572
- }
573
- }, {
574
- key: 'exit',
575
- value: function exit() {
576
- this.exiting = true;
577
- return this;
578
- }
579
- }, {
580
- key: 'switchTo',
581
- value: function switchTo(next, pipe) {
582
- if (typeof next === 'string' || next instanceof Pipe) {
583
- this.nextPipe = next;
584
- } else {
585
- this.next = next;
586
- if (pipe) {
587
- this.nextPipe = pipe;
588
- }
589
- }
590
- return this;
591
- }
592
- }, {
593
- key: 'push',
594
- value: function push(child, name) {
595
- child.parent = this;
596
- if (typeof name !== 'undefined') {
597
- child.childName = name;
598
- }
599
- child.root = this.root || this;
600
- child.options = child.options || this.options;
601
- if (!this.children) {
602
- this.children = [child];
603
- this.nextAfterChildren = this.next || null;
604
- this.next = child;
605
- } else {
606
- this.children[this.children.length - 1].next = child;
607
- this.children.push(child);
608
- }
609
- child.next = this;
610
- return this;
611
- }
612
- }]);
613
- return Context;
614
- }();
615
- var isArray = typeof Array.isArray === 'function' ? Array.isArray : function (a) {
616
- return a instanceof Array;
617
- };
618
- function cloneRegExp(re) {
619
- var regexMatch = /^\/(.*)\/([gimyu]*)$/.exec(re.toString());
620
- return new RegExp(regexMatch[1], regexMatch[2]);
621
- }
622
- function clone$1(arg) {
623
- if ((typeof arg === 'undefined' ? 'undefined' : _typeof(arg)) !== 'object') {
624
- return arg;
625
- }
626
- if (arg === null) {
627
- return null;
628
- }
629
- if (isArray(arg)) {
630
- return arg.map(clone$1);
631
- }
632
- if (arg instanceof Date) {
633
- return new Date(arg.getTime());
634
- }
635
- if (arg instanceof RegExp) {
636
- return cloneRegExp(arg);
637
- }
638
- var cloned = {};
639
- for (var name in arg) {
640
- if (Object.prototype.hasOwnProperty.call(arg, name)) {
641
- cloned[name] = clone$1(arg[name]);
642
- }
643
- }
644
- return cloned;
645
- }
646
- var DiffContext = function (_Context) {
647
- inherits(DiffContext, _Context);
648
- function DiffContext(left, right) {
649
- classCallCheck(this, DiffContext);
650
- var _this = possibleConstructorReturn(this, (DiffContext.__proto__ || Object.getPrototypeOf(DiffContext)).call(this));
651
- _this.left = left;
652
- _this.right = right;
653
- _this.pipe = 'diff';
654
- return _this;
655
- }
656
- createClass(DiffContext, [{
657
- key: 'setResult',
658
- value: function setResult(result) {
659
- if (this.options.cloneDiffValues && (typeof result === 'undefined' ? 'undefined' : _typeof(result)) === 'object') {
660
- var clone$$1 = typeof this.options.cloneDiffValues === 'function' ? this.options.cloneDiffValues : clone$1;
661
- if (_typeof(result[0]) === 'object') {
662
- result[0] = clone$$1(result[0]);
663
- }
664
- if (_typeof(result[1]) === 'object') {
665
- result[1] = clone$$1(result[1]);
666
- }
667
- }
668
- return Context.prototype.setResult.apply(this, arguments);
669
- }
670
- }]);
671
- return DiffContext;
672
- }(Context);
673
- var PatchContext = function (_Context) {
674
- inherits(PatchContext, _Context);
675
- function PatchContext(left, delta) {
676
- classCallCheck(this, PatchContext);
677
- var _this = possibleConstructorReturn(this, (PatchContext.__proto__ || Object.getPrototypeOf(PatchContext)).call(this));
678
- _this.left = left;
679
- _this.delta = delta;
680
- _this.pipe = 'patch';
681
- return _this;
682
- }
683
- return PatchContext;
684
- }(Context);
685
- var ReverseContext = function (_Context) {
686
- inherits(ReverseContext, _Context);
687
- function ReverseContext(delta) {
688
- classCallCheck(this, ReverseContext);
689
- var _this = possibleConstructorReturn(this, (ReverseContext.__proto__ || Object.getPrototypeOf(ReverseContext)).call(this));
690
- _this.delta = delta;
691
- _this.pipe = 'reverse';
692
- return _this;
693
- }
694
- return ReverseContext;
695
- }(Context);
696
- var isArray$1 = typeof Array.isArray === 'function' ? Array.isArray : function (a) {
697
- return a instanceof Array;
698
- };
699
- var diffFilter = function trivialMatchesDiffFilter(context) {
700
- if (context.left === context.right) {
701
- context.setResult(undefined).exit();
702
- return;
703
- }
704
- if (typeof context.left === 'undefined') {
705
- if (typeof context.right === 'function') {
706
- throw new Error('functions are not supported');
707
- }
708
- context.setResult([context.right]).exit();
709
- return;
710
- }
711
- if (typeof context.right === 'undefined') {
712
- context.setResult([context.left, 0, 0]).exit();
713
- return;
714
- }
715
- if (typeof context.left === 'function' || typeof context.right === 'function') {
716
- throw new Error('functions are not supported');
717
- }
718
- context.leftType = context.left === null ? 'null' : _typeof(context.left);
719
- context.rightType = context.right === null ? 'null' : _typeof(context.right);
720
- if (context.leftType !== context.rightType) {
721
- context.setResult([context.left, context.right]).exit();
722
- return;
723
- }
724
- if (context.leftType === 'boolean' || context.leftType === 'number') {
725
- context.setResult([context.left, context.right]).exit();
726
- return;
727
- }
728
- if (context.leftType === 'object') {
729
- context.leftIsArray = isArray$1(context.left);
730
- }
731
- if (context.rightType === 'object') {
732
- context.rightIsArray = isArray$1(context.right);
733
- }
734
- if (context.leftIsArray !== context.rightIsArray) {
735
- context.setResult([context.left, context.right]).exit();
736
- return;
737
- }
738
- if (context.left instanceof RegExp) {
739
- if (context.right instanceof RegExp) {
740
- context.setResult([context.left.toString(), context.right.toString()]).exit();
741
- } else {
742
- context.setResult([context.left, context.right]).exit();
743
- }
744
- }
745
- };
746
- diffFilter.filterName = 'trivial';
747
- var patchFilter = function trivialMatchesPatchFilter(context) {
748
- if (typeof context.delta === 'undefined') {
749
- context.setResult(context.left).exit();
750
- return;
751
- }
752
- context.nested = !isArray$1(context.delta);
753
- if (context.nested) {
754
- return;
755
- }
756
- if (context.delta.length === 1) {
757
- context.setResult(context.delta[0]).exit();
758
- return;
759
- }
760
- if (context.delta.length === 2) {
761
- if (context.left instanceof RegExp) {
762
- var regexArgs = /^\/(.*)\/([gimyu]+)$/.exec(context.delta[1]);
763
- if (regexArgs) {
764
- context.setResult(new RegExp(regexArgs[1], regexArgs[2])).exit();
765
- return;
766
- }
767
- }
768
- context.setResult(context.delta[1]).exit();
769
- return;
770
- }
771
- if (context.delta.length === 3 && context.delta[2] === 0) {
772
- context.setResult(undefined).exit();
773
- }
774
- };
775
- patchFilter.filterName = 'trivial';
776
- var reverseFilter = function trivialReferseFilter(context) {
777
- if (typeof context.delta === 'undefined') {
778
- context.setResult(context.delta).exit();
779
- return;
780
- }
781
- context.nested = !isArray$1(context.delta);
782
- if (context.nested) {
783
- return;
784
- }
785
- if (context.delta.length === 1) {
786
- context.setResult([context.delta[0], 0, 0]).exit();
787
- return;
788
- }
789
- if (context.delta.length === 2) {
790
- context.setResult([context.delta[1], context.delta[0]]).exit();
791
- return;
792
- }
793
- if (context.delta.length === 3 && context.delta[2] === 0) {
794
- context.setResult([context.delta[0]]).exit();
795
- }
796
- };
797
- reverseFilter.filterName = 'trivial';
798
- function collectChildrenDiffFilter(context) {
799
- if (!context || !context.children) {
800
- return;
801
- }
802
- var length = context.children.length;
803
- var child = void 0;
804
- var result = context.result;
805
- for (var index = 0; index < length; index++) {
806
- child = context.children[index];
807
- if (typeof child.result === 'undefined') {
808
- continue;
809
- }
810
- result = result || {};
811
- result[child.childName] = child.result;
812
- }
813
- if (result && context.leftIsArray) {
814
- result._t = 'a';
815
- }
816
- context.setResult(result).exit();
817
- }
818
- collectChildrenDiffFilter.filterName = 'collectChildren';
819
- function objectsDiffFilter(context) {
820
- if (context.leftIsArray || context.leftType !== 'object') {
821
- return;
822
- }
823
- var name = void 0;
824
- var child = void 0;
825
- var propertyFilter = context.options.propertyFilter;
826
- for (name in context.left) {
827
- if (!Object.prototype.hasOwnProperty.call(context.left, name)) {
828
- continue;
829
- }
830
- if (propertyFilter && !propertyFilter(name, context)) {
831
- continue;
832
- }
833
- child = new DiffContext(context.left[name], context.right[name]);
834
- context.push(child, name);
835
- }
836
- for (name in context.right) {
837
- if (!Object.prototype.hasOwnProperty.call(context.right, name)) {
838
- continue;
839
- }
840
- if (propertyFilter && !propertyFilter(name, context)) {
841
- continue;
842
- }
843
- if (typeof context.left[name] === 'undefined') {
844
- child = new DiffContext(undefined, context.right[name]);
845
- context.push(child, name);
846
- }
847
- }
848
- if (!context.children || context.children.length === 0) {
849
- context.setResult(undefined).exit();
850
- return;
851
- }
852
- context.exit();
853
- }
854
- objectsDiffFilter.filterName = 'objects';
855
- var patchFilter$1 = function nestedPatchFilter(context) {
856
- if (!context.nested) {
857
- return;
858
- }
859
- if (context.delta._t) {
860
- return;
861
- }
862
- var name = void 0;
863
- var child = void 0;
864
- for (name in context.delta) {
865
- child = new PatchContext(context.left[name], context.delta[name]);
866
- context.push(child, name);
867
- }
868
- context.exit();
869
- };
870
- patchFilter$1.filterName = 'objects';
871
- var collectChildrenPatchFilter = function collectChildrenPatchFilter(context) {
872
- if (!context || !context.children) {
873
- return;
874
- }
875
- if (context.delta._t) {
876
- return;
877
- }
878
- var length = context.children.length;
879
- var child = void 0;
880
- for (var index = 0; index < length; index++) {
881
- child = context.children[index];
882
- if (Object.prototype.hasOwnProperty.call(context.left, child.childName) && child.result === undefined) {
883
- delete context.left[child.childName];
884
- } else if (context.left[child.childName] !== child.result) {
885
- context.left[child.childName] = child.result;
886
- }
887
- }
888
- context.setResult(context.left).exit();
889
- };
890
- collectChildrenPatchFilter.filterName = 'collectChildren';
891
- var reverseFilter$1 = function nestedReverseFilter(context) {
892
- if (!context.nested) {
893
- return;
894
- }
895
- if (context.delta._t) {
896
- return;
897
- }
898
- var name = void 0;
899
- var child = void 0;
900
- for (name in context.delta) {
901
- child = new ReverseContext(context.delta[name]);
902
- context.push(child, name);
903
- }
904
- context.exit();
905
- };
906
- reverseFilter$1.filterName = 'objects';
907
- function collectChildrenReverseFilter(context) {
908
- if (!context || !context.children) {
909
- return;
910
- }
911
- if (context.delta._t) {
912
- return;
913
- }
914
- var length = context.children.length;
915
- var child = void 0;
916
- var delta = {};
917
- for (var index = 0; index < length; index++) {
918
- child = context.children[index];
919
- if (delta[child.childName] !== child.result) {
920
- delta[child.childName] = child.result;
921
- }
922
- }
923
- context.setResult(delta).exit();
924
- }
925
- collectChildrenReverseFilter.filterName = 'collectChildren';
926
-
927
- /*
928
-
929
- LCS implementation that supports arrays or strings
930
-
931
- reference: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
932
-
933
- */
934
-
935
- var defaultMatch = function defaultMatch(array1, array2, index1, index2) {
936
- return array1[index1] === array2[index2];
937
- };
938
- var lengthMatrix = function lengthMatrix(array1, array2, match, context) {
939
- var len1 = array1.length;
940
- var len2 = array2.length;
941
- var x = void 0,
942
- y = void 0;
943
-
944
- // initialize empty matrix of len1+1 x len2+1
945
- var matrix = [len1 + 1];
946
- for (x = 0; x < len1 + 1; x++) {
947
- matrix[x] = [len2 + 1];
948
- for (y = 0; y < len2 + 1; y++) {
949
- matrix[x][y] = 0;
950
- }
951
- }
952
- matrix.match = match;
953
- // save sequence lengths for each coordinate
954
- for (x = 1; x < len1 + 1; x++) {
955
- for (y = 1; y < len2 + 1; y++) {
956
- if (match(array1, array2, x - 1, y - 1, context)) {
957
- matrix[x][y] = matrix[x - 1][y - 1] + 1;
958
- } else {
959
- matrix[x][y] = Math.max(matrix[x - 1][y], matrix[x][y - 1]);
960
- }
961
- }
962
- }
963
- return matrix;
964
- };
965
- var backtrack = function backtrack(matrix, array1, array2, context) {
966
- var index1 = array1.length;
967
- var index2 = array2.length;
968
- var subsequence = {
969
- sequence: [],
970
- indices1: [],
971
- indices2: []
972
- };
973
- while (index1 !== 0 && index2 !== 0) {
974
- var sameLetter = matrix.match(array1, array2, index1 - 1, index2 - 1, context);
975
- if (sameLetter) {
976
- subsequence.sequence.unshift(array1[index1 - 1]);
977
- subsequence.indices1.unshift(index1 - 1);
978
- subsequence.indices2.unshift(index2 - 1);
979
- --index1;
980
- --index2;
981
- } else {
982
- var valueAtMatrixAbove = matrix[index1][index2 - 1];
983
- var valueAtMatrixLeft = matrix[index1 - 1][index2];
984
- if (valueAtMatrixAbove > valueAtMatrixLeft) {
985
- --index2;
986
- } else {
987
- --index1;
988
- }
989
- }
990
- }
991
- return subsequence;
992
- };
993
- var get$1 = function get(array1, array2, match, context) {
994
- var innerContext = context || {};
995
- var matrix = lengthMatrix(array1, array2, match || defaultMatch, innerContext);
996
- var result = backtrack(matrix, array1, array2, innerContext);
997
- if (typeof array1 === 'string' && typeof array2 === 'string') {
998
- result.sequence = result.sequence.join('');
999
- }
1000
- return result;
1001
- };
1002
- var lcs = {
1003
- get: get$1
1004
- };
1005
- var ARRAY_MOVE = 3;
1006
- var isArray$2 = typeof Array.isArray === 'function' ? Array.isArray : function (a) {
1007
- return a instanceof Array;
1008
- };
1009
- var arrayIndexOf = typeof Array.prototype.indexOf === 'function' ? function (array, item) {
1010
- return array.indexOf(item);
1011
- } : function (array, item) {
1012
- var length = array.length;
1013
- for (var i = 0; i < length; i++) {
1014
- if (array[i] === item) {
1015
- return i;
1016
- }
1017
- }
1018
- return -1;
1019
- };
1020
- function arraysHaveMatchByRef(array1, array2, len1, len2) {
1021
- for (var index1 = 0; index1 < len1; index1++) {
1022
- var val1 = array1[index1];
1023
- for (var index2 = 0; index2 < len2; index2++) {
1024
- var val2 = array2[index2];
1025
- if (index1 !== index2 && val1 === val2) {
1026
- return true;
1027
- }
1028
- }
1029
- }
1030
- }
1031
- function matchItems(array1, array2, index1, index2, context) {
1032
- var value1 = array1[index1];
1033
- var value2 = array2[index2];
1034
- if (value1 === value2) {
1035
- return true;
1036
- }
1037
- if ((typeof value1 === 'undefined' ? 'undefined' : _typeof(value1)) !== 'object' || (typeof value2 === 'undefined' ? 'undefined' : _typeof(value2)) !== 'object') {
1038
- return false;
1039
- }
1040
- var objectHash = context.objectHash;
1041
- if (!objectHash) {
1042
- // no way to match objects was provided, try match by position
1043
- return context.matchByPosition && index1 === index2;
1044
- }
1045
- var hash1 = void 0;
1046
- var hash2 = void 0;
1047
- if (typeof index1 === 'number') {
1048
- context.hashCache1 = context.hashCache1 || [];
1049
- hash1 = context.hashCache1[index1];
1050
- if (typeof hash1 === 'undefined') {
1051
- context.hashCache1[index1] = hash1 = objectHash(value1, index1);
1052
- }
1053
- } else {
1054
- hash1 = objectHash(value1);
1055
- }
1056
- if (typeof hash1 === 'undefined') {
1057
- return false;
1058
- }
1059
- if (typeof index2 === 'number') {
1060
- context.hashCache2 = context.hashCache2 || [];
1061
- hash2 = context.hashCache2[index2];
1062
- if (typeof hash2 === 'undefined') {
1063
- context.hashCache2[index2] = hash2 = objectHash(value2, index2);
1064
- }
1065
- } else {
1066
- hash2 = objectHash(value2);
1067
- }
1068
- if (typeof hash2 === 'undefined') {
1069
- return false;
1070
- }
1071
- return hash1 === hash2;
1072
- }
1073
- var diffFilter$1 = function arraysDiffFilter(context) {
1074
- if (!context.leftIsArray) {
1075
- return;
1076
- }
1077
- var matchContext = {
1078
- objectHash: context.options && context.options.objectHash,
1079
- matchByPosition: context.options && context.options.matchByPosition
1080
- };
1081
- var commonHead = 0;
1082
- var commonTail = 0;
1083
- var index = void 0;
1084
- var index1 = void 0;
1085
- var index2 = void 0;
1086
- var array1 = context.left;
1087
- var array2 = context.right;
1088
- var len1 = array1.length;
1089
- var len2 = array2.length;
1090
- var child = void 0;
1091
- if (len1 > 0 && len2 > 0 && !matchContext.objectHash && typeof matchContext.matchByPosition !== 'boolean') {
1092
- matchContext.matchByPosition = !arraysHaveMatchByRef(array1, array2, len1, len2);
1093
- }
1094
-
1095
- // separate common head
1096
- while (commonHead < len1 && commonHead < len2 && matchItems(array1, array2, commonHead, commonHead, matchContext)) {
1097
- index = commonHead;
1098
- child = new DiffContext(context.left[index], context.right[index]);
1099
- context.push(child, index);
1100
- commonHead++;
1101
- }
1102
- // separate common tail
1103
- while (commonTail + commonHead < len1 && commonTail + commonHead < len2 && matchItems(array1, array2, len1 - 1 - commonTail, len2 - 1 - commonTail, matchContext)) {
1104
- index1 = len1 - 1 - commonTail;
1105
- index2 = len2 - 1 - commonTail;
1106
- child = new DiffContext(context.left[index1], context.right[index2]);
1107
- context.push(child, index2);
1108
- commonTail++;
1109
- }
1110
- var result = void 0;
1111
- if (commonHead + commonTail === len1) {
1112
- if (len1 === len2) {
1113
- // arrays are identical
1114
- context.setResult(undefined).exit();
1115
- return;
1116
- }
1117
- // trivial case, a block (1 or more consecutive items) was added
1118
- result = result || {
1119
- _t: 'a'
1120
- };
1121
- for (index = commonHead; index < len2 - commonTail; index++) {
1122
- result[index] = [array2[index]];
1123
- }
1124
- context.setResult(result).exit();
1125
- return;
1126
- }
1127
- if (commonHead + commonTail === len2) {
1128
- // trivial case, a block (1 or more consecutive items) was removed
1129
- result = result || {
1130
- _t: 'a'
1131
- };
1132
- for (index = commonHead; index < len1 - commonTail; index++) {
1133
- result['_' + index] = [array1[index], 0, 0];
1134
- }
1135
- context.setResult(result).exit();
1136
- return;
1137
- }
1138
- // reset hash cache
1139
- delete matchContext.hashCache1;
1140
- delete matchContext.hashCache2;
1141
-
1142
- // diff is not trivial, find the LCS (Longest Common Subsequence)
1143
- var trimmed1 = array1.slice(commonHead, len1 - commonTail);
1144
- var trimmed2 = array2.slice(commonHead, len2 - commonTail);
1145
- var seq = lcs.get(trimmed1, trimmed2, matchItems, matchContext);
1146
- var removedItems = [];
1147
- result = result || {
1148
- _t: 'a'
1149
- };
1150
- for (index = commonHead; index < len1 - commonTail; index++) {
1151
- if (arrayIndexOf(seq.indices1, index - commonHead) < 0) {
1152
- // removed
1153
- result['_' + index] = [array1[index], 0, 0];
1154
- removedItems.push(index);
1155
- }
1156
- }
1157
- var detectMove = true;
1158
- if (context.options && context.options.arrays && context.options.arrays.detectMove === false) {
1159
- detectMove = false;
1160
- }
1161
- var includeValueOnMove = false;
1162
- if (context.options && context.options.arrays && context.options.arrays.includeValueOnMove) {
1163
- includeValueOnMove = true;
1164
- }
1165
- var removedItemsLength = removedItems.length;
1166
- for (index = commonHead; index < len2 - commonTail; index++) {
1167
- var indexOnArray2 = arrayIndexOf(seq.indices2, index - commonHead);
1168
- if (indexOnArray2 < 0) {
1169
- // added, try to match with a removed item and register as position move
1170
- var isMove = false;
1171
- if (detectMove && removedItemsLength > 0) {
1172
- for (var removeItemIndex1 = 0; removeItemIndex1 < removedItemsLength; removeItemIndex1++) {
1173
- index1 = removedItems[removeItemIndex1];
1174
- if (matchItems(trimmed1, trimmed2, index1 - commonHead, index - commonHead, matchContext)) {
1175
- // store position move as: [originalValue, newPosition, ARRAY_MOVE]
1176
- result['_' + index1].splice(1, 2, index, ARRAY_MOVE);
1177
- if (!includeValueOnMove) {
1178
- // don't include moved value on diff, to save bytes
1179
- result['_' + index1][0] = '';
1180
- }
1181
- index2 = index;
1182
- child = new DiffContext(context.left[index1], context.right[index2]);
1183
- context.push(child, index2);
1184
- removedItems.splice(removeItemIndex1, 1);
1185
- isMove = true;
1186
- break;
1187
- }
1188
- }
1189
- }
1190
- if (!isMove) {
1191
- // added
1192
- result[index] = [array2[index]];
1193
- }
1194
- } else {
1195
- // match, do inner diff
1196
- index1 = seq.indices1[indexOnArray2] + commonHead;
1197
- index2 = seq.indices2[indexOnArray2] + commonHead;
1198
- child = new DiffContext(context.left[index1], context.right[index2]);
1199
- context.push(child, index2);
1200
- }
1201
- }
1202
- context.setResult(result).exit();
1203
- };
1204
- diffFilter$1.filterName = 'arrays';
1205
- var compare = {
1206
- numerically: function numerically(a, b) {
1207
- return a - b;
1208
- },
1209
- numericallyBy: function numericallyBy(name) {
1210
- return function (a, b) {
1211
- return a[name] - b[name];
1212
- };
1213
- }
1214
- };
1215
- var patchFilter$2 = function nestedPatchFilter(context) {
1216
- if (!context.nested) {
1217
- return;
1218
- }
1219
- if (context.delta._t !== 'a') {
1220
- return;
1221
- }
1222
- var index = void 0;
1223
- var index1 = void 0;
1224
- var delta = context.delta;
1225
- var array = context.left;
1226
-
1227
- // first, separate removals, insertions and modifications
1228
- var toRemove = [];
1229
- var toInsert = [];
1230
- var toModify = [];
1231
- for (index in delta) {
1232
- if (index !== '_t') {
1233
- if (index[0] === '_') {
1234
- // removed item from original array
1235
- if (delta[index][2] === 0 || delta[index][2] === ARRAY_MOVE) {
1236
- toRemove.push(parseInt(index.slice(1), 10));
1237
- } else {
1238
- throw new Error('only removal or move can be applied at original array indices,' + (' invalid diff type: ' + delta[index][2]));
1239
- }
1240
- } else {
1241
- if (delta[index].length === 1) {
1242
- // added item at new array
1243
- toInsert.push({
1244
- index: parseInt(index, 10),
1245
- value: delta[index][0]
1246
- });
1247
- } else {
1248
- // modified item at new array
1249
- toModify.push({
1250
- index: parseInt(index, 10),
1251
- delta: delta[index]
1252
- });
1253
- }
1254
- }
1255
- }
1256
- }
1257
-
1258
- // remove items, in reverse order to avoid sawing our own floor
1259
- toRemove = toRemove.sort(compare.numerically);
1260
- for (index = toRemove.length - 1; index >= 0; index--) {
1261
- index1 = toRemove[index];
1262
- var indexDiff = delta['_' + index1];
1263
- var removedValue = array.splice(index1, 1)[0];
1264
- if (indexDiff[2] === ARRAY_MOVE) {
1265
- // reinsert later
1266
- toInsert.push({
1267
- index: indexDiff[1],
1268
- value: removedValue
1269
- });
1270
- }
1271
- }
1272
-
1273
- // insert items, in reverse order to avoid moving our own floor
1274
- toInsert = toInsert.sort(compare.numericallyBy('index'));
1275
- var toInsertLength = toInsert.length;
1276
- for (index = 0; index < toInsertLength; index++) {
1277
- var insertion = toInsert[index];
1278
- array.splice(insertion.index, 0, insertion.value);
1279
- }
1280
-
1281
- // apply modifications
1282
- var toModifyLength = toModify.length;
1283
- var child = void 0;
1284
- if (toModifyLength > 0) {
1285
- for (index = 0; index < toModifyLength; index++) {
1286
- var modification = toModify[index];
1287
- child = new PatchContext(context.left[modification.index], modification.delta);
1288
- context.push(child, modification.index);
1289
- }
1290
- }
1291
- if (!context.children) {
1292
- context.setResult(context.left).exit();
1293
- return;
1294
- }
1295
- context.exit();
1296
- };
1297
- patchFilter$2.filterName = 'arrays';
1298
- var collectChildrenPatchFilter$1 = function collectChildrenPatchFilter(context) {
1299
- if (!context || !context.children) {
1300
- return;
1301
- }
1302
- if (context.delta._t !== 'a') {
1303
- return;
1304
- }
1305
- var length = context.children.length;
1306
- var child = void 0;
1307
- for (var index = 0; index < length; index++) {
1308
- child = context.children[index];
1309
- context.left[child.childName] = child.result;
1310
- }
1311
- context.setResult(context.left).exit();
1312
- };
1313
- collectChildrenPatchFilter$1.filterName = 'arraysCollectChildren';
1314
- var reverseFilter$2 = function arraysReverseFilter(context) {
1315
- if (!context.nested) {
1316
- if (context.delta[2] === ARRAY_MOVE) {
1317
- context.newName = '_' + context.delta[1];
1318
- context.setResult([context.delta[0], parseInt(context.childName.substr(1), 10), ARRAY_MOVE]).exit();
1319
- }
1320
- return;
1321
- }
1322
- if (context.delta._t !== 'a') {
1323
- return;
1324
- }
1325
- var name = void 0;
1326
- var child = void 0;
1327
- for (name in context.delta) {
1328
- if (name === '_t') {
1329
- continue;
1330
- }
1331
- child = new ReverseContext(context.delta[name]);
1332
- context.push(child, name);
1333
- }
1334
- context.exit();
1335
- };
1336
- reverseFilter$2.filterName = 'arrays';
1337
- var reverseArrayDeltaIndex = function reverseArrayDeltaIndex(delta, index, itemDelta) {
1338
- if (typeof index === 'string' && index[0] === '_') {
1339
- return parseInt(index.substr(1), 10);
1340
- } else if (isArray$2(itemDelta) && itemDelta[2] === 0) {
1341
- return '_' + index;
1342
- }
1343
- var reverseIndex = +index;
1344
- for (var deltaIndex in delta) {
1345
- var deltaItem = delta[deltaIndex];
1346
- if (isArray$2(deltaItem)) {
1347
- if (deltaItem[2] === ARRAY_MOVE) {
1348
- var moveFromIndex = parseInt(deltaIndex.substr(1), 10);
1349
- var moveToIndex = deltaItem[1];
1350
- if (moveToIndex === +index) {
1351
- return moveFromIndex;
1352
- }
1353
- if (moveFromIndex <= reverseIndex && moveToIndex > reverseIndex) {
1354
- reverseIndex++;
1355
- } else if (moveFromIndex >= reverseIndex && moveToIndex < reverseIndex) {
1356
- reverseIndex--;
1357
- }
1358
- } else if (deltaItem[2] === 0) {
1359
- var deleteIndex = parseInt(deltaIndex.substr(1), 10);
1360
- if (deleteIndex <= reverseIndex) {
1361
- reverseIndex++;
1362
- }
1363
- } else if (deltaItem.length === 1 && deltaIndex <= reverseIndex) {
1364
- reverseIndex--;
1365
- }
1366
- }
1367
- }
1368
- return reverseIndex;
1369
- };
1370
- function collectChildrenReverseFilter$1(context) {
1371
- if (!context || !context.children) {
1372
- return;
1373
- }
1374
- if (context.delta._t !== 'a') {
1375
- return;
1376
- }
1377
- var length = context.children.length;
1378
- var child = void 0;
1379
- var delta = {
1380
- _t: 'a'
1381
- };
1382
- for (var index = 0; index < length; index++) {
1383
- child = context.children[index];
1384
- var name = child.newName;
1385
- if (typeof name === 'undefined') {
1386
- name = reverseArrayDeltaIndex(context.delta, child.childName, child.result);
1387
- }
1388
- if (delta[name] !== child.result) {
1389
- delta[name] = child.result;
1390
- }
1391
- }
1392
- context.setResult(delta).exit();
1393
- }
1394
- collectChildrenReverseFilter$1.filterName = 'arraysCollectChildren';
1395
- var diffFilter$2 = function datesDiffFilter(context) {
1396
- if (context.left instanceof Date) {
1397
- if (context.right instanceof Date) {
1398
- if (context.left.getTime() !== context.right.getTime()) {
1399
- context.setResult([context.left, context.right]);
1400
- } else {
1401
- context.setResult(undefined);
1402
- }
1403
- } else {
1404
- context.setResult([context.left, context.right]);
1405
- }
1406
- context.exit();
1407
- } else if (context.right instanceof Date) {
1408
- context.setResult([context.left, context.right]).exit();
1409
- }
1410
- };
1411
- diffFilter$2.filterName = 'dates';
1412
-
1413
- /* global diff_match_patch */
1414
- var TEXT_DIFF = 2;
1415
- var DEFAULT_MIN_LENGTH = 60;
1416
- var cachedDiffPatch = null;
1417
- var getDiffMatchPatch = function getDiffMatchPatch(required) {
1418
- /* jshint camelcase: false */
1419
-
1420
- if (!cachedDiffPatch) {
1421
- var instance = void 0;
1422
- /* eslint-disable camelcase, new-cap */
1423
- if (typeof diff_match_patch !== 'undefined') {
1424
- // already loaded, probably a browser
1425
- instance = typeof diff_match_patch === 'function' ? new diff_match_patch() : new diff_match_patch.diff_match_patch();
1426
- } else if (dmp__default["default"]) {
1427
- try {
1428
- instance = dmp__default["default"] && new dmp__default["default"]();
1429
- } catch (err) {
1430
- instance = null;
1431
- }
1432
- }
1433
- /* eslint-enable camelcase, new-cap */
1434
- if (!instance) {
1435
- if (!required) {
1436
- return null;
1437
- }
1438
- var error = new Error('text diff_match_patch library not found');
1439
- // eslint-disable-next-line camelcase
1440
- error.diff_match_patch_not_found = true;
1441
- throw error;
1442
- }
1443
- cachedDiffPatch = {
1444
- diff: function diff(txt1, txt2) {
1445
- return instance.patch_toText(instance.patch_make(txt1, txt2));
1446
- },
1447
- patch: function patch(txt1, _patch) {
1448
- var results = instance.patch_apply(instance.patch_fromText(_patch), txt1);
1449
- for (var i = 0; i < results[1].length; i++) {
1450
- if (!results[1][i]) {
1451
- var _error = new Error('text patch failed');
1452
- _error.textPatchFailed = true;
1453
- }
1454
- }
1455
- return results[0];
1456
- }
1457
- };
1458
- }
1459
- return cachedDiffPatch;
1460
- };
1461
- var diffFilter$3 = function textsDiffFilter(context) {
1462
- if (context.leftType !== 'string') {
1463
- return;
1464
- }
1465
- var minLength = context.options && context.options.textDiff && context.options.textDiff.minLength || DEFAULT_MIN_LENGTH;
1466
- if (context.left.length < minLength || context.right.length < minLength) {
1467
- context.setResult([context.left, context.right]).exit();
1468
- return;
1469
- }
1470
- // large text, try to use a text-diff algorithm
1471
- var diffMatchPatch = getDiffMatchPatch();
1472
- if (!diffMatchPatch) {
1473
- // diff-match-patch library not available,
1474
- // fallback to regular string replace
1475
- context.setResult([context.left, context.right]).exit();
1476
- return;
1477
- }
1478
- var diff = diffMatchPatch.diff;
1479
- context.setResult([diff(context.left, context.right), 0, TEXT_DIFF]).exit();
1480
- };
1481
- diffFilter$3.filterName = 'texts';
1482
- var patchFilter$3 = function textsPatchFilter(context) {
1483
- if (context.nested) {
1484
- return;
1485
- }
1486
- if (context.delta[2] !== TEXT_DIFF) {
1487
- return;
1488
- }
1489
-
1490
- // text-diff, use a text-patch algorithm
1491
- var patch = getDiffMatchPatch(true).patch;
1492
- context.setResult(patch(context.left, context.delta[0])).exit();
1493
- };
1494
- patchFilter$3.filterName = 'texts';
1495
- var textDeltaReverse = function textDeltaReverse(delta) {
1496
- var i = void 0;
1497
- var l = void 0;
1498
- var lines = void 0;
1499
- var line = void 0;
1500
- var lineTmp = void 0;
1501
- var header = null;
1502
- var headerRegex = /^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/;
1503
- var lineHeader = void 0;
1504
- lines = delta.split('\n');
1505
- for (i = 0, l = lines.length; i < l; i++) {
1506
- line = lines[i];
1507
- var lineStart = line.slice(0, 1);
1508
- if (lineStart === '@') {
1509
- header = headerRegex.exec(line);
1510
- lineHeader = i;
1511
-
1512
- // fix header
1513
- lines[lineHeader] = '@@ -' + header[3] + ',' + header[4] + ' +' + header[1] + ',' + header[2] + ' @@';
1514
- } else if (lineStart === '+') {
1515
- lines[i] = '-' + lines[i].slice(1);
1516
- if (lines[i - 1].slice(0, 1) === '+') {
1517
- // swap lines to keep default order (-+)
1518
- lineTmp = lines[i];
1519
- lines[i] = lines[i - 1];
1520
- lines[i - 1] = lineTmp;
1521
- }
1522
- } else if (lineStart === '-') {
1523
- lines[i] = '+' + lines[i].slice(1);
1524
- }
1525
- }
1526
- return lines.join('\n');
1527
- };
1528
- var reverseFilter$3 = function textsReverseFilter(context) {
1529
- if (context.nested) {
1530
- return;
1531
- }
1532
- if (context.delta[2] !== TEXT_DIFF) {
1533
- return;
1534
- }
1535
-
1536
- // text-diff, use a text-diff algorithm
1537
- context.setResult([textDeltaReverse(context.delta[0]), 0, TEXT_DIFF]).exit();
1538
- };
1539
- reverseFilter$3.filterName = 'texts';
1540
- var DiffPatcher = function () {
1541
- function DiffPatcher(options) {
1542
- classCallCheck(this, DiffPatcher);
1543
- this.processor = new Processor(options);
1544
- this.processor.pipe(new Pipe('diff').append(collectChildrenDiffFilter, diffFilter, diffFilter$2, diffFilter$3, objectsDiffFilter, diffFilter$1).shouldHaveResult());
1545
- this.processor.pipe(new Pipe('patch').append(collectChildrenPatchFilter, collectChildrenPatchFilter$1, patchFilter, patchFilter$3, patchFilter$1, patchFilter$2).shouldHaveResult());
1546
- this.processor.pipe(new Pipe('reverse').append(collectChildrenReverseFilter, collectChildrenReverseFilter$1, reverseFilter, reverseFilter$3, reverseFilter$1, reverseFilter$2).shouldHaveResult());
1547
- }
1548
- createClass(DiffPatcher, [{
1549
- key: 'options',
1550
- value: function options() {
1551
- var _processor;
1552
- return (_processor = this.processor).options.apply(_processor, arguments);
1553
- }
1554
- }, {
1555
- key: 'diff',
1556
- value: function diff(left, right) {
1557
- return this.processor.process(new DiffContext(left, right));
1558
- }
1559
- }, {
1560
- key: 'patch',
1561
- value: function patch(left, delta) {
1562
- return this.processor.process(new PatchContext(left, delta));
1563
- }
1564
- }, {
1565
- key: 'reverse',
1566
- value: function reverse(delta) {
1567
- return this.processor.process(new ReverseContext(delta));
1568
- }
1569
- }, {
1570
- key: 'unpatch',
1571
- value: function unpatch(right, delta) {
1572
- return this.patch(right, this.reverse(delta));
1573
- }
1574
- }, {
1575
- key: 'clone',
1576
- value: function clone$$1(value) {
1577
- return clone$1(value);
1578
- }
1579
- }]);
1580
- return DiffPatcher;
1581
- }();
1582
- var isArray$3 = typeof Array.isArray === 'function' ? Array.isArray : function (a) {
1583
- return a instanceof Array;
1584
- };
1585
- var getObjectKeys = typeof Object.keys === 'function' ? function (obj) {
1586
- return Object.keys(obj);
1587
- } : function (obj) {
1588
- var names = [];
1589
- for (var property in obj) {
1590
- if (Object.prototype.hasOwnProperty.call(obj, property)) {
1591
- names.push(property);
1592
- }
1593
- }
1594
- return names;
1595
- };
1596
- var trimUnderscore = function trimUnderscore(str) {
1597
- if (str.substr(0, 1) === '_') {
1598
- return str.slice(1);
1599
- }
1600
- return str;
1601
- };
1602
- var arrayKeyToSortNumber = function arrayKeyToSortNumber(key) {
1603
- if (key === '_t') {
1604
- return -1;
1605
- } else {
1606
- if (key.substr(0, 1) === '_') {
1607
- return parseInt(key.slice(1), 10);
1608
- } else {
1609
- return parseInt(key, 10) + 0.1;
1610
- }
1611
- }
1612
- };
1613
- var arrayKeyComparer = function arrayKeyComparer(key1, key2) {
1614
- return arrayKeyToSortNumber(key1) - arrayKeyToSortNumber(key2);
1615
- };
1616
- var BaseFormatter = function () {
1617
- function BaseFormatter() {
1618
- classCallCheck(this, BaseFormatter);
1619
- }
1620
- createClass(BaseFormatter, [{
1621
- key: 'format',
1622
- value: function format(delta, left) {
1623
- var context = {};
1624
- this.prepareContext(context);
1625
- this.recurse(context, delta, left);
1626
- return this.finalize(context);
1627
- }
1628
- }, {
1629
- key: 'prepareContext',
1630
- value: function prepareContext(context) {
1631
- context.buffer = [];
1632
- context.out = function () {
1633
- var _buffer;
1634
- (_buffer = this.buffer).push.apply(_buffer, arguments);
1635
- };
1636
- }
1637
- }, {
1638
- key: 'typeFormattterNotFound',
1639
- value: function typeFormattterNotFound(context, deltaType) {
1640
- throw new Error('cannot format delta type: ' + deltaType);
1641
- }
1642
- }, {
1643
- key: 'typeFormattterErrorFormatter',
1644
- value: function typeFormattterErrorFormatter(context, err) {
1645
- return err.toString();
1646
- }
1647
- }, {
1648
- key: 'finalize',
1649
- value: function finalize(_ref) {
1650
- var buffer = _ref.buffer;
1651
- if (isArray$3(buffer)) {
1652
- return buffer.join('');
1653
- }
1654
- }
1655
- }, {
1656
- key: 'recurse',
1657
- value: function recurse(context, delta, left, key, leftKey, movedFrom, isLast) {
1658
- var useMoveOriginHere = delta && movedFrom;
1659
- var leftValue = useMoveOriginHere ? movedFrom.value : left;
1660
- if (typeof delta === 'undefined' && typeof key === 'undefined') {
1661
- return undefined;
1662
- }
1663
- var type = this.getDeltaType(delta, movedFrom);
1664
- var nodeType = type === 'node' ? delta._t === 'a' ? 'array' : 'object' : '';
1665
- if (typeof key !== 'undefined') {
1666
- this.nodeBegin(context, key, leftKey, type, nodeType, isLast);
1667
- } else {
1668
- this.rootBegin(context, type, nodeType);
1669
- }
1670
- var typeFormattter = void 0;
1671
- try {
1672
- typeFormattter = this['format_' + type] || this.typeFormattterNotFound(context, type);
1673
- typeFormattter.call(this, context, delta, leftValue, key, leftKey, movedFrom);
1674
- } catch (err) {
1675
- this.typeFormattterErrorFormatter(context, err, delta, leftValue, key, leftKey, movedFrom);
1676
- if (typeof console !== 'undefined' && console.error) {
1677
- console.error(err.stack);
1678
- }
1679
- }
1680
- if (typeof key !== 'undefined') {
1681
- this.nodeEnd(context, key, leftKey, type, nodeType, isLast);
1682
- } else {
1683
- this.rootEnd(context, type, nodeType);
1684
- }
1685
- }
1686
- }, {
1687
- key: 'formatDeltaChildren',
1688
- value: function formatDeltaChildren(context, delta, left) {
1689
- var self = this;
1690
- this.forEachDeltaKey(delta, left, function (key, leftKey, movedFrom, isLast) {
1691
- self.recurse(context, delta[key], left ? left[leftKey] : undefined, key, leftKey, movedFrom, isLast);
1692
- });
1693
- }
1694
- }, {
1695
- key: 'forEachDeltaKey',
1696
- value: function forEachDeltaKey(delta, left, fn) {
1697
- var keys = getObjectKeys(delta);
1698
- var arrayKeys = delta._t === 'a';
1699
- var moveDestinations = {};
1700
- var name = void 0;
1701
- if (typeof left !== 'undefined') {
1702
- for (name in left) {
1703
- if (Object.prototype.hasOwnProperty.call(left, name)) {
1704
- if (typeof delta[name] === 'undefined' && (!arrayKeys || typeof delta['_' + name] === 'undefined')) {
1705
- keys.push(name);
1706
- }
1707
- }
1708
- }
1709
- }
1710
- // look for move destinations
1711
- for (name in delta) {
1712
- if (Object.prototype.hasOwnProperty.call(delta, name)) {
1713
- var value = delta[name];
1714
- if (isArray$3(value) && value[2] === 3) {
1715
- moveDestinations[value[1].toString()] = {
1716
- key: name,
1717
- value: left && left[parseInt(name.substr(1))]
1718
- };
1719
- if (this.includeMoveDestinations !== false) {
1720
- if (typeof left === 'undefined' && typeof delta[value[1]] === 'undefined') {
1721
- keys.push(value[1].toString());
1722
- }
1723
- }
1724
- }
1725
- }
1726
- }
1727
- if (arrayKeys) {
1728
- keys.sort(arrayKeyComparer);
1729
- } else {
1730
- keys.sort();
1731
- }
1732
- for (var index = 0, length = keys.length; index < length; index++) {
1733
- var key = keys[index];
1734
- if (arrayKeys && key === '_t') {
1735
- continue;
1736
- }
1737
- var leftKey = arrayKeys ? typeof key === 'number' ? key : parseInt(trimUnderscore(key), 10) : key;
1738
- var isLast = index === length - 1;
1739
- fn(key, leftKey, moveDestinations[leftKey], isLast);
1740
- }
1741
- }
1742
- }, {
1743
- key: 'getDeltaType',
1744
- value: function getDeltaType(delta, movedFrom) {
1745
- if (typeof delta === 'undefined') {
1746
- if (typeof movedFrom !== 'undefined') {
1747
- return 'movedestination';
1748
- }
1749
- return 'unchanged';
1750
- }
1751
- if (isArray$3(delta)) {
1752
- if (delta.length === 1) {
1753
- return 'added';
1754
- }
1755
- if (delta.length === 2) {
1756
- return 'modified';
1757
- }
1758
- if (delta.length === 3 && delta[2] === 0) {
1759
- return 'deleted';
1760
- }
1761
- if (delta.length === 3 && delta[2] === 2) {
1762
- return 'textdiff';
1763
- }
1764
- if (delta.length === 3 && delta[2] === 3) {
1765
- return 'moved';
1766
- }
1767
- } else if ((typeof delta === 'undefined' ? 'undefined' : _typeof(delta)) === 'object') {
1768
- return 'node';
1769
- }
1770
- return 'unknown';
1771
- }
1772
- }, {
1773
- key: 'parseTextDiff',
1774
- value: function parseTextDiff(value) {
1775
- var output = [];
1776
- var lines = value.split('\n@@ ');
1777
- for (var i = 0, l = lines.length; i < l; i++) {
1778
- var line = lines[i];
1779
- var lineOutput = {
1780
- pieces: []
1781
- };
1782
- var location = /^(?:@@ )?[-+]?(\d+),(\d+)/.exec(line).slice(1);
1783
- lineOutput.location = {
1784
- line: location[0],
1785
- chr: location[1]
1786
- };
1787
- var pieces = line.split('\n').slice(1);
1788
- for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
1789
- var piece = pieces[pieceIndex];
1790
- if (!piece.length) {
1791
- continue;
1792
- }
1793
- var pieceOutput = {
1794
- type: 'context'
1795
- };
1796
- if (piece.substr(0, 1) === '+') {
1797
- pieceOutput.type = 'added';
1798
- } else if (piece.substr(0, 1) === '-') {
1799
- pieceOutput.type = 'deleted';
1800
- }
1801
- pieceOutput.text = piece.slice(1);
1802
- lineOutput.pieces.push(pieceOutput);
1803
- }
1804
- output.push(lineOutput);
1805
- }
1806
- return output;
1807
- }
1808
- }]);
1809
- return BaseFormatter;
1810
- }();
1811
- var base = Object.freeze({
1812
- default: BaseFormatter
1813
- });
1814
- var HtmlFormatter = function (_BaseFormatter) {
1815
- inherits(HtmlFormatter, _BaseFormatter);
1816
- function HtmlFormatter() {
1817
- classCallCheck(this, HtmlFormatter);
1818
- return possibleConstructorReturn(this, (HtmlFormatter.__proto__ || Object.getPrototypeOf(HtmlFormatter)).apply(this, arguments));
1819
- }
1820
- createClass(HtmlFormatter, [{
1821
- key: 'typeFormattterErrorFormatter',
1822
- value: function typeFormattterErrorFormatter(context, err) {
1823
- context.out('<pre class="jsondiffpatch-error">' + err + '</pre>');
1824
- }
1825
- }, {
1826
- key: 'formatValue',
1827
- value: function formatValue(context, value) {
1828
- context.out('<pre>' + htmlEscape(JSON.stringify(value, null, 2)) + '</pre>');
1829
- }
1830
- }, {
1831
- key: 'formatTextDiffString',
1832
- value: function formatTextDiffString(context, value) {
1833
- var lines = this.parseTextDiff(value);
1834
- context.out('<ul class="jsondiffpatch-textdiff">');
1835
- for (var i = 0, l = lines.length; i < l; i++) {
1836
- var line = lines[i];
1837
- context.out('<li><div class="jsondiffpatch-textdiff-location">' + ('<span class="jsondiffpatch-textdiff-line-number">' + line.location.line + '</span><span class="jsondiffpatch-textdiff-char">' + line.location.chr + '</span></div><div class="jsondiffpatch-textdiff-line">'));
1838
- var pieces = line.pieces;
1839
- for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
1840
- /* global decodeURI */
1841
- var piece = pieces[pieceIndex];
1842
- context.out('<span class="jsondiffpatch-textdiff-' + piece.type + '">' + htmlEscape(decodeURI(piece.text)) + '</span>');
1843
- }
1844
- context.out('</div></li>');
1845
- }
1846
- context.out('</ul>');
1847
- }
1848
- }, {
1849
- key: 'rootBegin',
1850
- value: function rootBegin(context, type, nodeType) {
1851
- var nodeClass = 'jsondiffpatch-' + type + (nodeType ? ' jsondiffpatch-child-node-type-' + nodeType : '');
1852
- context.out('<div class="jsondiffpatch-delta ' + nodeClass + '">');
1853
- }
1854
- }, {
1855
- key: 'rootEnd',
1856
- value: function rootEnd(context) {
1857
- context.out('</div>' + (context.hasArrows ? '<script type="text/javascript">setTimeout(' + (adjustArrows.toString() + ',10);</script>') : ''));
1858
- }
1859
- }, {
1860
- key: 'nodeBegin',
1861
- value: function nodeBegin(context, key, leftKey, type, nodeType) {
1862
- var nodeClass = 'jsondiffpatch-' + type + (nodeType ? ' jsondiffpatch-child-node-type-' + nodeType : '');
1863
- context.out('<li class="' + nodeClass + '" data-key="' + leftKey + '">' + ('<div class="jsondiffpatch-property-name">' + leftKey + '</div>'));
1864
- }
1865
- }, {
1866
- key: 'nodeEnd',
1867
- value: function nodeEnd(context) {
1868
- context.out('</li>');
1869
- }
1870
-
1871
- /* jshint camelcase: false */
1872
- /* eslint-disable camelcase */
1873
- }, {
1874
- key: 'format_unchanged',
1875
- value: function format_unchanged(context, delta, left) {
1876
- if (typeof left === 'undefined') {
1877
- return;
1878
- }
1879
- context.out('<div class="jsondiffpatch-value">');
1880
- this.formatValue(context, left);
1881
- context.out('</div>');
1882
- }
1883
- }, {
1884
- key: 'format_movedestination',
1885
- value: function format_movedestination(context, delta, left) {
1886
- if (typeof left === 'undefined') {
1887
- return;
1888
- }
1889
- context.out('<div class="jsondiffpatch-value">');
1890
- this.formatValue(context, left);
1891
- context.out('</div>');
1892
- }
1893
- }, {
1894
- key: 'format_node',
1895
- value: function format_node(context, delta, left) {
1896
- // recurse
1897
- var nodeType = delta._t === 'a' ? 'array' : 'object';
1898
- context.out('<ul class="jsondiffpatch-node jsondiffpatch-node-type-' + nodeType + '">');
1899
- this.formatDeltaChildren(context, delta, left);
1900
- context.out('</ul>');
1901
- }
1902
- }, {
1903
- key: 'format_added',
1904
- value: function format_added(context, delta) {
1905
- context.out('<div class="jsondiffpatch-value">');
1906
- this.formatValue(context, delta[0]);
1907
- context.out('</div>');
1908
- }
1909
- }, {
1910
- key: 'format_modified',
1911
- value: function format_modified(context, delta) {
1912
- context.out('<div class="jsondiffpatch-value jsondiffpatch-left-value">');
1913
- this.formatValue(context, delta[0]);
1914
- context.out('</div>' + '<div class="jsondiffpatch-value jsondiffpatch-right-value">');
1915
- this.formatValue(context, delta[1]);
1916
- context.out('</div>');
1917
- }
1918
- }, {
1919
- key: 'format_deleted',
1920
- value: function format_deleted(context, delta) {
1921
- context.out('<div class="jsondiffpatch-value">');
1922
- this.formatValue(context, delta[0]);
1923
- context.out('</div>');
1924
- }
1925
- }, {
1926
- key: 'format_moved',
1927
- value: function format_moved(context, delta) {
1928
- context.out('<div class="jsondiffpatch-value">');
1929
- this.formatValue(context, delta[0]);
1930
- context.out('</div><div class="jsondiffpatch-moved-destination">' + delta[1] + '</div>');
1931
-
1932
- // draw an SVG arrow from here to move destination
1933
- context.out( /* jshint multistr: true */
1934
- '<div class="jsondiffpatch-arrow" ' + 'style="position: relative; left: -34px;">\n <svg width="30" height="60" ' + 'style="position: absolute; display: none;">\n <defs>\n <marker id="markerArrow" markerWidth="8" markerHeight="8"\n refx="2" refy="4"\n orient="auto" markerUnits="userSpaceOnUse">\n <path d="M1,1 L1,7 L7,4 L1,1" style="fill: #339;" />\n </marker>\n </defs>\n <path d="M30,0 Q-10,25 26,50"\n style="stroke: #88f; stroke-width: 2px; fill: none; ' + 'stroke-opacity: 0.5; marker-end: url(#markerArrow);"\n ></path>\n </svg>\n </div>');
1935
- context.hasArrows = true;
1936
- }
1937
- }, {
1938
- key: 'format_textdiff',
1939
- value: function format_textdiff(context, delta) {
1940
- context.out('<div class="jsondiffpatch-value">');
1941
- this.formatTextDiffString(context, delta[0]);
1942
- context.out('</div>');
1943
- }
1944
- }]);
1945
- return HtmlFormatter;
1946
- }(BaseFormatter);
1947
- function htmlEscape(text) {
1948
- var html = text;
1949
- var replacements = [[/&/g, '&amp;'], [/</g, '&lt;'], [/>/g, '&gt;'], [/'/g, '&apos;'], [/"/g, '&quot;']];
1950
- for (var i = 0; i < replacements.length; i++) {
1951
- html = html.replace(replacements[i][0], replacements[i][1]);
1952
- }
1953
- return html;
1954
- }
1955
- var adjustArrows = function jsondiffpatchHtmlFormatterAdjustArrows(nodeArg) {
1956
- var node = nodeArg || document;
1957
- var getElementText = function getElementText(_ref) {
1958
- var textContent = _ref.textContent,
1959
- innerText = _ref.innerText;
1960
- return textContent || innerText;
1961
- };
1962
- var eachByQuery = function eachByQuery(el, query, fn) {
1963
- var elems = el.querySelectorAll(query);
1964
- for (var i = 0, l = elems.length; i < l; i++) {
1965
- fn(elems[i]);
1966
- }
1967
- };
1968
- var eachChildren = function eachChildren(_ref2, fn) {
1969
- var children = _ref2.children;
1970
- for (var i = 0, l = children.length; i < l; i++) {
1971
- fn(children[i], i);
1972
- }
1973
- };
1974
- eachByQuery(node, '.jsondiffpatch-arrow', function (_ref3) {
1975
- var parentNode = _ref3.parentNode,
1976
- children = _ref3.children,
1977
- style = _ref3.style;
1978
- var arrowParent = parentNode;
1979
- var svg = children[0];
1980
- var path = svg.children[1];
1981
- svg.style.display = 'none';
1982
- var destination = getElementText(arrowParent.querySelector('.jsondiffpatch-moved-destination'));
1983
- var container = arrowParent.parentNode;
1984
- var destinationElem = void 0;
1985
- eachChildren(container, function (child) {
1986
- if (child.getAttribute('data-key') === destination) {
1987
- destinationElem = child;
1988
- }
1989
- });
1990
- if (!destinationElem) {
1991
- return;
1992
- }
1993
- try {
1994
- var distance = destinationElem.offsetTop - arrowParent.offsetTop;
1995
- svg.setAttribute('height', Math.abs(distance) + 6);
1996
- style.top = -8 + (distance > 0 ? 0 : distance) + 'px';
1997
- var curve = distance > 0 ? 'M30,0 Q-10,' + Math.round(distance / 2) + ' 26,' + (distance - 4) : 'M30,' + -distance + ' Q-10,' + Math.round(-distance / 2) + ' 26,4';
1998
- path.setAttribute('d', curve);
1999
- svg.style.display = '';
2000
- } catch (err) {}
2001
- });
2002
- };
2003
-
2004
- /* jshint camelcase: true */
2005
- /* eslint-enable camelcase */
2006
-
2007
- var showUnchanged = function showUnchanged(show, node, delay) {
2008
- var el = node || document.body;
2009
- var prefix = 'jsondiffpatch-unchanged-';
2010
- var classes = {
2011
- showing: prefix + 'showing',
2012
- hiding: prefix + 'hiding',
2013
- visible: prefix + 'visible',
2014
- hidden: prefix + 'hidden'
2015
- };
2016
- var list = el.classList;
2017
- if (!list) {
2018
- return;
2019
- }
2020
- if (!delay) {
2021
- list.remove(classes.showing);
2022
- list.remove(classes.hiding);
2023
- list.remove(classes.visible);
2024
- list.remove(classes.hidden);
2025
- if (show === false) {
2026
- list.add(classes.hidden);
2027
- }
2028
- return;
2029
- }
2030
- if (show === false) {
2031
- list.remove(classes.showing);
2032
- list.add(classes.visible);
2033
- setTimeout(function () {
2034
- list.add(classes.hiding);
2035
- }, 10);
2036
- } else {
2037
- list.remove(classes.hiding);
2038
- list.add(classes.showing);
2039
- list.remove(classes.hidden);
2040
- }
2041
- var intervalId = setInterval(function () {
2042
- adjustArrows(el);
2043
- }, 100);
2044
- setTimeout(function () {
2045
- list.remove(classes.showing);
2046
- list.remove(classes.hiding);
2047
- if (show === false) {
2048
- list.add(classes.hidden);
2049
- list.remove(classes.visible);
2050
- } else {
2051
- list.add(classes.visible);
2052
- list.remove(classes.hidden);
2053
- }
2054
- setTimeout(function () {
2055
- list.remove(classes.visible);
2056
- clearInterval(intervalId);
2057
- }, delay + 400);
2058
- }, delay);
2059
- };
2060
- var hideUnchanged = function hideUnchanged(node, delay) {
2061
- return showUnchanged(false, node, delay);
2062
- };
2063
- var defaultInstance = void 0;
2064
- function format(delta, left) {
2065
- if (!defaultInstance) {
2066
- defaultInstance = new HtmlFormatter();
2067
- }
2068
- return defaultInstance.format(delta, left);
2069
- }
2070
- var html = Object.freeze({
2071
- showUnchanged: showUnchanged,
2072
- hideUnchanged: hideUnchanged,
2073
- default: HtmlFormatter,
2074
- format: format
2075
- });
2076
- var AnnotatedFormatter = function (_BaseFormatter) {
2077
- inherits(AnnotatedFormatter, _BaseFormatter);
2078
- function AnnotatedFormatter() {
2079
- classCallCheck(this, AnnotatedFormatter);
2080
- var _this = possibleConstructorReturn(this, (AnnotatedFormatter.__proto__ || Object.getPrototypeOf(AnnotatedFormatter)).call(this));
2081
- _this.includeMoveDestinations = false;
2082
- return _this;
2083
- }
2084
- createClass(AnnotatedFormatter, [{
2085
- key: 'prepareContext',
2086
- value: function prepareContext(context) {
2087
- get(AnnotatedFormatter.prototype.__proto__ || Object.getPrototypeOf(AnnotatedFormatter.prototype), 'prepareContext', this).call(this, context);
2088
- context.indent = function (levels) {
2089
- this.indentLevel = (this.indentLevel || 0) + (typeof levels === 'undefined' ? 1 : levels);
2090
- this.indentPad = new Array(this.indentLevel + 1).join('&nbsp;&nbsp;');
2091
- };
2092
- context.row = function (json, htmlNote) {
2093
- context.out('<tr><td style="white-space: nowrap;">' + '<pre class="jsondiffpatch-annotated-indent"' + ' style="display: inline-block">');
2094
- context.out(context.indentPad);
2095
- context.out('</pre><pre style="display: inline-block">');
2096
- context.out(json);
2097
- context.out('</pre></td><td class="jsondiffpatch-delta-note"><div>');
2098
- context.out(htmlNote);
2099
- context.out('</div></td></tr>');
2100
- };
2101
- }
2102
- }, {
2103
- key: 'typeFormattterErrorFormatter',
2104
- value: function typeFormattterErrorFormatter(context, err) {
2105
- context.row('', '<pre class="jsondiffpatch-error">' + err + '</pre>');
2106
- }
2107
- }, {
2108
- key: 'formatTextDiffString',
2109
- value: function formatTextDiffString(context, value) {
2110
- var lines = this.parseTextDiff(value);
2111
- context.out('<ul class="jsondiffpatch-textdiff">');
2112
- for (var i = 0, l = lines.length; i < l; i++) {
2113
- var line = lines[i];
2114
- context.out('<li><div class="jsondiffpatch-textdiff-location">' + ('<span class="jsondiffpatch-textdiff-line-number">' + line.location.line + '</span><span class="jsondiffpatch-textdiff-char">' + line.location.chr + '</span></div><div class="jsondiffpatch-textdiff-line">'));
2115
- var pieces = line.pieces;
2116
- for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
2117
- var piece = pieces[pieceIndex];
2118
- context.out('<span class="jsondiffpatch-textdiff-' + piece.type + '">' + piece.text + '</span>');
2119
- }
2120
- context.out('</div></li>');
2121
- }
2122
- context.out('</ul>');
2123
- }
2124
- }, {
2125
- key: 'rootBegin',
2126
- value: function rootBegin(context, type, nodeType) {
2127
- context.out('<table class="jsondiffpatch-annotated-delta">');
2128
- if (type === 'node') {
2129
- context.row('{');
2130
- context.indent();
2131
- }
2132
- if (nodeType === 'array') {
2133
- context.row('"_t": "a",', 'Array delta (member names indicate array indices)');
2134
- }
2135
- }
2136
- }, {
2137
- key: 'rootEnd',
2138
- value: function rootEnd(context, type) {
2139
- if (type === 'node') {
2140
- context.indent(-1);
2141
- context.row('}');
2142
- }
2143
- context.out('</table>');
2144
- }
2145
- }, {
2146
- key: 'nodeBegin',
2147
- value: function nodeBegin(context, key, leftKey, type, nodeType) {
2148
- context.row('&quot;' + key + '&quot;: {');
2149
- if (type === 'node') {
2150
- context.indent();
2151
- }
2152
- if (nodeType === 'array') {
2153
- context.row('"_t": "a",', 'Array delta (member names indicate array indices)');
2154
- }
2155
- }
2156
- }, {
2157
- key: 'nodeEnd',
2158
- value: function nodeEnd(context, key, leftKey, type, nodeType, isLast) {
2159
- if (type === 'node') {
2160
- context.indent(-1);
2161
- }
2162
- context.row('}' + (isLast ? '' : ','));
2163
- }
2164
-
2165
- /* jshint camelcase: false */
2166
-
2167
- /* eslint-disable camelcase */
2168
- }, {
2169
- key: 'format_unchanged',
2170
- value: function format_unchanged() {}
2171
- }, {
2172
- key: 'format_movedestination',
2173
- value: function format_movedestination() {}
2174
- }, {
2175
- key: 'format_node',
2176
- value: function format_node(context, delta, left) {
2177
- // recurse
2178
- this.formatDeltaChildren(context, delta, left);
2179
- }
2180
- }]);
2181
- return AnnotatedFormatter;
2182
- }(BaseFormatter);
2183
-
2184
- /* eslint-enable camelcase */
2185
-
2186
- var wrapPropertyName = function wrapPropertyName(name) {
2187
- return '<pre style="display:inline-block">&quot;' + name + '&quot;</pre>';
2188
- };
2189
- var deltaAnnotations = {
2190
- added: function added(delta, left, key, leftKey) {
2191
- var formatLegend = ' <pre>([newValue])</pre>';
2192
- if (typeof leftKey === 'undefined') {
2193
- return 'new value' + formatLegend;
2194
- }
2195
- if (typeof leftKey === 'number') {
2196
- return 'insert at index ' + leftKey + formatLegend;
2197
- }
2198
- return 'add property ' + wrapPropertyName(leftKey) + formatLegend;
2199
- },
2200
- modified: function modified(delta, left, key, leftKey) {
2201
- var formatLegend = ' <pre>([previousValue, newValue])</pre>';
2202
- if (typeof leftKey === 'undefined') {
2203
- return 'modify value' + formatLegend;
2204
- }
2205
- if (typeof leftKey === 'number') {
2206
- return 'modify at index ' + leftKey + formatLegend;
2207
- }
2208
- return 'modify property ' + wrapPropertyName(leftKey) + formatLegend;
2209
- },
2210
- deleted: function deleted(delta, left, key, leftKey) {
2211
- var formatLegend = ' <pre>([previousValue, 0, 0])</pre>';
2212
- if (typeof leftKey === 'undefined') {
2213
- return 'delete value' + formatLegend;
2214
- }
2215
- if (typeof leftKey === 'number') {
2216
- return 'remove index ' + leftKey + formatLegend;
2217
- }
2218
- return 'delete property ' + wrapPropertyName(leftKey) + formatLegend;
2219
- },
2220
- moved: function moved(delta, left, key, leftKey) {
2221
- return 'move from <span title="(position to remove at original state)">' + ('index ' + leftKey + '</span> to <span title="(position to insert at final') + (' state)">index ' + delta[1] + '</span>');
2222
- },
2223
- textdiff: function textdiff(delta, left, key, leftKey) {
2224
- var location = typeof leftKey === 'undefined' ? '' : typeof leftKey === 'number' ? ' at index ' + leftKey : ' at property ' + wrapPropertyName(leftKey);
2225
- return 'text diff' + location + ', format is <a href="https://code.google.com/' + 'p/google-diff-match-patch/wiki/Unidiff">a variation of Unidiff</a>';
2226
- }
2227
- };
2228
- var formatAnyChange = function formatAnyChange(context, delta) {
2229
- var deltaType = this.getDeltaType(delta);
2230
- var annotator = deltaAnnotations[deltaType];
2231
- var htmlNote = annotator && annotator.apply(annotator, Array.prototype.slice.call(arguments, 1));
2232
- var json = JSON.stringify(delta, null, 2);
2233
- if (deltaType === 'textdiff') {
2234
- // split text diffs lines
2235
- json = json.split('\\n').join('\\n"+\n "');
2236
- }
2237
- context.indent();
2238
- context.row(json, htmlNote);
2239
- context.indent(-1);
2240
- };
2241
-
2242
- /* eslint-disable camelcase */
2243
- AnnotatedFormatter.prototype.format_added = formatAnyChange;
2244
- AnnotatedFormatter.prototype.format_modified = formatAnyChange;
2245
- AnnotatedFormatter.prototype.format_deleted = formatAnyChange;
2246
- AnnotatedFormatter.prototype.format_moved = formatAnyChange;
2247
- AnnotatedFormatter.prototype.format_textdiff = formatAnyChange;
2248
- var defaultInstance$1 = void 0;
2249
- function format$1(delta, left) {
2250
- if (!defaultInstance$1) {
2251
- defaultInstance$1 = new AnnotatedFormatter();
2252
- }
2253
- return defaultInstance$1.format(delta, left);
2254
- }
2255
- var annotated = Object.freeze({
2256
- default: AnnotatedFormatter,
2257
- format: format$1
2258
- });
2259
- var OPERATIONS = {
2260
- add: 'add',
2261
- remove: 'remove',
2262
- replace: 'replace',
2263
- move: 'move'
2264
- };
2265
- var JSONFormatter = function (_BaseFormatter) {
2266
- inherits(JSONFormatter, _BaseFormatter);
2267
- function JSONFormatter() {
2268
- classCallCheck(this, JSONFormatter);
2269
- var _this = possibleConstructorReturn(this, (JSONFormatter.__proto__ || Object.getPrototypeOf(JSONFormatter)).call(this));
2270
- _this.includeMoveDestinations = true;
2271
- return _this;
2272
- }
2273
- createClass(JSONFormatter, [{
2274
- key: 'prepareContext',
2275
- value: function prepareContext(context) {
2276
- get(JSONFormatter.prototype.__proto__ || Object.getPrototypeOf(JSONFormatter.prototype), 'prepareContext', this).call(this, context);
2277
- context.result = [];
2278
- context.path = [];
2279
- context.pushCurrentOp = function (obj) {
2280
- var op = obj.op,
2281
- value = obj.value;
2282
- var val = {
2283
- op: op,
2284
- path: this.currentPath()
2285
- };
2286
- if (typeof value !== 'undefined') {
2287
- val.value = value;
2288
- }
2289
- this.result.push(val);
2290
- };
2291
- context.pushMoveOp = function (to) {
2292
- var from = this.currentPath();
2293
- this.result.push({
2294
- op: OPERATIONS.move,
2295
- from: from,
2296
- path: this.toPath(to)
2297
- });
2298
- };
2299
- context.currentPath = function () {
2300
- return '/' + this.path.join('/');
2301
- };
2302
- context.toPath = function (toPath) {
2303
- var to = this.path.slice();
2304
- to[to.length - 1] = toPath;
2305
- return '/' + to.join('/');
2306
- };
2307
- }
2308
- }, {
2309
- key: 'typeFormattterErrorFormatter',
2310
- value: function typeFormattterErrorFormatter(context, err) {
2311
- context.out('[ERROR] ' + err);
2312
- }
2313
- }, {
2314
- key: 'rootBegin',
2315
- value: function rootBegin() {}
2316
- }, {
2317
- key: 'rootEnd',
2318
- value: function rootEnd() {}
2319
- }, {
2320
- key: 'nodeBegin',
2321
- value: function nodeBegin(_ref, key, leftKey) {
2322
- var path = _ref.path;
2323
- path.push(leftKey);
2324
- }
2325
- }, {
2326
- key: 'nodeEnd',
2327
- value: function nodeEnd(_ref2) {
2328
- var path = _ref2.path;
2329
- path.pop();
2330
- }
2331
-
2332
- /* jshint camelcase: false */
2333
- /* eslint-disable camelcase */
2334
- }, {
2335
- key: 'format_unchanged',
2336
- value: function format_unchanged() {}
2337
- }, {
2338
- key: 'format_movedestination',
2339
- value: function format_movedestination() {}
2340
- }, {
2341
- key: 'format_node',
2342
- value: function format_node(context, delta, left) {
2343
- this.formatDeltaChildren(context, delta, left);
2344
- }
2345
- }, {
2346
- key: 'format_added',
2347
- value: function format_added(context, delta) {
2348
- context.pushCurrentOp({
2349
- op: OPERATIONS.add,
2350
- value: delta[0]
2351
- });
2352
- }
2353
- }, {
2354
- key: 'format_modified',
2355
- value: function format_modified(context, delta) {
2356
- context.pushCurrentOp({
2357
- op: OPERATIONS.replace,
2358
- value: delta[1]
2359
- });
2360
- }
2361
- }, {
2362
- key: 'format_deleted',
2363
- value: function format_deleted(context) {
2364
- context.pushCurrentOp({
2365
- op: OPERATIONS.remove
2366
- });
2367
- }
2368
- }, {
2369
- key: 'format_moved',
2370
- value: function format_moved(context, delta) {
2371
- var to = delta[1];
2372
- context.pushMoveOp(to);
2373
- }
2374
- }, {
2375
- key: 'format_textdiff',
2376
- value: function format_textdiff() {
2377
- throw new Error('Not implemented');
2378
- }
2379
- }, {
2380
- key: 'format',
2381
- value: function format(delta, left) {
2382
- var context = {};
2383
- this.prepareContext(context);
2384
- this.recurse(context, delta, left);
2385
- return context.result;
2386
- }
2387
- }]);
2388
- return JSONFormatter;
2389
- }(BaseFormatter);
2390
- var last = function last(arr) {
2391
- return arr[arr.length - 1];
2392
- };
2393
- var sortBy = function sortBy(arr, pred) {
2394
- arr.sort(pred);
2395
- return arr;
2396
- };
2397
- var compareByIndexDesc = function compareByIndexDesc(indexA, indexB) {
2398
- var lastA = parseInt(indexA, 10);
2399
- var lastB = parseInt(indexB, 10);
2400
- if (!(isNaN(lastA) || isNaN(lastB))) {
2401
- return lastB - lastA;
2402
- } else {
2403
- return 0;
2404
- }
2405
- };
2406
- var opsByDescendingOrder = function opsByDescendingOrder(removeOps) {
2407
- return sortBy(removeOps, function (a, b) {
2408
- var splitA = a.path.split('/');
2409
- var splitB = b.path.split('/');
2410
- if (splitA.length !== splitB.length) {
2411
- return splitA.length - splitB.length;
2412
- } else {
2413
- return compareByIndexDesc(last(splitA), last(splitB));
2414
- }
2415
- });
2416
- };
2417
- var partitionOps = function partitionOps(arr, fns) {
2418
- var initArr = Array(fns.length + 1).fill().map(function () {
2419
- return [];
2420
- });
2421
- return arr.map(function (item) {
2422
- var position = fns.map(function (fn) {
2423
- return fn(item);
2424
- }).indexOf(true);
2425
- if (position < 0) {
2426
- position = fns.length;
2427
- }
2428
- return {
2429
- item: item,
2430
- position: position
2431
- };
2432
- }).reduce(function (acc, item) {
2433
- acc[item.position].push(item.item);
2434
- return acc;
2435
- }, initArr);
2436
- };
2437
- var isMoveOp = function isMoveOp(_ref3) {
2438
- var op = _ref3.op;
2439
- return op === 'move';
2440
- };
2441
- var isRemoveOp = function isRemoveOp(_ref4) {
2442
- var op = _ref4.op;
2443
- return op === 'remove';
2444
- };
2445
- var reorderOps = function reorderOps(diff) {
2446
- var _partitionOps = partitionOps(diff, [isMoveOp, isRemoveOp]),
2447
- _partitionOps2 = slicedToArray(_partitionOps, 3),
2448
- moveOps = _partitionOps2[0],
2449
- removedOps = _partitionOps2[1],
2450
- restOps = _partitionOps2[2];
2451
- var removeOpsReverse = opsByDescendingOrder(removedOps);
2452
- return [].concat(toConsumableArray(removeOpsReverse), toConsumableArray(moveOps), toConsumableArray(restOps));
2453
- };
2454
- var defaultInstance$2 = void 0;
2455
- var format$2 = function format(delta, left) {
2456
- if (!defaultInstance$2) {
2457
- defaultInstance$2 = new JSONFormatter();
2458
- }
2459
- return reorderOps(defaultInstance$2.format(delta, left));
2460
- };
2461
- var log = function log(delta, left) {
2462
- console.log(format$2(delta, left));
2463
- };
2464
- var jsonpatch = Object.freeze({
2465
- default: JSONFormatter,
2466
- partitionOps: partitionOps,
2467
- format: format$2,
2468
- log: log
2469
- });
2470
- function chalkColor(name) {
2471
- return chalk__default["default"] && chalk__default["default"][name] || function () {
2472
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
2473
- args[_key] = arguments[_key];
2474
- }
2475
- return args;
2476
- };
2477
- }
2478
- var colors = {
2479
- added: chalkColor('green'),
2480
- deleted: chalkColor('red'),
2481
- movedestination: chalkColor('gray'),
2482
- moved: chalkColor('yellow'),
2483
- unchanged: chalkColor('gray'),
2484
- error: chalkColor('white.bgRed'),
2485
- textDiffLine: chalkColor('gray')
2486
- };
2487
- var ConsoleFormatter = function (_BaseFormatter) {
2488
- inherits(ConsoleFormatter, _BaseFormatter);
2489
- function ConsoleFormatter() {
2490
- classCallCheck(this, ConsoleFormatter);
2491
- var _this = possibleConstructorReturn(this, (ConsoleFormatter.__proto__ || Object.getPrototypeOf(ConsoleFormatter)).call(this));
2492
- _this.includeMoveDestinations = false;
2493
- return _this;
2494
- }
2495
- createClass(ConsoleFormatter, [{
2496
- key: 'prepareContext',
2497
- value: function prepareContext(context) {
2498
- get(ConsoleFormatter.prototype.__proto__ || Object.getPrototypeOf(ConsoleFormatter.prototype), 'prepareContext', this).call(this, context);
2499
- context.indent = function (levels) {
2500
- this.indentLevel = (this.indentLevel || 0) + (typeof levels === 'undefined' ? 1 : levels);
2501
- this.indentPad = new Array(this.indentLevel + 1).join(' ');
2502
- this.outLine();
2503
- };
2504
- context.outLine = function () {
2505
- this.buffer.push('\n' + (this.indentPad || ''));
2506
- };
2507
- context.out = function () {
2508
- for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2509
- args[_key2] = arguments[_key2];
2510
- }
2511
- for (var i = 0, l = args.length; i < l; i++) {
2512
- var lines = args[i].split('\n');
2513
- var text = lines.join('\n' + (this.indentPad || ''));
2514
- if (this.color && this.color[0]) {
2515
- text = this.color[0](text);
2516
- }
2517
- this.buffer.push(text);
2518
- }
2519
- };
2520
- context.pushColor = function (color) {
2521
- this.color = this.color || [];
2522
- this.color.unshift(color);
2523
- };
2524
- context.popColor = function () {
2525
- this.color = this.color || [];
2526
- this.color.shift();
2527
- };
2528
- }
2529
- }, {
2530
- key: 'typeFormattterErrorFormatter',
2531
- value: function typeFormattterErrorFormatter(context, err) {
2532
- context.pushColor(colors.error);
2533
- context.out('[ERROR]' + err);
2534
- context.popColor();
2535
- }
2536
- }, {
2537
- key: 'formatValue',
2538
- value: function formatValue(context, value) {
2539
- context.out(JSON.stringify(value, null, 2));
2540
- }
2541
- }, {
2542
- key: 'formatTextDiffString',
2543
- value: function formatTextDiffString(context, value) {
2544
- var lines = this.parseTextDiff(value);
2545
- context.indent();
2546
- for (var i = 0, l = lines.length; i < l; i++) {
2547
- var line = lines[i];
2548
- context.pushColor(colors.textDiffLine);
2549
- context.out(line.location.line + ',' + line.location.chr + ' ');
2550
- context.popColor();
2551
- var pieces = line.pieces;
2552
- for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
2553
- var piece = pieces[pieceIndex];
2554
- context.pushColor(colors[piece.type]);
2555
- context.out(piece.text);
2556
- context.popColor();
2557
- }
2558
- if (i < l - 1) {
2559
- context.outLine();
2560
- }
2561
- }
2562
- context.indent(-1);
2563
- }
2564
- }, {
2565
- key: 'rootBegin',
2566
- value: function rootBegin(context, type, nodeType) {
2567
- context.pushColor(colors[type]);
2568
- if (type === 'node') {
2569
- context.out(nodeType === 'array' ? '[' : '{');
2570
- context.indent();
2571
- }
2572
- }
2573
- }, {
2574
- key: 'rootEnd',
2575
- value: function rootEnd(context, type, nodeType) {
2576
- if (type === 'node') {
2577
- context.indent(-1);
2578
- context.out(nodeType === 'array' ? ']' : '}');
2579
- }
2580
- context.popColor();
2581
- }
2582
- }, {
2583
- key: 'nodeBegin',
2584
- value: function nodeBegin(context, key, leftKey, type, nodeType) {
2585
- context.pushColor(colors[type]);
2586
- context.out(leftKey + ': ');
2587
- if (type === 'node') {
2588
- context.out(nodeType === 'array' ? '[' : '{');
2589
- context.indent();
2590
- }
2591
- }
2592
- }, {
2593
- key: 'nodeEnd',
2594
- value: function nodeEnd(context, key, leftKey, type, nodeType, isLast) {
2595
- if (type === 'node') {
2596
- context.indent(-1);
2597
- context.out(nodeType === 'array' ? ']' : '}' + (isLast ? '' : ','));
2598
- }
2599
- if (!isLast) {
2600
- context.outLine();
2601
- }
2602
- context.popColor();
2603
- }
2604
-
2605
- /* jshint camelcase: false */
2606
- /* eslint-disable camelcase */
2607
- }, {
2608
- key: 'format_unchanged',
2609
- value: function format_unchanged(context, delta, left) {
2610
- if (typeof left === 'undefined') {
2611
- return;
2612
- }
2613
- this.formatValue(context, left);
2614
- }
2615
- }, {
2616
- key: 'format_movedestination',
2617
- value: function format_movedestination(context, delta, left) {
2618
- if (typeof left === 'undefined') {
2619
- return;
2620
- }
2621
- this.formatValue(context, left);
2622
- }
2623
- }, {
2624
- key: 'format_node',
2625
- value: function format_node(context, delta, left) {
2626
- // recurse
2627
- this.formatDeltaChildren(context, delta, left);
2628
- }
2629
- }, {
2630
- key: 'format_added',
2631
- value: function format_added(context, delta) {
2632
- this.formatValue(context, delta[0]);
2633
- }
2634
- }, {
2635
- key: 'format_modified',
2636
- value: function format_modified(context, delta) {
2637
- context.pushColor(colors.deleted);
2638
- this.formatValue(context, delta[0]);
2639
- context.popColor();
2640
- context.out(' => ');
2641
- context.pushColor(colors.added);
2642
- this.formatValue(context, delta[1]);
2643
- context.popColor();
2644
- }
2645
- }, {
2646
- key: 'format_deleted',
2647
- value: function format_deleted(context, delta) {
2648
- this.formatValue(context, delta[0]);
2649
- }
2650
- }, {
2651
- key: 'format_moved',
2652
- value: function format_moved(context, delta) {
2653
- context.out('==> ' + delta[1]);
2654
- }
2655
- }, {
2656
- key: 'format_textdiff',
2657
- value: function format_textdiff(context, delta) {
2658
- this.formatTextDiffString(context, delta[0]);
2659
- }
2660
- }]);
2661
- return ConsoleFormatter;
2662
- }(BaseFormatter);
2663
- var defaultInstance$3 = void 0;
2664
- var format$3 = function format(delta, left) {
2665
- if (!defaultInstance$3) {
2666
- defaultInstance$3 = new ConsoleFormatter();
2667
- }
2668
- return defaultInstance$3.format(delta, left);
2669
- };
2670
- function log$1(delta, left) {
2671
- console.log(format$3(delta, left));
2672
- }
2673
- var console$1 = Object.freeze({
2674
- default: ConsoleFormatter,
2675
- format: format$3,
2676
- log: log$1
2677
- });
2678
- Object.freeze({
2679
- base: base,
2680
- html: html,
2681
- annotated: annotated,
2682
- jsonpatch: jsonpatch,
2683
- console: console$1
2684
- });
2685
-
2686
242
  function objectHash(obj, index) {
2687
243
  var objIndex = "$$index:".concat(index);
2688
- return _typeof$1(obj) === 'object' && obj !== null ? obj.id || obj.name || obj.url || objIndex : objIndex;
244
+ return _typeof(obj) === 'object' && obj !== null ? obj.id || obj.name || obj.url || objIndex : objIndex;
2689
245
  }
2690
- var diffpatcher = new DiffPatcher({
246
+ var diffpatcher = new jsondiffpatch_cjs.DiffPatcher({
2691
247
  objectHash: objectHash,
2692
248
  arrays: {
2693
249
  // detect items moved inside the array
@@ -2849,7 +405,7 @@
2849
405
  * false otherwise
2850
406
  */
2851
407
  function isChangeAction(obj, key) {
2852
- return REGEX_NUMBER$4.test(key) && (_typeof$1(obj[key]) === 'object' || typeof obj[key] === 'string');
408
+ return REGEX_NUMBER$4.test(key) && (_typeof(obj[key]) === 'object' || typeof obj[key] === 'string');
2853
409
  }
2854
410
 
2855
411
  /**
@@ -2865,7 +421,7 @@
2865
421
  * false otherwise
2866
422
  */
2867
423
  function isRemoveAction$1(obj, key) {
2868
- return REGEX_UNDERSCORE_NUMBER$4.test(key) && Array.isArray(obj[key]) && obj[key].length === 3 && (_typeof$1(obj[key][0]) === 'object' || typeof obj[key][0] === 'string') && obj[key][1] === 0 && obj[key][2] === 0;
424
+ return REGEX_UNDERSCORE_NUMBER$4.test(key) && Array.isArray(obj[key]) && obj[key].length === 3 && (_typeof(obj[key][0]) === 'object' || typeof obj[key][0] === 'string') && obj[key][1] === 0 && obj[key][2] === 0;
2869
425
  }
2870
426
 
2871
427
  /**
@@ -2958,6 +514,11 @@
2958
514
  };
2959
515
  };
2960
516
 
517
+ /* actions that start with 'set' can generate undefined valued */
518
+ var isOptionalField = function isOptionalField(action) {
519
+ return action.startsWith('set');
520
+ };
521
+
2961
522
  /**
2962
523
  * Builds actions for simple object properties, given a list of actions
2963
524
  * E.g. [{ action: `changeName`, key: 'name' }]
@@ -2968,13 +529,17 @@
2968
529
  * @param {Object} options.oldObj - the object that needs to be updated
2969
530
  * @param {Object} options.newObj - the new representation of the object
2970
531
  * @param {Boolean} options.shouldOmitEmptyString - a flag to determine if we should treat an empty string a NON-value
532
+ * @param {Boolean} options.shouldUnsetOmittedProperties - a flag to determine if we should unset fields which are omitted in the newObj
533
+ * @param {Boolean} options.shouldPreventUnsettingRequiredFields - a flag to determine if required fields should be unset
2971
534
  */
2972
535
  function buildBaseAttributesActions(_ref) {
2973
536
  var actions = _ref.actions,
2974
537
  diff = _ref.diff,
2975
538
  oldObj = _ref.oldObj,
2976
539
  newObj = _ref.newObj,
2977
- shouldOmitEmptyString = _ref.shouldOmitEmptyString;
540
+ shouldOmitEmptyString = _ref.shouldOmitEmptyString,
541
+ shouldUnsetOmittedProperties = _ref.shouldUnsetOmittedProperties,
542
+ shouldPreventUnsettingRequiredFields = _ref.shouldPreventUnsettingRequiredFields;
2978
543
  var isEmptyValue = createIsEmptyValue(shouldOmitEmptyString ? [undefined, null, ''] : [undefined, null]);
2979
544
  return actions.map(function (item) {
2980
545
  var key = item.key; // e.g.: name, description, ...
@@ -2984,7 +549,9 @@
2984
549
  var now = newObj[key];
2985
550
  var isNotDefinedBefore = isEmptyValue(oldObj[key]);
2986
551
  var isNotDefinedNow = isEmptyValue(newObj[key]);
552
+ var isOmitted = !Object.keys(newObj).includes(key);
2987
553
  if (!delta) return undefined;
554
+ if (isNotDefinedNow && !isOptionalField(item.action) && shouldPreventUnsettingRequiredFields) return undefined;
2988
555
  if (isNotDefinedNow && isNotDefinedBefore) return undefined;
2989
556
  if (!isNotDefinedNow && isNotDefinedBefore)
2990
557
  // no value previously set
@@ -2993,8 +560,8 @@
2993
560
  }, actionKey, now);
2994
561
 
2995
562
  /* no new value */
2996
- if (isNotDefinedNow && !{}.hasOwnProperty.call(newObj, key)) return undefined;
2997
- if (isNotDefinedNow && {}.hasOwnProperty.call(newObj, key))
563
+ if (isNotDefinedNow && isOmitted && !shouldUnsetOmittedProperties) return undefined;
564
+ if (isNotDefinedNow)
2998
565
  // value unset
2999
566
  return {
3000
567
  action: item.action
@@ -3104,7 +671,9 @@
3104
671
  diff: diff,
3105
672
  oldObj: oldObj,
3106
673
  newObj: newObj,
3107
- shouldOmitEmptyString: config.shouldOmitEmptyString
674
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
675
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
676
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
3108
677
  });
3109
678
  }
3110
679
  function actionsMapReferences$3(diff, oldObj, newObj) {
@@ -3152,7 +721,7 @@
3152
721
  return acc;
3153
722
  }, {});
3154
723
  for (var i = 0; i < newObj[key].length; i++) {
3155
- if (!isNil__default["default"](newObj[key][i]) && _typeof$1(newObj[key][i]) === 'object' && !isNil__default["default"](newObj[key][i].id)) {
724
+ if (!isNil__default["default"](newObj[key][i]) && _typeof(newObj[key][i]) === 'object' && !isNil__default["default"](newObj[key][i].id)) {
3156
725
  // Since its unordered array elements then check if the element on `oldObj` exists by id
3157
726
  var foundObject = hashMapValue[newObj[key][i].id];
3158
727
  if (!isNil__default["default"](foundObject)) {
@@ -3174,7 +743,7 @@
3174
743
  merged[key] = isNil__default["default"](newObj[key]) ? [] : newObj[key];
3175
744
  return merged;
3176
745
  }
3177
- if (!isNil__default["default"](newObj[key]) && _typeof$1(value) === 'object' &&
746
+ if (!isNil__default["default"](newObj[key]) && _typeof(value) === 'object' &&
3178
747
  // Ignore Date as this will create invalid object since typeof date === 'object' return true
3179
748
  // ex: {date: new Date()} will result {date: {}}
3180
749
  !(value instanceof Date)) {
@@ -3306,7 +875,9 @@
3306
875
  diff: diff,
3307
876
  oldObj: oldObj,
3308
877
  newObj: newObj,
3309
- shouldOmitEmptyString: config.shouldOmitEmptyString
878
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
879
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
880
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
3310
881
  });
3311
882
  }
3312
883
  function actionsMapSetDefaultBase(diff, oldObj, newObj) {
@@ -3316,7 +887,9 @@
3316
887
  diff: diff,
3317
888
  oldObj: oldObj,
3318
889
  newObj: newObj,
3319
- shouldOmitEmptyString: config.shouldOmitEmptyString
890
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
891
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
892
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
3320
893
  });
3321
894
  }
3322
895
  function actionsMapReferences$2(diff, oldObj, newObj) {
@@ -3512,7 +1085,9 @@
3512
1085
  diff: diff,
3513
1086
  oldObj: oldObj,
3514
1087
  newObj: newObj,
3515
- shouldOmitEmptyString: config.shouldOmitEmptyString
1088
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
1089
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
1090
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
3516
1091
  });
3517
1092
  }
3518
1093
  function actionsMapReferences$1(diff, oldObj, newObj) {
@@ -3762,7 +1337,7 @@
3762
1337
  currencyCode: diffedValue.currencyCode ? getDeltaValue(diffedValue.currencyCode) : attribute.value.currencyCode
3763
1338
  };else if (diffedValue.key)
3764
1339
  // Enum / LEnum (use only the key)
3765
- action.value = getDeltaValue(diffedValue.key);else if (_typeof$1(diffedValue) === 'object') if ({}.hasOwnProperty.call(diffedValue, '_t') && diffedValue._t === 'a') {
1340
+ action.value = getDeltaValue(diffedValue.key);else if (_typeof(diffedValue) === 'object') if ({}.hasOwnProperty.call(diffedValue, '_t') && diffedValue._t === 'a') {
3766
1341
  // set-typed attribute
3767
1342
  action = _objectSpread2(_objectSpread2({}, action), {}, {
3768
1343
  value: attribute.value
@@ -3794,7 +1369,7 @@
3794
1369
  action: 'addExternalImage',
3795
1370
  variantId: oldVariant.id,
3796
1371
  image: getDeltaValue(image)
3797
- });else if (_typeof$1(image) === 'object') if ({}.hasOwnProperty.call(image, 'url') && image.url.length === 2) {
1372
+ });else if (_typeof(image) === 'object') if ({}.hasOwnProperty.call(image, 'url') && image.url.length === 2) {
3798
1373
  // There is a new image, remove the old one first.
3799
1374
  actions.push({
3800
1375
  action: 'removeImage',
@@ -4029,15 +1604,19 @@
4029
1604
  diff: diff,
4030
1605
  oldObj: oldObj,
4031
1606
  newObj: newObj,
4032
- shouldOmitEmptyString: config.shouldOmitEmptyString
1607
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
1608
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
4033
1609
  });
4034
1610
  }
4035
1611
  function actionsMapMeta(diff, oldObj, newObj) {
1612
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
4036
1613
  return buildBaseAttributesActions({
4037
1614
  actions: metaActionsList,
4038
1615
  diff: diff,
4039
1616
  oldObj: oldObj,
4040
- newObj: newObj
1617
+ newObj: newObj,
1618
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
1619
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
4041
1620
  });
4042
1621
  }
4043
1622
  function actionsMapAddVariants(diff, oldObj, newObj) {
@@ -4347,7 +1926,9 @@
4347
1926
  diff: diff,
4348
1927
  oldObj: oldObj,
4349
1928
  newObj: newObj,
4350
- shouldOmitEmptyString: config.shouldOmitEmptyString
1929
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
1930
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
1931
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4351
1932
  });
4352
1933
  }
4353
1934
  function actionsMapDeliveries(diff, oldObj, newObj) {
@@ -4566,7 +2147,9 @@
4566
2147
  diff: diff,
4567
2148
  oldObj: oldObj,
4568
2149
  newObj: newObj,
4569
- shouldOmitEmptyString: config.shouldOmitEmptyString
2150
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
2151
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
2152
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4570
2153
  });
4571
2154
  }
4572
2155
 
@@ -4654,7 +2237,9 @@
4654
2237
  diff: diff,
4655
2238
  oldObj: oldObj,
4656
2239
  newObj: newObj,
4657
- shouldOmitEmptyString: config.shouldOmitEmptyString
2240
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
2241
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
2242
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4658
2243
  });
4659
2244
  }
4660
2245
 
@@ -4705,7 +2290,9 @@
4705
2290
  diff: diff,
4706
2291
  oldObj: oldObj,
4707
2292
  newObj: newObj,
4708
- shouldOmitEmptyString: config.shouldOmitEmptyString
2293
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
2294
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
2295
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4709
2296
  });
4710
2297
  }
4711
2298
 
@@ -4775,7 +2362,9 @@
4775
2362
  diff: diff,
4776
2363
  oldObj: oldObj,
4777
2364
  newObj: newObj,
4778
- shouldOmitEmptyString: config.shouldOmitEmptyString
2365
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
2366
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
2367
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
4779
2368
  });
4780
2369
  }
4781
2370
 
@@ -4883,8 +2472,8 @@
4883
2472
  if (cache === void 0) {
4884
2473
  cache = getNewCache();
4885
2474
  }
4886
- var isCacheableA = !!a && _typeof$1(a) === 'object';
4887
- var isCacheableB = !!b && _typeof$1(b) === 'object';
2475
+ var isCacheableA = !!a && _typeof(a) === 'object';
2476
+ var isCacheableB = !!b && _typeof(b) === 'object';
4888
2477
  if (isCacheableA || isCacheableB) {
4889
2478
  var hasA = isCacheableA && cache.has(a);
4890
2479
  var hasB = isCacheableB && cache.has(b);
@@ -5050,7 +2639,7 @@
5050
2639
  if (a === b) {
5051
2640
  return true;
5052
2641
  }
5053
- if (a && b && _typeof$1(a) === 'object' && _typeof$1(b) === 'object') {
2642
+ if (a && b && _typeof(a) === 'object' && _typeof(b) === 'object') {
5054
2643
  if (isPlainObject(a) && isPlainObject(b)) {
5055
2644
  return areObjectsEqual(a, b, isEqual, meta);
5056
2645
  }
@@ -5123,7 +2712,9 @@
5123
2712
  diff: diff,
5124
2713
  oldObj: oldObj,
5125
2714
  newObj: newObj,
5126
- shouldOmitEmptyString: config.shouldOmitEmptyString
2715
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
2716
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
2717
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5127
2718
  });
5128
2719
  }
5129
2720
  function actionsMapRates(diff, oldObj, newObj) {
@@ -5211,7 +2802,9 @@
5211
2802
  diff: diff,
5212
2803
  oldObj: oldObj,
5213
2804
  newObj: newObj,
5214
- shouldOmitEmptyString: config.shouldOmitEmptyString
2805
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
2806
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
2807
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5215
2808
  });
5216
2809
  }
5217
2810
  function actionsMapLocations(diff, oldObj, newObj) {
@@ -5316,7 +2909,9 @@
5316
2909
  diff: diff,
5317
2910
  oldObj: oldObj,
5318
2911
  newObj: newObj,
5319
- shouldOmitEmptyString: config.shouldOmitEmptyString
2912
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
2913
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
2914
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5320
2915
  });
5321
2916
  }
5322
2917
  var addShippingRates = function addShippingRates(newZoneRate) {
@@ -5439,7 +3034,8 @@
5439
3034
  actions: baseActionsList$8,
5440
3035
  oldObj: previous,
5441
3036
  newObj: next,
5442
- shouldOmitEmptyString: config.shouldOmitEmptyString
3037
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3038
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
5443
3039
  });
5444
3040
  }
5445
3041
 
@@ -5696,7 +3292,9 @@
5696
3292
  diff: diff,
5697
3293
  oldObj: oldObj,
5698
3294
  newObj: newObj,
5699
- shouldOmitEmptyString: config.shouldOmitEmptyString
3295
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3296
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3297
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5700
3298
  });
5701
3299
  }
5702
3300
  function actionsMapRoles(diff, oldObj, newObj) {
@@ -5782,7 +3380,9 @@
5782
3380
  diff: diff,
5783
3381
  oldObj: oldObj,
5784
3382
  newObj: newObj,
5785
- shouldOmitEmptyString: config.shouldOmitEmptyString
3383
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3384
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3385
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5786
3386
  });
5787
3387
  }
5788
3388
 
@@ -5833,7 +3433,9 @@
5833
3433
  diff: diff,
5834
3434
  oldObj: oldObj,
5835
3435
  newObj: newObj,
5836
- shouldOmitEmptyString: config.shouldOmitEmptyString
3436
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3437
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3438
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
5837
3439
  });
5838
3440
  }
5839
3441
  function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next) {
@@ -6028,6 +3630,7 @@
6028
3630
  });
6029
3631
  }
6030
3632
  var actionsMapBusinessUnit = function actionsMapBusinessUnit(diff, oldObj, newObj) {
3633
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6031
3634
  var businessUnits = diff.businessUnits;
6032
3635
  if (!businessUnits) {
6033
3636
  return [];
@@ -6036,10 +3639,13 @@
6036
3639
  actions: myBusinessUnitActionsList,
6037
3640
  diff: businessUnits,
6038
3641
  oldObj: oldObj.businessUnits,
6039
- newObj: newObj.businessUnits
3642
+ newObj: newObj.businessUnits,
3643
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3644
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
6040
3645
  });
6041
3646
  };
6042
3647
  function actionsMapSearchIndexingConfiguration(diff, oldObj, newObj) {
3648
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6043
3649
  var searchIndexing = diff.searchIndexing;
6044
3650
  if (!searchIndexing) {
6045
3651
  return [];
@@ -6052,7 +3658,10 @@
6052
3658
  actions: customerSearchActionsList,
6053
3659
  diff: diff.searchIndexing.customers,
6054
3660
  oldObj: oldObj.searchIndexing.customers,
6055
- newObj: newObj.searchIndexing.customers
3661
+ newObj: newObj.searchIndexing.customers,
3662
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3663
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3664
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
6056
3665
  });
6057
3666
  }
6058
3667
 
@@ -6095,11 +3704,15 @@
6095
3704
  key: 'supplyChannels'
6096
3705
  }];
6097
3706
  function actionsMapBase$3(diff, oldObj, newObj) {
3707
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6098
3708
  return buildBaseAttributesActions({
6099
3709
  actions: baseActionsList$3,
6100
3710
  diff: diff,
6101
3711
  oldObj: oldObj,
6102
- newObj: newObj
3712
+ newObj: newObj,
3713
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3714
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3715
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
6103
3716
  });
6104
3717
  }
6105
3718
 
@@ -6116,10 +3729,11 @@
6116
3729
  };
6117
3730
  }
6118
3731
  var stores = (function (actionGroupList) {
3732
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6119
3733
  var mapActionGroup = createMapActionGroup(actionGroupList);
6120
3734
  var doMapActions = createStoresMapActions(mapActionGroup);
6121
3735
  var onBeforeApplyingDiff = null;
6122
- var buildActions = createBuildActions(diff, doMapActions, onBeforeApplyingDiff);
3736
+ var buildActions = createBuildActions(diff, doMapActions, onBeforeApplyingDiff, options);
6123
3737
  return {
6124
3738
  buildActions: buildActions
6125
3739
  };
@@ -6133,11 +3747,15 @@
6133
3747
  key: 'key'
6134
3748
  }];
6135
3749
  function actionsMapBase$2(diff, oldObj, newObj) {
3750
+ var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6136
3751
  return buildBaseAttributesActions({
6137
3752
  actions: baseActionsList$2,
6138
3753
  diff: diff,
6139
3754
  oldObj: oldObj,
6140
- newObj: newObj
3755
+ newObj: newObj,
3756
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3757
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3758
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
6141
3759
  });
6142
3760
  }
6143
3761
 
@@ -6194,7 +3812,9 @@
6194
3812
  diff: diff,
6195
3813
  oldObj: oldObj,
6196
3814
  newObj: newObj,
6197
- shouldOmitEmptyString: config.shouldOmitEmptyString
3815
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3816
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3817
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
6198
3818
  });
6199
3819
  }
6200
3820
 
@@ -6240,7 +3860,9 @@
6240
3860
  diff: diff,
6241
3861
  oldObj: oldObj,
6242
3862
  newObj: newObj,
6243
- shouldOmitEmptyString: config.shouldOmitEmptyString
3863
+ shouldOmitEmptyString: config.shouldOmitEmptyString,
3864
+ shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
3865
+ shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
6244
3866
  });
6245
3867
  }
6246
3868
  function actionsMapAttributes(diff, oldObj, newObj) {