@commercetools/sync-actions 6.1.1 → 7.0.0-rc.2
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.
- package/dist/sync-actions.cjs.js +1353 -92
- package/dist/sync-actions.es.js +1292 -18
- package/dist/sync-actions.umd.js +1357 -95
- package/dist/sync-actions.umd.min.js +1 -1
- package/lib/cart-discounts-actions.js +31 -0
- package/lib/cart-discounts.js +70 -0
- package/lib/categories.js +106 -0
- package/lib/category-actions.js +117 -0
- package/lib/channels.js +0 -0
- package/lib/customer-actions.js +125 -0
- package/lib/customer-group-actions.js +23 -0
- package/lib/customer-group.js +70 -0
- package/lib/customers.js +95 -0
- package/lib/discount-codes-actions.js +31 -0
- package/lib/discount-codes.js +80 -0
- package/lib/index.js +90 -0
- package/lib/inventories.js +89 -0
- package/lib/inventory-actions.js +42 -0
- package/lib/order-actions.js +71 -0
- package/lib/orders.js +89 -0
- package/lib/product-actions.js +779 -0
- package/lib/product-discounts-actions.js +27 -0
- package/lib/product-discounts.js +71 -0
- package/lib/products.js +208 -0
- package/lib/utils/clone.js +9 -0
- package/lib/utils/common-actions.js +157 -0
- package/lib/utils/create-build-actions.js +74 -0
- package/lib/utils/create-build-array-actions.js +146 -0
- package/lib/utils/create-map-action-group.js +35 -0
- package/lib/utils/diffpatcher.js +93 -0
- package/lib/utils/find-matching-pairs.js +67 -0
- package/package.json +4 -5
- package/CHANGELOG.md +0 -211
package/dist/sync-actions.cjs.js
CHANGED
|
@@ -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:
|
|
41
|
-
configurable:
|
|
42
|
-
writable:
|
|
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 =
|
|
57
|
-
o =
|
|
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 =
|
|
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),
|
|
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
|
|
109
|
-
for (r = 0; r <
|
|
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.
|
|
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
|
|
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 (
|
|
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
|
|
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 !
|
|
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 (
|
|
203
|
-
if (
|
|
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,1215 @@ 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
|
+
|
|
1511
|
+
function create(options) {
|
|
1512
|
+
return new DiffPatcher(options);
|
|
1513
|
+
}
|
|
1514
|
+
|
|
250
1515
|
function objectHash(obj, index) {
|
|
251
1516
|
var objIndex = "$$index:".concat(index);
|
|
252
1517
|
return _typeof(obj) === 'object' && obj !== null ? obj.id || obj.name || obj.url || objIndex : objIndex;
|
|
253
1518
|
}
|
|
254
|
-
var diffpatcher =
|
|
1519
|
+
var diffpatcher = create({
|
|
255
1520
|
objectHash: objectHash,
|
|
256
1521
|
arrays: {
|
|
257
1522
|
// detect items moved inside the array
|
|
@@ -581,7 +1846,7 @@ function buildBaseAttributesActions(_ref) {
|
|
|
581
1846
|
action: item.action
|
|
582
1847
|
}, actionKey, patched);
|
|
583
1848
|
}).filter(function (action) {
|
|
584
|
-
return !
|
|
1849
|
+
return !isNil(action);
|
|
585
1850
|
});
|
|
586
1851
|
}
|
|
587
1852
|
|
|
@@ -688,7 +1953,6 @@ function actionsMapReferences$3(diff, oldObj, newObj) {
|
|
|
688
1953
|
return buildReferenceActions({
|
|
689
1954
|
actions: referenceActionsList$3,
|
|
690
1955
|
diff: diff,
|
|
691
|
-
oldObj: oldObj,
|
|
692
1956
|
newObj: newObj
|
|
693
1957
|
});
|
|
694
1958
|
}
|
|
@@ -714,7 +1978,7 @@ var CUSTOM = 'custom';
|
|
|
714
1978
|
function copyEmptyArrayProps() {
|
|
715
1979
|
var oldObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
716
1980
|
var newObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
717
|
-
if (!
|
|
1981
|
+
if (!isNil(oldObj) && !isNil(newObj)) {
|
|
718
1982
|
var nextObjectWithEmptyArray = Object.entries(oldObj).reduce(function (merged, _ref) {
|
|
719
1983
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
720
1984
|
key = _ref2[0],
|
|
@@ -729,10 +1993,10 @@ function copyEmptyArrayProps() {
|
|
|
729
1993
|
return acc;
|
|
730
1994
|
}, {});
|
|
731
1995
|
for (var i = 0; i < newObj[key].length; i++) {
|
|
732
|
-
if (!
|
|
1996
|
+
if (!isNil(newObj[key][i]) && _typeof(newObj[key][i]) === 'object' && !isNil(newObj[key][i].id)) {
|
|
733
1997
|
// Since its unordered array elements then check if the element on `oldObj` exists by id
|
|
734
1998
|
var foundObject = hashMapValue[newObj[key][i].id];
|
|
735
|
-
if (!
|
|
1999
|
+
if (!isNil(foundObject)) {
|
|
736
2000
|
var _copyEmptyArrayProps = copyEmptyArrayProps(foundObject, newObj[key][i]),
|
|
737
2001
|
_copyEmptyArrayProps2 = _slicedToArray(_copyEmptyArrayProps, 2),
|
|
738
2002
|
nestedObject = _copyEmptyArrayProps2[1];
|
|
@@ -748,10 +2012,10 @@ function copyEmptyArrayProps() {
|
|
|
748
2012
|
return merged;
|
|
749
2013
|
}
|
|
750
2014
|
if (Array.isArray(value)) {
|
|
751
|
-
merged[key] =
|
|
2015
|
+
merged[key] = isNil(newObj[key]) ? [] : newObj[key];
|
|
752
2016
|
return merged;
|
|
753
2017
|
}
|
|
754
|
-
if (!
|
|
2018
|
+
if (!isNil(newObj[key]) && _typeof(value) === 'object' &&
|
|
755
2019
|
// Ignore Date as this will create invalid object since typeof date === 'object' return true
|
|
756
2020
|
// ex: {date: new Date()} will result {date: {}}
|
|
757
2021
|
!(value instanceof Date)) {
|
|
@@ -786,7 +2050,7 @@ function createCategoryMapActions(mapActionGroup, syncActionConfig) {
|
|
|
786
2050
|
allActions.push(mapActionGroup('assets', function () {
|
|
787
2051
|
return actionsMapAssets$1(diff, oldObj, newObj);
|
|
788
2052
|
}));
|
|
789
|
-
return
|
|
2053
|
+
return flatten(allActions);
|
|
790
2054
|
};
|
|
791
2055
|
}
|
|
792
2056
|
var categories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -904,7 +2168,6 @@ function actionsMapReferences$2(diff, oldObj, newObj) {
|
|
|
904
2168
|
return buildReferenceActions({
|
|
905
2169
|
actions: referenceActionsList$2,
|
|
906
2170
|
diff: diff,
|
|
907
|
-
oldObj: oldObj,
|
|
908
2171
|
newObj: newObj
|
|
909
2172
|
});
|
|
910
2173
|
}
|
|
@@ -1012,7 +2275,7 @@ function buildAuthenticationModeActions(_ref) {
|
|
|
1012
2275
|
authMode: patched
|
|
1013
2276
|
}, value, newObj.password);
|
|
1014
2277
|
}).filter(function (action) {
|
|
1015
|
-
return !
|
|
2278
|
+
return !isNil(action);
|
|
1016
2279
|
});
|
|
1017
2280
|
}
|
|
1018
2281
|
|
|
@@ -1043,7 +2306,7 @@ function createCustomerMapActions(mapActionGroup, syncActionConfig) {
|
|
|
1043
2306
|
allActions.push(mapActionGroup('authenticationModes', function () {
|
|
1044
2307
|
return actionsMapAuthenticationModes(diff, oldObj, newObj);
|
|
1045
2308
|
}));
|
|
1046
|
-
return
|
|
2309
|
+
return flatten(allActions);
|
|
1047
2310
|
};
|
|
1048
2311
|
}
|
|
1049
2312
|
var customers = (function (actionGroupList, syncActionConfig) {
|
|
@@ -1102,7 +2365,6 @@ function actionsMapReferences$1(diff, oldObj, newObj) {
|
|
|
1102
2365
|
return buildReferenceActions({
|
|
1103
2366
|
actions: referenceActionsList$1,
|
|
1104
2367
|
diff: diff,
|
|
1105
|
-
oldObj: oldObj,
|
|
1106
2368
|
newObj: newObj
|
|
1107
2369
|
});
|
|
1108
2370
|
}
|
|
@@ -1119,7 +2381,7 @@ function createInventoryMapActions(mapActionGroup, syncActionConfig) {
|
|
|
1119
2381
|
allActions.push(mapActionGroup('custom', function () {
|
|
1120
2382
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
1121
2383
|
}));
|
|
1122
|
-
return
|
|
2384
|
+
return flatten(allActions);
|
|
1123
2385
|
};
|
|
1124
2386
|
}
|
|
1125
2387
|
var inventories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -1186,7 +2448,7 @@ function findMatchingPairs(diff) {
|
|
|
1186
2448
|
var _preProcessCollection2 = preProcessCollection(now, identifier),
|
|
1187
2449
|
nowObjRefByIdentifier = _preProcessCollection2.refByIdentifier,
|
|
1188
2450
|
nowObjRefByIndex = _preProcessCollection2.refByIndex;
|
|
1189
|
-
|
|
2451
|
+
forEach(diff, function (item, key) {
|
|
1190
2452
|
if (REGEX_NUMBER$3.test(key)) {
|
|
1191
2453
|
var matchingIdentifier = nowObjRefByIndex[key];
|
|
1192
2454
|
result[key] = [beforeObjRefByIdentifier[matchingIdentifier], key];
|
|
@@ -1367,7 +2629,7 @@ function _buildVariantImagesAction(diffedImages) {
|
|
|
1367
2629
|
var actions = [];
|
|
1368
2630
|
// generate a hashMap to be able to reference the right image from both ends
|
|
1369
2631
|
var matchingImagePairs = findMatchingPairs(diffedImages, oldVariant.images, newVariant.images, 'url');
|
|
1370
|
-
|
|
2632
|
+
forEach(diffedImages, function (image, key) {
|
|
1371
2633
|
var _extractMatchingPairs = extractMatchingPairs(matchingImagePairs, key, oldVariant.images, newVariant.images),
|
|
1372
2634
|
oldObj = _extractMatchingPairs.oldObj,
|
|
1373
2635
|
newObj = _extractMatchingPairs.newObj;
|
|
@@ -1424,7 +2686,7 @@ function _buildVariantPricesAction(diffedPrices) {
|
|
|
1424
2686
|
|
|
1425
2687
|
// generate a hashMap to be able to reference the right image from both ends
|
|
1426
2688
|
var matchingPricePairs = findMatchingPairs(diffedPrices, oldVariant.prices, newVariant.prices);
|
|
1427
|
-
|
|
2689
|
+
forEach(diffedPrices, function (price, key) {
|
|
1428
2690
|
var _extractMatchingPairs2 = extractMatchingPairs(matchingPricePairs, key, oldVariant.prices, newVariant.prices),
|
|
1429
2691
|
oldObj = _extractMatchingPairs2.oldObj,
|
|
1430
2692
|
newObj = _extractMatchingPairs2.newObj;
|
|
@@ -1472,7 +2734,7 @@ function _buildVariantPricesAction(diffedPrices) {
|
|
|
1472
2734
|
function _buildVariantAttributesActions(attributes, oldVariant, newVariant, sameForAllAttributeNames) {
|
|
1473
2735
|
var actions = [];
|
|
1474
2736
|
if (!attributes) return actions;
|
|
1475
|
-
|
|
2737
|
+
forEach(attributes, function (value, key) {
|
|
1476
2738
|
if (REGEX_NUMBER$2.test(key)) {
|
|
1477
2739
|
if (Array.isArray(value)) {
|
|
1478
2740
|
var id = oldVariant.id;
|
|
@@ -1537,8 +2799,8 @@ function _buildVariantChangeAssetOrderAction(diffAssets, oldVariant, newVariant)
|
|
|
1537
2799
|
}).filter(function (_) {
|
|
1538
2800
|
return _ !== undefined;
|
|
1539
2801
|
});
|
|
1540
|
-
var assetIdsToKeep =
|
|
1541
|
-
var assetIdsToRemove =
|
|
2802
|
+
var assetIdsToKeep = intersection(assetIdsCurrent, assetIdsBefore);
|
|
2803
|
+
var assetIdsToRemove = without.apply(void 0, [assetIdsBefore].concat(_toConsumableArray(assetIdsToKeep)));
|
|
1542
2804
|
var changeAssetOrderAction = _objectSpread2({
|
|
1543
2805
|
action: 'changeAssetOrder',
|
|
1544
2806
|
assetOrder: assetIdsToKeep.concat(assetIdsToRemove)
|
|
@@ -1550,7 +2812,7 @@ function _buildVariantAssetsActions(diffAssets, oldVariant, newVariant) {
|
|
|
1550
2812
|
|
|
1551
2813
|
// generate a hashMap to be able to reference the right asset from both ends
|
|
1552
2814
|
var matchingAssetPairs = findMatchingPairs(diffAssets, oldVariant.assets, newVariant.assets);
|
|
1553
|
-
|
|
2815
|
+
forEach(diffAssets, function (asset, key) {
|
|
1554
2816
|
var _extractMatchingPairs3 = extractMatchingPairs(matchingAssetPairs, key, oldVariant.assets, newVariant.assets),
|
|
1555
2817
|
oldAsset = _extractMatchingPairs3.oldObj,
|
|
1556
2818
|
newAsset = _extractMatchingPairs3.newObj;
|
|
@@ -1649,7 +2911,6 @@ function actionsMapReferences(diff, oldObj, newObj) {
|
|
|
1649
2911
|
return buildReferenceActions({
|
|
1650
2912
|
actions: referenceActionsList,
|
|
1651
2913
|
diff: diff,
|
|
1652
|
-
oldObj: oldObj,
|
|
1653
2914
|
newObj: newObj
|
|
1654
2915
|
});
|
|
1655
2916
|
}
|
|
@@ -1658,7 +2919,7 @@ function actionsMapCategories(diff) {
|
|
|
1658
2919
|
if (!diff.categories) return actions;
|
|
1659
2920
|
var addToCategoryActions = [];
|
|
1660
2921
|
var removeFromCategoryActions = [];
|
|
1661
|
-
|
|
2922
|
+
forEach(diff.categories, function (category) {
|
|
1662
2923
|
if (Array.isArray(category)) {
|
|
1663
2924
|
var action = {
|
|
1664
2925
|
category: category[0]
|
|
@@ -1703,7 +2964,7 @@ function actionsMapCategoryOrderHints(diff) {
|
|
|
1703
2964
|
function actionsMapAssets(diff, oldObj, newObj, variantHashMap) {
|
|
1704
2965
|
var allAssetsActions = [];
|
|
1705
2966
|
var variants = diff.variants;
|
|
1706
|
-
if (variants)
|
|
2967
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1707
2968
|
var _extractMatchingPairs4 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1708
2969
|
oldVariant = _extractMatchingPairs4.oldObj,
|
|
1709
2970
|
newVariant = _extractMatchingPairs4.newObj;
|
|
@@ -1719,7 +2980,7 @@ function actionsMapAttributes$1(diff, oldObj, newObj) {
|
|
|
1719
2980
|
var variantHashMap = arguments.length > 4 ? arguments[4] : undefined;
|
|
1720
2981
|
var actions = [];
|
|
1721
2982
|
var variants = diff.variants;
|
|
1722
|
-
if (variants)
|
|
2983
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1723
2984
|
var _extractMatchingPairs5 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1724
2985
|
oldVariant = _extractMatchingPairs5.oldObj,
|
|
1725
2986
|
newVariant = _extractMatchingPairs5.newObj;
|
|
@@ -1736,14 +2997,14 @@ function actionsMapAttributes$1(diff, oldObj, newObj) {
|
|
|
1736
2997
|
|
|
1737
2998
|
// Ensure that an action is unique.
|
|
1738
2999
|
// This is especially necessary for SFA attributes.
|
|
1739
|
-
return
|
|
3000
|
+
return uniqWith(actions, function (a, b) {
|
|
1740
3001
|
return a.action === b.action && a.name === b.name && a.variantId === b.variantId;
|
|
1741
3002
|
});
|
|
1742
3003
|
}
|
|
1743
3004
|
function actionsMapImages(diff, oldObj, newObj, variantHashMap) {
|
|
1744
3005
|
var actions = [];
|
|
1745
3006
|
var variants = diff.variants;
|
|
1746
|
-
if (variants)
|
|
3007
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1747
3008
|
var _extractMatchingPairs6 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1748
3009
|
oldVariant = _extractMatchingPairs6.oldObj,
|
|
1749
3010
|
newVariant = _extractMatchingPairs6.newObj;
|
|
@@ -1759,7 +3020,7 @@ function actionsMapPrices(diff, oldObj, newObj, variantHashMap, enableDiscounted
|
|
|
1759
3020
|
var changePriceActions = [];
|
|
1760
3021
|
var removePriceActions = [];
|
|
1761
3022
|
var variants = diff.variants;
|
|
1762
|
-
if (variants)
|
|
3023
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1763
3024
|
var _extractMatchingPairs7 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1764
3025
|
oldVariant = _extractMatchingPairs7.oldObj,
|
|
1765
3026
|
newVariant = _extractMatchingPairs7.newObj;
|
|
@@ -1781,13 +3042,13 @@ function actionsMapPrices(diff, oldObj, newObj, variantHashMap, enableDiscounted
|
|
|
1781
3042
|
function actionsMapPricesCustom(diff, oldObj, newObj, variantHashMap) {
|
|
1782
3043
|
var actions = [];
|
|
1783
3044
|
var variants = diff.variants;
|
|
1784
|
-
if (variants)
|
|
3045
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1785
3046
|
var _extractMatchingPairs8 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1786
3047
|
oldVariant = _extractMatchingPairs8.oldObj,
|
|
1787
3048
|
newVariant = _extractMatchingPairs8.newObj;
|
|
1788
3049
|
if (variant && variant.prices && (REGEX_UNDERSCORE_NUMBER$2.test(key) || REGEX_NUMBER$2.test(key))) {
|
|
1789
3050
|
var priceHashMap = findMatchingPairs(variant.prices, oldVariant.prices, newVariant.prices);
|
|
1790
|
-
|
|
3051
|
+
forEach(variant.prices, function (price, index) {
|
|
1791
3052
|
var _extractMatchingPairs9 = extractMatchingPairs(priceHashMap, index, oldVariant.prices, newVariant.prices),
|
|
1792
3053
|
oldPrice = _extractMatchingPairs9.oldObj,
|
|
1793
3054
|
newPrice = _extractMatchingPairs9.newObj;
|
|
@@ -1871,12 +3132,12 @@ function createProductMapActions(mapActionGroup, syncActionConfig) {
|
|
|
1871
3132
|
allActions.push(mapActionGroup('assets', function () {
|
|
1872
3133
|
return actionsMapAssets(diff, oldObj, newObj, variantHashMap);
|
|
1873
3134
|
}));
|
|
1874
|
-
if (publish === true || staged === false) return
|
|
3135
|
+
if (publish === true || staged === false) return flatten(allActions).map(function (action) {
|
|
1875
3136
|
return _objectSpread2(_objectSpread2({}, action), {}, {
|
|
1876
3137
|
staged: false
|
|
1877
3138
|
});
|
|
1878
3139
|
});
|
|
1879
|
-
return
|
|
3140
|
+
return flatten(allActions);
|
|
1880
3141
|
};
|
|
1881
3142
|
}
|
|
1882
3143
|
function moveMasterVariantsIntoVariants(before, now) {
|
|
@@ -1959,7 +3220,7 @@ function _buildDeliveryParcelsAction(diffedParcels) {
|
|
|
1959
3220
|
|
|
1960
3221
|
// generate a hashMap to be able to reference the right image from both ends
|
|
1961
3222
|
var matchingParcelPairs = findMatchingPairs(diffedParcels, oldDelivery.parcels, newDelivery.parcels);
|
|
1962
|
-
|
|
3223
|
+
forEach(diffedParcels, function (parcel, key) {
|
|
1963
3224
|
var _extractMatchingPairs = extractMatchingPairs(matchingParcelPairs, key, oldDelivery.parcels, newDelivery.parcels),
|
|
1964
3225
|
oldObj = _extractMatchingPairs.oldObj;
|
|
1965
3226
|
if (isAddAction(key, parcel)) {
|
|
@@ -2001,7 +3262,7 @@ function actionsMapParcels(diff, oldObj, newObj, deliveryHashMap) {
|
|
|
2001
3262
|
if (!deliveries) return [];
|
|
2002
3263
|
var addParcelActions = [];
|
|
2003
3264
|
var removeParcelActions = [];
|
|
2004
|
-
if (deliveries)
|
|
3265
|
+
if (deliveries) forEach(deliveries, function (delivery, key) {
|
|
2005
3266
|
var _extractMatchingPairs2 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
|
|
2006
3267
|
oldDelivery = _extractMatchingPairs2.oldObj,
|
|
2007
3268
|
newDelivery = _extractMatchingPairs2.newObj;
|
|
@@ -2022,7 +3283,7 @@ function actionsMapDeliveryItems(diff, oldObj, newObj, deliveryHashMap) {
|
|
|
2022
3283
|
var deliveries = shippingInfo.deliveries;
|
|
2023
3284
|
if (!deliveries) return [];
|
|
2024
3285
|
var setDeliveryItemsActions = [];
|
|
2025
|
-
|
|
3286
|
+
forEach(deliveries, function (delivery, key) {
|
|
2026
3287
|
var _extractMatchingPairs3 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
|
|
2027
3288
|
newDelivery = _extractMatchingPairs3.newObj;
|
|
2028
3289
|
if (REGEX_UNDERSCORE_NUMBER$1.test(key) || REGEX_NUMBER$1.test(key)) {
|
|
@@ -2091,13 +3352,13 @@ function createOrderMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2091
3352
|
allActions.push(mapActionGroup('items', function () {
|
|
2092
3353
|
return actionsMapDeliveryItems(diff, oldObj, newObj, deliveryHashMap);
|
|
2093
3354
|
}));
|
|
2094
|
-
allActions.push(
|
|
3355
|
+
allActions.push(flatten(mapActionGroup('returnInfo', function () {
|
|
2095
3356
|
return actionsMapReturnsInfo(diff, oldObj, newObj);
|
|
2096
3357
|
})));
|
|
2097
3358
|
allActions.push(mapActionGroup('custom', function () {
|
|
2098
3359
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2099
3360
|
}));
|
|
2100
|
-
return
|
|
3361
|
+
return flatten(allActions);
|
|
2101
3362
|
};
|
|
2102
3363
|
}
|
|
2103
3364
|
var orders = (function (actionGroupList, syncActionConfig) {
|
|
@@ -2191,7 +3452,7 @@ function createProductDiscountsMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2191
3452
|
allActions.push(mapActionGroup('base', function () {
|
|
2192
3453
|
return actionsMapBase$f(diff, oldObj, newObj, syncActionConfig);
|
|
2193
3454
|
}));
|
|
2194
|
-
return combineValidityActions(
|
|
3455
|
+
return combineValidityActions(flatten(allActions));
|
|
2195
3456
|
};
|
|
2196
3457
|
}
|
|
2197
3458
|
var productDiscounts = (function (actionGroupList) {
|
|
@@ -2260,7 +3521,7 @@ function createDiscountCodesMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2260
3521
|
allActions.push(mapActionGroup('custom', function () {
|
|
2261
3522
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2262
3523
|
}));
|
|
2263
|
-
return combineValidityActions(
|
|
3524
|
+
return combineValidityActions(flatten(allActions));
|
|
2264
3525
|
};
|
|
2265
3526
|
}
|
|
2266
3527
|
var discountCodes = (function (actionGroupList) {
|
|
@@ -2313,7 +3574,7 @@ function createCustomerGroupMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2313
3574
|
allActions.push(mapActionGroup('custom', function () {
|
|
2314
3575
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2315
3576
|
}));
|
|
2316
|
-
return
|
|
3577
|
+
return flatten(allActions);
|
|
2317
3578
|
};
|
|
2318
3579
|
}
|
|
2319
3580
|
var customerGroup = (function (actionGroupList) {
|
|
@@ -2385,7 +3646,7 @@ function createCartDiscountsMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2385
3646
|
allActions.push(mapActionGroup('custom', function () {
|
|
2386
3647
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2387
3648
|
}));
|
|
2388
|
-
return combineValidityActions(
|
|
3649
|
+
return combineValidityActions(flatten(allActions));
|
|
2389
3650
|
};
|
|
2390
3651
|
}
|
|
2391
3652
|
var cartDiscounts = (function (actionGroupList) {
|
|
@@ -2765,7 +4026,7 @@ function createTaxCategoriesMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2765
4026
|
allActions.push(mapActionGroup('rates', function () {
|
|
2766
4027
|
return actionsMapRates(diff, oldObj, newObj);
|
|
2767
4028
|
}));
|
|
2768
|
-
return
|
|
4029
|
+
return flatten(allActions);
|
|
2769
4030
|
};
|
|
2770
4031
|
}
|
|
2771
4032
|
var taxCategories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -2856,10 +4117,10 @@ function createZonesMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2856
4117
|
allActions.push(mapActionGroup('base', function () {
|
|
2857
4118
|
return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
|
|
2858
4119
|
}));
|
|
2859
|
-
allActions.push(
|
|
4120
|
+
allActions.push(flatten(mapActionGroup('locations', function () {
|
|
2860
4121
|
return actionsMapLocations(diff, oldObj, newObj);
|
|
2861
4122
|
})));
|
|
2862
|
-
return
|
|
4123
|
+
return flatten(allActions);
|
|
2863
4124
|
};
|
|
2864
4125
|
}
|
|
2865
4126
|
var zones = (function (actionGroupList, syncActionConfig) {
|
|
@@ -2975,7 +4236,7 @@ function actionsMapZoneRates(diff, oldObj, newObj) {
|
|
|
2975
4236
|
if (diff.zoneRates[key].shippingRates) return [].concat(_toConsumableArray(actions), _toConsumableArray(actionsMapZoneRatesShippingRates(diff.zoneRates[key], oldZoneRate, newZoneRate)));
|
|
2976
4237
|
return actions;
|
|
2977
4238
|
}, []);
|
|
2978
|
-
return
|
|
4239
|
+
return flatten(hasZoneActions ? [].concat(_toConsumableArray(shippingRateActions), [{
|
|
2979
4240
|
action: 'removeZone',
|
|
2980
4241
|
zone: oldZoneRate.zone
|
|
2981
4242
|
}, {
|
|
@@ -2992,13 +4253,13 @@ function createShippingMethodsMapActions(mapActionGroup, syncActionConfig) {
|
|
|
2992
4253
|
allActions.push(mapActionGroup('base', function () {
|
|
2993
4254
|
return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
|
|
2994
4255
|
}));
|
|
2995
|
-
allActions.push(
|
|
4256
|
+
allActions.push(flatten(mapActionGroup('zoneRates', function () {
|
|
2996
4257
|
return actionsMapZoneRates(diff, oldObj, newObj);
|
|
2997
4258
|
})));
|
|
2998
4259
|
allActions.push(mapActionGroup('custom', function () {
|
|
2999
4260
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
3000
4261
|
}));
|
|
3001
|
-
return
|
|
4262
|
+
return flatten(allActions);
|
|
3002
4263
|
};
|
|
3003
4264
|
}
|
|
3004
4265
|
var shippingMethods = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3130,7 +4391,7 @@ var generateUpdateActionsForAttributeDefinitions = function generateUpdateAction
|
|
|
3130
4391
|
action: 'removeAttributeDefinition',
|
|
3131
4392
|
name: attributeDef.previous.name
|
|
3132
4393
|
};
|
|
3133
|
-
})), _toConsumableArray(
|
|
4394
|
+
})), _toConsumableArray(flatten(updatedAttributeDefinitions.map(function (updatedAttributeDefinition) {
|
|
3134
4395
|
return generateBaseFieldsUpdateActions(updatedAttributeDefinition.previous, updatedAttributeDefinition.next, {
|
|
3135
4396
|
label: {
|
|
3136
4397
|
action: 'changeLabel',
|
|
@@ -3180,7 +4441,7 @@ var generateUpdateActionsForAttributeEnumValues = function generateUpdateActions
|
|
|
3180
4441
|
return _objectSpread2(_objectSpread2({}, nextEnumUpdateActions), {}, _defineProperty({}, removedAttributeEnumValue.hint.attributeName, _objectSpread2(_objectSpread2({}, removedAttributeEnumValueOfSameAttributeName), {}, {
|
|
3181
4442
|
keys: [].concat(_toConsumableArray(removedAttributeEnumValueOfSameAttributeName.keys), [removedAttributeEnumValue.previous.key])
|
|
3182
4443
|
})));
|
|
3183
|
-
}, {}))), _toConsumableArray(
|
|
4444
|
+
}, {}))), _toConsumableArray(flatten(updatedAttributeEnumValues.map(function (updatedAttributeEnumValue) {
|
|
3184
4445
|
var updateActions = generateBaseFieldsUpdateActions(updatedAttributeEnumValue.previous, updatedAttributeEnumValue.next, {
|
|
3185
4446
|
key: {
|
|
3186
4447
|
action: 'changeEnumKey',
|
|
@@ -3254,7 +4515,7 @@ var actionsMapForHints = function actionsMapForHints() {
|
|
|
3254
4515
|
|
|
3255
4516
|
function createProductTypeMapActions(mapActionGroup, syncActionConfig) {
|
|
3256
4517
|
return function doMapActions(diff, next, previous, options) {
|
|
3257
|
-
return
|
|
4518
|
+
return flatten([
|
|
3258
4519
|
// we support only base fields for the product type,
|
|
3259
4520
|
// for attributes, applying hints would be recommended
|
|
3260
4521
|
mapActionGroup('base', function () {
|
|
@@ -3350,7 +4611,7 @@ function createStatesMapActions(mapActionGroup, syncActionConfig) {
|
|
|
3350
4611
|
roleActions.push(mapActionGroup('roles', function () {
|
|
3351
4612
|
return actionsMapRoles(diff, oldObj, newObj);
|
|
3352
4613
|
}));
|
|
3353
|
-
return
|
|
4614
|
+
return flatten([].concat(baseActions, _toConsumableArray(groupRoleActions(roleActions))));
|
|
3354
4615
|
};
|
|
3355
4616
|
}
|
|
3356
4617
|
var states = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3403,7 +4664,7 @@ function createChannelsMapActions$1(mapActionGroup, syncActionConfig) {
|
|
|
3403
4664
|
allActions.push(mapActionGroup('custom', function () {
|
|
3404
4665
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
3405
4666
|
}));
|
|
3406
|
-
return
|
|
4667
|
+
return flatten(allActions);
|
|
3407
4668
|
};
|
|
3408
4669
|
}
|
|
3409
4670
|
var channels = (function (actionGroupList) {
|
|
@@ -3474,7 +4735,7 @@ function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next
|
|
|
3474
4735
|
var foundPreviousEnum = previous.values.find(function (previousEnum) {
|
|
3475
4736
|
return previousEnum.key === newEnum.key;
|
|
3476
4737
|
});
|
|
3477
|
-
var isLabelEqual =
|
|
4738
|
+
var isLabelEqual = isEqual(foundPreviousEnum.label, newEnum.label);
|
|
3478
4739
|
if (isKeyChanged) {
|
|
3479
4740
|
// these actions is then flatten in the end
|
|
3480
4741
|
changeActions.push({
|
|
@@ -3503,7 +4764,7 @@ function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next
|
|
|
3503
4764
|
// following lists are necessary to ensure that when we change the
|
|
3504
4765
|
// order of enumValues, we generate one updateAction instead of one at a time.
|
|
3505
4766
|
var newEnumValuesOrder = [];
|
|
3506
|
-
|
|
4767
|
+
flatten(buildArrayActions(attributeDiff, previous, next)).forEach(function (updateAction) {
|
|
3507
4768
|
if (updateAction.action === changeEnumOrderActionName) {
|
|
3508
4769
|
newEnumValuesOrder = next.values.map(function (enumValue) {
|
|
3509
4770
|
return enumValue.key;
|
|
@@ -3518,7 +4779,7 @@ function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next
|
|
|
3518
4779
|
}
|
|
3519
4780
|
function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPaths) {
|
|
3520
4781
|
var actions = [];
|
|
3521
|
-
|
|
4782
|
+
forEach(fieldDefinitionsDiff, function (diffValue, diffKey) {
|
|
3522
4783
|
var extractedPairs = extractMatchingPairs(diffPaths, diffKey, previous, next);
|
|
3523
4784
|
if (getIsChangedOperation(diffKey)) {
|
|
3524
4785
|
var _diffValue$type;
|
|
@@ -3569,7 +4830,7 @@ function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPa
|
|
|
3569
4830
|
// in order to prevent any eventual removal of `addAction`.
|
|
3570
4831
|
// List of `removeActions` can be found here
|
|
3571
4832
|
// https://docs.commercetools.com/http-api-projects-types.html#change-key
|
|
3572
|
-
var sortedActions =
|
|
4833
|
+
var sortedActions = sortBy(actions, function (action) {
|
|
3573
4834
|
return action.action !== 'removeFieldDefinition';
|
|
3574
4835
|
});
|
|
3575
4836
|
return sortedActions;
|
|
@@ -3583,7 +4844,7 @@ function createTypeMapActions(mapActionGroup, syncActionConfig) {
|
|
|
3583
4844
|
}), mapActionGroup('fieldDefinitions', function () {
|
|
3584
4845
|
return actionsMapFieldDefinitions(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, findMatchingPairs(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, 'name'));
|
|
3585
4846
|
}));
|
|
3586
|
-
return
|
|
4847
|
+
return flatten(allActions);
|
|
3587
4848
|
};
|
|
3588
4849
|
}
|
|
3589
4850
|
var types = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3685,7 +4946,7 @@ function createChannelsMapActions(mapActionGroup, syncActionConfig) {
|
|
|
3685
4946
|
allActions.push(mapActionGroup('searchIndexingConfiguration', function () {
|
|
3686
4947
|
return actionsMapSearchIndexingConfiguration(diff, oldObj, newObj);
|
|
3687
4948
|
}));
|
|
3688
|
-
return
|
|
4949
|
+
return flatten(allActions);
|
|
3689
4950
|
};
|
|
3690
4951
|
}
|
|
3691
4952
|
var projects = (function (actionGroupList) {
|
|
@@ -3733,7 +4994,7 @@ function createStoresMapActions(mapActionGroup) {
|
|
|
3733
4994
|
allActions.push(mapActionGroup('custom', function () {
|
|
3734
4995
|
return actionsMapCustom(diff, next, previous);
|
|
3735
4996
|
}));
|
|
3736
|
-
return
|
|
4997
|
+
return flatten(allActions);
|
|
3737
4998
|
};
|
|
3738
4999
|
}
|
|
3739
5000
|
var stores = (function (actionGroupList) {
|
|
@@ -3776,7 +5037,7 @@ function createProductSelectionsMapActions(mapActionGroup) {
|
|
|
3776
5037
|
allActions.push(mapActionGroup('custom', function () {
|
|
3777
5038
|
return actionsMapCustom(diff, next, previous);
|
|
3778
5039
|
}));
|
|
3779
|
-
return
|
|
5040
|
+
return flatten(allActions);
|
|
3780
5041
|
};
|
|
3781
5042
|
}
|
|
3782
5043
|
var productSelections = (function (actionGroupList) {
|
|
@@ -3911,10 +5172,10 @@ function createAttributeGroupsMapActions(mapActionGroup, syncActionConfig) {
|
|
|
3911
5172
|
allActions.push(mapActionGroup('base', function () {
|
|
3912
5173
|
return actionsMapBase(diff, oldObj, newObj, syncActionConfig);
|
|
3913
5174
|
}));
|
|
3914
|
-
allActions.push(
|
|
5175
|
+
allActions.push(flatten(mapActionGroup('attributes', function () {
|
|
3915
5176
|
return actionsMapAttributes(diff, oldObj, newObj);
|
|
3916
5177
|
})));
|
|
3917
|
-
return
|
|
5178
|
+
return flatten(allActions);
|
|
3918
5179
|
};
|
|
3919
5180
|
}
|
|
3920
5181
|
var attributeGroups = (function (actionGroupList, syncActionConfig) {
|