@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,28 +1,14 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var flatten = require('lodash.flatten');
6
4
  var isEqual = require('lodash.isequal');
7
5
  var isNil = require('lodash.isnil');
8
- var jsondiffpatch_cjs = require('jsondiffpatch/dist/jsondiffpatch.cjs');
9
6
  var forEach = require('lodash.foreach');
10
7
  var uniqWith = require('lodash.uniqwith');
11
8
  var intersection = require('lodash.intersection');
12
9
  var without = require('lodash.without');
13
10
  var sortBy = require('lodash.sortby');
14
11
 
15
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
-
17
- var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
18
- var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
19
- var isNil__default = /*#__PURE__*/_interopDefaultLegacy(isNil);
20
- var forEach__default = /*#__PURE__*/_interopDefaultLegacy(forEach);
21
- var uniqWith__default = /*#__PURE__*/_interopDefaultLegacy(uniqWith);
22
- var intersection__default = /*#__PURE__*/_interopDefaultLegacy(intersection);
23
- var without__default = /*#__PURE__*/_interopDefaultLegacy(without);
24
- var sortBy__default = /*#__PURE__*/_interopDefaultLegacy(sortBy);
25
-
26
12
  function _arrayLikeToArray(r, a) {
27
13
  (null == a || a > r.length) && (a = r.length);
28
14
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
@@ -34,14 +20,69 @@ function _arrayWithHoles(r) {
34
20
  function _arrayWithoutHoles(r) {
35
21
  if (Array.isArray(r)) return _arrayLikeToArray(r);
36
22
  }
23
+ function _assertThisInitialized(e) {
24
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
25
+ return e;
26
+ }
27
+ function _callSuper(t, o, e) {
28
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, [], _getPrototypeOf(t).constructor) : o.apply(t, e));
29
+ }
30
+ function _classCallCheck(a, n) {
31
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
32
+ }
33
+ function _defineProperties(e, r) {
34
+ for (var t = 0; t < r.length; t++) {
35
+ var o = r[t];
36
+ o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
37
+ }
38
+ }
39
+ function _createClass(e, r, t) {
40
+ return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
41
+ writable: false
42
+ }), e;
43
+ }
37
44
  function _defineProperty(e, r, t) {
38
45
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
39
46
  value: t,
40
- enumerable: !0,
41
- configurable: !0,
42
- writable: !0
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true
43
50
  }) : e[r] = t, e;
44
51
  }
52
+ function _get() {
53
+ return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
54
+ var p = _superPropBase(e, t);
55
+ if (p) {
56
+ var n = Object.getOwnPropertyDescriptor(p, t);
57
+ return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
58
+ }
59
+ }, _get.apply(null, arguments);
60
+ }
61
+ function _getPrototypeOf(t) {
62
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
63
+ return t.__proto__ || Object.getPrototypeOf(t);
64
+ }, _getPrototypeOf(t);
65
+ }
66
+ function _inherits(t, e) {
67
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
68
+ t.prototype = Object.create(e && e.prototype, {
69
+ constructor: {
70
+ value: t,
71
+ writable: true,
72
+ configurable: true
73
+ }
74
+ }), Object.defineProperty(t, "prototype", {
75
+ writable: false
76
+ }), e && _setPrototypeOf(t, e);
77
+ }
78
+ function _isNativeReflectConstruct() {
79
+ try {
80
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
81
+ } catch (t) {}
82
+ return (_isNativeReflectConstruct = function () {
83
+ return !!t;
84
+ })();
85
+ }
45
86
  function _iterableToArray(r) {
46
87
  if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
47
88
  }
