@commercetools/sync-actions 6.1.1 → 7.0.0-rc.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,7 +1,6 @@
1
1
  import flatten from 'lodash.flatten';
2
2
  import isEqual from 'lodash.isequal';
3
3
  import isNil from 'lodash.isnil';
4
- import { DiffPatcher } from 'jsondiffpatch/dist/jsondiffpatch.cjs';
5
4
  import forEach from 'lodash.foreach';
6
5
  import uniqWith from 'lodash.uniqwith';
7
6
  import intersection from 'lodash.intersection';
@@ -19,14 +18,69 @@ function _arrayWithHoles(r) {
19
18
  function _arrayWithoutHoles(r) {
20
19
  if (Array.isArray(r)) return _arrayLikeToArray(r);
21
20
  }
21
+ function _assertThisInitialized(e) {
22
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
23
+ return e;
24
+ }
25
+ function _callSuper(t, o, e) {
26
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, [], _getPrototypeOf(t).constructor) : o.apply(t, e));
27
+ }
28
+ function _classCallCheck(a, n) {
29
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
30
+ }
31
+ function _defineProperties(e, r) {
32
+ for (var t = 0; t < r.length; t++) {
33
+ var o = r[t];
34
+ o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
35
+ }
36
+ }
37
+ function _createClass(e, r, t) {
38
+ return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
39
+ writable: false
40
+ }), e;
41
+ }
22
42
  function _defineProperty(e, r, t) {
23
43
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
24
44
  value: t,
25
- enumerable: !0,
26
- configurable: !0,
27
- writable: !0
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true
28
48
  }) : e[r] = t, e;
29
49
  }
50
+ function _get() {
51
+ return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
52
+ var p = _superPropBase(e, t);
53
+ if (p) {
54
+ var n = Object.getOwnPropertyDescriptor(p, t);
55
+ return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
56
+ }
57
+ }, _get.apply(null, arguments);
58
+ }
59
+ function _getPrototypeOf(t) {
60
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
61
+ return t.__proto__ || Object.getPrototypeOf(t);
62
+ }, _getPrototypeOf(t);
63
+ }
64
+ function _inherits(t, e) {
65
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
66
+ t.prototype = Object.create(e && e.prototype, {
67
+ constructor: {
68
+ value: t,
69
+ writable: true,
70
+ configurable: true
71
+ }
72
+ }), Object.defineProperty(t, "prototype", {
73
+ writable: false
74
+ }), e && _setPrototypeOf(t, e);
75
+ }
76
+ function _isNativeReflectConstruct() {
77
+ try {
78
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
79
+ } catch (t) {}
80
+ return (_isNativeReflectConstruct = function () {
81
+ return !!t;
82
+ })();
83
+ }
30
84
  function _iterableToArray(r) {
31
85
  if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
32
86
  }