@@ -53,15 +94,15 @@ function _iterableToArrayLimit(r, l) {
53
94
  i,
54
95
  u,
55
96
  a = [],
56
- f = !0,
57
- o = !1;
97
+ f = true,
98
+ o = false;
58
99
  try {
59
100
  if (i = (t = t.call(r)).next, 0 === l) {
60
101
  if (Object(t) !== t) return;
61
102
  f = !1;
62
103
  } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
63
104
  } catch (r) {
64
- o = !0, n = r;
105
+ o = true, n = r;
65
106
  } finally {
66
107
  try {
67
108
  if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
@@ -91,7 +132,7 @@ function ownKeys(e, r) {
91
132
  function _objectSpread2(e) {
92
133
  for (var r = 1; r < arguments.length; r++) {
93
134
  var t = null != arguments[r] ? arguments[r] : {};
94
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
135
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
95
136
  _defineProperty(e, r, t[r]);
96
137
  }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
97
138
  Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
@@ -105,8 +146,8 @@ function _objectWithoutProperties(e, t) {
105
146
  r,
106
147
  i = _objectWithoutPropertiesLoose(e, t);
107
148
  if (Object.getOwnPropertySymbols) {
108
- var s = Object.getOwnPropertySymbols(e);
109
- for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
149
+ var n = Object.getOwnPropertySymbols(e);
150
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
110
151
  }
111
152
  return i;
112
153
  }
@@ -114,14 +155,34 @@ function _objectWithoutPropertiesLoose(r, e) {
114
155
  if (null == r) return {};
115
156
  var t = {};
116
157
  for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
117
- if (e.includes(n)) continue;
158
+ if (-1 !== e.indexOf(n)) continue;
118
159
  t[n] = r[n];
119
160
  }
120
161
  return t;
121
162
  }
163
+ function _possibleConstructorReturn(t, e) {
164
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
165
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
166
+ return _assertThisInitialized(t);
167
+ }
168
+ function _setPrototypeOf(t, e) {
169
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
170
+ return t.__proto__ = e, t;
171
+ }, _setPrototypeOf(t, e);
172
+ }
122
173
  function _slicedToArray(r, e) {
123
174
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
124
175
  }
176
+ function _superPropBase(t, o) {
177
+ for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
178
+ return t;
179
+ }
180
+ function _superPropGet(t, o, e, r) {
181
+ var p = _get(_getPrototypeOf(t.prototype ), o, e);
182
+ return 2 & r && "function" == typeof p ? function (t) {
183
+ return p.apply(e, t);
184
+ } : p;
185
+ }
125
186
  function _toConsumableArray(r) {
126
187
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
127
188
  }
@@ -129,11 +190,11 @@ function _toPrimitive(t, r) {
129
190
  if ("object" != typeof t || !t) return t;
130
191
  var e = t[Symbol.toPrimitive];
131
192
  if (void 0 !== e) {
132
- var i = e.call(t, r || "default");
193
+ var i = e.call(t, r);
133
194
  if ("object" != typeof i) return i;
134
195
  throw new TypeError("@@toPrimitive must return a primitive value.");
135
196
  }
136
- return ("string" === r ? String : Number)(t);
197
+ return (String )(t);
137
198
  }
138
199
  function _toPropertyKey(t) {
139
200
  var i = _toPrimitive(t, "string");
@@ -175,7 +236,7 @@ var createPriceComparator = function createPriceComparator(price) {
175
236
  function arePricesStructurallyEqual(oldPrice, newPrice) {
176
237
  var oldPriceComparison = createPriceComparator(oldPrice);
177
238
  var newPriceComparison = createPriceComparator(newPrice);
178
- return isEqual__default["default"](newPriceComparison, oldPriceComparison);
239
+ return isEqual(newPriceComparison, oldPriceComparison);
179
240
  }
180
241
  function extractPriceFromPreviousVariant(newPrice, previousVariant) {
181
242
  if (!previousVariant) return null;
@@ -190,7 +251,7 @@ function injectMissingPriceIds(nextVariants, previousVariants) {
190
251
  restOfVariant = _objectWithoutProperties(newVariant, _excluded$2);
191
252
  if (!prices) return restOfVariant;
192
253
  var oldVariant = previousVariants.find(function (previousVariant) {
193
- return !isNil__default["default"](previousVariant.id) && previousVariant.id === newVariant.id || !isNil__default["default"](previousVariant.key) && previousVariant.key === newVariant.key || !isNil__default["default"](previousVariant.sku) && previousVariant.sku === newVariant.sku;
254
+ return !isNil(previousVariant.id) && previousVariant.id === newVariant.id || !isNil(previousVariant.key) && previousVariant.key === newVariant.key || !isNil(previousVariant.sku) && previousVariant.sku === newVariant.sku;
194
255
  });
195
256
  return _objectSpread2(_objectSpread2({}, restOfVariant), {}, {
196
257
  prices: prices.map(function (price) {
@@ -199,8 +260,8 @@ function injectMissingPriceIds(nextVariants, previousVariants) {
199
260
  if (oldPrice) {
200
261
  // copy ID if not provided
201
262
  if (!newPrice.id) newPrice.id = oldPrice.id;
202
- if (isNil__default["default"](newPrice.value.type)) newPrice.value.type = oldPrice.value.type;
203
- if (isNil__default["default"](newPrice.value.fractionDigits)) newPrice.value.fractionDigits = oldPrice.value.fractionDigits;
263
+ if (isNil(newPrice.value.type)) newPrice.value.type = oldPrice.value.type;
264
+ if (isNil(newPrice.value.fractionDigits)) newPrice.value.fractionDigits = oldPrice.value.fractionDigits;
204
265
  }
205
266
  return newPrice;
206
267
  })
@@ -247,11 +308,1211 @@ function createMapActionGroup() {
247
308
  };
248
309
  }
249
310
 
311
+ var Processor = /*#__PURE__*/function () {
312
+ function Processor(options) {
313
+ _classCallCheck(this, Processor);
314
+ this.selfOptions = options || {};
315
+ this.pipes = {};
316
+ }
317
+ return _createClass(Processor, [{
318
+ key: "options",
319
+ value: function options(_options) {
320
+ if (_options) {
321
+ this.selfOptions = _options;
322
+ }
323
+ return this.selfOptions;
324
+ }
325
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
326
+ }, {
327
+ key: "pipe",
328
+ value: function pipe(name, pipeArg) {
329
+ var pipe = pipeArg;
330
+ if (typeof name === 'string') {
331
+ if (typeof pipe === 'undefined') {
332
+ return this.pipes[name];
333
+ } else {
334
+ this.pipes[name] = pipe;
335
+ }
336
+ }
337
+ if (name && name.name) {
338
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
339
+ pipe = name;
340
+ if (pipe.processor === this) {
341
+ return pipe;
342
+ }
343
+ this.pipes[pipe.name] = pipe;
344
+ }
345
+ pipe.processor = this;
346
+ return pipe;
347
+ }
348
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
349
+ }, {
350
+ key: "process",
351
+ value: function process(input, pipe) {
352
+ var context = input;
353
+ context.options = this.options();
354
+ var nextPipe = pipe || input.pipe || 'default';
355
+ var lastPipe;
356
+ while (nextPipe) {
357
+ if (typeof context.nextAfterChildren !== 'undefined') {
358
+ // children processed and coming back to parent
359
+ context.next = context.nextAfterChildren;
360
+ context.nextAfterChildren = null;
361
+ }
362
+ if (typeof nextPipe === 'string') {
363
+ nextPipe = this.pipe(nextPipe);
364
+ }
365
+ nextPipe.process(context);
366
+ lastPipe = nextPipe;
367
+ nextPipe = null;
368
+ if (context) {
369
+ if (context.next) {
370
+ context = context.next;
371
+ nextPipe = context.pipe || lastPipe;
372
+ }
373
+ }
374
+ }
375
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
376
+ return context.hasResult ? context.result : undefined;
377
+ }
378
+ }]);
379
+ }();
380
+
381
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
382
+ var Pipe = /*#__PURE__*/function () {
383
+ function Pipe(name) {
384
+ _classCallCheck(this, Pipe);
385
+ this.name = name;
386
+ this.filters = [];
387
+ }
388
+ return _createClass(Pipe, [{
389
+ key: "process",
390
+ value: function process(input) {
391
+ if (!this.processor) {
392
+ throw new Error('add this pipe to a processor before using it');
393
+ }
394
+ var debug = this.debug;
395
+ var length = this.filters.length;
396
+ var context = input;
397
+ for (var index = 0; index < length; index++) {
398
+ var filter = this.filters[index];
399
+ if (debug) {
400
+ this.log("filter: ".concat(filter.filterName));
401
+ }
402
+ filter(context);
403
+ if (_typeof(context) === 'object' && context.exiting) {
404
+ context.exiting = false;
405
+ break;
406
+ }
407
+ }
408
+ if (!context.next && this.resultCheck) {
409
+ this.resultCheck(context);
410
+ }
411
+ }
412
+ }, {
413
+ key: "log",
414
+ value: function log(msg) {
415
+ console.log("[jsondiffpatch] ".concat(this.name, " pipe, ").concat(msg));
416
+ }
417
+ }, {
418
+ key: "append",
419
+ value: function append() {
420
+ var _this$filters;
421
+ (_this$filters = this.filters).push.apply(_this$filters, arguments);
422
+ return this;
423
+ }
424
+ }, {
425
+ key: "prepend",
426
+ value: function prepend() {
427
+ var _this$filters2;
428
+ (_this$filters2 = this.filters).unshift.apply(_this$filters2, arguments);
429
+ return this;
430
+ }
431
+ }, {
432
+ key: "indexOf",
433
+ value: function indexOf(filterName) {
434
+ if (!filterName) {
435
+ throw new Error('a filter name is required');
436
+ }
437
+ for (var index = 0; index < this.filters.length; index++) {
438
+ var filter = this.filters[index];
439
+ if (filter.filterName === filterName) {
440
+ return index;
441
+ }
442
+ }
443
+ throw new Error("filter not found: ".concat(filterName));
444
+ }
445
+ }, {
446
+ key: "list",
447
+ value: function list() {
448
+ return this.filters.map(function (f) {
449
+ return f.filterName;
450
+ });
451
+ }
452
+ }, {
453
+ key: "after",
454
+ value: function after(filterName) {
455
+ var _this$filters3;
456
+ var index = this.indexOf(filterName);
457
+ for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
458
+ params[_key - 1] = arguments[_key];
459
+ }
460
+ (_this$filters3 = this.filters).splice.apply(_this$filters3, [index + 1, 0].concat(params));
461
+ return this;
462
+ }
463
+ }, {
464
+ key: "before",
465
+ value: function before(filterName) {
466
+ var _this$filters4;
467
+ var index = this.indexOf(filterName);
468
+ for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
469
+ params[_key2 - 1] = arguments[_key2];
470
+ }
471
+ (_this$filters4 = this.filters).splice.apply(_this$filters4, [index, 0].concat(params));
472
+ return this;
473
+ }
474
+ }, {
475
+ key: "replace",
476
+ value: function replace(filterName) {
477
+ var _this$filters5;
478
+ var index = this.indexOf(filterName);
479
+ for (var _len3 = arguments.length, params = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
480
+ params[_key3 - 1] = arguments[_key3];
481
+ }
482
+ (_this$filters5 = this.filters).splice.apply(_this$filters5, [index, 1].concat(params));
483
+ return this;
484
+ }
485
+ }, {
486
+ key: "remove",
487
+ value: function remove(filterName) {
488
+ var index = this.indexOf(filterName);
489
+ this.filters.splice(index, 1);
490
+ return this;
491
+ }
492
+ }, {
493
+ key: "clear",
494
+ value: function clear() {
495
+ this.filters.length = 0;
496
+ return this;
497
+ }
498
+ }, {
499
+ key: "shouldHaveResult",
500
+ value: function shouldHaveResult(should) {
501
+ var _this = this;
502
+ if (should === false) {
503
+ this.resultCheck = null;
504
+ return;
505
+ }
506
+ if (this.resultCheck) {
507
+ return;
508
+ }
509
+ this.resultCheck = function (context) {
510
+ if (!context.hasResult) {
511
+ console.log(context);
512
+ var error = new Error("".concat(_this.name, " failed"));
513
+ error.noResult = true;
514
+ throw error;
515
+ }
516
+ };
517
+ return this;
518
+ }
519
+ }]);
520
+ }();
521
+
522
+ var Context = /*#__PURE__*/function () {
523
+ function Context() {
524
+ _classCallCheck(this, Context);
525
+ }
526
+ return _createClass(Context, [{
527
+ key: "setResult",
528
+ value: function setResult(result) {
529
+ this.result = result;
530
+ this.hasResult = true;
531
+ return this;
532
+ }
533
+ }, {
534
+ key: "exit",
535
+ value: function exit() {
536
+ this.exiting = true;
537
+ return this;
538
+ }
539
+ }, {
540
+ key: "push",
541
+ value: function push(child, name) {
542
+ child.parent = this;
543
+ if (typeof name !== 'undefined') {
544
+ child.childName = name;
545
+ }
546
+ child.root = this.root || this;
547
+ child.options = child.options || this.options;
548
+ if (!this.children) {
549
+ this.children = [child];
550
+ this.nextAfterChildren = this.next || null;
551
+ this.next = child;
552
+ } else {
553
+ this.children[this.children.length - 1].next = child;
554
+ this.children.push(child);
555
+ }
556
+ child.next = this;
557
+ return this;
558
+ }
559
+ }]);
560
+ }();
561
+
562
+ function cloneRegExp(re) {
563
+ var regexMatch = /^\/(.*)\/([gimyu]*)$/.exec(re.toString());
564
+ return new RegExp(regexMatch[1], regexMatch[2]);
565
+ }
566
+ function clone$1(arg) {
567
+ if (_typeof(arg) !== 'object') {
568
+ return arg;
569
+ }
570
+ if (arg === null) {
571
+ return null;
572
+ }
573
+ if (Array.isArray(arg)) {
574
+ return arg.map(clone$1);
575
+ }
576
+ if (arg instanceof Date) {
577
+ return new Date(arg.getTime());
578
+ }
579
+ if (arg instanceof RegExp) {
580
+ return cloneRegExp(arg);
581
+ }
582
+ var cloned = {};
583
+ for (var name in arg) {
584
+ if (Object.prototype.hasOwnProperty.call(arg, name)) {
585
+ cloned[name] = clone$1(arg[name]);
586
+ }
587
+ }
588
+ return cloned;
589
+ }
590
+
591
+ var DiffContext = /*#__PURE__*/function (_Context) {
592
+ function DiffContext(left, right) {
593
+ var _this;
594
+ _classCallCheck(this, DiffContext);
595
+ _this = _callSuper(this, DiffContext);
596
+ _this.left = left;
597
+ _this.right = right;
598
+ _this.pipe = 'diff';
599
+ return _this;
600
+ }
601
+ _inherits(DiffContext, _Context);
602
+ return _createClass(DiffContext, [{
603
+ key: "setResult",
604
+ value: function setResult(result) {
605
+ if (this.options.cloneDiffValues && _typeof(result) === 'object') {
606
+ var clone = typeof this.options.cloneDiffValues === 'function' ? this.options.cloneDiffValues : clone$1;
607
+ if (_typeof(result[0]) === 'object') {
608
+ result[0] = clone(result[0]);
609
+ }
610
+ if (_typeof(result[1]) === 'object') {
611
+ result[1] = clone(result[1]);
612
+ }
613
+ }
614
+ return _superPropGet(DiffContext, "setResult", this, 3)([result]);
615
+ }
616
+ }]);
617
+ }(Context);
618
+
619
+ var PatchContext = /*#__PURE__*/function (_Context) {
620
+ function PatchContext(left, delta) {
621
+ var _this;
622
+ _classCallCheck(this, PatchContext);
623
+ _this = _callSuper(this, PatchContext);
624
+ _this.left = left;
625
+ _this.delta = delta;
626
+ _this.pipe = 'patch';
627
+ return _this;
628
+ }
629
+ _inherits(PatchContext, _Context);
630
+ return _createClass(PatchContext);
631
+ }(Context);
632
+
633
+ var ReverseContext = /*#__PURE__*/function (_Context) {
634
+ function ReverseContext(delta) {
635
+ var _this;
636
+ _classCallCheck(this, ReverseContext);
637
+ _this = _callSuper(this, ReverseContext);
638
+ _this.delta = delta;
639
+ _this.pipe = 'reverse';
640
+ return _this;
641
+ }
642
+ _inherits(ReverseContext, _Context);
643
+ return _createClass(ReverseContext);
644
+ }(Context);
645
+
646
+ var diffFilter$3 = function trivialMatchesDiffFilter(context) {
647
+ if (context.left === context.right) {
648
+ context.setResult(undefined).exit();
649
+ return;
650
+ }
651
+ if (typeof context.left === 'undefined') {
652
+ if (typeof context.right === 'function') {
653
+ throw new Error('functions are not supported');
654
+ }
655
+ context.setResult([context.right]).exit();
656
+ return;
657
+ }
658
+ if (typeof context.right === 'undefined') {
659
+ context.setResult([context.left, 0, 0]).exit();
660
+ return;
661
+ }
662
+ if (typeof context.left === 'function' || typeof context.right === 'function') {
663
+ throw new Error('functions are not supported');
664
+ }
665
+ context.leftType = context.left === null ? 'null' : _typeof(context.left);
666
+ context.rightType = context.right === null ? 'null' : _typeof(context.right);
667
+ if (context.leftType !== context.rightType) {
668
+ context.setResult([context.left, context.right]).exit();
669
+ return;
670
+ }
671
+ if (context.leftType === 'boolean' || context.leftType === 'number') {
672
+ context.setResult([context.left, context.right]).exit();
673
+ return;
674
+ }
675
+ if (context.leftType === 'object') {
676
+ context.leftIsArray = Array.isArray(context.left);
677
+ }
678
+ if (context.rightType === 'object') {
679
+ context.rightIsArray = Array.isArray(context.right);
680
+ }
681
+ if (context.leftIsArray !== context.rightIsArray) {
682
+ context.setResult([context.left, context.right]).exit();
683
+ return;
684
+ }
685
+ if (context.left instanceof RegExp) {
686
+ if (context.right instanceof RegExp) {
687
+ context.setResult([context.left.toString(), context.right.toString()]).exit();
688
+ } else {
689
+ context.setResult([context.left, context.right]).exit();
690
+ }
691
+ }
692
+ };
693
+ diffFilter$3.filterName = 'trivial';
694
+ var patchFilter$3 = function trivialMatchesPatchFilter(context) {
695
+ if (typeof context.delta === 'undefined') {
696
+ context.setResult(context.left).exit();
697
+ return;
698
+ }
699
+ context.nested = !Array.isArray(context.delta);
700
+ if (context.nested) {
701
+ return;
702
+ }
703
+ var nonNestedDelta = context.delta;
704
+ if (nonNestedDelta.length === 1) {
705
+ context.setResult(nonNestedDelta[0]).exit();
706
+ return;
707
+ }
708
+ if (nonNestedDelta.length === 2) {
709
+ if (context.left instanceof RegExp) {
710
+ var regexArgs = /^\/(.*)\/([gimyu]+)$/.exec(nonNestedDelta[1]);
711
+ if (regexArgs) {
712
+ context.setResult(new RegExp(regexArgs[1], regexArgs[2])).exit();
713
+ return;
714
+ }
715
+ }
716
+ context.setResult(nonNestedDelta[1]).exit();
717
+ return;
718
+ }
719
+ if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
720
+ context.setResult(undefined).exit();
721
+ }
722
+ };
723
+ patchFilter$3.filterName = 'trivial';
724
+ var reverseFilter$3 = function trivialReferseFilter(context) {
725
+ if (typeof context.delta === 'undefined') {
726
+ context.setResult(context.delta).exit();
727
+ return;
728
+ }
729
+ context.nested = !Array.isArray(context.delta);
730
+ if (context.nested) {
731
+ return;
732
+ }
733
+ var nonNestedDelta = context.delta;
734
+ if (nonNestedDelta.length === 1) {
735
+ context.setResult([nonNestedDelta[0], 0, 0]).exit();
736
+ return;
737
+ }
738
+ if (nonNestedDelta.length === 2) {
739
+ context.setResult([nonNestedDelta[1], nonNestedDelta[0]]).exit();
740
+ return;
741
+ }
742
+ if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
743
+ context.setResult([nonNestedDelta[0]]).exit();
744
+ }
745
+ };
746
+ reverseFilter$3.filterName = 'trivial';
747
+
748
+ var collectChildrenDiffFilter = function collectChildrenDiffFilter(context) {
749
+ if (!context || !context.children) {
750
+ return;
751
+ }
752
+ var length = context.children.length;
753
+ var child;
754
+ var result = context.result;
755
+ for (var index = 0; index < length; index++) {
756
+ child = context.children[index];
757
+ if (typeof child.result === 'undefined') {
758
+ continue;
759
+ }
760
+ result = result || {};
761
+ result[child.childName] = child.result;
762
+ }
763
+ if (result && context.leftIsArray) {
764
+ result._t = 'a';
765
+ }
766
+ context.setResult(result).exit();
767
+ };
768
+ collectChildrenDiffFilter.filterName = 'collectChildren';
769
+ var objectsDiffFilter = function objectsDiffFilter(context) {
770
+ if (context.leftIsArray || context.leftType !== 'object') {
771
+ return;
772
+ }
773
+ var left = context.left;
774
+ var right = context.right;
775
+ var name;
776
+ var child;
777
+ var propertyFilter = context.options.propertyFilter;
778
+ for (name in left) {
779
+ if (!Object.prototype.hasOwnProperty.call(left, name)) {
780
+ continue;
781
+ }
782
+ if (propertyFilter && !propertyFilter(name, context)) {
783
+ continue;
784
+ }
785
+ child = new DiffContext(left[name], right[name]);
786
+ context.push(child, name);
787
+ }
788
+ for (name in right) {
789
+ if (!Object.prototype.hasOwnProperty.call(right, name)) {
790
+ continue;
791
+ }
792
+ if (propertyFilter && !propertyFilter(name, context)) {
793
+ continue;
794
+ }
795
+ if (typeof left[name] === 'undefined') {
796
+ child = new DiffContext(undefined, right[name]);
797
+ context.push(child, name);
798
+ }
799
+ }
800
+ if (!context.children || context.children.length === 0) {
801
+ context.setResult(undefined).exit();
802
+ return;
803
+ }
804
+ context.exit();
805
+ };
806
+ objectsDiffFilter.filterName = 'objects';
807
+ var patchFilter$2 = function nestedPatchFilter(context) {
808
+ if (!context.nested) {
809
+ return;
810
+ }
811
+ var nestedDelta = context.delta;
812
+ if (nestedDelta._t) {
813
+ return;
814
+ }
815
+ var objectDelta = nestedDelta;
816
+ var name;
817
+ var child;
818
+ for (name in objectDelta) {
819
+ child = new PatchContext(context.left[name], objectDelta[name]);
820
+ context.push(child, name);
821
+ }
822
+ context.exit();
823
+ };
824
+ patchFilter$2.filterName = 'objects';
825
+ var collectChildrenPatchFilter$1 = function collectChildrenPatchFilter(context) {
826
+ if (!context || !context.children) {
827
+ return;
828
+ }
829
+ var deltaWithChildren = context.delta;
830
+ if (deltaWithChildren._t) {
831
+ return;
832
+ }
833
+ var object = context.left;
834
+ var length = context.children.length;
835
+ var child;
836
+ for (var index = 0; index < length; index++) {
837
+ child = context.children[index];
838
+ var property = child.childName;
839
+ if (Object.prototype.hasOwnProperty.call(context.left, property) && child.result === undefined) {
840
+ delete object[property];
841
+ } else if (object[property] !== child.result) {
842
+ object[property] = child.result;
843
+ }
844
+ }
845
+ context.setResult(object).exit();
846
+ };
847
+ collectChildrenPatchFilter$1.filterName = 'collectChildren';
848
+ var reverseFilter$2 = function nestedReverseFilter(context) {
849
+ if (!context.nested) {
850
+ return;
851
+ }
852
+ var nestedDelta = context.delta;
853
+ if (nestedDelta._t) {
854
+ return;
855
+ }
856
+ var objectDelta = context.delta;
857
+ var name;
858
+ var child;
859
+ for (name in objectDelta) {
860
+ child = new ReverseContext(objectDelta[name]);
861
+ context.push(child, name);
862
+ }
863
+ context.exit();
864
+ };
865
+ reverseFilter$2.filterName = 'objects';
866
+ var collectChildrenReverseFilter$1 = function collectChildrenReverseFilter(context) {
867
+ if (!context || !context.children) {
868
+ return;
869
+ }
870
+ var deltaWithChildren = context.delta;
871
+ if (deltaWithChildren._t) {
872
+ return;
873
+ }
874
+ var length = context.children.length;
875
+ var child;
876
+ var delta = {};
877
+ for (var index = 0; index < length; index++) {
878
+ child = context.children[index];
879
+ var property = child.childName;
880
+ if (delta[property] !== child.result) {
881
+ delta[property] = child.result;
882
+ }
883
+ }
884
+ context.setResult(delta).exit();
885
+ };
886
+ collectChildrenReverseFilter$1.filterName = 'collectChildren';
887
+
888
+ /*
889
+
890
+ LCS implementation that supports arrays or strings
891
+
892
+ reference: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
893
+
894
+ */
895
+ var defaultMatch = function defaultMatch(array1, array2, index1, index2) {
896
+ return array1[index1] === array2[index2];
897
+ };
898
+ var lengthMatrix = function lengthMatrix(array1, array2, match, context) {
899
+ var len1 = array1.length;
900
+ var len2 = array2.length;
901
+ var x, y;
902
+ // initialize empty matrix of len1+1 x len2+1
903
+ var matrix = new Array(len1 + 1);
904
+ for (x = 0; x < len1 + 1; x++) {
905
+ matrix[x] = new Array(len2 + 1);
906
+ for (y = 0; y < len2 + 1; y++) {
907
+ matrix[x][y] = 0;
908
+ }
909
+ }
910
+ matrix.match = match;
911
+ // save sequence lengths for each coordinate
912
+ for (x = 1; x < len1 + 1; x++) {
913
+ for (y = 1; y < len2 + 1; y++) {
914
+ if (match(array1, array2, x - 1, y - 1, context)) {
915
+ matrix[x][y] = matrix[x - 1][y - 1] + 1;
916
+ } else {
917
+ matrix[x][y] = Math.max(matrix[x - 1][y], matrix[x][y - 1]);
918
+ }
919
+ }
920
+ }
921
+ return matrix;
922
+ };
923
+ var backtrack = function backtrack(matrix, array1, array2, context) {
924
+ var index1 = array1.length;
925
+ var index2 = array2.length;
926
+ var subsequence = {
927
+ sequence: [],
928
+ indices1: [],
929
+ indices2: []
930
+ };
931
+ while (index1 !== 0 && index2 !== 0) {
932
+ var sameLetter = matrix.match(array1, array2, index1 - 1, index2 - 1, context);
933
+ if (sameLetter) {
934
+ subsequence.sequence.unshift(array1[index1 - 1]);
935
+ subsequence.indices1.unshift(index1 - 1);
936
+ subsequence.indices2.unshift(index2 - 1);
937
+ --index1;
938
+ --index2;
939
+ } else {
940
+ var valueAtMatrixAbove = matrix[index1][index2 - 1];
941
+ var valueAtMatrixLeft = matrix[index1 - 1][index2];
942
+ if (valueAtMatrixAbove > valueAtMatrixLeft) {
943
+ --index2;
944
+ } else {
945
+ --index1;
946
+ }
947
+ }
948
+ }
949
+ return subsequence;
950
+ };
951
+ var get = function get(array1, array2, match, context) {
952
+ var innerContext = context || {};
953
+ var matrix = lengthMatrix(array1, array2, match || defaultMatch, innerContext);
954
+ return backtrack(matrix, array1, array2, innerContext);
955
+ };
956
+ var lcs = {
957
+ get: get
958
+ };
959
+
960
+ var ARRAY_MOVE = 3;
961
+ function arraysHaveMatchByRef(array1, array2, len1, len2) {
962
+ for (var index1 = 0; index1 < len1; index1++) {
963
+ var val1 = array1[index1];
964
+ for (var index2 = 0; index2 < len2; index2++) {
965
+ var val2 = array2[index2];
966
+ if (index1 !== index2 && val1 === val2) {
967
+ return true;
968
+ }
969
+ }
970
+ }
971
+ }
972
+ function matchItems(array1, array2, index1, index2, context) {
973
+ var value1 = array1[index1];
974
+ var value2 = array2[index2];
975
+ if (value1 === value2) {
976
+ return true;
977
+ }
978
+ if (_typeof(value1) !== 'object' || _typeof(value2) !== 'object') {
979
+ return false;
980
+ }
981
+ var objectHash = context.objectHash;
982
+ if (!objectHash) {
983
+ // no way to match objects was provided, try match by position
984
+ return context.matchByPosition && index1 === index2;
985
+ }
986
+ context.hashCache1 = context.hashCache1 || [];
987
+ var hash1 = context.hashCache1[index1];
988
+ if (typeof hash1 === 'undefined') {
989
+ context.hashCache1[index1] = hash1 = objectHash(value1, index1);
990
+ }
991
+ if (typeof hash1 === 'undefined') {
992
+ return false;
993
+ }
994
+ context.hashCache2 = context.hashCache2 || [];
995
+ var hash2 = context.hashCache2[index2];
996
+ if (typeof hash2 === 'undefined') {
997
+ context.hashCache2[index2] = hash2 = objectHash(value2, index2);
998
+ }
999
+ if (typeof hash2 === 'undefined') {
1000
+ return false;
1001
+ }
1002
+ return hash1 === hash2;
1003
+ }
1004
+ var diffFilter$2 = function arraysDiffFilter(context) {
1005
+ if (!context.leftIsArray) {
1006
+ return;
1007
+ }
1008
+ var matchContext = {
1009
+ objectHash: context.options && context.options.objectHash,
1010
+ matchByPosition: context.options && context.options.matchByPosition
1011
+ };
1012
+ var commonHead = 0;
1013
+ var commonTail = 0;
1014
+ var index;
1015
+ var index1;
1016
+ var index2;
1017
+ var array1 = context.left;
1018
+ var array2 = context.right;
1019
+ var len1 = array1.length;
1020
+ var len2 = array2.length;
1021
+ var child;
1022
+ if (len1 > 0 && len2 > 0 && !matchContext.objectHash && typeof matchContext.matchByPosition !== 'boolean') {
1023
+ matchContext.matchByPosition = !arraysHaveMatchByRef(array1, array2, len1, len2);
1024
+ }
1025
+ // separate common head
1026
+ while (commonHead < len1 && commonHead < len2 && matchItems(array1, array2, commonHead, commonHead, matchContext)) {
1027
+ index = commonHead;
1028
+ child = new DiffContext(array1[index], array2[index]);
1029
+ context.push(child, index);
1030
+ commonHead++;
1031
+ }
1032
+ // separate common tail
1033
+ while (commonTail + commonHead < len1 && commonTail + commonHead < len2 && matchItems(array1, array2, len1 - 1 - commonTail, len2 - 1 - commonTail, matchContext)) {
1034
+ index1 = len1 - 1 - commonTail;
1035
+ index2 = len2 - 1 - commonTail;
1036
+ child = new DiffContext(array1[index1], array2[index2]);
1037
+ context.push(child, index2);
1038
+ commonTail++;
1039
+ }
1040
+ var result;
1041
+ if (commonHead + commonTail === len1) {
1042
+ if (len1 === len2) {
1043
+ // arrays are identical
1044
+ context.setResult(undefined).exit();
1045
+ return;
1046
+ }
1047
+ // trivial case, a block (1 or more consecutive items) was added
1048
+ result = result || {
1049
+ _t: 'a'
1050
+ };
1051
+ for (index = commonHead; index < len2 - commonTail; index++) {
1052
+ result[index] = [array2[index]];
1053
+ }
1054
+ context.setResult(result).exit();
1055
+ return;
1056
+ }
1057
+ if (commonHead + commonTail === len2) {
1058
+ // trivial case, a block (1 or more consecutive items) was removed
1059
+ result = result || {
1060
+ _t: 'a'
1061
+ };
1062
+ for (index = commonHead; index < len1 - commonTail; index++) {
1063
+ result["_".concat(index)] = [array1[index], 0, 0];
1064
+ }
1065
+ context.setResult(result).exit();
1066
+ return;
1067
+ }
1068
+ // reset hash cache
1069
+ delete matchContext.hashCache1;
1070
+ delete matchContext.hashCache2;
1071
+ // diff is not trivial, find the LCS (Longest Common Subsequence)
1072
+ var trimmed1 = array1.slice(commonHead, len1 - commonTail);
1073
+ var trimmed2 = array2.slice(commonHead, len2 - commonTail);
1074
+ var seq = lcs.get(trimmed1, trimmed2, matchItems, matchContext);
1075
+ var removedItems = [];
1076
+ result = result || {
1077
+ _t: 'a'
1078
+ };
1079
+ for (index = commonHead; index < len1 - commonTail; index++) {
1080
+ if (seq.indices1.indexOf(index - commonHead) < 0) {
1081
+ // removed
1082
+ result["_".concat(index)] = [array1[index], 0, 0];
1083
+ removedItems.push(index);
1084
+ }
1085
+ }
1086
+ var detectMove = true;
1087
+ if (context.options && context.options.arrays && context.options.arrays.detectMove === false) {
1088
+ detectMove = false;
1089
+ }
1090
+ var includeValueOnMove = false;
1091
+ if (context.options && context.options.arrays && context.options.arrays.includeValueOnMove) {
1092
+ includeValueOnMove = true;
1093
+ }
1094
+ var removedItemsLength = removedItems.length;
1095
+ for (index = commonHead; index < len2 - commonTail; index++) {
1096
+ var indexOnArray2 = seq.indices2.indexOf(index - commonHead);
1097
+ if (indexOnArray2 < 0) {
1098
+ // added, try to match with a removed item and register as position move
1099
+ var isMove = false;
1100
+ if (detectMove && removedItemsLength > 0) {
1101
+ for (var removeItemIndex1 = 0; removeItemIndex1 < removedItemsLength; removeItemIndex1++) {
1102
+ index1 = removedItems[removeItemIndex1];
1103
+ if (matchItems(trimmed1, trimmed2, index1 - commonHead, index - commonHead, matchContext)) {
1104
+ // store position move as: [originalValue, newPosition, ARRAY_MOVE]
1105
+ result["_".concat(index1)].splice(1, 2, index, ARRAY_MOVE);
1106
+ if (!includeValueOnMove) {
1107
+ // don't include moved value on diff, to save bytes
1108
+ result["_".concat(index1)][0] = '';
1109
+ }
1110
+ index2 = index;
1111
+ child = new DiffContext(array1[index1], array2[index2]);
1112
+ context.push(child, index2);
1113
+ removedItems.splice(removeItemIndex1, 1);
1114
+ isMove = true;
1115
+ break;
1116
+ }
1117
+ }
1118
+ }
1119
+ if (!isMove) {
1120
+ // added
1121
+ result[index] = [array2[index]];
1122
+ }
1123
+ } else {
1124
+ // match, do inner diff
1125
+ index1 = seq.indices1[indexOnArray2] + commonHead;
1126
+ index2 = seq.indices2[indexOnArray2] + commonHead;
1127
+ child = new DiffContext(array1[index1], array2[index2]);
1128
+ context.push(child, index2);
1129
+ }
1130
+ }
1131
+ context.setResult(result).exit();
1132
+ };
1133
+ diffFilter$2.filterName = 'arrays';
1134
+ var compare = {
1135
+ numerically: function numerically(a, b) {
1136
+ return a - b;
1137
+ },
1138
+ numericallyBy: function numericallyBy(name) {
1139
+ return function (a, b) {
1140
+ return a[name] - b[name];
1141
+ };
1142
+ }
1143
+ };
1144
+ var patchFilter$1 = function nestedPatchFilter(context) {
1145
+ if (!context.nested) {
1146
+ return;
1147
+ }
1148
+ var nestedDelta = context.delta;
1149
+ if (nestedDelta._t !== 'a') {
1150
+ return;
1151
+ }
1152
+ var index;
1153
+ var index1;
1154
+ var delta = nestedDelta;
1155
+ var array = context.left;
1156
+ // first, separate removals, insertions and modifications
1157
+ var toRemove = [];
1158
+ var toInsert = [];
1159
+ var toModify = [];
1160
+ for (index in delta) {
1161
+ if (index !== '_t') {
1162
+ if (index[0] === '_') {
1163
+ var removedOrMovedIndex = index;
1164
+ // removed item from original array
1165
+ if (delta[removedOrMovedIndex][2] === 0 || delta[removedOrMovedIndex][2] === ARRAY_MOVE) {
1166
+ toRemove.push(parseInt(index.slice(1), 10));
1167
+ } else {
1168
+ throw new Error('only removal or move can be applied at original array indices,' + " invalid diff type: ".concat(delta[removedOrMovedIndex][2]));
1169
+ }
1170
+ } else {
1171
+ var numberIndex = index;
1172
+ if (delta[numberIndex].length === 1) {
1173
+ // added item at new array
1174
+ toInsert.push({
1175
+ index: parseInt(numberIndex, 10),
1176
+ value: delta[numberIndex][0]
1177
+ });
1178
+ } else {
1179
+ // modified item at new array
1180
+ toModify.push({
1181
+ index: parseInt(numberIndex, 10),
1182
+ delta: delta[numberIndex]
1183
+ });
1184
+ }
1185
+ }
1186
+ }
1187
+ }
1188
+ // remove items, in reverse order to avoid sawing our own floor
1189
+ toRemove = toRemove.sort(compare.numerically);
1190
+ for (index = toRemove.length - 1; index >= 0; index--) {
1191
+ index1 = toRemove[index];
1192
+ var indexDiff = delta["_".concat(index1)];
1193
+ var removedValue = array.splice(index1, 1)[0];
1194
+ if (indexDiff[2] === ARRAY_MOVE) {
1195
+ // reinsert later
1196
+ toInsert.push({
1197
+ index: indexDiff[1],
1198
+ value: removedValue
1199
+ });
1200
+ }
1201
+ }
1202
+ // insert items, in reverse order to avoid moving our own floor
1203
+ toInsert = toInsert.sort(compare.numericallyBy('index'));
1204
+ var toInsertLength = toInsert.length;
1205
+ for (index = 0; index < toInsertLength; index++) {
1206
+ var insertion = toInsert[index];
1207
+ array.splice(insertion.index, 0, insertion.value);
1208
+ }
1209
+ // apply modifications
1210
+ var toModifyLength = toModify.length;
1211
+ var child;
1212
+ if (toModifyLength > 0) {
1213
+ for (index = 0; index < toModifyLength; index++) {
1214
+ var modification = toModify[index];
1215
+ child = new PatchContext(array[modification.index], modification.delta);
1216
+ context.push(child, modification.index);
1217
+ }
1218
+ }
1219
+ if (!context.children) {
1220
+ context.setResult(array).exit();
1221
+ return;
1222
+ }
1223
+ context.exit();
1224
+ };
1225
+ patchFilter$1.filterName = 'arrays';
1226
+ var collectChildrenPatchFilter = function collectChildrenPatchFilter(context) {
1227
+ if (!context || !context.children) {
1228
+ return;
1229
+ }
1230
+ var deltaWithChildren = context.delta;
1231
+ if (deltaWithChildren._t !== 'a') {
1232
+ return;
1233
+ }
1234
+ var array = context.left;
1235
+ var length = context.children.length;
1236
+ var child;
1237
+ for (var index = 0; index < length; index++) {
1238
+ child = context.children[index];
1239
+ var arrayIndex = child.childName;
1240
+ array[arrayIndex] = child.result;
1241
+ }
1242
+ context.setResult(array).exit();
1243
+ };
1244
+ collectChildrenPatchFilter.filterName = 'arraysCollectChildren';
1245
+ var reverseFilter$1 = function arraysReverseFilter(context) {
1246
+ if (!context.nested) {
1247
+ var nonNestedDelta = context.delta;
1248
+ if (nonNestedDelta[2] === ARRAY_MOVE) {
1249
+ var arrayMoveDelta = nonNestedDelta;
1250
+ context.newName = "_".concat(arrayMoveDelta[1]);
1251
+ context.setResult([arrayMoveDelta[0], parseInt(context.childName.substring(1), 10), ARRAY_MOVE]).exit();
1252
+ }
1253
+ return;
1254
+ }
1255
+ var nestedDelta = context.delta;
1256
+ if (nestedDelta._t !== 'a') {
1257
+ return;
1258
+ }
1259
+ var arrayDelta = nestedDelta;
1260
+ var name;
1261
+ var child;
1262
+ for (name in arrayDelta) {
1263
+ if (name === '_t') {
1264
+ continue;
1265
+ }
1266
+ child = new ReverseContext(arrayDelta[name]);
1267
+ context.push(child, name);
1268
+ }
1269
+ context.exit();
1270
+ };
1271
+ reverseFilter$1.filterName = 'arrays';
1272
+ var reverseArrayDeltaIndex = function reverseArrayDeltaIndex(delta, index, itemDelta) {
1273
+ if (typeof index === 'string' && index[0] === '_') {
1274
+ return parseInt(index.substring(1), 10);
1275
+ } else if (Array.isArray(itemDelta) && itemDelta[2] === 0) {
1276
+ return "_".concat(index);
1277
+ }
1278
+ var reverseIndex = +index;
1279
+ for (var deltaIndex in delta) {
1280
+ var deltaItem = delta[deltaIndex];
1281
+ if (Array.isArray(deltaItem)) {
1282
+ if (deltaItem[2] === ARRAY_MOVE) {
1283
+ var moveFromIndex = parseInt(deltaIndex.substring(1), 10);
1284
+ var moveToIndex = deltaItem[1];
1285
+ if (moveToIndex === +index) {
1286
+ return moveFromIndex;
1287
+ }
1288
+ if (moveFromIndex <= reverseIndex && moveToIndex > reverseIndex) {
1289
+ reverseIndex++;
1290
+ } else if (moveFromIndex >= reverseIndex && moveToIndex < reverseIndex) {
1291
+ reverseIndex--;
1292
+ }
1293
+ } else if (deltaItem[2] === 0) {
1294
+ var deleteIndex = parseInt(deltaIndex.substring(1), 10);
1295
+ if (deleteIndex <= reverseIndex) {
1296
+ reverseIndex++;
1297
+ }
1298
+ } else if (deltaItem.length === 1 && parseInt(deltaIndex, 10) <= reverseIndex) {
1299
+ reverseIndex--;
1300
+ }
1301
+ }
1302
+ }
1303
+ return reverseIndex;
1304
+ };
1305
+ var collectChildrenReverseFilter = function collectChildrenReverseFilter(context) {
1306
+ if (!context || !context.children) {
1307
+ return;
1308
+ }
1309
+ var deltaWithChildren = context.delta;
1310
+ if (deltaWithChildren._t !== 'a') {
1311
+ return;
1312
+ }
1313
+ var arrayDelta = deltaWithChildren;
1314
+ var length = context.children.length;
1315
+ var child;
1316
+ var delta = {
1317
+ _t: 'a'
1318
+ };
1319
+ for (var index = 0; index < length; index++) {
1320
+ child = context.children[index];
1321
+ var name = child.newName;
1322
+ if (typeof name === 'undefined') {
1323
+ name = reverseArrayDeltaIndex(arrayDelta, child.childName, child.result);
1324
+ }
1325
+ if (delta[name] !== child.result) {
1326
+ // There's no way to type this well.
1327
+ delta[name] = child.result;
1328
+ }
1329
+ }
1330
+ context.setResult(delta).exit();
1331
+ };
1332
+ collectChildrenReverseFilter.filterName = 'arraysCollectChildren';
1333
+
1334
+ var diffFilter$1 = function datesDiffFilter(context) {
1335
+ if (context.left instanceof Date) {
1336
+ if (context.right instanceof Date) {
1337
+ if (context.left.getTime() !== context.right.getTime()) {
1338
+ context.setResult([context.left, context.right]);
1339
+ } else {
1340
+ context.setResult(undefined);
1341
+ }
1342
+ } else {
1343
+ context.setResult([context.left, context.right]);
1344
+ }
1345
+ context.exit();
1346
+ } else if (context.right instanceof Date) {
1347
+ context.setResult([context.left, context.right]).exit();
1348
+ }
1349
+ };
1350
+ diffFilter$1.filterName = 'dates';
1351
+
1352
+ var TEXT_DIFF = 2;
1353
+ var DEFAULT_MIN_LENGTH = 60;
1354
+ var cachedDiffPatch = null;
1355
+ function getDiffMatchPatch(options, required) {
1356
+ var _a;
1357
+ if (!cachedDiffPatch) {
1358
+ var instance;
1359
+ if ((_a = options === null || options === void 0 ? void 0 : options.textDiff) === null || _a === void 0 ? void 0 : _a.diffMatchPatch) {
1360
+ instance = new options.textDiff.diffMatchPatch();
1361
+ } else {
1362
+ if (!required) {
1363
+ return null;
1364
+ }
1365
+ 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.');
1366
+ // eslint-disable-next-line camelcase
1367
+ error.diff_match_patch_not_found = true;
1368
+ throw error;
1369
+ }
1370
+ cachedDiffPatch = {
1371
+ diff: function diff(txt1, txt2) {
1372
+ return instance.patch_toText(instance.patch_make(txt1, txt2));
1373
+ },
1374
+ patch: function patch(txt1, _patch) {
1375
+ var results = instance.patch_apply(instance.patch_fromText(_patch), txt1);
1376
+ for (var i = 0; i < results[1].length; i++) {
1377
+ if (!results[1][i]) {
1378
+ var _error = new Error('text patch failed');
1379
+ _error.textPatchFailed = true;
1380
+ }
1381
+ }
1382
+ return results[0];
1383
+ }
1384
+ };
1385
+ }
1386
+ return cachedDiffPatch;
1387
+ }
1388
+ var diffFilter = function textsDiffFilter(context) {
1389
+ if (context.leftType !== 'string') {
1390
+ return;
1391
+ }
1392
+ var left = context.left;
1393
+ var right = context.right;
1394
+ var minLength = context.options && context.options.textDiff && context.options.textDiff.minLength || DEFAULT_MIN_LENGTH;
1395
+ if (left.length < minLength || right.length < minLength) {
1396
+ context.setResult([left, right]).exit();
1397
+ return;
1398
+ }
1399
+ // large text, try to use a text-diff algorithm
1400
+ var diffMatchPatch = getDiffMatchPatch(context.options);
1401
+ if (!diffMatchPatch) {
1402
+ // diff-match-patch library not available,
1403
+ // fallback to regular string replace
1404
+ context.setResult([left, right]).exit();
1405
+ return;
1406
+ }
1407
+ var diff = diffMatchPatch.diff;
1408
+ context.setResult([diff(left, right), 0, TEXT_DIFF]).exit();
1409
+ };
1410
+ diffFilter.filterName = 'texts';
1411
+ var patchFilter = function textsPatchFilter(context) {
1412
+ if (context.nested) {
1413
+ return;
1414
+ }
1415
+ var nonNestedDelta = context.delta;
1416
+ if (nonNestedDelta[2] !== TEXT_DIFF) {
1417
+ return;
1418
+ }
1419
+ var textDiffDelta = nonNestedDelta;
1420
+ // text-diff, use a text-patch algorithm
1421
+ var patch = getDiffMatchPatch(context.options, true).patch;
1422
+ context.setResult(patch(context.left, textDiffDelta[0])).exit();
1423
+ };
1424
+ patchFilter.filterName = 'texts';
1425
+ var textDeltaReverse = function textDeltaReverse(delta) {
1426
+ var i;
1427
+ var l;
1428
+ var line;
1429
+ var lineTmp;
1430
+ var header = null;
1431
+ var headerRegex = /^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/;
1432
+ var lineHeader;
1433
+ var lines = delta.split('\n');
1434
+ for (i = 0, l = lines.length; i < l; i++) {
1435
+ line = lines[i];
1436
+ var lineStart = line.slice(0, 1);
1437
+ if (lineStart === '@') {
1438
+ header = headerRegex.exec(line);
1439
+ lineHeader = i;
1440
+ // fix header
1441
+ lines[lineHeader] = '@@ -' + header[3] + ',' + header[4] + ' +' + header[1] + ',' + header[2] + ' @@';
1442
+ } else if (lineStart === '+') {
1443
+ lines[i] = '-' + lines[i].slice(1);
1444
+ if (lines[i - 1].slice(0, 1) === '+') {
1445
+ // swap lines to keep default order (-+)
1446
+ lineTmp = lines[i];
1447
+ lines[i] = lines[i - 1];
1448
+ lines[i - 1] = lineTmp;
1449
+ }
1450
+ } else if (lineStart === '-') {
1451
+ lines[i] = '+' + lines[i].slice(1);
1452
+ }
1453
+ }
1454
+ return lines.join('\n');
1455
+ };
1456
+ var reverseFilter = function textsReverseFilter(context) {
1457
+ if (context.nested) {
1458
+ return;
1459
+ }
1460
+ var nonNestedDelta = context.delta;
1461
+ if (nonNestedDelta[2] !== TEXT_DIFF) {
1462
+ return;
1463
+ }
1464
+ var textDiffDelta = nonNestedDelta;
1465
+ // text-diff, use a text-diff algorithm
1466
+ context.setResult([textDeltaReverse(textDiffDelta[0]), 0, TEXT_DIFF]).exit();
1467
+ };
1468
+ reverseFilter.filterName = 'texts';
1469
+
1470
+ var DiffPatcher = /*#__PURE__*/function () {
1471
+ function DiffPatcher(options) {
1472
+ _classCallCheck(this, DiffPatcher);
1473
+ this.processor = new Processor(options);
1474
+ this.processor.pipe(new Pipe('diff').append(collectChildrenDiffFilter, diffFilter$3, diffFilter$1, diffFilter, objectsDiffFilter, diffFilter$2).shouldHaveResult());
1475
+ this.processor.pipe(new Pipe('patch').append(collectChildrenPatchFilter$1, collectChildrenPatchFilter, patchFilter$3, patchFilter, patchFilter$2, patchFilter$1).shouldHaveResult());
1476
+ this.processor.pipe(new Pipe('reverse').append(collectChildrenReverseFilter$1, collectChildrenReverseFilter, reverseFilter$3, reverseFilter, reverseFilter$2, reverseFilter$1).shouldHaveResult());
1477
+ }
1478
+ return _createClass(DiffPatcher, [{
1479
+ key: "options",
1480
+ value: function options(_options) {
1481
+ return this.processor.options(_options);
1482
+ }
1483
+ }, {
1484
+ key: "diff",
1485
+ value: function diff(left, right) {
1486
+ return this.processor.process(new DiffContext(left, right));
1487
+ }
1488
+ }, {
1489
+ key: "patch",
1490
+ value: function patch(left, delta) {
1491
+ return this.processor.process(new PatchContext(left, delta));
1492
+ }
1493
+ }, {
1494
+ key: "reverse",
1495
+ value: function reverse(delta) {
1496
+ return this.processor.process(new ReverseContext(delta));
1497
+ }
1498
+ }, {
1499
+ key: "unpatch",
1500
+ value: function unpatch(right, delta) {
1501
+ return this.patch(right, this.reverse(delta));
1502
+ }
1503
+ }, {
1504
+ key: "clone",
1505
+ value: function clone(value) {
1506
+ return clone$1(value);
1507
+ }
1508
+ }]);
1509
+ }();
1510
+
250
1511
  function objectHash(obj, index) {
251
1512
  var objIndex = "$$index:".concat(index);
252
1513
  return _typeof(obj) === 'object' && obj !== null ? obj.id || obj.name || obj.url || objIndex : objIndex;
253
1514
  }
254
- var diffpatcher = new jsondiffpatch_cjs.DiffPatcher({
1515
+ var diffpatcher = new DiffPatcher({
255
1516
  objectHash: objectHash,
256
1517
  arrays: {
257
1518
  // detect items moved inside the array
@@ -581,7 +1842,7 @@ function buildBaseAttributesActions(_ref) {
581
1842
  action: item.action
582
1843
  }, actionKey, patched);
583
1844
  }).filter(function (action) {
584
- return !isNil__default["default"](action);
1845
+ return !isNil(action);
585
1846
  });
586
1847
  }
587
1848
 
@@ -688,7 +1949,6 @@ function actionsMapReferences$3(diff, oldObj, newObj) {
688
1949
  return buildReferenceActions({
689
1950
  actions: referenceActionsList$3,
690
1951
  diff: diff,
691
- oldObj: oldObj,
692
1952
  newObj: newObj
693
1953
  });
694
1954
  }
@@ -714,7 +1974,7 @@ var CUSTOM = 'custom';
714
1974
  function copyEmptyArrayProps() {
715
1975
  var oldObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
716
1976
  var newObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
717
- if (!isNil__default["default"](oldObj) && !isNil__default["default"](newObj)) {
1977
+ if (!isNil(oldObj) && !isNil(newObj)) {
718
1978
  var nextObjectWithEmptyArray = Object.entries(oldObj).reduce(function (merged, _ref) {
719
1979
  var _ref2 = _slicedToArray(_ref, 2),
720
1980
  key = _ref2[0],
@@ -729,10 +1989,10 @@ function copyEmptyArrayProps() {
729
1989
  return acc;
730
1990
  }, {});
731
1991
  for (var i = 0; i < newObj[key].length; i++) {
732
- if (!isNil__default["default"](newObj[key][i]) && _typeof(newObj[key][i]) === 'object' && !isNil__default["default"](newObj[key][i].id)) {
1992
+ if (!isNil(newObj[key][i]) && _typeof(newObj[key][i]) === 'object' && !isNil(newObj[key][i].id)) {
733
1993
  // Since its unordered array elements then check if the element on `oldObj` exists by id
734
1994
  var foundObject = hashMapValue[newObj[key][i].id];
735
- if (!isNil__default["default"](foundObject)) {
1995
+ if (!isNil(foundObject)) {
736
1996
  var _copyEmptyArrayProps = copyEmptyArrayProps(foundObject, newObj[key][i]),
737
1997
  _copyEmptyArrayProps2 = _slicedToArray(_copyEmptyArrayProps, 2),
738
1998
  nestedObject = _copyEmptyArrayProps2[1];
@@ -748,10 +2008,10 @@ function copyEmptyArrayProps() {
748
2008
  return merged;
749
2009
  }
750
2010
  if (Array.isArray(value)) {
751
- merged[key] = isNil__default["default"](newObj[key]) ? [] : newObj[key];
2011
+ merged[key] = isNil(newObj[key]) ? [] : newObj[key];
752
2012
  return merged;
753
2013
  }
754
- if (!isNil__default["default"](newObj[key]) && _typeof(value) === 'object' &&
2014
+ if (!isNil(newObj[key]) && _typeof(value) === 'object' &&
755
2015
  // Ignore Date as this will create invalid object since typeof date === 'object' return true
756
2016
  // ex: {date: new Date()} will result {date: {}}
757
2017
  !(value instanceof Date)) {
@@ -786,7 +2046,7 @@ function createCategoryMapActions(mapActionGroup, syncActionConfig) {
786
2046
  allActions.push(mapActionGroup('assets', function () {
787
2047
  return actionsMapAssets$1(diff, oldObj, newObj);
788
2048
  }));
789
- return flatten__default["default"](allActions);
2049
+ return flatten(allActions);
790
2050
  };
791
2051
  }
792
2052
  var categories = (function (actionGroupList, syncActionConfig) {
@@ -904,7 +2164,6 @@ function actionsMapReferences$2(diff, oldObj, newObj) {
904
2164
  return buildReferenceActions({
905
2165
  actions: referenceActionsList$2,
906
2166
  diff: diff,
907
- oldObj: oldObj,
908
2167
  newObj: newObj
909
2168
  });
910
2169
  }
@@ -1012,7 +2271,7 @@ function buildAuthenticationModeActions(_ref) {
1012
2271
  authMode: patched
1013
2272
  }, value, newObj.password);
1014
2273
  }).filter(function (action) {
1015
- return !isNil__default["default"](action);
2274
+ return !isNil(action);
1016
2275
  });
1017
2276
  }
1018
2277
 
@@ -1043,7 +2302,7 @@ function createCustomerMapActions(mapActionGroup, syncActionConfig) {
1043
2302
  allActions.push(mapActionGroup('authenticationModes', function () {
1044
2303
  return actionsMapAuthenticationModes(diff, oldObj, newObj);
1045
2304
  }));
1046
- return flatten__default["default"](allActions);
2305
+ return flatten(allActions);
1047
2306
  };
1048
2307
  }
1049
2308
  var customers = (function (actionGroupList, syncActionConfig) {
@@ -1102,7 +2361,6 @@ function actionsMapReferences$1(diff, oldObj, newObj) {
1102
2361
  return buildReferenceActions({
1103
2362
  actions: referenceActionsList$1,
1104
2363
  diff: diff,
1105
- oldObj: oldObj,
1106
2364
  newObj: newObj
1107
2365
  });
1108
2366
  }
@@ -1119,7 +2377,7 @@ function createInventoryMapActions(mapActionGroup, syncActionConfig) {
1119
2377
  allActions.push(mapActionGroup('custom', function () {
1120
2378
  return actionsMapCustom(diff, newObj, oldObj);
1121
2379
  }));
1122
- return flatten__default["default"](allActions);
2380
+ return flatten(allActions);
1123
2381
  };
1124
2382
  }
1125
2383
  var inventories = (function (actionGroupList, syncActionConfig) {
@@ -1186,7 +2444,7 @@ function findMatchingPairs(diff) {
1186
2444
  var _preProcessCollection2 = preProcessCollection(now, identifier),
1187
2445
  nowObjRefByIdentifier = _preProcessCollection2.refByIdentifier,
1188
2446
  nowObjRefByIndex = _preProcessCollection2.refByIndex;
1189
- forEach__default["default"](diff, function (item, key) {
2447
+ forEach(diff, function (item, key) {
1190
2448
  if (REGEX_NUMBER$3.test(key)) {
1191
2449
  var matchingIdentifier = nowObjRefByIndex[key];
1192
2450
  result[key] = [beforeObjRefByIdentifier[matchingIdentifier], key];
@@ -1367,7 +2625,7 @@ function _buildVariantImagesAction(diffedImages) {
1367
2625
  var actions = [];
1368
2626
  // generate a hashMap to be able to reference the right image from both ends
1369
2627
  var matchingImagePairs = findMatchingPairs(diffedImages, oldVariant.images, newVariant.images, 'url');
1370
- forEach__default["default"](diffedImages, function (image, key) {
2628
+ forEach(diffedImages, function (image, key) {
1371
2629
  var _extractMatchingPairs = extractMatchingPairs(matchingImagePairs, key, oldVariant.images, newVariant.images),
1372
2630
  oldObj = _extractMatchingPairs.oldObj,
1373
2631
  newObj = _extractMatchingPairs.newObj;
@@ -1424,7 +2682,7 @@ function _buildVariantPricesAction(diffedPrices) {
1424
2682
 
1425
2683
  // generate a hashMap to be able to reference the right image from both ends
1426
2684
  var matchingPricePairs = findMatchingPairs(diffedPrices, oldVariant.prices, newVariant.prices);
1427
- forEach__default["default"](diffedPrices, function (price, key) {
2685
+ forEach(diffedPrices, function (price, key) {
1428
2686
  var _extractMatchingPairs2 = extractMatchingPairs(matchingPricePairs, key, oldVariant.prices, newVariant.prices),
1429
2687
  oldObj = _extractMatchingPairs2.oldObj,
1430
2688
  newObj = _extractMatchingPairs2.newObj;
@@ -1472,7 +2730,7 @@ function _buildVariantPricesAction(diffedPrices) {
1472
2730
  function _buildVariantAttributesActions(attributes, oldVariant, newVariant, sameForAllAttributeNames) {
1473
2731
  var actions = [];
1474
2732
  if (!attributes) return actions;
1475
- forEach__default["default"](attributes, function (value, key) {
2733
+ forEach(attributes, function (value, key) {
1476
2734
  if (REGEX_NUMBER$2.test(key)) {
1477
2735
  if (Array.isArray(value)) {
1478
2736
  var id = oldVariant.id;
@@ -1537,8 +2795,8 @@ function _buildVariantChangeAssetOrderAction(diffAssets, oldVariant, newVariant)
1537
2795
  }).filter(function (_) {
1538
2796
  return _ !== undefined;
1539
2797
  });
1540
- var assetIdsToKeep = intersection__default["default"](assetIdsCurrent, assetIdsBefore);
1541
- var assetIdsToRemove = without__default["default"].apply(void 0, [assetIdsBefore].concat(_toConsumableArray(assetIdsToKeep)));
2798
+ var assetIdsToKeep = intersection(assetIdsCurrent, assetIdsBefore);
2799
+ var assetIdsToRemove = without.apply(void 0, [assetIdsBefore].concat(_toConsumableArray(assetIdsToKeep)));
1542
2800
  var changeAssetOrderAction = _objectSpread2({
1543
2801
  action: 'changeAssetOrder',
1544
2802
  assetOrder: assetIdsToKeep.concat(assetIdsToRemove)
@@ -1550,7 +2808,7 @@ function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) {
1550
2808
 
1551
2809
  // generate a hashMap to be able to reference the right asset from both ends
1552
2810
  var matchingAssetPairs = findMatchingPairs(diffAssets, oldVariant.assets, newVariant.assets);
1553
- forEach__default["default"](diffAssets, function (asset, key) {
2811
+ forEach(diffAssets, function (asset, key) {
1554
2812
  var _extractMatchingPairs3 = extractMatchingPairs(matchingAssetPairs, key, oldVariant.assets, newVariant.assets),
1555
2813
  oldAsset = _extractMatchingPairs3.oldObj,
1556
2814
  newAsset = _extractMatchingPairs3.newObj;
@@ -1649,7 +2907,6 @@ function actionsMapReferences(diff, oldObj, newObj) {
1649
2907
  return buildReferenceActions({
1650
2908
  actions: referenceActionsList,
1651
2909
  diff: diff,
1652
- oldObj: oldObj,
1653
2910
  newObj: newObj
1654
2911
  });
1655
2912
  }
@@ -1658,7 +2915,7 @@ function actionsMapCategories(diff) {
1658
2915
  if (!diff.categories) return actions;
1659
2916
  var addToCategoryActions = [];
1660
2917
  var removeFromCategoryActions = [];
1661
- forEach__default["default"](diff.categories, function (category) {
2918
+ forEach(diff.categories, function (category) {
1662
2919
  if (Array.isArray(category)) {
1663
2920
  var action = {
1664
2921
  category: category[0]
@@ -1703,7 +2960,7 @@ function actionsMapCategoryOrderHints(diff) {
1703
2960
  function actionsMapAssets(diff, oldObj, newObj, variantHashMap) {
1704
2961
  var allAssetsActions = [];
1705
2962
  var variants = diff.variants;
1706
- if (variants) forEach__default["default"](variants, function (variant, key) {
2963
+ if (variants) forEach(variants, function (variant, key) {
1707
2964
  var _extractMatchingPairs4 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
1708
2965
  oldVariant = _extractMatchingPairs4.oldObj,
1709
2966
  newVariant = _extractMatchingPairs4.newObj;
@@ -1719,7 +2976,7 @@ function actionsMapAttributes$1(diff, oldObj, newObj) {
1719
2976
  var variantHashMap = arguments.length > 4 ? arguments[4] : undefined;
1720
2977
  var actions = [];
1721
2978
  var variants = diff.variants;
1722
- if (variants) forEach__default["default"](variants, function (variant, key) {
2979
+ if (variants) forEach(variants, function (variant, key) {
1723
2980
  var _extractMatchingPairs5 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
1724
2981
  oldVariant = _extractMatchingPairs5.oldObj,
1725
2982
  newVariant = _extractMatchingPairs5.newObj;
@@ -1736,14 +2993,14 @@ function actionsMapAttributes$1(diff, oldObj, newObj) {
1736
2993
 
1737
2994
  // Ensure that an action is unique.
1738
2995
  // This is especially necessary for SFA attributes.
1739
- return uniqWith__default["default"](actions, function (a, b) {
2996
+ return uniqWith(actions, function (a, b) {
1740
2997
  return a.action === b.action && a.name === b.name && a.variantId === b.variantId;
1741
2998
  });
1742
2999
  }
1743
3000
  function actionsMapImages(diff, oldObj, newObj, variantHashMap) {
1744
3001
  var actions = [];
1745
3002
  var variants = diff.variants;
1746
- if (variants) forEach__default["default"](variants, function (variant, key) {
3003
+ if (variants) forEach(variants, function (variant, key) {
1747
3004
  var _extractMatchingPairs6 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
1748
3005
  oldVariant = _extractMatchingPairs6.oldObj,
1749
3006
  newVariant = _extractMatchingPairs6.newObj;
@@ -1759,7 +3016,7 @@ function actionsMapPrices(diff, oldObj, newObj, variantHashMap, enableDiscounted
1759
3016
  var changePriceActions = [];
1760
3017
  var removePriceActions = [];
1761
3018
  var variants = diff.variants;
1762
- if (variants) forEach__default["default"](variants, function (variant, key) {
3019
+ if (variants) forEach(variants, function (variant, key) {
1763
3020
  var _extractMatchingPairs7 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
1764
3021
  oldVariant = _extractMatchingPairs7.oldObj,
1765
3022
  newVariant = _extractMatchingPairs7.newObj;
@@ -1781,13 +3038,13 @@ function actionsMapPrices(diff, oldObj, newObj, variantHashMap, enableDiscounted
1781
3038
  function actionsMapPricesCustom(diff, oldObj, newObj, variantHashMap) {
1782
3039
  var actions = [];
1783
3040
  var variants = diff.variants;
1784
- if (variants) forEach__default["default"](variants, function (variant, key) {
3041
+ if (variants) forEach(variants, function (variant, key) {
1785
3042
  var _extractMatchingPairs8 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
1786
3043
  oldVariant = _extractMatchingPairs8.oldObj,
1787
3044
  newVariant = _extractMatchingPairs8.newObj;
1788
3045
  if (variant && variant.prices && (REGEX_UNDERSCORE_NUMBER$2.test(key) || REGEX_NUMBER$2.test(key))) {
1789
3046
  var priceHashMap = findMatchingPairs(variant.prices, oldVariant.prices, newVariant.prices);
1790
- forEach__default["default"](variant.prices, function (price, index) {
3047
+ forEach(variant.prices, function (price, index) {
1791
3048
  var _extractMatchingPairs9 = extractMatchingPairs(priceHashMap, index, oldVariant.prices, newVariant.prices),
1792
3049
  oldPrice = _extractMatchingPairs9.oldObj,
1793
3050
  newPrice = _extractMatchingPairs9.newObj;
@@ -1871,12 +3128,12 @@ function createProductMapActions(mapActionGroup, syncActionConfig) {
1871
3128
  allActions.push(mapActionGroup('assets', function () {
1872
3129
  return actionsMapAssets(diff, oldObj, newObj, variantHashMap);
1873
3130
  }));
1874
- if (publish === true || staged === false) return flatten__default["default"](allActions).map(function (action) {
3131
+ if (publish === true || staged === false) return flatten(allActions).map(function (action) {
1875
3132
  return _objectSpread2(_objectSpread2({}, action), {}, {
1876
3133
  staged: false
1877
3134
  });
1878
3135
  });
1879
- return flatten__default["default"](allActions);
3136
+ return flatten(allActions);
1880
3137
  };
1881
3138
  }
1882
3139
  function moveMasterVariantsIntoVariants(before, now) {
@@ -1959,7 +3216,7 @@ function _buildDeliveryParcelsAction(diffedParcels) {
1959
3216
 
1960
3217
  // generate a hashMap to be able to reference the right image from both ends
1961
3218
  var matchingParcelPairs = findMatchingPairs(diffedParcels, oldDelivery.parcels, newDelivery.parcels);
1962
- forEach__default["default"](diffedParcels, function (parcel, key) {
3219
+ forEach(diffedParcels, function (parcel, key) {
1963
3220
  var _extractMatchingPairs = extractMatchingPairs(matchingParcelPairs, key, oldDelivery.parcels, newDelivery.parcels),
1964
3221
  oldObj = _extractMatchingPairs.oldObj;
1965
3222
  if (isAddAction(key, parcel)) {
@@ -2001,7 +3258,7 @@ function actionsMapParcels(diff, oldObj, newObj, deliveryHashMap) {
2001
3258
  if (!deliveries) return [];
2002
3259
  var addParcelActions = [];
2003
3260
  var removeParcelActions = [];
2004
- if (deliveries) forEach__default["default"](deliveries, function (delivery, key) {
3261
+ if (deliveries) forEach(deliveries, function (delivery, key) {
2005
3262
  var _extractMatchingPairs2 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
2006
3263
  oldDelivery = _extractMatchingPairs2.oldObj,
2007
3264
  newDelivery = _extractMatchingPairs2.newObj;
@@ -2022,7 +3279,7 @@ function actionsMapDeliveryItems(diff, oldObj, newObj, deliveryHashMap) {
2022
3279
  var deliveries = shippingInfo.deliveries;
2023
3280
  if (!deliveries) return [];
2024
3281
  var setDeliveryItemsActions = [];
2025
- forEach__default["default"](deliveries, function (delivery, key) {
3282
+ forEach(deliveries, function (delivery, key) {
2026
3283
  var _extractMatchingPairs3 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
2027
3284
  newDelivery = _extractMatchingPairs3.newObj;
2028
3285
  if (REGEX_UNDERSCORE_NUMBER$1.test(key) || REGEX_NUMBER$1.test(key)) {
@@ -2091,13 +3348,13 @@ function createOrderMapActions(mapActionGroup, syncActionConfig) {
2091
3348
  allActions.push(mapActionGroup('items', function () {
2092
3349
  return actionsMapDeliveryItems(diff, oldObj, newObj, deliveryHashMap);
2093
3350
  }));
2094
- allActions.push(flatten__default["default"](mapActionGroup('returnInfo', function () {
3351
+ allActions.push(flatten(mapActionGroup('returnInfo', function () {
2095
3352
  return actionsMapReturnsInfo(diff, oldObj, newObj);
2096
3353
  })));
2097
3354
  allActions.push(mapActionGroup('custom', function () {
2098
3355
  return actionsMapCustom(diff, newObj, oldObj);
2099
3356
  }));
2100
- return flatten__default["default"](allActions);
3357
+ return flatten(allActions);
2101
3358
  };
2102
3359
  }
2103
3360
  var orders = (function (actionGroupList, syncActionConfig) {
@@ -2191,7 +3448,7 @@ function createProductDiscountsMapActions(mapActionGroup, syncActionConfig) {
2191
3448
  allActions.push(mapActionGroup('base', function () {
2192
3449
  return actionsMapBase$f(diff, oldObj, newObj, syncActionConfig);
2193
3450
  }));
2194
- return combineValidityActions(flatten__default["default"](allActions));
3451
+ return combineValidityActions(flatten(allActions));
2195
3452
  };
2196
3453
  }
2197
3454
  var productDiscounts = (function (actionGroupList) {
@@ -2260,7 +3517,7 @@ function createDiscountCodesMapActions(mapActionGroup, syncActionConfig) {
2260
3517
  allActions.push(mapActionGroup('custom', function () {
2261
3518
  return actionsMapCustom(diff, newObj, oldObj);
2262
3519
  }));
2263
- return combineValidityActions(flatten__default["default"](allActions));
3520
+ return combineValidityActions(flatten(allActions));
2264
3521
  };
2265
3522
  }
2266
3523
  var discountCodes = (function (actionGroupList) {
@@ -2313,7 +3570,7 @@ function createCustomerGroupMapActions(mapActionGroup, syncActionConfig) {
2313
3570
  allActions.push(mapActionGroup('custom', function () {
2314
3571
  return actionsMapCustom(diff, newObj, oldObj);
2315
3572
  }));
2316
- return flatten__default["default"](allActions);
3573
+ return flatten(allActions);
2317
3574
  };
2318
3575
  }
2319
3576
  var customerGroup = (function (actionGroupList) {
@@ -2385,7 +3642,7 @@ function createCartDiscountsMapActions(mapActionGroup, syncActionConfig) {
2385
3642
  allActions.push(mapActionGroup('custom', function () {
2386
3643
  return actionsMapCustom(diff, newObj, oldObj);
2387
3644
  }));
2388
- return combineValidityActions(flatten__default["default"](allActions));
3645
+ return combineValidityActions(flatten(allActions));
2389
3646
  };
2390
3647
  }
2391
3648
  var cartDiscounts = (function (actionGroupList) {
@@ -2765,7 +4022,7 @@ function createTaxCategoriesMapActions(mapActionGroup, syncActionConfig) {
2765
4022
  allActions.push(mapActionGroup('rates', function () {
2766
4023
  return actionsMapRates(diff, oldObj, newObj);
2767
4024
  }));
2768
- return flatten__default["default"](allActions);
4025
+ return flatten(allActions);
2769
4026
  };
2770
4027
  }
2771
4028
  var taxCategories = (function (actionGroupList, syncActionConfig) {
@@ -2856,10 +4113,10 @@ function createZonesMapActions(mapActionGroup, syncActionConfig) {
2856
4113
  allActions.push(mapActionGroup('base', function () {
2857
4114
  return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
2858
4115
  }));
2859
- allActions.push(flatten__default["default"](mapActionGroup('locations', function () {
4116
+ allActions.push(flatten(mapActionGroup('locations', function () {
2860
4117
  return actionsMapLocations(diff, oldObj, newObj);
2861
4118
  })));
2862
- return flatten__default["default"](allActions);
4119
+ return flatten(allActions);
2863
4120
  };
2864
4121
  }
2865
4122
  var zones = (function (actionGroupList, syncActionConfig) {
@@ -2975,7 +4232,7 @@ function actionsMapZoneRates(diff, oldObj, newObj) {
2975
4232
  if (diff.zoneRates[key].shippingRates) return [].concat(_toConsumableArray(actions), _toConsumableArray(actionsMapZoneRatesShippingRates(diff.zoneRates[key], oldZoneRate, newZoneRate)));
2976
4233
  return actions;
2977
4234
  }, []);
2978
- return flatten__default["default"](hasZoneActions ? [].concat(_toConsumableArray(shippingRateActions), [{
4235
+ return flatten(hasZoneActions ? [].concat(_toConsumableArray(shippingRateActions), [{
2979
4236
  action: 'removeZone',
2980
4237
  zone: oldZoneRate.zone
2981
4238
  }, {
@@ -2992,13 +4249,13 @@ function createShippingMethodsMapActions(mapActionGroup, syncActionConfig) {
2992
4249
  allActions.push(mapActionGroup('base', function () {
2993
4250
  return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
2994
4251
  }));
2995
- allActions.push(flatten__default["default"](mapActionGroup('zoneRates', function () {
4252
+ allActions.push(flatten(mapActionGroup('zoneRates', function () {
2996
4253
  return actionsMapZoneRates(diff, oldObj, newObj);
2997
4254
  })));
2998
4255
  allActions.push(mapActionGroup('custom', function () {
2999
4256
  return actionsMapCustom(diff, newObj, oldObj);
3000
4257
  }));
3001
- return flatten__default["default"](allActions);
4258
+ return flatten(allActions);
3002
4259
  };
3003
4260
  }
3004
4261
  var shippingMethods = (function (actionGroupList, syncActionConfig) {
@@ -3130,7 +4387,7 @@ var generateUpdateActionsForAttributeDefinitions = function generateUpdateAction
3130
4387
  action: 'removeAttributeDefinition',
3131
4388
  name: attributeDef.previous.name
3132
4389
  };
3133
- })), _toConsumableArray(flatten__default["default"](updatedAttributeDefinitions.map(function (updatedAttributeDefinition) {
4390
+ })), _toConsumableArray(flatten(updatedAttributeDefinitions.map(function (updatedAttributeDefinition) {
3134
4391
  return generateBaseFieldsUpdateActions(updatedAttributeDefinition.previous, updatedAttributeDefinition.next, {
3135
4392
  label: {
3136
4393
  action: 'changeLabel',
@@ -3180,7 +4437,7 @@ var generateUpdateActionsForAttributeEnumValues = function generateUpdateActions
3180
4437
  return _objectSpread2(_objectSpread2({}, nextEnumUpdateActions), {}, _defineProperty({}, removedAttributeEnumValue.hint.attributeName, _objectSpread2(_objectSpread2({}, removedAttributeEnumValueOfSameAttributeName), {}, {
3181
4438
  keys: [].concat(_toConsumableArray(removedAttributeEnumValueOfSameAttributeName.keys), [removedAttributeEnumValue.previous.key])
3182
4439
  })));
3183
- }, {}))), _toConsumableArray(flatten__default["default"](updatedAttributeEnumValues.map(function (updatedAttributeEnumValue) {
4440
+ }, {}))), _toConsumableArray(flatten(updatedAttributeEnumValues.map(function (updatedAttributeEnumValue) {
3184
4441
  var updateActions = generateBaseFieldsUpdateActions(updatedAttributeEnumValue.previous, updatedAttributeEnumValue.next, {
3185
4442
  key: {
3186
4443
  action: 'changeEnumKey',
@@ -3254,7 +4511,7 @@ var actionsMapForHints = function actionsMapForHints() {
3254
4511
 
3255
4512
  function createProductTypeMapActions(mapActionGroup, syncActionConfig) {
3256
4513
  return function doMapActions(diff, next, previous, options) {
3257
- return flatten__default["default"]([
4514
+ return flatten([
3258
4515
  // we support only base fields for the product type,
3259
4516
  // for attributes, applying hints would be recommended
3260
4517
  mapActionGroup('base', function () {
@@ -3350,7 +4607,7 @@ function createStatesMapActions(mapActionGroup, syncActionConfig) {
3350
4607
  roleActions.push(mapActionGroup('roles', function () {
3351
4608
  return actionsMapRoles(diff, oldObj, newObj);
3352
4609
  }));
3353
- return flatten__default["default"]([].concat(baseActions, _toConsumableArray(groupRoleActions(roleActions))));
4610
+ return flatten([].concat(baseActions, _toConsumableArray(groupRoleActions(roleActions))));
3354
4611
  };
3355
4612
  }
3356
4613
  var states = (function (actionGroupList, syncActionConfig) {
@@ -3403,7 +4660,7 @@ function createChannelsMapActions$1(mapActionGroup, syncActionConfig) {
3403
4660
  allActions.push(mapActionGroup('custom', function () {
3404
4661
  return actionsMapCustom(diff, newObj, oldObj);
3405
4662
  }));
3406
- return flatten__default["default"](allActions);
4663
+ return flatten(allActions);
3407
4664
  };
3408
4665
  }
3409
4666
  var channels = (function (actionGroupList) {
@@ -3474,7 +4731,7 @@ function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next
3474
4731
  var foundPreviousEnum = previous.values.find(function (previousEnum) {
3475
4732
  return previousEnum.key === newEnum.key;
3476
4733
  });
3477
- var isLabelEqual = isEqual__default["default"](foundPreviousEnum.label, newEnum.label);
4734
+ var isLabelEqual = isEqual(foundPreviousEnum.label, newEnum.label);
3478
4735
  if (isKeyChanged) {
3479
4736
  // these actions is then flatten in the end
3480
4737
  changeActions.push({
@@ -3503,7 +4760,7 @@ function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next
3503
4760
  // following lists are necessary to ensure that when we change the
3504
4761
  // order of enumValues, we generate one updateAction instead of one at a time.
3505
4762
  var newEnumValuesOrder = [];
3506
- flatten__default["default"](buildArrayActions(attributeDiff, previous, next)).forEach(function (updateAction) {
4763
+ flatten(buildArrayActions(attributeDiff, previous, next)).forEach(function (updateAction) {
3507
4764
  if (updateAction.action === changeEnumOrderActionName) {
3508
4765
  newEnumValuesOrder = next.values.map(function (enumValue) {
3509
4766
  return enumValue.key;
@@ -3518,7 +4775,7 @@ function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next
3518
4775
  }
3519
4776
  function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPaths) {
3520
4777
  var actions = [];
3521
- forEach__default["default"](fieldDefinitionsDiff, function (diffValue, diffKey) {
4778
+ forEach(fieldDefinitionsDiff, function (diffValue, diffKey) {
3522
4779
  var extractedPairs = extractMatchingPairs(diffPaths, diffKey, previous, next);
3523
4780
  if (getIsChangedOperation(diffKey)) {
3524
4781
  var _diffValue$type;
@@ -3569,7 +4826,7 @@ function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPa
3569
4826
  // in order to prevent any eventual removal of `addAction`.
3570
4827
  // List of `removeActions` can be found here
3571
4828
  // https://docs.commercetools.com/http-api-projects-types.html#change-key
3572
- var sortedActions = sortBy__default["default"](actions, function (action) {
4829
+ var sortedActions = sortBy(actions, function (action) {
3573
4830
  return action.action !== 'removeFieldDefinition';
3574
4831
  });
3575
4832
  return sortedActions;
@@ -3583,7 +4840,7 @@ function createTypeMapActions(mapActionGroup, syncActionConfig) {
3583
4840
  }), mapActionGroup('fieldDefinitions', function () {
3584
4841
  return actionsMapFieldDefinitions(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, findMatchingPairs(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, 'name'));
3585
4842
  }));
3586
- return flatten__default["default"](allActions);
4843
+ return flatten(allActions);
3587
4844
  };
3588
4845
  }
3589
4846
  var types = (function (actionGroupList, syncActionConfig) {
@@ -3685,7 +4942,7 @@ function createChannelsMapActions(mapActionGroup, syncActionConfig) {
3685
4942
  allActions.push(mapActionGroup('searchIndexingConfiguration', function () {
3686
4943
  return actionsMapSearchIndexingConfiguration(diff, oldObj, newObj);
3687
4944
  }));
3688
- return flatten__default["default"](allActions);
4945
+ return flatten(allActions);
3689
4946
  };
3690
4947
  }
3691
4948
  var projects = (function (actionGroupList) {
@@ -3733,7 +4990,7 @@ function createStoresMapActions(mapActionGroup) {
3733
4990
  allActions.push(mapActionGroup('custom', function () {
3734
4991
  return actionsMapCustom(diff, next, previous);
3735
4992
  }));
3736
- return flatten__default["default"](allActions);
4993
+ return flatten(allActions);
3737
4994
  };
3738
4995
  }
3739
4996
  var stores = (function (actionGroupList) {
@@ -3776,7 +5033,7 @@ function createProductSelectionsMapActions(mapActionGroup) {
3776
5033
  allActions.push(mapActionGroup('custom', function () {
3777
5034
  return actionsMapCustom(diff, next, previous);
3778
5035
  }));
3779
- return flatten__default["default"](allActions);
5036
+ return flatten(allActions);
3780
5037
  };
3781
5038
  }
3782
5039
  var productSelections = (function (actionGroupList) {
@@ -3911,10 +5168,10 @@ function createAttributeGroupsMapActions(mapActionGroup, syncActionConfig) {
3911
5168
  allActions.push(mapActionGroup('base', function () {
3912
5169
  return actionsMapBase(diff, oldObj, newObj, syncActionConfig);
3913
5170
  }));
3914
- allActions.push(flatten__default["default"](mapActionGroup('attributes', function () {
5171
+ allActions.push(flatten(mapActionGroup('attributes', function () {
3915
5172
  return actionsMapAttributes(diff, oldObj, newObj);
3916
5173
  })));
3917
- return flatten__default["default"](allActions);
5174
+ return flatten(allActions);
3918
5175
  };
3919
5176
  }
3920
5177
  var attributeGroups = (function (actionGroupList, syncActionConfig) {