@@ -38,15 +92,15 @@ function _iterableToArrayLimit(r, l) {
38
92
  i,
39
93
  u,
40
94
  a = [],
41
- f = !0,
42
- o = !1;
95
+ f = true,
96
+ o = false;
43
97
  try {
44
98
  if (i = (t = t.call(r)).next, 0 === l) {
45
99
  if (Object(t) !== t) return;
46
100
  f = !1;
47
101
  } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
48
102
  } catch (r) {
49
- o = !0, n = r;
103
+ o = true, n = r;
50
104
  } finally {
51
105
  try {
52
106
  if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
@@ -76,7 +130,7 @@ function ownKeys(e, r) {
76
130
  function _objectSpread2(e) {
77
131
  for (var r = 1; r < arguments.length; r++) {
78
132
  var t = null != arguments[r] ? arguments[r] : {};
79
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
133
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
80
134
  _defineProperty(e, r, t[r]);
81
135
  }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
82
136
  Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
@@ -90,8 +144,8 @@ function _objectWithoutProperties(e, t) {
90
144
  r,
91
145
  i = _objectWithoutPropertiesLoose(e, t);
92
146
  if (Object.getOwnPropertySymbols) {
93
- var s = Object.getOwnPropertySymbols(e);
94
- for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
147
+ var n = Object.getOwnPropertySymbols(e);
148
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
95
149
  }
96
150
  return i;
97
151
  }
@@ -99,14 +153,34 @@ function _objectWithoutPropertiesLoose(r, e) {
99
153
  if (null == r) return {};
100
154
  var t = {};
101
155
  for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
102
- if (e.includes(n)) continue;
156
+ if (-1 !== e.indexOf(n)) continue;
103
157
  t[n] = r[n];
104
158
  }
105
159
  return t;
106
160
  }
161
+ function _possibleConstructorReturn(t, e) {
162
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
163
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
164
+ return _assertThisInitialized(t);
165
+ }
166
+ function _setPrototypeOf(t, e) {
167
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
168
+ return t.__proto__ = e, t;
169
+ }, _setPrototypeOf(t, e);
170
+ }
107
171
  function _slicedToArray(r, e) {
108
172
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
109
173
  }
174
+ function _superPropBase(t, o) {
175
+ for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
176
+ return t;
177
+ }
178
+ function _superPropGet(t, o, e, r) {
179
+ var p = _get(_getPrototypeOf(t.prototype ), o, e);
180
+ return 2 & r && "function" == typeof p ? function (t) {
181
+ return p.apply(e, t);
182
+ } : p;
183
+ }
110
184
  function _toConsumableArray(r) {
111
185
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
112
186
  }
@@ -114,11 +188,11 @@ function _toPrimitive(t, r) {
114
188
  if ("object" != typeof t || !t) return t;
115
189
  var e = t[Symbol.toPrimitive];
116
190
  if (void 0 !== e) {
117
- var i = e.call(t, r || "default");
191
+ var i = e.call(t, r);
118
192
  if ("object" != typeof i) return i;
119
193
  throw new TypeError("@@toPrimitive must return a primitive value.");
120
194
  }
121
- return ("string" === r ? String : Number)(t);
195
+ return (String )(t);
122
196
  }
123
197
  function _toPropertyKey(t) {
124
198
  var i = _toPrimitive(t, "string");
@@ -232,6 +306,1206 @@ function createMapActionGroup() {
232
306
  };
233
307
  }
234
308
 
309
+ var Processor = /*#__PURE__*/function () {
310
+ function Processor(options) {
311
+ _classCallCheck(this, Processor);
312
+ this.selfOptions = options || {};
313
+ this.pipes = {};
314
+ }
315
+ return _createClass(Processor, [{
316
+ key: "options",
317
+ value: function options(_options) {
318
+ if (_options) {
319
+ this.selfOptions = _options;
320
+ }
321
+ return this.selfOptions;
322
+ }
323
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
324
+ }, {
325
+ key: "pipe",
326
+ value: function pipe(name, pipeArg) {
327
+ var pipe = pipeArg;
328
+ if (typeof name === 'string') {
329
+ if (typeof pipe === 'undefined') {
330
+ return this.pipes[name];
331
+ } else {
332
+ this.pipes[name] = pipe;
333
+ }
334
+ }
335
+ if (name && name.name) {
336
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
337
+ pipe = name;
338
+ if (pipe.processor === this) {
339
+ return pipe;
340
+ }
341
+ this.pipes[pipe.name] = pipe;
342
+ }
343
+ pipe.processor = this;
344
+ return pipe;
345
+ }
346
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
347
+ }, {
348
+ key: "process",
349
+ value: function process(input, pipe) {
350
+ var context = input;
351
+ context.options = this.options();
352
+ var nextPipe = pipe || input.pipe || 'default';
353
+ var lastPipe;
354
+ while (nextPipe) {
355
+ if (typeof context.nextAfterChildren !== 'undefined') {
356
+ // children processed and coming back to parent
357
+ context.next = context.nextAfterChildren;
358
+ context.nextAfterChildren = null;
359
+ }
360
+ if (typeof nextPipe === 'string') {
361
+ nextPipe = this.pipe(nextPipe);
362
+ }
363
+ nextPipe.process(context);
364
+ lastPipe = nextPipe;
365
+ nextPipe = null;
366
+ if (context) {
367
+ if (context.next) {
368
+ context = context.next;
369
+ nextPipe = context.pipe || lastPipe;
370
+ }
371
+ }
372
+ }
373
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
374
+ return context.hasResult ? context.result : undefined;
375
+ }
376
+ }]);
377
+ }();
378
+
379
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
380
+ var Pipe = /*#__PURE__*/function () {
381
+ function Pipe(name) {
382
+ _classCallCheck(this, Pipe);
383
+ this.name = name;
384
+ this.filters = [];
385
+ }
386
+ return _createClass(Pipe, [{
387
+ key: "process",
388
+ value: function process(input) {
389
+ if (!this.processor) {
390
+ throw new Error('add this pipe to a processor before using it');
391
+ }
392
+ var debug = this.debug;
393
+ var length = this.filters.length;
394
+ var context = input;
395
+ for (var index = 0; index < length; index++) {
396
+ var filter = this.filters[index];
397
+ if (debug) {
398
+ this.log("filter: ".concat(filter.filterName));
399
+ }
400
+ filter(context);
401
+ if (_typeof(context) === 'object' && context.exiting) {
402
+ context.exiting = false;
403
+ break;
404
+ }
405
+ }
406
+ if (!context.next && this.resultCheck) {
407
+ this.resultCheck(context);
408
+ }
409
+ }
410
+ }, {
411
+ key: "log",
412
+ value: function log(msg) {
413
+ console.log("[jsondiffpatch] ".concat(this.name, " pipe, ").concat(msg));
414
+ }
415
+ }, {
416
+ key: "append",
417
+ value: function append() {
418
+ var _this$filters;
419
+ (_this$filters = this.filters).push.apply(_this$filters, arguments);
420
+ return this;
421
+ }
422
+ }, {
423
+ key: "prepend",
424
+ value: function prepend() {
425
+ var _this$filters2;
426
+ (_this$filters2 = this.filters).unshift.apply(_this$filters2, arguments);
427
+ return this;
428
+ }
429
+ }, {
430
+ key: "indexOf",
431
+ value: function indexOf(filterName) {
432
+ if (!filterName) {
433
+ throw new Error('a filter name is required');
434
+ }
435
+ for (var index = 0; index < this.filters.length; index++) {
436
+ var filter = this.filters[index];
437
+ if (filter.filterName === filterName) {
438
+ return index;
439
+ }
440
+ }
441
+ throw new Error("filter not found: ".concat(filterName));
442
+ }
443
+ }, {
444
+ key: "list",
445
+ value: function list() {
446
+ return this.filters.map(function (f) {
447
+ return f.filterName;
448
+ });
449
+ }
450
+ }, {
451
+ key: "after",
452
+ value: function after(filterName) {
453
+ var _this$filters3;
454
+ var index = this.indexOf(filterName);
455
+ for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
456
+ params[_key - 1] = arguments[_key];
457
+ }
458
+ (_this$filters3 = this.filters).splice.apply(_this$filters3, [index + 1, 0].concat(params));
459
+ return this;
460
+ }
461
+ }, {
462
+ key: "before",
463
+ value: function before(filterName) {
464
+ var _this$filters4;
465
+ var index = this.indexOf(filterName);
466
+ for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
467
+ params[_key2 - 1] = arguments[_key2];
468
+ }
469
+ (_this$filters4 = this.filters).splice.apply(_this$filters4, [index, 0].concat(params));
470
+ return this;
471
+ }
472
+ }, {
473
+ key: "replace",
474
+ value: function replace(filterName) {
475
+ var _this$filters5;
476
+ var index = this.indexOf(filterName);
477
+ for (var _len3 = arguments.length, params = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
478
+ params[_key3 - 1] = arguments[_key3];
479
+ }
480
+ (_this$filters5 = this.filters).splice.apply(_this$filters5, [index, 1].concat(params));
481
+ return this;
482
+ }
483
+ }, {
484
+ key: "remove",
485
+ value: function remove(filterName) {
486
+ var index = this.indexOf(filterName);
487
+ this.filters.splice(index, 1);
488
+ return this;
489
+ }
490
+ }, {
491
+ key: "clear",
492
+ value: function clear() {
493
+ this.filters.length = 0;
494
+ return this;
495
+ }
496
+ }, {
497
+ key: "shouldHaveResult",
498
+ value: function shouldHaveResult(should) {
499
+ var _this = this;
500
+ if (should === false) {
501
+ this.resultCheck = null;
502
+ return;
503
+ }
504
+ if (this.resultCheck) {
505
+ return;
506
+ }
507
+ this.resultCheck = function (context) {
508
+ if (!context.hasResult) {
509
+ console.log(context);
510
+ var error = new Error("".concat(_this.name, " failed"));
511
+ error.noResult = true;
512
+ throw error;
513
+ }
514
+ };
515
+ return this;
516
+ }
517
+ }]);
518
+ }();
519
+
520
+ var Context = /*#__PURE__*/function () {
521
+ function Context() {
522
+ _classCallCheck(this, Context);
523
+ }
524
+ return _createClass(Context, [{
525
+ key: "setResult",
526
+ value: function setResult(result) {
527
+ this.result = result;
528
+ this.hasResult = true;
529
+ return this;
530
+ }
531
+ }, {
532
+ key: "exit",
533
+ value: function exit() {
534
+ this.exiting = true;
535
+ return this;
536
+ }
537
+ }, {
538
+ key: "push",
539
+ value: function push(child, name) {
540
+ child.parent = this;
541
+ if (typeof name !== 'undefined') {
542
+ child.childName = name;
543
+ }
544
+ child.root = this.root || this;
545
+ child.options = child.options || this.options;
546
+ if (!this.children) {
547
+ this.children = [child];
548
+ this.nextAfterChildren = this.next || null;
549
+ this.next = child;
550
+ } else {
551
+ this.children[this.children.length - 1].next = child;
552
+ this.children.push(child);
553
+ }
554
+ child.next = this;
555
+ return this;
556
+ }
557
+ }]);
558
+ }();
559
+
560
+ function cloneRegExp(re) {
561
+ var regexMatch = /^\/(.*)\/([gimyu]*)$/.exec(re.toString());
562
+ return new RegExp(regexMatch[1], regexMatch[2]);
563
+ }
564
+ function clone$1(arg) {
565
+ if (_typeof(arg) !== 'object') {
566
+ return arg;
567
+ }
568
+ if (arg === null) {
569
+ return null;
570
+ }
571
+ if (Array.isArray(arg)) {
572
+ return arg.map(clone$1);
573
+ }
574
+ if (arg instanceof Date) {
575
+ return new Date(arg.getTime());
576
+ }
577
+ if (arg instanceof RegExp) {
578
+ return cloneRegExp(arg);
579
+ }
580
+ var cloned = {};
581
+ for (var name in arg) {
582
+ if (Object.prototype.hasOwnProperty.call(arg, name)) {
583
+ cloned[name] = clone$1(arg[name]);
584
+ }
585
+ }
586
+ return cloned;
587
+ }
588
+
589
+ var DiffContext = /*#__PURE__*/function (_Context) {
590
+ function DiffContext(left, right) {
591
+ var _this;
592
+ _classCallCheck(this, DiffContext);
593
+ _this = _callSuper(this, DiffContext);
594
+ _this.left = left;
595
+ _this.right = right;
596
+ _this.pipe = 'diff';
597
+ return _this;
598
+ }
599
+ _inherits(DiffContext, _Context);
600
+ return _createClass(DiffContext, [{
601
+ key: "setResult",
602
+ value: function setResult(result) {
603
+ if (this.options.cloneDiffValues && _typeof(result) === 'object') {
604
+ var clone = typeof this.options.cloneDiffValues === 'function' ? this.options.cloneDiffValues : clone$1;
605
+ if (_typeof(result[0]) === 'object') {
606
+ result[0] = clone(result[0]);
607
+ }
608
+ if (_typeof(result[1]) === 'object') {
609
+ result[1] = clone(result[1]);
610
+ }
611
+ }
612
+ return _superPropGet(DiffContext, "setResult", this, 3)([result]);
613
+ }
614
+ }]);
615
+ }(Context);
616
+
617
+ var PatchContext = /*#__PURE__*/function (_Context) {
618
+ function PatchContext(left, delta) {
619
+ var _this;
620
+ _classCallCheck(this, PatchContext);
621
+ _this = _callSuper(this, PatchContext);
622
+ _this.left = left;
623
+ _this.delta = delta;
624
+ _this.pipe = 'patch';
625
+ return _this;
626
+ }
627
+ _inherits(PatchContext, _Context);
628
+ return _createClass(PatchContext);
629
+ }(Context);
630
+
631
+ var ReverseContext = /*#__PURE__*/function (_Context) {
632
+ function ReverseContext(delta) {
633
+ var _this;
634
+ _classCallCheck(this, ReverseContext);
635
+ _this = _callSuper(this, ReverseContext);
636
+ _this.delta = delta;
637
+ _this.pipe = 'reverse';
638
+ return _this;
639
+ }
640
+ _inherits(ReverseContext, _Context);
641
+ return _createClass(ReverseContext);
642
+ }(Context);
643
+
644
+ var diffFilter$3 = function trivialMatchesDiffFilter(context) {
645
+ if (context.left === context.right) {
646
+ context.setResult(undefined).exit();
647
+ return;
648
+ }
649
+ if (typeof context.left === 'undefined') {
650
+ if (typeof context.right === 'function') {
651
+ throw new Error('functions are not supported');
652
+ }
653
+ context.setResult([context.right]).exit();
654
+ return;
655
+ }
656
+ if (typeof context.right === 'undefined') {
657
+ context.setResult([context.left, 0, 0]).exit();
658
+ return;
659
+ }
660
+ if (typeof context.left === 'function' || typeof context.right === 'function') {
661
+ throw new Error('functions are not supported');
662
+ }
663
+ context.leftType = context.left === null ? 'null' : _typeof(context.left);
664
+ context.rightType = context.right === null ? 'null' : _typeof(context.right);
665
+ if (context.leftType !== context.rightType) {
666
+ context.setResult([context.left, context.right]).exit();
667
+ return;
668
+ }
669
+ if (context.leftType === 'boolean' || context.leftType === 'number') {
670
+ context.setResult([context.left, context.right]).exit();
671
+ return;
672
+ }
673
+ if (context.leftType === 'object') {
674
+ context.leftIsArray = Array.isArray(context.left);
675
+ }
676
+ if (context.rightType === 'object') {
677
+ context.rightIsArray = Array.isArray(context.right);
678
+ }
679
+ if (context.leftIsArray !== context.rightIsArray) {
680
+ context.setResult([context.left, context.right]).exit();
681
+ return;
682
+ }
683
+ if (context.left instanceof RegExp) {
684
+ if (context.right instanceof RegExp) {
685
+ context.setResult([context.left.toString(), context.right.toString()]).exit();
686
+ } else {
687
+ context.setResult([context.left, context.right]).exit();
688
+ }
689
+ }
690
+ };
691
+ diffFilter$3.filterName = 'trivial';
692
+ var patchFilter$3 = function trivialMatchesPatchFilter(context) {
693
+ if (typeof context.delta === 'undefined') {
694
+ context.setResult(context.left).exit();
695
+ return;
696
+ }
697
+ context.nested = !Array.isArray(context.delta);
698
+ if (context.nested) {
699
+ return;
700
+ }
701
+ var nonNestedDelta = context.delta;
702
+ if (nonNestedDelta.length === 1) {
703
+ context.setResult(nonNestedDelta[0]).exit();
704
+ return;
705
+ }
706
+ if (nonNestedDelta.length === 2) {
707
+ if (context.left instanceof RegExp) {
708
+ var regexArgs = /^\/(.*)\/([gimyu]+)$/.exec(nonNestedDelta[1]);
709
+ if (regexArgs) {
710
+ context.setResult(new RegExp(regexArgs[1], regexArgs[2])).exit();
711
+ return;
712
+ }
713
+ }
714
+ context.setResult(nonNestedDelta[1]).exit();
715
+ return;
716
+ }
717
+ if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
718
+ context.setResult(undefined).exit();
719
+ }
720
+ };
721
+ patchFilter$3.filterName = 'trivial';
722
+ var reverseFilter$3 = function trivialReferseFilter(context) {
723
+ if (typeof context.delta === 'undefined') {
724
+ context.setResult(context.delta).exit();
725
+ return;
726
+ }
727
+ context.nested = !Array.isArray(context.delta);
728
+ if (context.nested) {
729
+ return;
730
+ }
731
+ var nonNestedDelta = context.delta;
732
+ if (nonNestedDelta.length === 1) {
733
+ context.setResult([nonNestedDelta[0], 0, 0]).exit();
734
+ return;
735
+ }
736
+ if (nonNestedDelta.length === 2) {
737
+ context.setResult([nonNestedDelta[1], nonNestedDelta[0]]).exit();
738
+ return;
739
+ }
740
+ if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
741
+ context.setResult([nonNestedDelta[0]]).exit();
742
+ }
743
+ };
744
+ reverseFilter$3.filterName = 'trivial';
745
+
746
+ var collectChildrenDiffFilter = function collectChildrenDiffFilter(context) {
747
+ if (!context || !context.children) {
748
+ return;
749
+ }
750
+ var length = context.children.length;
751
+ var child;
752
+ var result = context.result;
753
+ for (var index = 0; index < length; index++) {
754
+ child = context.children[index];
755
+ if (typeof child.result === 'undefined') {
756
+ continue;
757
+ }
758
+ result = result || {};
759
+ result[child.childName] = child.result;
760
+ }
761
+ if (result && context.leftIsArray) {
762
+ result._t = 'a';
763
+ }
764
+ context.setResult(result).exit();
765
+ };
766
+ collectChildrenDiffFilter.filterName = 'collectChildren';
767
+ var objectsDiffFilter = function objectsDiffFilter(context) {
768
+ if (context.leftIsArray || context.leftType !== 'object') {
769
+ return;
770
+ }
771
+ var left = context.left;
772
+ var right = context.right;
773
+ var name;
774
+ var child;
775
+ var propertyFilter = context.options.propertyFilter;
776
+ for (name in left) {
777
+ if (!Object.prototype.hasOwnProperty.call(left, name)) {
778
+ continue;
779
+ }
780
+ if (propertyFilter && !propertyFilter(name, context)) {
781
+ continue;
782
+ }
783
+ child = new DiffContext(left[name], right[name]);
784
+ context.push(child, name);
785
+ }
786
+ for (name in right) {
787
+ if (!Object.prototype.hasOwnProperty.call(right, name)) {
788
+ continue;
789
+ }
790
+ if (propertyFilter && !propertyFilter(name, context)) {
791
+ continue;
792
+ }
793
+ if (typeof left[name] === 'undefined') {
794
+ child = new DiffContext(undefined, right[name]);
795
+ context.push(child, name);
796
+ }
797
+ }
798
+ if (!context.children || context.children.length === 0) {
799
+ context.setResult(undefined).exit();
800
+ return;
801
+ }
802
+ context.exit();
803
+ };
804
+ objectsDiffFilter.filterName = 'objects';
805
+ var patchFilter$2 = function nestedPatchFilter(context) {
806
+ if (!context.nested) {
807
+ return;
808
+ }
809
+ var nestedDelta = context.delta;
810
+ if (nestedDelta._t) {
811
+ return;
812
+ }
813
+ var objectDelta = nestedDelta;
814
+ var name;
815
+ var child;
816
+ for (name in objectDelta) {
817
+ child = new PatchContext(context.left[name], objectDelta[name]);
818
+ context.push(child, name);
819
+ }
820
+ context.exit();
821
+ };
822
+ patchFilter$2.filterName = 'objects';
823
+ var collectChildrenPatchFilter$1 = function collectChildrenPatchFilter(context) {
824
+ if (!context || !context.children) {
825
+ return;
826
+ }
827
+ var deltaWithChildren = context.delta;
828
+ if (deltaWithChildren._t) {
829
+ return;
830
+ }
831
+ var object = context.left;
832
+ var length = context.children.length;
833
+ var child;
834
+ for (var index = 0; index < length; index++) {
835
+ child = context.children[index];
836
+ var property = child.childName;
837
+ if (Object.prototype.hasOwnProperty.call(context.left, property) && child.result === undefined) {
838
+ delete object[property];
839
+ } else if (object[property] !== child.result) {
840
+ object[property] = child.result;
841
+ }
842
+ }
843
+ context.setResult(object).exit();
844
+ };
845
+ collectChildrenPatchFilter$1.filterName = 'collectChildren';
846
+ var reverseFilter$2 = function nestedReverseFilter(context) {
847
+ if (!context.nested) {
848
+ return;
849
+ }
850
+ var nestedDelta = context.delta;
851
+ if (nestedDelta._t) {
852
+ return;
853
+ }
854
+ var objectDelta = context.delta;
855
+ var name;
856
+ var child;
857
+ for (name in objectDelta) {
858
+ child = new ReverseContext(objectDelta[name]);
859
+ context.push(child, name);
860
+ }
861
+ context.exit();
862
+ };
863
+ reverseFilter$2.filterName = 'objects';
864
+ var collectChildrenReverseFilter$1 = function collectChildrenReverseFilter(context) {
865
+ if (!context || !context.children) {
866
+ return;
867
+ }
868
+ var deltaWithChildren = context.delta;
869
+ if (deltaWithChildren._t) {
870
+ return;
871
+ }
872
+ var length = context.children.length;
873
+ var child;
874
+ var delta = {};
875
+ for (var index = 0; index < length; index++) {
876
+ child = context.children[index];
877
+ var property = child.childName;
878
+ if (delta[property] !== child.result) {
879
+ delta[property] = child.result;
880
+ }
881
+ }
882
+ context.setResult(delta).exit();
883
+ };
884
+ collectChildrenReverseFilter$1.filterName = 'collectChildren';
885
+
886
+ /*
887
+
888
+ LCS implementation that supports arrays or strings
889
+
890
+ reference: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
891
+
892
+ */
893
+ var defaultMatch = function defaultMatch(array1, array2, index1, index2) {
894
+ return array1[index1] === array2[index2];
895
+ };
896
+ var lengthMatrix = function lengthMatrix(array1, array2, match, context) {
897
+ var len1 = array1.length;
898
+ var len2 = array2.length;
899
+ var x, y;
900
+ // initialize empty matrix of len1+1 x len2+1
901
+ var matrix = new Array(len1 + 1);
902
+ for (x = 0; x < len1 + 1; x++) {
903
+ matrix[x] = new Array(len2 + 1);
904
+ for (y = 0; y < len2 + 1; y++) {
905
+ matrix[x][y] = 0;
906
+ }
907
+ }
908
+ matrix.match = match;
909
+ // save sequence lengths for each coordinate
910
+ for (x = 1; x < len1 + 1; x++) {
911
+ for (y = 1; y < len2 + 1; y++) {
912
+ if (match(array1, array2, x - 1, y - 1, context)) {
913
+ matrix[x][y] = matrix[x - 1][y - 1] + 1;
914
+ } else {
915
+ matrix[x][y] = Math.max(matrix[x - 1][y], matrix[x][y - 1]);
916
+ }
917
+ }
918
+ }
919
+ return matrix;
920
+ };
921
+ var backtrack = function backtrack(matrix, array1, array2, context) {
922
+ var index1 = array1.length;
923
+ var index2 = array2.length;
924
+ var subsequence = {
925
+ sequence: [],
926
+ indices1: [],
927
+ indices2: []
928
+ };
929
+ while (index1 !== 0 && index2 !== 0) {
930
+ var sameLetter = matrix.match(array1, array2, index1 - 1, index2 - 1, context);
931
+ if (sameLetter) {
932
+ subsequence.sequence.unshift(array1[index1 - 1]);
933
+ subsequence.indices1.unshift(index1 - 1);
934
+ subsequence.indices2.unshift(index2 - 1);
935
+ --index1;
936
+ --index2;
937
+ } else {
938
+ var valueAtMatrixAbove = matrix[index1][index2 - 1];
939
+ var valueAtMatrixLeft = matrix[index1 - 1][index2];
940
+ if (valueAtMatrixAbove > valueAtMatrixLeft) {
941
+ --index2;
942
+ } else {
943
+ --index1;
944
+ }
945
+ }
946
+ }
947
+ return subsequence;
948
+ };
949
+ var get = function get(array1, array2, match, context) {
950
+ var innerContext = context || {};
951
+ var matrix = lengthMatrix(array1, array2, match || defaultMatch, innerContext);
952
+ return backtrack(matrix, array1, array2, innerContext);
953
+ };
954
+ var lcs = {
955
+ get: get
956
+ };
957
+
958
+ var ARRAY_MOVE = 3;
959
+ function arraysHaveMatchByRef(array1, array2, len1, len2) {
960
+ for (var index1 = 0; index1 < len1; index1++) {
961
+ var val1 = array1[index1];
962
+ for (var index2 = 0; index2 < len2; index2++) {
963
+ var val2 = array2[index2];
964
+ if (index1 !== index2 && val1 === val2) {
965
+ return true;
966
+ }
967
+ }
968
+ }
969
+ }
970
+ function matchItems(array1, array2, index1, index2, context) {
971
+ var value1 = array1[index1];
972
+ var value2 = array2[index2];
973
+ if (value1 === value2) {
974
+ return true;
975
+ }
976
+ if (_typeof(value1) !== 'object' || _typeof(value2) !== 'object') {
977
+ return false;
978
+ }
979
+ var objectHash = context.objectHash;
980
+ if (!objectHash) {
981
+ // no way to match objects was provided, try match by position
982
+ return context.matchByPosition && index1 === index2;
983
+ }
984
+ context.hashCache1 = context.hashCache1 || [];
985
+ var hash1 = context.hashCache1[index1];
986
+ if (typeof hash1 === 'undefined') {
987
+ context.hashCache1[index1] = hash1 = objectHash(value1, index1);
988
+ }
989
+ if (typeof hash1 === 'undefined') {
990
+ return false;
991
+ }
992
+ context.hashCache2 = context.hashCache2 || [];
993
+ var hash2 = context.hashCache2[index2];
994
+ if (typeof hash2 === 'undefined') {
995
+ context.hashCache2[index2] = hash2 = objectHash(value2, index2);
996
+ }
997
+ if (typeof hash2 === 'undefined') {
998
+ return false;
999
+ }
1000
+ return hash1 === hash2;
1001
+ }
1002
+ var diffFilter$2 = function arraysDiffFilter(context) {
1003
+ if (!context.leftIsArray) {
1004
+ return;
1005
+ }
1006
+ var matchContext = {
1007
+ objectHash: context.options && context.options.objectHash,
1008
+ matchByPosition: context.options && context.options.matchByPosition
1009
+ };
1010
+ var commonHead = 0;
1011
+ var commonTail = 0;
1012
+ var index;
1013
+ var index1;
1014
+ var index2;
1015
+ var array1 = context.left;
1016
+ var array2 = context.right;
1017
+ var len1 = array1.length;
1018
+ var len2 = array2.length;
1019
+ var child;
1020
+ if (len1 > 0 && len2 > 0 && !matchContext.objectHash && typeof matchContext.matchByPosition !== 'boolean') {
1021
+ matchContext.matchByPosition = !arraysHaveMatchByRef(array1, array2, len1, len2);
1022
+ }
1023
+ // separate common head
1024
+ while (commonHead < len1 && commonHead < len2 && matchItems(array1, array2, commonHead, commonHead, matchContext)) {
1025
+ index = commonHead;
1026
+ child = new DiffContext(array1[index], array2[index]);
1027
+ context.push(child, index);
1028
+ commonHead++;
1029
+ }
1030
+ // separate common tail
1031
+ while (commonTail + commonHead < len1 && commonTail + commonHead < len2 && matchItems(array1, array2, len1 - 1 - commonTail, len2 - 1 - commonTail, matchContext)) {
1032
+ index1 = len1 - 1 - commonTail;
1033
+ index2 = len2 - 1 - commonTail;
1034
+ child = new DiffContext(array1[index1], array2[index2]);
1035
+ context.push(child, index2);
1036
+ commonTail++;
1037
+ }
1038
+ var result;
1039
+ if (commonHead + commonTail === len1) {
1040
+ if (len1 === len2) {
1041
+ // arrays are identical
1042
+ context.setResult(undefined).exit();
1043
+ return;
1044
+ }
1045
+ // trivial case, a block (1 or more consecutive items) was added
1046
+ result = result || {
1047
+ _t: 'a'
1048
+ };
1049
+ for (index = commonHead; index < len2 - commonTail; index++) {
1050
+ result[index] = [array2[index]];
1051
+ }
1052
+ context.setResult(result).exit();
1053
+ return;
1054
+ }
1055
+ if (commonHead + commonTail === len2) {
1056
+ // trivial case, a block (1 or more consecutive items) was removed
1057
+ result = result || {
1058
+ _t: 'a'
1059
+ };
1060
+ for (index = commonHead; index < len1 - commonTail; index++) {
1061
+ result["_".concat(index)] = [array1[index], 0, 0];
1062
+ }
1063
+ context.setResult(result).exit();
1064
+ return;
1065
+ }
1066
+ // reset hash cache
1067
+ delete matchContext.hashCache1;
1068
+ delete matchContext.hashCache2;
1069
+ // diff is not trivial, find the LCS (Longest Common Subsequence)
1070
+ var trimmed1 = array1.slice(commonHead, len1 - commonTail);
1071
+ var trimmed2 = array2.slice(commonHead, len2 - commonTail);
1072
+ var seq = lcs.get(trimmed1, trimmed2, matchItems, matchContext);
1073
+ var removedItems = [];
1074
+ result = result || {
1075
+ _t: 'a'
1076
+ };
1077
+ for (index = commonHead; index < len1 - commonTail; index++) {
1078
+ if (seq.indices1.indexOf(index - commonHead) < 0) {
1079
+ // removed
1080
+ result["_".concat(index)] = [array1[index], 0, 0];
1081
+ removedItems.push(index);
1082
+ }
1083
+ }
1084
+ var detectMove = true;
1085
+ if (context.options && context.options.arrays && context.options.arrays.detectMove === false) {
1086
+ detectMove = false;
1087
+ }
1088
+ var includeValueOnMove = false;
1089
+ if (context.options && context.options.arrays && context.options.arrays.includeValueOnMove) {
1090
+ includeValueOnMove = true;
1091
+ }
1092
+ var removedItemsLength = removedItems.length;
1093
+ for (index = commonHead; index < len2 - commonTail; index++) {
1094
+ var indexOnArray2 = seq.indices2.indexOf(index - commonHead);
1095
+ if (indexOnArray2 < 0) {
1096
+ // added, try to match with a removed item and register as position move
1097
+ var isMove = false;
1098
+ if (detectMove && removedItemsLength > 0) {
1099
+ for (var removeItemIndex1 = 0; removeItemIndex1 < removedItemsLength; removeItemIndex1++) {
1100
+ index1 = removedItems[removeItemIndex1];
1101
+ if (matchItems(trimmed1, trimmed2, index1 - commonHead, index - commonHead, matchContext)) {
1102
+ // store position move as: [originalValue, newPosition, ARRAY_MOVE]
1103
+ result["_".concat(index1)].splice(1, 2, index, ARRAY_MOVE);
1104
+ if (!includeValueOnMove) {
1105
+ // don't include moved value on diff, to save bytes
1106
+ result["_".concat(index1)][0] = '';
1107
+ }
1108
+ index2 = index;
1109
+ child = new DiffContext(array1[index1], array2[index2]);
1110
+ context.push(child, index2);
1111
+ removedItems.splice(removeItemIndex1, 1);
1112
+ isMove = true;
1113
+ break;
1114
+ }
1115
+ }
1116
+ }
1117
+ if (!isMove) {
1118
+ // added
1119
+ result[index] = [array2[index]];
1120
+ }
1121
+ } else {
1122
+ // match, do inner diff
1123
+ index1 = seq.indices1[indexOnArray2] + commonHead;
1124
+ index2 = seq.indices2[indexOnArray2] + commonHead;
1125
+ child = new DiffContext(array1[index1], array2[index2]);
1126
+ context.push(child, index2);
1127
+ }
1128
+ }
1129
+ context.setResult(result).exit();
1130
+ };
1131
+ diffFilter$2.filterName = 'arrays';
1132
+ var compare = {
1133
+ numerically: function numerically(a, b) {
1134
+ return a - b;
1135
+ },
1136
+ numericallyBy: function numericallyBy(name) {
1137
+ return function (a, b) {
1138
+ return a[name] - b[name];
1139
+ };
1140
+ }
1141
+ };
1142
+ var patchFilter$1 = function nestedPatchFilter(context) {
1143
+ if (!context.nested) {
1144
+ return;
1145
+ }
1146
+ var nestedDelta = context.delta;
1147
+ if (nestedDelta._t !== 'a') {
1148
+ return;
1149
+ }
1150
+ var index;
1151
+ var index1;
1152
+ var delta = nestedDelta;
1153
+ var array = context.left;
1154
+ // first, separate removals, insertions and modifications
1155
+ var toRemove = [];
1156
+ var toInsert = [];
1157
+ var toModify = [];
1158
+ for (index in delta) {
1159
+ if (index !== '_t') {
1160
+ if (index[0] === '_') {
1161
+ var removedOrMovedIndex = index;
1162
+ // removed item from original array
1163
+ if (delta[removedOrMovedIndex][2] === 0 || delta[removedOrMovedIndex][2] === ARRAY_MOVE) {
1164
+ toRemove.push(parseInt(index.slice(1), 10));
1165
+ } else {
1166
+ throw new Error('only removal or move can be applied at original array indices,' + " invalid diff type: ".concat(delta[removedOrMovedIndex][2]));
1167
+ }
1168
+ } else {
1169
+ var numberIndex = index;
1170
+ if (delta[numberIndex].length === 1) {
1171
+ // added item at new array
1172
+ toInsert.push({
1173
+ index: parseInt(numberIndex, 10),
1174
+ value: delta[numberIndex][0]
1175
+ });
1176
+ } else {
1177
+ // modified item at new array
1178
+ toModify.push({
1179
+ index: parseInt(numberIndex, 10),
1180
+ delta: delta[numberIndex]
1181
+ });
1182
+ }
1183
+ }
1184
+ }
1185
+ }
1186
+ // remove items, in reverse order to avoid sawing our own floor
1187
+ toRemove = toRemove.sort(compare.numerically);
1188
+ for (index = toRemove.length - 1; index >= 0; index--) {
1189
+ index1 = toRemove[index];
1190
+ var indexDiff = delta["_".concat(index1)];
1191
+ var removedValue = array.splice(index1, 1)[0];
1192
+ if (indexDiff[2] === ARRAY_MOVE) {
1193
+ // reinsert later
1194
+ toInsert.push({
1195
+ index: indexDiff[1],
1196
+ value: removedValue
1197
+ });
1198
+ }
1199
+ }
1200
+ // insert items, in reverse order to avoid moving our own floor
1201
+ toInsert = toInsert.sort(compare.numericallyBy('index'));
1202
+ var toInsertLength = toInsert.length;
1203
+ for (index = 0; index < toInsertLength; index++) {
1204
+ var insertion = toInsert[index];
1205
+ array.splice(insertion.index, 0, insertion.value);
1206
+ }
1207
+ // apply modifications
1208
+ var toModifyLength = toModify.length;
1209
+ var child;
1210
+ if (toModifyLength > 0) {
1211
+ for (index = 0; index < toModifyLength; index++) {
1212
+ var modification = toModify[index];
1213
+ child = new PatchContext(array[modification.index], modification.delta);
1214
+ context.push(child, modification.index);
1215
+ }
1216
+ }
1217
+ if (!context.children) {
1218
+ context.setResult(array).exit();
1219
+ return;
1220
+ }
1221
+ context.exit();
1222
+ };
1223
+ patchFilter$1.filterName = 'arrays';
1224
+ var collectChildrenPatchFilter = function collectChildrenPatchFilter(context) {
1225
+ if (!context || !context.children) {
1226
+ return;
1227
+ }
1228
+ var deltaWithChildren = context.delta;
1229
+ if (deltaWithChildren._t !== 'a') {
1230
+ return;
1231
+ }
1232
+ var array = context.left;
1233
+ var length = context.children.length;
1234
+ var child;
1235
+ for (var index = 0; index < length; index++) {
1236
+ child = context.children[index];
1237
+ var arrayIndex = child.childName;
1238
+ array[arrayIndex] = child.result;
1239
+ }
1240
+ context.setResult(array).exit();
1241
+ };
1242
+ collectChildrenPatchFilter.filterName = 'arraysCollectChildren';
1243
+ var reverseFilter$1 = function arraysReverseFilter(context) {
1244
+ if (!context.nested) {
1245
+ var nonNestedDelta = context.delta;
1246
+ if (nonNestedDelta[2] === ARRAY_MOVE) {
1247
+ var arrayMoveDelta = nonNestedDelta;
1248
+ context.newName = "_".concat(arrayMoveDelta[1]);
1249
+ context.setResult([arrayMoveDelta[0], parseInt(context.childName.substring(1), 10), ARRAY_MOVE]).exit();
1250
+ }
1251
+ return;
1252
+ }
1253
+ var nestedDelta = context.delta;
1254
+ if (nestedDelta._t !== 'a') {
1255
+ return;
1256
+ }
1257
+ var arrayDelta = nestedDelta;
1258
+ var name;
1259
+ var child;
1260
+ for (name in arrayDelta) {
1261
+ if (name === '_t') {
1262
+ continue;
1263
+ }
1264
+ child = new ReverseContext(arrayDelta[name]);
1265
+ context.push(child, name);
1266
+ }
1267
+ context.exit();
1268
+ };
1269
+ reverseFilter$1.filterName = 'arrays';
1270
+ var reverseArrayDeltaIndex = function reverseArrayDeltaIndex(delta, index, itemDelta) {
1271
+ if (typeof index === 'string' && index[0] === '_') {
1272
+ return parseInt(index.substring(1), 10);
1273
+ } else if (Array.isArray(itemDelta) && itemDelta[2] === 0) {
1274
+ return "_".concat(index);
1275
+ }
1276
+ var reverseIndex = +index;
1277
+ for (var deltaIndex in delta) {
1278
+ var deltaItem = delta[deltaIndex];
1279
+ if (Array.isArray(deltaItem)) {
1280
+ if (deltaItem[2] === ARRAY_MOVE) {
1281
+ var moveFromIndex = parseInt(deltaIndex.substring(1), 10);
1282
+ var moveToIndex = deltaItem[1];
1283
+ if (moveToIndex === +index) {
1284
+ return moveFromIndex;
1285
+ }
1286
+ if (moveFromIndex <= reverseIndex && moveToIndex > reverseIndex) {
1287
+ reverseIndex++;
1288
+ } else if (moveFromIndex >= reverseIndex && moveToIndex < reverseIndex) {
1289
+ reverseIndex--;
1290
+ }
1291
+ } else if (deltaItem[2] === 0) {
1292
+ var deleteIndex = parseInt(deltaIndex.substring(1), 10);
1293
+ if (deleteIndex <= reverseIndex) {
1294
+ reverseIndex++;
1295
+ }
1296
+ } else if (deltaItem.length === 1 && parseInt(deltaIndex, 10) <= reverseIndex) {
1297
+ reverseIndex--;
1298
+ }
1299
+ }
1300
+ }
1301
+ return reverseIndex;
1302
+ };
1303
+ var collectChildrenReverseFilter = function collectChildrenReverseFilter(context) {
1304
+ if (!context || !context.children) {
1305
+ return;
1306
+ }
1307
+ var deltaWithChildren = context.delta;
1308
+ if (deltaWithChildren._t !== 'a') {
1309
+ return;
1310
+ }
1311
+ var arrayDelta = deltaWithChildren;
1312
+ var length = context.children.length;
1313
+ var child;
1314
+ var delta = {
1315
+ _t: 'a'
1316
+ };
1317
+ for (var index = 0; index < length; index++) {
1318
+ child = context.children[index];
1319
+ var name = child.newName;
1320
+ if (typeof name === 'undefined') {
1321
+ name = reverseArrayDeltaIndex(arrayDelta, child.childName, child.result);
1322
+ }
1323
+ if (delta[name] !== child.result) {
1324
+ // There's no way to type this well.
1325
+ delta[name] = child.result;
1326
+ }
1327
+ }
1328
+ context.setResult(delta).exit();
1329
+ };
1330
+ collectChildrenReverseFilter.filterName = 'arraysCollectChildren';
1331
+
1332
+ var diffFilter$1 = function datesDiffFilter(context) {
1333
+ if (context.left instanceof Date) {
1334
+ if (context.right instanceof Date) {
1335
+ if (context.left.getTime() !== context.right.getTime()) {
1336
+ context.setResult([context.left, context.right]);
1337
+ } else {
1338
+ context.setResult(undefined);
1339
+ }
1340
+ } else {
1341
+ context.setResult([context.left, context.right]);
1342
+ }
1343
+ context.exit();
1344
+ } else if (context.right instanceof Date) {
1345
+ context.setResult([context.left, context.right]).exit();
1346
+ }
1347
+ };
1348
+ diffFilter$1.filterName = 'dates';
1349
+
1350
+ var TEXT_DIFF = 2;
1351
+ var DEFAULT_MIN_LENGTH = 60;
1352
+ var cachedDiffPatch = null;
1353
+ function getDiffMatchPatch(options, required) {
1354
+ var _a;
1355
+ if (!cachedDiffPatch) {
1356
+ var instance;
1357
+ if ((_a = options === null || options === void 0 ? void 0 : options.textDiff) === null || _a === void 0 ? void 0 : _a.diffMatchPatch) {
1358
+ instance = new options.textDiff.diffMatchPatch();
1359
+ } else {
1360
+ if (!required) {
1361
+ return null;
1362
+ }
1363
+ var error = new Error('The diff-match-patch library was not provided. Pass the library in through the options or use the `jsondiffpatch/with-text-diffs` entry-point.');
1364
+ // eslint-disable-next-line camelcase
1365
+ error.diff_match_patch_not_found = true;
1366
+ throw error;
1367
+ }
1368
+ cachedDiffPatch = {
1369
+ diff: function diff(txt1, txt2) {
1370
+ return instance.patch_toText(instance.patch_make(txt1, txt2));
1371
+ },
1372
+ patch: function patch(txt1, _patch) {
1373
+ var results = instance.patch_apply(instance.patch_fromText(_patch), txt1);
1374
+ for (var i = 0; i < results[1].length; i++) {
1375
+ if (!results[1][i]) {
1376
+ var _error = new Error('text patch failed');
1377
+ _error.textPatchFailed = true;
1378
+ }
1379
+ }
1380
+ return results[0];
1381
+ }
1382
+ };
1383
+ }
1384
+ return cachedDiffPatch;
1385
+ }
1386
+ var diffFilter = function textsDiffFilter(context) {
1387
+ if (context.leftType !== 'string') {
1388
+ return;
1389
+ }
1390
+ var left = context.left;
1391
+ var right = context.right;
1392
+ var minLength = context.options && context.options.textDiff && context.options.textDiff.minLength || DEFAULT_MIN_LENGTH;
1393
+ if (left.length < minLength || right.length < minLength) {
1394
+ context.setResult([left, right]).exit();
1395
+ return;
1396
+ }
1397
+ // large text, try to use a text-diff algorithm
1398
+ var diffMatchPatch = getDiffMatchPatch(context.options);
1399
+ if (!diffMatchPatch) {
1400
+ // diff-match-patch library not available,
1401
+ // fallback to regular string replace
1402
+ context.setResult([left, right]).exit();
1403
+ return;
1404
+ }
1405
+ var diff = diffMatchPatch.diff;
1406
+ context.setResult([diff(left, right), 0, TEXT_DIFF]).exit();
1407
+ };
1408
+ diffFilter.filterName = 'texts';
1409
+ var patchFilter = function textsPatchFilter(context) {
1410
+ if (context.nested) {
1411
+ return;
1412
+ }
1413
+ var nonNestedDelta = context.delta;
1414
+ if (nonNestedDelta[2] !== TEXT_DIFF) {
1415
+ return;
1416
+ }
1417
+ var textDiffDelta = nonNestedDelta;
1418
+ // text-diff, use a text-patch algorithm
1419
+ var patch = getDiffMatchPatch(context.options, true).patch;
1420
+ context.setResult(patch(context.left, textDiffDelta[0])).exit();
1421
+ };
1422
+ patchFilter.filterName = 'texts';
1423
+ var textDeltaReverse = function textDeltaReverse(delta) {
1424
+ var i;
1425
+ var l;
1426
+ var line;
1427
+ var lineTmp;
1428
+ var header = null;
1429
+ var headerRegex = /^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/;
1430
+ var lineHeader;
1431
+ var lines = delta.split('\n');
1432
+ for (i = 0, l = lines.length; i < l; i++) {
1433
+ line = lines[i];
1434
+ var lineStart = line.slice(0, 1);
1435
+ if (lineStart === '@') {
1436
+ header = headerRegex.exec(line);
1437
+ lineHeader = i;
1438
+ // fix header
1439
+ lines[lineHeader] = '@@ -' + header[3] + ',' + header[4] + ' +' + header[1] + ',' + header[2] + ' @@';
1440
+ } else if (lineStart === '+') {
1441
+ lines[i] = '-' + lines[i].slice(1);
1442
+ if (lines[i - 1].slice(0, 1) === '+') {
1443
+ // swap lines to keep default order (-+)
1444
+ lineTmp = lines[i];
1445
+ lines[i] = lines[i - 1];
1446
+ lines[i - 1] = lineTmp;
1447
+ }
1448
+ } else if (lineStart === '-') {
1449
+ lines[i] = '+' + lines[i].slice(1);
1450
+ }
1451
+ }
1452
+ return lines.join('\n');
1453
+ };
1454
+ var reverseFilter = function textsReverseFilter(context) {
1455
+ if (context.nested) {
1456
+ return;
1457
+ }
1458
+ var nonNestedDelta = context.delta;
1459
+ if (nonNestedDelta[2] !== TEXT_DIFF) {
1460
+ return;
1461
+ }
1462
+ var textDiffDelta = nonNestedDelta;
1463
+ // text-diff, use a text-diff algorithm
1464
+ context.setResult([textDeltaReverse(textDiffDelta[0]), 0, TEXT_DIFF]).exit();
1465
+ };
1466
+ reverseFilter.filterName = 'texts';
1467
+
1468
+ var DiffPatcher = /*#__PURE__*/function () {
1469
+ function DiffPatcher(options) {
1470
+ _classCallCheck(this, DiffPatcher);
1471
+ this.processor = new Processor(options);
1472
+ this.processor.pipe(new Pipe('diff').append(collectChildrenDiffFilter, diffFilter$3, diffFilter$1, diffFilter, objectsDiffFilter, diffFilter$2).shouldHaveResult());
1473
+ this.processor.pipe(new Pipe('patch').append(collectChildrenPatchFilter$1, collectChildrenPatchFilter, patchFilter$3, patchFilter, patchFilter$2, patchFilter$1).shouldHaveResult());
1474
+ this.processor.pipe(new Pipe('reverse').append(collectChildrenReverseFilter$1, collectChildrenReverseFilter, reverseFilter$3, reverseFilter, reverseFilter$2, reverseFilter$1).shouldHaveResult());
1475
+ }
1476
+ return _createClass(DiffPatcher, [{
1477
+ key: "options",
1478
+ value: function options(_options) {
1479
+ return this.processor.options(_options);
1480
+ }
1481
+ }, {
1482
+ key: "diff",
1483
+ value: function diff(left, right) {
1484
+ return this.processor.process(new DiffContext(left, right));
1485
+ }
1486
+ }, {
1487
+ key: "patch",
1488
+ value: function patch(left, delta) {
1489
+ return this.processor.process(new PatchContext(left, delta));
1490
+ }
1491
+ }, {
1492
+ key: "reverse",
1493
+ value: function reverse(delta) {
1494
+ return this.processor.process(new ReverseContext(delta));
1495
+ }
1496
+ }, {
1497
+ key: "unpatch",
1498
+ value: function unpatch(right, delta) {
1499
+ return this.patch(right, this.reverse(delta));
1500
+ }
1501
+ }, {
1502
+ key: "clone",
1503
+ value: function clone(value) {
1504
+ return clone$1(value);
1505
+ }
1506
+ }]);
1507
+ }();
1508
+
235
1509
  function objectHash(obj, index) {
236
1510
  var objIndex = "$$index:".concat(index);
237
1511
  return _typeof(obj) === 'object' && obj !== null ? obj.id || obj.name || obj.url || objIndex : objIndex;
@@ -673,7 +1947,6 @@ function actionsMapReferences$3(diff, oldObj, newObj) {
673
1947
  return buildReferenceActions({
674
1948
  actions: referenceActionsList$3,
675
1949
  diff: diff,
676
- oldObj: oldObj,
677
1950
  newObj: newObj
678
1951
  });
679
1952
  }
@@ -889,7 +2162,6 @@ function actionsMapReferences$2(diff, oldObj, newObj) {
889
2162
  return buildReferenceActions({
890
2163
  actions: referenceActionsList$2,
891
2164
  diff: diff,
892
- oldObj: oldObj,
893
2165
  newObj: newObj
894
2166
  });
895
2167
  }
@@ -1087,7 +2359,6 @@ function actionsMapReferences$1(diff, oldObj, newObj) {
1087
2359
  return buildReferenceActions({
1088
2360
  actions: referenceActionsList$1,
1089
2361
  diff: diff,
1090
- oldObj: oldObj,
1091
2362
  newObj: newObj
1092
2363
  });
1093
2364
  }
@@ -1634,7 +2905,6 @@ function actionsMapReferences(diff, oldObj, newObj) {
1634
2905
  return buildReferenceActions({
1635
2906
  actions: referenceActionsList,
1636
2907
  diff: diff,
1637
- oldObj: oldObj,
1638
2908
  newObj: newObj
1639
2909
  });
1640
2910
  }