@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.
- package/dist/sync-actions.cjs.js +1349 -92
- package/dist/sync-actions.es.js +1287 -17
- package/dist/sync-actions.umd.js +1353 -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.umd.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash.flatten'), require('lodash.isequal'), require('lodash.isnil'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'lodash.flatten', 'lodash.isequal', 'lodash.isnil', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CommercetoolsSyncActions = {}, global.flatten, global.isEqual, global.isNil, global.
|
|
5
|
-
})(this, (function (exports, flatten, isEqual, isNil,
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
-
|
|
9
|
-
var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
10
|
-
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
11
|
-
var isNil__default = /*#__PURE__*/_interopDefaultLegacy(isNil);
|
|
12
|
-
var forEach__default = /*#__PURE__*/_interopDefaultLegacy(forEach);
|
|
13
|
-
var uniqWith__default = /*#__PURE__*/_interopDefaultLegacy(uniqWith);
|
|
14
|
-
var intersection__default = /*#__PURE__*/_interopDefaultLegacy(intersection);
|
|
15
|
-
var without__default = /*#__PURE__*/_interopDefaultLegacy(without);
|
|
16
|
-
var sortBy__default = /*#__PURE__*/_interopDefaultLegacy(sortBy);
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash.flatten'), require('lodash.isequal'), require('lodash.isnil'), require('lodash.foreach'), require('lodash.uniqwith'), require('lodash.intersection'), require('lodash.without'), require('lodash.sortby')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'lodash.flatten', 'lodash.isequal', 'lodash.isnil', 'lodash.foreach', 'lodash.uniqwith', 'lodash.intersection', 'lodash.without', 'lodash.sortby'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CommercetoolsSyncActions = {}, global.flatten, global.isEqual, global.isNil, global.forEach, global.uniqWith, global.intersection, global.without, global.sortBy));
|
|
5
|
+
})(this, (function (exports, flatten, isEqual, isNil, forEach, uniqWith, intersection, without, sortBy) { 'use strict';
|
|
17
6
|
|
|
18
7
|
function _arrayLikeToArray(r, a) {
|
|
19
8
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -26,14 +15,69 @@
|
|
|
26
15
|
function _arrayWithoutHoles(r) {
|
|
27
16
|
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
28
17
|
}
|
|
18
|
+
function _assertThisInitialized(e) {
|
|
19
|
+
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
20
|
+
return e;
|
|
21
|
+
}
|
|
22
|
+
function _callSuper(t, o, e) {
|
|
23
|
+
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
24
|
+
}
|
|
25
|
+
function _classCallCheck(a, n) {
|
|
26
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
27
|
+
}
|
|
28
|
+
function _defineProperties(e, r) {
|
|
29
|
+
for (var t = 0; t < r.length; t++) {
|
|
30
|
+
var o = r[t];
|
|
31
|
+
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function _createClass(e, r, t) {
|
|
35
|
+
return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
|
|
36
|
+
writable: false
|
|
37
|
+
}), e;
|
|
38
|
+
}
|
|
29
39
|
function _defineProperty(e, r, t) {
|
|
30
40
|
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
31
41
|
value: t,
|
|
32
|
-
enumerable:
|
|
33
|
-
configurable:
|
|
34
|
-
writable:
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true
|
|
35
45
|
}) : e[r] = t, e;
|
|
36
46
|
}
|
|
47
|
+
function _get() {
|
|
48
|
+
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
|
|
49
|
+
var p = _superPropBase(e, t);
|
|
50
|
+
if (p) {
|
|
51
|
+
var n = Object.getOwnPropertyDescriptor(p, t);
|
|
52
|
+
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
|
|
53
|
+
}
|
|
54
|
+
}, _get.apply(null, arguments);
|
|
55
|
+
}
|
|
56
|
+
function _getPrototypeOf(t) {
|
|
57
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
58
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
59
|
+
}, _getPrototypeOf(t);
|
|
60
|
+
}
|
|
61
|
+
function _inherits(t, e) {
|
|
62
|
+
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
63
|
+
t.prototype = Object.create(e && e.prototype, {
|
|
64
|
+
constructor: {
|
|
65
|
+
value: t,
|
|
66
|
+
writable: true,
|
|
67
|
+
configurable: true
|
|
68
|
+
}
|
|
69
|
+
}), Object.defineProperty(t, "prototype", {
|
|
70
|
+
writable: false
|
|
71
|
+
}), e && _setPrototypeOf(t, e);
|
|
72
|
+
}
|
|
73
|
+
function _isNativeReflectConstruct() {
|
|
74
|
+
try {
|
|
75
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
76
|
+
} catch (t) {}
|
|
77
|
+
return (_isNativeReflectConstruct = function () {
|
|
78
|
+
return !!t;
|
|
79
|
+
})();
|
|
80
|
+
}
|
|
37
81
|
function _iterableToArray(r) {
|
|
38
82
|
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
39
83
|
}
|
|
@@ -45,15 +89,15 @@
|
|
|
45
89
|
i,
|
|
46
90
|
u,
|
|
47
91
|
a = [],
|
|
48
|
-
f =
|
|
49
|
-
o =
|
|
92
|
+
f = true,
|
|
93
|
+
o = false;
|
|
50
94
|
try {
|
|
51
95
|
if (i = (t = t.call(r)).next, 0 === l) {
|
|
52
96
|
if (Object(t) !== t) return;
|
|
53
97
|
f = !1;
|
|
54
98
|
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
55
99
|
} catch (r) {
|
|
56
|
-
o =
|
|
100
|
+
o = true, n = r;
|
|
57
101
|
} finally {
|
|
58
102
|
try {
|
|
59
103
|
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
@@ -83,7 +127,7 @@
|
|
|
83
127
|
function _objectSpread2(e) {
|
|
84
128
|
for (var r = 1; r < arguments.length; r++) {
|
|
85
129
|
var t = null != arguments[r] ? arguments[r] : {};
|
|
86
|
-
r % 2 ? ownKeys(Object(t),
|
|
130
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
87
131
|
_defineProperty(e, r, t[r]);
|
|
88
132
|
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
89
133
|
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
@@ -97,8 +141,8 @@
|
|
|
97
141
|
r,
|
|
98
142
|
i = _objectWithoutPropertiesLoose(e, t);
|
|
99
143
|
if (Object.getOwnPropertySymbols) {
|
|
100
|
-
var
|
|
101
|
-
for (r = 0; r <
|
|
144
|
+
var n = Object.getOwnPropertySymbols(e);
|
|
145
|
+
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
102
146
|
}
|
|
103
147
|
return i;
|
|
104
148
|
}
|
|
@@ -106,14 +150,34 @@
|
|
|
106
150
|
if (null == r) return {};
|
|
107
151
|
var t = {};
|
|
108
152
|
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
109
|
-
if (e.
|
|
153
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
110
154
|
t[n] = r[n];
|
|
111
155
|
}
|
|
112
156
|
return t;
|
|
113
157
|
}
|
|
158
|
+
function _possibleConstructorReturn(t, e) {
|
|
159
|
+
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
|
160
|
+
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
161
|
+
return _assertThisInitialized(t);
|
|
162
|
+
}
|
|
163
|
+
function _setPrototypeOf(t, e) {
|
|
164
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
165
|
+
return t.__proto__ = e, t;
|
|
166
|
+
}, _setPrototypeOf(t, e);
|
|
167
|
+
}
|
|
114
168
|
function _slicedToArray(r, e) {
|
|
115
169
|
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
116
170
|
}
|
|
171
|
+
function _superPropBase(t, o) {
|
|
172
|
+
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
|
|
173
|
+
return t;
|
|
174
|
+
}
|
|
175
|
+
function _superPropGet(t, o, e, r) {
|
|
176
|
+
var p = _get(_getPrototypeOf(t.prototype ), o, e);
|
|
177
|
+
return 2 & r && "function" == typeof p ? function (t) {
|
|
178
|
+
return p.apply(e, t);
|
|
179
|
+
} : p;
|
|
180
|
+
}
|
|
117
181
|
function _toConsumableArray(r) {
|
|
118
182
|
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
119
183
|
}
|
|
@@ -121,11 +185,11 @@
|
|
|
121
185
|
if ("object" != typeof t || !t) return t;
|
|
122
186
|
var e = t[Symbol.toPrimitive];
|
|
123
187
|
if (void 0 !== e) {
|
|
124
|
-
var i = e.call(t, r
|
|
188
|
+
var i = e.call(t, r);
|
|
125
189
|
if ("object" != typeof i) return i;
|
|
126
190
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
127
191
|
}
|
|
128
|
-
return (
|
|
192
|
+
return (String )(t);
|
|
129
193
|
}
|
|
130
194
|
function _toPropertyKey(t) {
|
|
131
195
|
var i = _toPrimitive(t, "string");
|
|
@@ -167,7 +231,7 @@
|
|
|
167
231
|
function arePricesStructurallyEqual(oldPrice, newPrice) {
|
|
168
232
|
var oldPriceComparison = createPriceComparator(oldPrice);
|
|
169
233
|
var newPriceComparison = createPriceComparator(newPrice);
|
|
170
|
-
return
|
|
234
|
+
return isEqual(newPriceComparison, oldPriceComparison);
|
|
171
235
|
}
|
|
172
236
|
function extractPriceFromPreviousVariant(newPrice, previousVariant) {
|
|
173
237
|
if (!previousVariant) return null;
|
|
@@ -182,7 +246,7 @@
|
|
|
182
246
|
restOfVariant = _objectWithoutProperties(newVariant, _excluded$2);
|
|
183
247
|
if (!prices) return restOfVariant;
|
|
184
248
|
var oldVariant = previousVariants.find(function (previousVariant) {
|
|
185
|
-
return !
|
|
249
|
+
return !isNil(previousVariant.id) && previousVariant.id === newVariant.id || !isNil(previousVariant.key) && previousVariant.key === newVariant.key || !isNil(previousVariant.sku) && previousVariant.sku === newVariant.sku;
|
|
186
250
|
});
|
|
187
251
|
return _objectSpread2(_objectSpread2({}, restOfVariant), {}, {
|
|
188
252
|
prices: prices.map(function (price) {
|
|
@@ -191,8 +255,8 @@
|
|
|
191
255
|
if (oldPrice) {
|
|
192
256
|
// copy ID if not provided
|
|
193
257
|
if (!newPrice.id) newPrice.id = oldPrice.id;
|
|
194
|
-
if (
|
|
195
|
-
if (
|
|
258
|
+
if (isNil(newPrice.value.type)) newPrice.value.type = oldPrice.value.type;
|
|
259
|
+
if (isNil(newPrice.value.fractionDigits)) newPrice.value.fractionDigits = oldPrice.value.fractionDigits;
|
|
196
260
|
}
|
|
197
261
|
return newPrice;
|
|
198
262
|
})
|
|
@@ -239,11 +303,1211 @@
|
|
|
239
303
|
};
|
|
240
304
|
}
|
|
241
305
|
|
|
306
|
+
var Processor = /*#__PURE__*/function () {
|
|
307
|
+
function Processor(options) {
|
|
308
|
+
_classCallCheck(this, Processor);
|
|
309
|
+
this.selfOptions = options || {};
|
|
310
|
+
this.pipes = {};
|
|
311
|
+
}
|
|
312
|
+
return _createClass(Processor, [{
|
|
313
|
+
key: "options",
|
|
314
|
+
value: function options(_options) {
|
|
315
|
+
if (_options) {
|
|
316
|
+
this.selfOptions = _options;
|
|
317
|
+
}
|
|
318
|
+
return this.selfOptions;
|
|
319
|
+
}
|
|
320
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
321
|
+
}, {
|
|
322
|
+
key: "pipe",
|
|
323
|
+
value: function pipe(name, pipeArg) {
|
|
324
|
+
var pipe = pipeArg;
|
|
325
|
+
if (typeof name === 'string') {
|
|
326
|
+
if (typeof pipe === 'undefined') {
|
|
327
|
+
return this.pipes[name];
|
|
328
|
+
} else {
|
|
329
|
+
this.pipes[name] = pipe;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (name && name.name) {
|
|
333
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
334
|
+
pipe = name;
|
|
335
|
+
if (pipe.processor === this) {
|
|
336
|
+
return pipe;
|
|
337
|
+
}
|
|
338
|
+
this.pipes[pipe.name] = pipe;
|
|
339
|
+
}
|
|
340
|
+
pipe.processor = this;
|
|
341
|
+
return pipe;
|
|
342
|
+
}
|
|
343
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
344
|
+
}, {
|
|
345
|
+
key: "process",
|
|
346
|
+
value: function process(input, pipe) {
|
|
347
|
+
var context = input;
|
|
348
|
+
context.options = this.options();
|
|
349
|
+
var nextPipe = pipe || input.pipe || 'default';
|
|
350
|
+
var lastPipe;
|
|
351
|
+
while (nextPipe) {
|
|
352
|
+
if (typeof context.nextAfterChildren !== 'undefined') {
|
|
353
|
+
// children processed and coming back to parent
|
|
354
|
+
context.next = context.nextAfterChildren;
|
|
355
|
+
context.nextAfterChildren = null;
|
|
356
|
+
}
|
|
357
|
+
if (typeof nextPipe === 'string') {
|
|
358
|
+
nextPipe = this.pipe(nextPipe);
|
|
359
|
+
}
|
|
360
|
+
nextPipe.process(context);
|
|
361
|
+
lastPipe = nextPipe;
|
|
362
|
+
nextPipe = null;
|
|
363
|
+
if (context) {
|
|
364
|
+
if (context.next) {
|
|
365
|
+
context = context.next;
|
|
366
|
+
nextPipe = context.pipe || lastPipe;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
371
|
+
return context.hasResult ? context.result : undefined;
|
|
372
|
+
}
|
|
373
|
+
}]);
|
|
374
|
+
}();
|
|
375
|
+
|
|
376
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
377
|
+
var Pipe = /*#__PURE__*/function () {
|
|
378
|
+
function Pipe(name) {
|
|
379
|
+
_classCallCheck(this, Pipe);
|
|
380
|
+
this.name = name;
|
|
381
|
+
this.filters = [];
|
|
382
|
+
}
|
|
383
|
+
return _createClass(Pipe, [{
|
|
384
|
+
key: "process",
|
|
385
|
+
value: function process(input) {
|
|
386
|
+
if (!this.processor) {
|
|
387
|
+
throw new Error('add this pipe to a processor before using it');
|
|
388
|
+
}
|
|
389
|
+
var debug = this.debug;
|
|
390
|
+
var length = this.filters.length;
|
|
391
|
+
var context = input;
|
|
392
|
+
for (var index = 0; index < length; index++) {
|
|
393
|
+
var filter = this.filters[index];
|
|
394
|
+
if (debug) {
|
|
395
|
+
this.log("filter: ".concat(filter.filterName));
|
|
396
|
+
}
|
|
397
|
+
filter(context);
|
|
398
|
+
if (_typeof(context) === 'object' && context.exiting) {
|
|
399
|
+
context.exiting = false;
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (!context.next && this.resultCheck) {
|
|
404
|
+
this.resultCheck(context);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}, {
|
|
408
|
+
key: "log",
|
|
409
|
+
value: function log(msg) {
|
|
410
|
+
console.log("[jsondiffpatch] ".concat(this.name, " pipe, ").concat(msg));
|
|
411
|
+
}
|
|
412
|
+
}, {
|
|
413
|
+
key: "append",
|
|
414
|
+
value: function append() {
|
|
415
|
+
var _this$filters;
|
|
416
|
+
(_this$filters = this.filters).push.apply(_this$filters, arguments);
|
|
417
|
+
return this;
|
|
418
|
+
}
|
|
419
|
+
}, {
|
|
420
|
+
key: "prepend",
|
|
421
|
+
value: function prepend() {
|
|
422
|
+
var _this$filters2;
|
|
423
|
+
(_this$filters2 = this.filters).unshift.apply(_this$filters2, arguments);
|
|
424
|
+
return this;
|
|
425
|
+
}
|
|
426
|
+
}, {
|
|
427
|
+
key: "indexOf",
|
|
428
|
+
value: function indexOf(filterName) {
|
|
429
|
+
if (!filterName) {
|
|
430
|
+
throw new Error('a filter name is required');
|
|
431
|
+
}
|
|
432
|
+
for (var index = 0; index < this.filters.length; index++) {
|
|
433
|
+
var filter = this.filters[index];
|
|
434
|
+
if (filter.filterName === filterName) {
|
|
435
|
+
return index;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
throw new Error("filter not found: ".concat(filterName));
|
|
439
|
+
}
|
|
440
|
+
}, {
|
|
441
|
+
key: "list",
|
|
442
|
+
value: function list() {
|
|
443
|
+
return this.filters.map(function (f) {
|
|
444
|
+
return f.filterName;
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}, {
|
|
448
|
+
key: "after",
|
|
449
|
+
value: function after(filterName) {
|
|
450
|
+
var _this$filters3;
|
|
451
|
+
var index = this.indexOf(filterName);
|
|
452
|
+
for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
453
|
+
params[_key - 1] = arguments[_key];
|
|
454
|
+
}
|
|
455
|
+
(_this$filters3 = this.filters).splice.apply(_this$filters3, [index + 1, 0].concat(params));
|
|
456
|
+
return this;
|
|
457
|
+
}
|
|
458
|
+
}, {
|
|
459
|
+
key: "before",
|
|
460
|
+
value: function before(filterName) {
|
|
461
|
+
var _this$filters4;
|
|
462
|
+
var index = this.indexOf(filterName);
|
|
463
|
+
for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
464
|
+
params[_key2 - 1] = arguments[_key2];
|
|
465
|
+
}
|
|
466
|
+
(_this$filters4 = this.filters).splice.apply(_this$filters4, [index, 0].concat(params));
|
|
467
|
+
return this;
|
|
468
|
+
}
|
|
469
|
+
}, {
|
|
470
|
+
key: "replace",
|
|
471
|
+
value: function replace(filterName) {
|
|
472
|
+
var _this$filters5;
|
|
473
|
+
var index = this.indexOf(filterName);
|
|
474
|
+
for (var _len3 = arguments.length, params = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
475
|
+
params[_key3 - 1] = arguments[_key3];
|
|
476
|
+
}
|
|
477
|
+
(_this$filters5 = this.filters).splice.apply(_this$filters5, [index, 1].concat(params));
|
|
478
|
+
return this;
|
|
479
|
+
}
|
|
480
|
+
}, {
|
|
481
|
+
key: "remove",
|
|
482
|
+
value: function remove(filterName) {
|
|
483
|
+
var index = this.indexOf(filterName);
|
|
484
|
+
this.filters.splice(index, 1);
|
|
485
|
+
return this;
|
|
486
|
+
}
|
|
487
|
+
}, {
|
|
488
|
+
key: "clear",
|
|
489
|
+
value: function clear() {
|
|
490
|
+
this.filters.length = 0;
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
493
|
+
}, {
|
|
494
|
+
key: "shouldHaveResult",
|
|
495
|
+
value: function shouldHaveResult(should) {
|
|
496
|
+
var _this = this;
|
|
497
|
+
if (should === false) {
|
|
498
|
+
this.resultCheck = null;
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
if (this.resultCheck) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
this.resultCheck = function (context) {
|
|
505
|
+
if (!context.hasResult) {
|
|
506
|
+
console.log(context);
|
|
507
|
+
var error = new Error("".concat(_this.name, " failed"));
|
|
508
|
+
error.noResult = true;
|
|
509
|
+
throw error;
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
return this;
|
|
513
|
+
}
|
|
514
|
+
}]);
|
|
515
|
+
}();
|
|
516
|
+
|
|
517
|
+
var Context = /*#__PURE__*/function () {
|
|
518
|
+
function Context() {
|
|
519
|
+
_classCallCheck(this, Context);
|
|
520
|
+
}
|
|
521
|
+
return _createClass(Context, [{
|
|
522
|
+
key: "setResult",
|
|
523
|
+
value: function setResult(result) {
|
|
524
|
+
this.result = result;
|
|
525
|
+
this.hasResult = true;
|
|
526
|
+
return this;
|
|
527
|
+
}
|
|
528
|
+
}, {
|
|
529
|
+
key: "exit",
|
|
530
|
+
value: function exit() {
|
|
531
|
+
this.exiting = true;
|
|
532
|
+
return this;
|
|
533
|
+
}
|
|
534
|
+
}, {
|
|
535
|
+
key: "push",
|
|
536
|
+
value: function push(child, name) {
|
|
537
|
+
child.parent = this;
|
|
538
|
+
if (typeof name !== 'undefined') {
|
|
539
|
+
child.childName = name;
|
|
540
|
+
}
|
|
541
|
+
child.root = this.root || this;
|
|
542
|
+
child.options = child.options || this.options;
|
|
543
|
+
if (!this.children) {
|
|
544
|
+
this.children = [child];
|
|
545
|
+
this.nextAfterChildren = this.next || null;
|
|
546
|
+
this.next = child;
|
|
547
|
+
} else {
|
|
548
|
+
this.children[this.children.length - 1].next = child;
|
|
549
|
+
this.children.push(child);
|
|
550
|
+
}
|
|
551
|
+
child.next = this;
|
|
552
|
+
return this;
|
|
553
|
+
}
|
|
554
|
+
}]);
|
|
555
|
+
}();
|
|
556
|
+
|
|
557
|
+
function cloneRegExp(re) {
|
|
558
|
+
var regexMatch = /^\/(.*)\/([gimyu]*)$/.exec(re.toString());
|
|
559
|
+
return new RegExp(regexMatch[1], regexMatch[2]);
|
|
560
|
+
}
|
|
561
|
+
function clone$1(arg) {
|
|
562
|
+
if (_typeof(arg) !== 'object') {
|
|
563
|
+
return arg;
|
|
564
|
+
}
|
|
565
|
+
if (arg === null) {
|
|
566
|
+
return null;
|
|
567
|
+
}
|
|
568
|
+
if (Array.isArray(arg)) {
|
|
569
|
+
return arg.map(clone$1);
|
|
570
|
+
}
|
|
571
|
+
if (arg instanceof Date) {
|
|
572
|
+
return new Date(arg.getTime());
|
|
573
|
+
}
|
|
574
|
+
if (arg instanceof RegExp) {
|
|
575
|
+
return cloneRegExp(arg);
|
|
576
|
+
}
|
|
577
|
+
var cloned = {};
|
|
578
|
+
for (var name in arg) {
|
|
579
|
+
if (Object.prototype.hasOwnProperty.call(arg, name)) {
|
|
580
|
+
cloned[name] = clone$1(arg[name]);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return cloned;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
var DiffContext = /*#__PURE__*/function (_Context) {
|
|
587
|
+
function DiffContext(left, right) {
|
|
588
|
+
var _this;
|
|
589
|
+
_classCallCheck(this, DiffContext);
|
|
590
|
+
_this = _callSuper(this, DiffContext);
|
|
591
|
+
_this.left = left;
|
|
592
|
+
_this.right = right;
|
|
593
|
+
_this.pipe = 'diff';
|
|
594
|
+
return _this;
|
|
595
|
+
}
|
|
596
|
+
_inherits(DiffContext, _Context);
|
|
597
|
+
return _createClass(DiffContext, [{
|
|
598
|
+
key: "setResult",
|
|
599
|
+
value: function setResult(result) {
|
|
600
|
+
if (this.options.cloneDiffValues && _typeof(result) === 'object') {
|
|
601
|
+
var clone = typeof this.options.cloneDiffValues === 'function' ? this.options.cloneDiffValues : clone$1;
|
|
602
|
+
if (_typeof(result[0]) === 'object') {
|
|
603
|
+
result[0] = clone(result[0]);
|
|
604
|
+
}
|
|
605
|
+
if (_typeof(result[1]) === 'object') {
|
|
606
|
+
result[1] = clone(result[1]);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return _superPropGet(DiffContext, "setResult", this, 3)([result]);
|
|
610
|
+
}
|
|
611
|
+
}]);
|
|
612
|
+
}(Context);
|
|
613
|
+
|
|
614
|
+
var PatchContext = /*#__PURE__*/function (_Context) {
|
|
615
|
+
function PatchContext(left, delta) {
|
|
616
|
+
var _this;
|
|
617
|
+
_classCallCheck(this, PatchContext);
|
|
618
|
+
_this = _callSuper(this, PatchContext);
|
|
619
|
+
_this.left = left;
|
|
620
|
+
_this.delta = delta;
|
|
621
|
+
_this.pipe = 'patch';
|
|
622
|
+
return _this;
|
|
623
|
+
}
|
|
624
|
+
_inherits(PatchContext, _Context);
|
|
625
|
+
return _createClass(PatchContext);
|
|
626
|
+
}(Context);
|
|
627
|
+
|
|
628
|
+
var ReverseContext = /*#__PURE__*/function (_Context) {
|
|
629
|
+
function ReverseContext(delta) {
|
|
630
|
+
var _this;
|
|
631
|
+
_classCallCheck(this, ReverseContext);
|
|
632
|
+
_this = _callSuper(this, ReverseContext);
|
|
633
|
+
_this.delta = delta;
|
|
634
|
+
_this.pipe = 'reverse';
|
|
635
|
+
return _this;
|
|
636
|
+
}
|
|
637
|
+
_inherits(ReverseContext, _Context);
|
|
638
|
+
return _createClass(ReverseContext);
|
|
639
|
+
}(Context);
|
|
640
|
+
|
|
641
|
+
var diffFilter$3 = function trivialMatchesDiffFilter(context) {
|
|
642
|
+
if (context.left === context.right) {
|
|
643
|
+
context.setResult(undefined).exit();
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (typeof context.left === 'undefined') {
|
|
647
|
+
if (typeof context.right === 'function') {
|
|
648
|
+
throw new Error('functions are not supported');
|
|
649
|
+
}
|
|
650
|
+
context.setResult([context.right]).exit();
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (typeof context.right === 'undefined') {
|
|
654
|
+
context.setResult([context.left, 0, 0]).exit();
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (typeof context.left === 'function' || typeof context.right === 'function') {
|
|
658
|
+
throw new Error('functions are not supported');
|
|
659
|
+
}
|
|
660
|
+
context.leftType = context.left === null ? 'null' : _typeof(context.left);
|
|
661
|
+
context.rightType = context.right === null ? 'null' : _typeof(context.right);
|
|
662
|
+
if (context.leftType !== context.rightType) {
|
|
663
|
+
context.setResult([context.left, context.right]).exit();
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
if (context.leftType === 'boolean' || context.leftType === 'number') {
|
|
667
|
+
context.setResult([context.left, context.right]).exit();
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
if (context.leftType === 'object') {
|
|
671
|
+
context.leftIsArray = Array.isArray(context.left);
|
|
672
|
+
}
|
|
673
|
+
if (context.rightType === 'object') {
|
|
674
|
+
context.rightIsArray = Array.isArray(context.right);
|
|
675
|
+
}
|
|
676
|
+
if (context.leftIsArray !== context.rightIsArray) {
|
|
677
|
+
context.setResult([context.left, context.right]).exit();
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
if (context.left instanceof RegExp) {
|
|
681
|
+
if (context.right instanceof RegExp) {
|
|
682
|
+
context.setResult([context.left.toString(), context.right.toString()]).exit();
|
|
683
|
+
} else {
|
|
684
|
+
context.setResult([context.left, context.right]).exit();
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
diffFilter$3.filterName = 'trivial';
|
|
689
|
+
var patchFilter$3 = function trivialMatchesPatchFilter(context) {
|
|
690
|
+
if (typeof context.delta === 'undefined') {
|
|
691
|
+
context.setResult(context.left).exit();
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
context.nested = !Array.isArray(context.delta);
|
|
695
|
+
if (context.nested) {
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
var nonNestedDelta = context.delta;
|
|
699
|
+
if (nonNestedDelta.length === 1) {
|
|
700
|
+
context.setResult(nonNestedDelta[0]).exit();
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
if (nonNestedDelta.length === 2) {
|
|
704
|
+
if (context.left instanceof RegExp) {
|
|
705
|
+
var regexArgs = /^\/(.*)\/([gimyu]+)$/.exec(nonNestedDelta[1]);
|
|
706
|
+
if (regexArgs) {
|
|
707
|
+
context.setResult(new RegExp(regexArgs[1], regexArgs[2])).exit();
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
context.setResult(nonNestedDelta[1]).exit();
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
|
|
715
|
+
context.setResult(undefined).exit();
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
patchFilter$3.filterName = 'trivial';
|
|
719
|
+
var reverseFilter$3 = function trivialReferseFilter(context) {
|
|
720
|
+
if (typeof context.delta === 'undefined') {
|
|
721
|
+
context.setResult(context.delta).exit();
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
context.nested = !Array.isArray(context.delta);
|
|
725
|
+
if (context.nested) {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
var nonNestedDelta = context.delta;
|
|
729
|
+
if (nonNestedDelta.length === 1) {
|
|
730
|
+
context.setResult([nonNestedDelta[0], 0, 0]).exit();
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (nonNestedDelta.length === 2) {
|
|
734
|
+
context.setResult([nonNestedDelta[1], nonNestedDelta[0]]).exit();
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
|
|
738
|
+
context.setResult([nonNestedDelta[0]]).exit();
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
reverseFilter$3.filterName = 'trivial';
|
|
742
|
+
|
|
743
|
+
var collectChildrenDiffFilter = function collectChildrenDiffFilter(context) {
|
|
744
|
+
if (!context || !context.children) {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
var length = context.children.length;
|
|
748
|
+
var child;
|
|
749
|
+
var result = context.result;
|
|
750
|
+
for (var index = 0; index < length; index++) {
|
|
751
|
+
child = context.children[index];
|
|
752
|
+
if (typeof child.result === 'undefined') {
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
result = result || {};
|
|
756
|
+
result[child.childName] = child.result;
|
|
757
|
+
}
|
|
758
|
+
if (result && context.leftIsArray) {
|
|
759
|
+
result._t = 'a';
|
|
760
|
+
}
|
|
761
|
+
context.setResult(result).exit();
|
|
762
|
+
};
|
|
763
|
+
collectChildrenDiffFilter.filterName = 'collectChildren';
|
|
764
|
+
var objectsDiffFilter = function objectsDiffFilter(context) {
|
|
765
|
+
if (context.leftIsArray || context.leftType !== 'object') {
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
var left = context.left;
|
|
769
|
+
var right = context.right;
|
|
770
|
+
var name;
|
|
771
|
+
var child;
|
|
772
|
+
var propertyFilter = context.options.propertyFilter;
|
|
773
|
+
for (name in left) {
|
|
774
|
+
if (!Object.prototype.hasOwnProperty.call(left, name)) {
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
if (propertyFilter && !propertyFilter(name, context)) {
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
child = new DiffContext(left[name], right[name]);
|
|
781
|
+
context.push(child, name);
|
|
782
|
+
}
|
|
783
|
+
for (name in right) {
|
|
784
|
+
if (!Object.prototype.hasOwnProperty.call(right, name)) {
|
|
785
|
+
continue;
|
|
786
|
+
}
|
|
787
|
+
if (propertyFilter && !propertyFilter(name, context)) {
|
|
788
|
+
continue;
|
|
789
|
+
}
|
|
790
|
+
if (typeof left[name] === 'undefined') {
|
|
791
|
+
child = new DiffContext(undefined, right[name]);
|
|
792
|
+
context.push(child, name);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
if (!context.children || context.children.length === 0) {
|
|
796
|
+
context.setResult(undefined).exit();
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
context.exit();
|
|
800
|
+
};
|
|
801
|
+
objectsDiffFilter.filterName = 'objects';
|
|
802
|
+
var patchFilter$2 = function nestedPatchFilter(context) {
|
|
803
|
+
if (!context.nested) {
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
var nestedDelta = context.delta;
|
|
807
|
+
if (nestedDelta._t) {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
var objectDelta = nestedDelta;
|
|
811
|
+
var name;
|
|
812
|
+
var child;
|
|
813
|
+
for (name in objectDelta) {
|
|
814
|
+
child = new PatchContext(context.left[name], objectDelta[name]);
|
|
815
|
+
context.push(child, name);
|
|
816
|
+
}
|
|
817
|
+
context.exit();
|
|
818
|
+
};
|
|
819
|
+
patchFilter$2.filterName = 'objects';
|
|
820
|
+
var collectChildrenPatchFilter$1 = function collectChildrenPatchFilter(context) {
|
|
821
|
+
if (!context || !context.children) {
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
var deltaWithChildren = context.delta;
|
|
825
|
+
if (deltaWithChildren._t) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
var object = context.left;
|
|
829
|
+
var length = context.children.length;
|
|
830
|
+
var child;
|
|
831
|
+
for (var index = 0; index < length; index++) {
|
|
832
|
+
child = context.children[index];
|
|
833
|
+
var property = child.childName;
|
|
834
|
+
if (Object.prototype.hasOwnProperty.call(context.left, property) && child.result === undefined) {
|
|
835
|
+
delete object[property];
|
|
836
|
+
} else if (object[property] !== child.result) {
|
|
837
|
+
object[property] = child.result;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
context.setResult(object).exit();
|
|
841
|
+
};
|
|
842
|
+
collectChildrenPatchFilter$1.filterName = 'collectChildren';
|
|
843
|
+
var reverseFilter$2 = function nestedReverseFilter(context) {
|
|
844
|
+
if (!context.nested) {
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
var nestedDelta = context.delta;
|
|
848
|
+
if (nestedDelta._t) {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
var objectDelta = context.delta;
|
|
852
|
+
var name;
|
|
853
|
+
var child;
|
|
854
|
+
for (name in objectDelta) {
|
|
855
|
+
child = new ReverseContext(objectDelta[name]);
|
|
856
|
+
context.push(child, name);
|
|
857
|
+
}
|
|
858
|
+
context.exit();
|
|
859
|
+
};
|
|
860
|
+
reverseFilter$2.filterName = 'objects';
|
|
861
|
+
var collectChildrenReverseFilter$1 = function collectChildrenReverseFilter(context) {
|
|
862
|
+
if (!context || !context.children) {
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
var deltaWithChildren = context.delta;
|
|
866
|
+
if (deltaWithChildren._t) {
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
var length = context.children.length;
|
|
870
|
+
var child;
|
|
871
|
+
var delta = {};
|
|
872
|
+
for (var index = 0; index < length; index++) {
|
|
873
|
+
child = context.children[index];
|
|
874
|
+
var property = child.childName;
|
|
875
|
+
if (delta[property] !== child.result) {
|
|
876
|
+
delta[property] = child.result;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
context.setResult(delta).exit();
|
|
880
|
+
};
|
|
881
|
+
collectChildrenReverseFilter$1.filterName = 'collectChildren';
|
|
882
|
+
|
|
883
|
+
/*
|
|
884
|
+
|
|
885
|
+
LCS implementation that supports arrays or strings
|
|
886
|
+
|
|
887
|
+
reference: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
|
|
888
|
+
|
|
889
|
+
*/
|
|
890
|
+
var defaultMatch = function defaultMatch(array1, array2, index1, index2) {
|
|
891
|
+
return array1[index1] === array2[index2];
|
|
892
|
+
};
|
|
893
|
+
var lengthMatrix = function lengthMatrix(array1, array2, match, context) {
|
|
894
|
+
var len1 = array1.length;
|
|
895
|
+
var len2 = array2.length;
|
|
896
|
+
var x, y;
|
|
897
|
+
// initialize empty matrix of len1+1 x len2+1
|
|
898
|
+
var matrix = new Array(len1 + 1);
|
|
899
|
+
for (x = 0; x < len1 + 1; x++) {
|
|
900
|
+
matrix[x] = new Array(len2 + 1);
|
|
901
|
+
for (y = 0; y < len2 + 1; y++) {
|
|
902
|
+
matrix[x][y] = 0;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
matrix.match = match;
|
|
906
|
+
// save sequence lengths for each coordinate
|
|
907
|
+
for (x = 1; x < len1 + 1; x++) {
|
|
908
|
+
for (y = 1; y < len2 + 1; y++) {
|
|
909
|
+
if (match(array1, array2, x - 1, y - 1, context)) {
|
|
910
|
+
matrix[x][y] = matrix[x - 1][y - 1] + 1;
|
|
911
|
+
} else {
|
|
912
|
+
matrix[x][y] = Math.max(matrix[x - 1][y], matrix[x][y - 1]);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return matrix;
|
|
917
|
+
};
|
|
918
|
+
var backtrack = function backtrack(matrix, array1, array2, context) {
|
|
919
|
+
var index1 = array1.length;
|
|
920
|
+
var index2 = array2.length;
|
|
921
|
+
var subsequence = {
|
|
922
|
+
sequence: [],
|
|
923
|
+
indices1: [],
|
|
924
|
+
indices2: []
|
|
925
|
+
};
|
|
926
|
+
while (index1 !== 0 && index2 !== 0) {
|
|
927
|
+
var sameLetter = matrix.match(array1, array2, index1 - 1, index2 - 1, context);
|
|
928
|
+
if (sameLetter) {
|
|
929
|
+
subsequence.sequence.unshift(array1[index1 - 1]);
|
|
930
|
+
subsequence.indices1.unshift(index1 - 1);
|
|
931
|
+
subsequence.indices2.unshift(index2 - 1);
|
|
932
|
+
--index1;
|
|
933
|
+
--index2;
|
|
934
|
+
} else {
|
|
935
|
+
var valueAtMatrixAbove = matrix[index1][index2 - 1];
|
|
936
|
+
var valueAtMatrixLeft = matrix[index1 - 1][index2];
|
|
937
|
+
if (valueAtMatrixAbove > valueAtMatrixLeft) {
|
|
938
|
+
--index2;
|
|
939
|
+
} else {
|
|
940
|
+
--index1;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
return subsequence;
|
|
945
|
+
};
|
|
946
|
+
var get = function get(array1, array2, match, context) {
|
|
947
|
+
var innerContext = context || {};
|
|
948
|
+
var matrix = lengthMatrix(array1, array2, match || defaultMatch, innerContext);
|
|
949
|
+
return backtrack(matrix, array1, array2, innerContext);
|
|
950
|
+
};
|
|
951
|
+
var lcs = {
|
|
952
|
+
get: get
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
var ARRAY_MOVE = 3;
|
|
956
|
+
function arraysHaveMatchByRef(array1, array2, len1, len2) {
|
|
957
|
+
for (var index1 = 0; index1 < len1; index1++) {
|
|
958
|
+
var val1 = array1[index1];
|
|
959
|
+
for (var index2 = 0; index2 < len2; index2++) {
|
|
960
|
+
var val2 = array2[index2];
|
|
961
|
+
if (index1 !== index2 && val1 === val2) {
|
|
962
|
+
return true;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
function matchItems(array1, array2, index1, index2, context) {
|
|
968
|
+
var value1 = array1[index1];
|
|
969
|
+
var value2 = array2[index2];
|
|
970
|
+
if (value1 === value2) {
|
|
971
|
+
return true;
|
|
972
|
+
}
|
|
973
|
+
if (_typeof(value1) !== 'object' || _typeof(value2) !== 'object') {
|
|
974
|
+
return false;
|
|
975
|
+
}
|
|
976
|
+
var objectHash = context.objectHash;
|
|
977
|
+
if (!objectHash) {
|
|
978
|
+
// no way to match objects was provided, try match by position
|
|
979
|
+
return context.matchByPosition && index1 === index2;
|
|
980
|
+
}
|
|
981
|
+
context.hashCache1 = context.hashCache1 || [];
|
|
982
|
+
var hash1 = context.hashCache1[index1];
|
|
983
|
+
if (typeof hash1 === 'undefined') {
|
|
984
|
+
context.hashCache1[index1] = hash1 = objectHash(value1, index1);
|
|
985
|
+
}
|
|
986
|
+
if (typeof hash1 === 'undefined') {
|
|
987
|
+
return false;
|
|
988
|
+
}
|
|
989
|
+
context.hashCache2 = context.hashCache2 || [];
|
|
990
|
+
var hash2 = context.hashCache2[index2];
|
|
991
|
+
if (typeof hash2 === 'undefined') {
|
|
992
|
+
context.hashCache2[index2] = hash2 = objectHash(value2, index2);
|
|
993
|
+
}
|
|
994
|
+
if (typeof hash2 === 'undefined') {
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
return hash1 === hash2;
|
|
998
|
+
}
|
|
999
|
+
var diffFilter$2 = function arraysDiffFilter(context) {
|
|
1000
|
+
if (!context.leftIsArray) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
var matchContext = {
|
|
1004
|
+
objectHash: context.options && context.options.objectHash,
|
|
1005
|
+
matchByPosition: context.options && context.options.matchByPosition
|
|
1006
|
+
};
|
|
1007
|
+
var commonHead = 0;
|
|
1008
|
+
var commonTail = 0;
|
|
1009
|
+
var index;
|
|
1010
|
+
var index1;
|
|
1011
|
+
var index2;
|
|
1012
|
+
var array1 = context.left;
|
|
1013
|
+
var array2 = context.right;
|
|
1014
|
+
var len1 = array1.length;
|
|
1015
|
+
var len2 = array2.length;
|
|
1016
|
+
var child;
|
|
1017
|
+
if (len1 > 0 && len2 > 0 && !matchContext.objectHash && typeof matchContext.matchByPosition !== 'boolean') {
|
|
1018
|
+
matchContext.matchByPosition = !arraysHaveMatchByRef(array1, array2, len1, len2);
|
|
1019
|
+
}
|
|
1020
|
+
// separate common head
|
|
1021
|
+
while (commonHead < len1 && commonHead < len2 && matchItems(array1, array2, commonHead, commonHead, matchContext)) {
|
|
1022
|
+
index = commonHead;
|
|
1023
|
+
child = new DiffContext(array1[index], array2[index]);
|
|
1024
|
+
context.push(child, index);
|
|
1025
|
+
commonHead++;
|
|
1026
|
+
}
|
|
1027
|
+
// separate common tail
|
|
1028
|
+
while (commonTail + commonHead < len1 && commonTail + commonHead < len2 && matchItems(array1, array2, len1 - 1 - commonTail, len2 - 1 - commonTail, matchContext)) {
|
|
1029
|
+
index1 = len1 - 1 - commonTail;
|
|
1030
|
+
index2 = len2 - 1 - commonTail;
|
|
1031
|
+
child = new DiffContext(array1[index1], array2[index2]);
|
|
1032
|
+
context.push(child, index2);
|
|
1033
|
+
commonTail++;
|
|
1034
|
+
}
|
|
1035
|
+
var result;
|
|
1036
|
+
if (commonHead + commonTail === len1) {
|
|
1037
|
+
if (len1 === len2) {
|
|
1038
|
+
// arrays are identical
|
|
1039
|
+
context.setResult(undefined).exit();
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
// trivial case, a block (1 or more consecutive items) was added
|
|
1043
|
+
result = result || {
|
|
1044
|
+
_t: 'a'
|
|
1045
|
+
};
|
|
1046
|
+
for (index = commonHead; index < len2 - commonTail; index++) {
|
|
1047
|
+
result[index] = [array2[index]];
|
|
1048
|
+
}
|
|
1049
|
+
context.setResult(result).exit();
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (commonHead + commonTail === len2) {
|
|
1053
|
+
// trivial case, a block (1 or more consecutive items) was removed
|
|
1054
|
+
result = result || {
|
|
1055
|
+
_t: 'a'
|
|
1056
|
+
};
|
|
1057
|
+
for (index = commonHead; index < len1 - commonTail; index++) {
|
|
1058
|
+
result["_".concat(index)] = [array1[index], 0, 0];
|
|
1059
|
+
}
|
|
1060
|
+
context.setResult(result).exit();
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
// reset hash cache
|
|
1064
|
+
delete matchContext.hashCache1;
|
|
1065
|
+
delete matchContext.hashCache2;
|
|
1066
|
+
// diff is not trivial, find the LCS (Longest Common Subsequence)
|
|
1067
|
+
var trimmed1 = array1.slice(commonHead, len1 - commonTail);
|
|
1068
|
+
var trimmed2 = array2.slice(commonHead, len2 - commonTail);
|
|
1069
|
+
var seq = lcs.get(trimmed1, trimmed2, matchItems, matchContext);
|
|
1070
|
+
var removedItems = [];
|
|
1071
|
+
result = result || {
|
|
1072
|
+
_t: 'a'
|
|
1073
|
+
};
|
|
1074
|
+
for (index = commonHead; index < len1 - commonTail; index++) {
|
|
1075
|
+
if (seq.indices1.indexOf(index - commonHead) < 0) {
|
|
1076
|
+
// removed
|
|
1077
|
+
result["_".concat(index)] = [array1[index], 0, 0];
|
|
1078
|
+
removedItems.push(index);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
var detectMove = true;
|
|
1082
|
+
if (context.options && context.options.arrays && context.options.arrays.detectMove === false) {
|
|
1083
|
+
detectMove = false;
|
|
1084
|
+
}
|
|
1085
|
+
var includeValueOnMove = false;
|
|
1086
|
+
if (context.options && context.options.arrays && context.options.arrays.includeValueOnMove) {
|
|
1087
|
+
includeValueOnMove = true;
|
|
1088
|
+
}
|
|
1089
|
+
var removedItemsLength = removedItems.length;
|
|
1090
|
+
for (index = commonHead; index < len2 - commonTail; index++) {
|
|
1091
|
+
var indexOnArray2 = seq.indices2.indexOf(index - commonHead);
|
|
1092
|
+
if (indexOnArray2 < 0) {
|
|
1093
|
+
// added, try to match with a removed item and register as position move
|
|
1094
|
+
var isMove = false;
|
|
1095
|
+
if (detectMove && removedItemsLength > 0) {
|
|
1096
|
+
for (var removeItemIndex1 = 0; removeItemIndex1 < removedItemsLength; removeItemIndex1++) {
|
|
1097
|
+
index1 = removedItems[removeItemIndex1];
|
|
1098
|
+
if (matchItems(trimmed1, trimmed2, index1 - commonHead, index - commonHead, matchContext)) {
|
|
1099
|
+
// store position move as: [originalValue, newPosition, ARRAY_MOVE]
|
|
1100
|
+
result["_".concat(index1)].splice(1, 2, index, ARRAY_MOVE);
|
|
1101
|
+
if (!includeValueOnMove) {
|
|
1102
|
+
// don't include moved value on diff, to save bytes
|
|
1103
|
+
result["_".concat(index1)][0] = '';
|
|
1104
|
+
}
|
|
1105
|
+
index2 = index;
|
|
1106
|
+
child = new DiffContext(array1[index1], array2[index2]);
|
|
1107
|
+
context.push(child, index2);
|
|
1108
|
+
removedItems.splice(removeItemIndex1, 1);
|
|
1109
|
+
isMove = true;
|
|
1110
|
+
break;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
if (!isMove) {
|
|
1115
|
+
// added
|
|
1116
|
+
result[index] = [array2[index]];
|
|
1117
|
+
}
|
|
1118
|
+
} else {
|
|
1119
|
+
// match, do inner diff
|
|
1120
|
+
index1 = seq.indices1[indexOnArray2] + commonHead;
|
|
1121
|
+
index2 = seq.indices2[indexOnArray2] + commonHead;
|
|
1122
|
+
child = new DiffContext(array1[index1], array2[index2]);
|
|
1123
|
+
context.push(child, index2);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
context.setResult(result).exit();
|
|
1127
|
+
};
|
|
1128
|
+
diffFilter$2.filterName = 'arrays';
|
|
1129
|
+
var compare = {
|
|
1130
|
+
numerically: function numerically(a, b) {
|
|
1131
|
+
return a - b;
|
|
1132
|
+
},
|
|
1133
|
+
numericallyBy: function numericallyBy(name) {
|
|
1134
|
+
return function (a, b) {
|
|
1135
|
+
return a[name] - b[name];
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
var patchFilter$1 = function nestedPatchFilter(context) {
|
|
1140
|
+
if (!context.nested) {
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
var nestedDelta = context.delta;
|
|
1144
|
+
if (nestedDelta._t !== 'a') {
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
var index;
|
|
1148
|
+
var index1;
|
|
1149
|
+
var delta = nestedDelta;
|
|
1150
|
+
var array = context.left;
|
|
1151
|
+
// first, separate removals, insertions and modifications
|
|
1152
|
+
var toRemove = [];
|
|
1153
|
+
var toInsert = [];
|
|
1154
|
+
var toModify = [];
|
|
1155
|
+
for (index in delta) {
|
|
1156
|
+
if (index !== '_t') {
|
|
1157
|
+
if (index[0] === '_') {
|
|
1158
|
+
var removedOrMovedIndex = index;
|
|
1159
|
+
// removed item from original array
|
|
1160
|
+
if (delta[removedOrMovedIndex][2] === 0 || delta[removedOrMovedIndex][2] === ARRAY_MOVE) {
|
|
1161
|
+
toRemove.push(parseInt(index.slice(1), 10));
|
|
1162
|
+
} else {
|
|
1163
|
+
throw new Error('only removal or move can be applied at original array indices,' + " invalid diff type: ".concat(delta[removedOrMovedIndex][2]));
|
|
1164
|
+
}
|
|
1165
|
+
} else {
|
|
1166
|
+
var numberIndex = index;
|
|
1167
|
+
if (delta[numberIndex].length === 1) {
|
|
1168
|
+
// added item at new array
|
|
1169
|
+
toInsert.push({
|
|
1170
|
+
index: parseInt(numberIndex, 10),
|
|
1171
|
+
value: delta[numberIndex][0]
|
|
1172
|
+
});
|
|
1173
|
+
} else {
|
|
1174
|
+
// modified item at new array
|
|
1175
|
+
toModify.push({
|
|
1176
|
+
index: parseInt(numberIndex, 10),
|
|
1177
|
+
delta: delta[numberIndex]
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
// remove items, in reverse order to avoid sawing our own floor
|
|
1184
|
+
toRemove = toRemove.sort(compare.numerically);
|
|
1185
|
+
for (index = toRemove.length - 1; index >= 0; index--) {
|
|
1186
|
+
index1 = toRemove[index];
|
|
1187
|
+
var indexDiff = delta["_".concat(index1)];
|
|
1188
|
+
var removedValue = array.splice(index1, 1)[0];
|
|
1189
|
+
if (indexDiff[2] === ARRAY_MOVE) {
|
|
1190
|
+
// reinsert later
|
|
1191
|
+
toInsert.push({
|
|
1192
|
+
index: indexDiff[1],
|
|
1193
|
+
value: removedValue
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
// insert items, in reverse order to avoid moving our own floor
|
|
1198
|
+
toInsert = toInsert.sort(compare.numericallyBy('index'));
|
|
1199
|
+
var toInsertLength = toInsert.length;
|
|
1200
|
+
for (index = 0; index < toInsertLength; index++) {
|
|
1201
|
+
var insertion = toInsert[index];
|
|
1202
|
+
array.splice(insertion.index, 0, insertion.value);
|
|
1203
|
+
}
|
|
1204
|
+
// apply modifications
|
|
1205
|
+
var toModifyLength = toModify.length;
|
|
1206
|
+
var child;
|
|
1207
|
+
if (toModifyLength > 0) {
|
|
1208
|
+
for (index = 0; index < toModifyLength; index++) {
|
|
1209
|
+
var modification = toModify[index];
|
|
1210
|
+
child = new PatchContext(array[modification.index], modification.delta);
|
|
1211
|
+
context.push(child, modification.index);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
if (!context.children) {
|
|
1215
|
+
context.setResult(array).exit();
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
context.exit();
|
|
1219
|
+
};
|
|
1220
|
+
patchFilter$1.filterName = 'arrays';
|
|
1221
|
+
var collectChildrenPatchFilter = function collectChildrenPatchFilter(context) {
|
|
1222
|
+
if (!context || !context.children) {
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
var deltaWithChildren = context.delta;
|
|
1226
|
+
if (deltaWithChildren._t !== 'a') {
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1229
|
+
var array = context.left;
|
|
1230
|
+
var length = context.children.length;
|
|
1231
|
+
var child;
|
|
1232
|
+
for (var index = 0; index < length; index++) {
|
|
1233
|
+
child = context.children[index];
|
|
1234
|
+
var arrayIndex = child.childName;
|
|
1235
|
+
array[arrayIndex] = child.result;
|
|
1236
|
+
}
|
|
1237
|
+
context.setResult(array).exit();
|
|
1238
|
+
};
|
|
1239
|
+
collectChildrenPatchFilter.filterName = 'arraysCollectChildren';
|
|
1240
|
+
var reverseFilter$1 = function arraysReverseFilter(context) {
|
|
1241
|
+
if (!context.nested) {
|
|
1242
|
+
var nonNestedDelta = context.delta;
|
|
1243
|
+
if (nonNestedDelta[2] === ARRAY_MOVE) {
|
|
1244
|
+
var arrayMoveDelta = nonNestedDelta;
|
|
1245
|
+
context.newName = "_".concat(arrayMoveDelta[1]);
|
|
1246
|
+
context.setResult([arrayMoveDelta[0], parseInt(context.childName.substring(1), 10), ARRAY_MOVE]).exit();
|
|
1247
|
+
}
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
var nestedDelta = context.delta;
|
|
1251
|
+
if (nestedDelta._t !== 'a') {
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
var arrayDelta = nestedDelta;
|
|
1255
|
+
var name;
|
|
1256
|
+
var child;
|
|
1257
|
+
for (name in arrayDelta) {
|
|
1258
|
+
if (name === '_t') {
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
child = new ReverseContext(arrayDelta[name]);
|
|
1262
|
+
context.push(child, name);
|
|
1263
|
+
}
|
|
1264
|
+
context.exit();
|
|
1265
|
+
};
|
|
1266
|
+
reverseFilter$1.filterName = 'arrays';
|
|
1267
|
+
var reverseArrayDeltaIndex = function reverseArrayDeltaIndex(delta, index, itemDelta) {
|
|
1268
|
+
if (typeof index === 'string' && index[0] === '_') {
|
|
1269
|
+
return parseInt(index.substring(1), 10);
|
|
1270
|
+
} else if (Array.isArray(itemDelta) && itemDelta[2] === 0) {
|
|
1271
|
+
return "_".concat(index);
|
|
1272
|
+
}
|
|
1273
|
+
var reverseIndex = +index;
|
|
1274
|
+
for (var deltaIndex in delta) {
|
|
1275
|
+
var deltaItem = delta[deltaIndex];
|
|
1276
|
+
if (Array.isArray(deltaItem)) {
|
|
1277
|
+
if (deltaItem[2] === ARRAY_MOVE) {
|
|
1278
|
+
var moveFromIndex = parseInt(deltaIndex.substring(1), 10);
|
|
1279
|
+
var moveToIndex = deltaItem[1];
|
|
1280
|
+
if (moveToIndex === +index) {
|
|
1281
|
+
return moveFromIndex;
|
|
1282
|
+
}
|
|
1283
|
+
if (moveFromIndex <= reverseIndex && moveToIndex > reverseIndex) {
|
|
1284
|
+
reverseIndex++;
|
|
1285
|
+
} else if (moveFromIndex >= reverseIndex && moveToIndex < reverseIndex) {
|
|
1286
|
+
reverseIndex--;
|
|
1287
|
+
}
|
|
1288
|
+
} else if (deltaItem[2] === 0) {
|
|
1289
|
+
var deleteIndex = parseInt(deltaIndex.substring(1), 10);
|
|
1290
|
+
if (deleteIndex <= reverseIndex) {
|
|
1291
|
+
reverseIndex++;
|
|
1292
|
+
}
|
|
1293
|
+
} else if (deltaItem.length === 1 && parseInt(deltaIndex, 10) <= reverseIndex) {
|
|
1294
|
+
reverseIndex--;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
return reverseIndex;
|
|
1299
|
+
};
|
|
1300
|
+
var collectChildrenReverseFilter = function collectChildrenReverseFilter(context) {
|
|
1301
|
+
if (!context || !context.children) {
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
var deltaWithChildren = context.delta;
|
|
1305
|
+
if (deltaWithChildren._t !== 'a') {
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
var arrayDelta = deltaWithChildren;
|
|
1309
|
+
var length = context.children.length;
|
|
1310
|
+
var child;
|
|
1311
|
+
var delta = {
|
|
1312
|
+
_t: 'a'
|
|
1313
|
+
};
|
|
1314
|
+
for (var index = 0; index < length; index++) {
|
|
1315
|
+
child = context.children[index];
|
|
1316
|
+
var name = child.newName;
|
|
1317
|
+
if (typeof name === 'undefined') {
|
|
1318
|
+
name = reverseArrayDeltaIndex(arrayDelta, child.childName, child.result);
|
|
1319
|
+
}
|
|
1320
|
+
if (delta[name] !== child.result) {
|
|
1321
|
+
// There's no way to type this well.
|
|
1322
|
+
delta[name] = child.result;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
context.setResult(delta).exit();
|
|
1326
|
+
};
|
|
1327
|
+
collectChildrenReverseFilter.filterName = 'arraysCollectChildren';
|
|
1328
|
+
|
|
1329
|
+
var diffFilter$1 = function datesDiffFilter(context) {
|
|
1330
|
+
if (context.left instanceof Date) {
|
|
1331
|
+
if (context.right instanceof Date) {
|
|
1332
|
+
if (context.left.getTime() !== context.right.getTime()) {
|
|
1333
|
+
context.setResult([context.left, context.right]);
|
|
1334
|
+
} else {
|
|
1335
|
+
context.setResult(undefined);
|
|
1336
|
+
}
|
|
1337
|
+
} else {
|
|
1338
|
+
context.setResult([context.left, context.right]);
|
|
1339
|
+
}
|
|
1340
|
+
context.exit();
|
|
1341
|
+
} else if (context.right instanceof Date) {
|
|
1342
|
+
context.setResult([context.left, context.right]).exit();
|
|
1343
|
+
}
|
|
1344
|
+
};
|
|
1345
|
+
diffFilter$1.filterName = 'dates';
|
|
1346
|
+
|
|
1347
|
+
var TEXT_DIFF = 2;
|
|
1348
|
+
var DEFAULT_MIN_LENGTH = 60;
|
|
1349
|
+
var cachedDiffPatch = null;
|
|
1350
|
+
function getDiffMatchPatch(options, required) {
|
|
1351
|
+
var _a;
|
|
1352
|
+
if (!cachedDiffPatch) {
|
|
1353
|
+
var instance;
|
|
1354
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.textDiff) === null || _a === void 0 ? void 0 : _a.diffMatchPatch) {
|
|
1355
|
+
instance = new options.textDiff.diffMatchPatch();
|
|
1356
|
+
} else {
|
|
1357
|
+
if (!required) {
|
|
1358
|
+
return null;
|
|
1359
|
+
}
|
|
1360
|
+
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.');
|
|
1361
|
+
// eslint-disable-next-line camelcase
|
|
1362
|
+
error.diff_match_patch_not_found = true;
|
|
1363
|
+
throw error;
|
|
1364
|
+
}
|
|
1365
|
+
cachedDiffPatch = {
|
|
1366
|
+
diff: function diff(txt1, txt2) {
|
|
1367
|
+
return instance.patch_toText(instance.patch_make(txt1, txt2));
|
|
1368
|
+
},
|
|
1369
|
+
patch: function patch(txt1, _patch) {
|
|
1370
|
+
var results = instance.patch_apply(instance.patch_fromText(_patch), txt1);
|
|
1371
|
+
for (var i = 0; i < results[1].length; i++) {
|
|
1372
|
+
if (!results[1][i]) {
|
|
1373
|
+
var _error = new Error('text patch failed');
|
|
1374
|
+
_error.textPatchFailed = true;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
return results[0];
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
return cachedDiffPatch;
|
|
1382
|
+
}
|
|
1383
|
+
var diffFilter = function textsDiffFilter(context) {
|
|
1384
|
+
if (context.leftType !== 'string') {
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
var left = context.left;
|
|
1388
|
+
var right = context.right;
|
|
1389
|
+
var minLength = context.options && context.options.textDiff && context.options.textDiff.minLength || DEFAULT_MIN_LENGTH;
|
|
1390
|
+
if (left.length < minLength || right.length < minLength) {
|
|
1391
|
+
context.setResult([left, right]).exit();
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
// large text, try to use a text-diff algorithm
|
|
1395
|
+
var diffMatchPatch = getDiffMatchPatch(context.options);
|
|
1396
|
+
if (!diffMatchPatch) {
|
|
1397
|
+
// diff-match-patch library not available,
|
|
1398
|
+
// fallback to regular string replace
|
|
1399
|
+
context.setResult([left, right]).exit();
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
var diff = diffMatchPatch.diff;
|
|
1403
|
+
context.setResult([diff(left, right), 0, TEXT_DIFF]).exit();
|
|
1404
|
+
};
|
|
1405
|
+
diffFilter.filterName = 'texts';
|
|
1406
|
+
var patchFilter = function textsPatchFilter(context) {
|
|
1407
|
+
if (context.nested) {
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
var nonNestedDelta = context.delta;
|
|
1411
|
+
if (nonNestedDelta[2] !== TEXT_DIFF) {
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
var textDiffDelta = nonNestedDelta;
|
|
1415
|
+
// text-diff, use a text-patch algorithm
|
|
1416
|
+
var patch = getDiffMatchPatch(context.options, true).patch;
|
|
1417
|
+
context.setResult(patch(context.left, textDiffDelta[0])).exit();
|
|
1418
|
+
};
|
|
1419
|
+
patchFilter.filterName = 'texts';
|
|
1420
|
+
var textDeltaReverse = function textDeltaReverse(delta) {
|
|
1421
|
+
var i;
|
|
1422
|
+
var l;
|
|
1423
|
+
var line;
|
|
1424
|
+
var lineTmp;
|
|
1425
|
+
var header = null;
|
|
1426
|
+
var headerRegex = /^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/;
|
|
1427
|
+
var lineHeader;
|
|
1428
|
+
var lines = delta.split('\n');
|
|
1429
|
+
for (i = 0, l = lines.length; i < l; i++) {
|
|
1430
|
+
line = lines[i];
|
|
1431
|
+
var lineStart = line.slice(0, 1);
|
|
1432
|
+
if (lineStart === '@') {
|
|
1433
|
+
header = headerRegex.exec(line);
|
|
1434
|
+
lineHeader = i;
|
|
1435
|
+
// fix header
|
|
1436
|
+
lines[lineHeader] = '@@ -' + header[3] + ',' + header[4] + ' +' + header[1] + ',' + header[2] + ' @@';
|
|
1437
|
+
} else if (lineStart === '+') {
|
|
1438
|
+
lines[i] = '-' + lines[i].slice(1);
|
|
1439
|
+
if (lines[i - 1].slice(0, 1) === '+') {
|
|
1440
|
+
// swap lines to keep default order (-+)
|
|
1441
|
+
lineTmp = lines[i];
|
|
1442
|
+
lines[i] = lines[i - 1];
|
|
1443
|
+
lines[i - 1] = lineTmp;
|
|
1444
|
+
}
|
|
1445
|
+
} else if (lineStart === '-') {
|
|
1446
|
+
lines[i] = '+' + lines[i].slice(1);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
return lines.join('\n');
|
|
1450
|
+
};
|
|
1451
|
+
var reverseFilter = function textsReverseFilter(context) {
|
|
1452
|
+
if (context.nested) {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
var nonNestedDelta = context.delta;
|
|
1456
|
+
if (nonNestedDelta[2] !== TEXT_DIFF) {
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
var textDiffDelta = nonNestedDelta;
|
|
1460
|
+
// text-diff, use a text-diff algorithm
|
|
1461
|
+
context.setResult([textDeltaReverse(textDiffDelta[0]), 0, TEXT_DIFF]).exit();
|
|
1462
|
+
};
|
|
1463
|
+
reverseFilter.filterName = 'texts';
|
|
1464
|
+
|
|
1465
|
+
var DiffPatcher = /*#__PURE__*/function () {
|
|
1466
|
+
function DiffPatcher(options) {
|
|
1467
|
+
_classCallCheck(this, DiffPatcher);
|
|
1468
|
+
this.processor = new Processor(options);
|
|
1469
|
+
this.processor.pipe(new Pipe('diff').append(collectChildrenDiffFilter, diffFilter$3, diffFilter$1, diffFilter, objectsDiffFilter, diffFilter$2).shouldHaveResult());
|
|
1470
|
+
this.processor.pipe(new Pipe('patch').append(collectChildrenPatchFilter$1, collectChildrenPatchFilter, patchFilter$3, patchFilter, patchFilter$2, patchFilter$1).shouldHaveResult());
|
|
1471
|
+
this.processor.pipe(new Pipe('reverse').append(collectChildrenReverseFilter$1, collectChildrenReverseFilter, reverseFilter$3, reverseFilter, reverseFilter$2, reverseFilter$1).shouldHaveResult());
|
|
1472
|
+
}
|
|
1473
|
+
return _createClass(DiffPatcher, [{
|
|
1474
|
+
key: "options",
|
|
1475
|
+
value: function options(_options) {
|
|
1476
|
+
return this.processor.options(_options);
|
|
1477
|
+
}
|
|
1478
|
+
}, {
|
|
1479
|
+
key: "diff",
|
|
1480
|
+
value: function diff(left, right) {
|
|
1481
|
+
return this.processor.process(new DiffContext(left, right));
|
|
1482
|
+
}
|
|
1483
|
+
}, {
|
|
1484
|
+
key: "patch",
|
|
1485
|
+
value: function patch(left, delta) {
|
|
1486
|
+
return this.processor.process(new PatchContext(left, delta));
|
|
1487
|
+
}
|
|
1488
|
+
}, {
|
|
1489
|
+
key: "reverse",
|
|
1490
|
+
value: function reverse(delta) {
|
|
1491
|
+
return this.processor.process(new ReverseContext(delta));
|
|
1492
|
+
}
|
|
1493
|
+
}, {
|
|
1494
|
+
key: "unpatch",
|
|
1495
|
+
value: function unpatch(right, delta) {
|
|
1496
|
+
return this.patch(right, this.reverse(delta));
|
|
1497
|
+
}
|
|
1498
|
+
}, {
|
|
1499
|
+
key: "clone",
|
|
1500
|
+
value: function clone(value) {
|
|
1501
|
+
return clone$1(value);
|
|
1502
|
+
}
|
|
1503
|
+
}]);
|
|
1504
|
+
}();
|
|
1505
|
+
|
|
242
1506
|
function objectHash(obj, index) {
|
|
243
1507
|
var objIndex = "$$index:".concat(index);
|
|
244
1508
|
return _typeof(obj) === 'object' && obj !== null ? obj.id || obj.name || obj.url || objIndex : objIndex;
|
|
245
1509
|
}
|
|
246
|
-
var diffpatcher = new
|
|
1510
|
+
var diffpatcher = new DiffPatcher({
|
|
247
1511
|
objectHash: objectHash,
|
|
248
1512
|
arrays: {
|
|
249
1513
|
// detect items moved inside the array
|
|
@@ -573,7 +1837,7 @@
|
|
|
573
1837
|
action: item.action
|
|
574
1838
|
}, actionKey, patched);
|
|
575
1839
|
}).filter(function (action) {
|
|
576
|
-
return !
|
|
1840
|
+
return !isNil(action);
|
|
577
1841
|
});
|
|
578
1842
|
}
|
|
579
1843
|
|
|
@@ -680,7 +1944,6 @@
|
|
|
680
1944
|
return buildReferenceActions({
|
|
681
1945
|
actions: referenceActionsList$3,
|
|
682
1946
|
diff: diff,
|
|
683
|
-
oldObj: oldObj,
|
|
684
1947
|
newObj: newObj
|
|
685
1948
|
});
|
|
686
1949
|
}
|
|
@@ -706,7 +1969,7 @@
|
|
|
706
1969
|
function copyEmptyArrayProps() {
|
|
707
1970
|
var oldObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
708
1971
|
var newObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
709
|
-
if (!
|
|
1972
|
+
if (!isNil(oldObj) && !isNil(newObj)) {
|
|
710
1973
|
var nextObjectWithEmptyArray = Object.entries(oldObj).reduce(function (merged, _ref) {
|
|
711
1974
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
712
1975
|
key = _ref2[0],
|
|
@@ -721,10 +1984,10 @@
|
|
|
721
1984
|
return acc;
|
|
722
1985
|
}, {});
|
|
723
1986
|
for (var i = 0; i < newObj[key].length; i++) {
|
|
724
|
-
if (!
|
|
1987
|
+
if (!isNil(newObj[key][i]) && _typeof(newObj[key][i]) === 'object' && !isNil(newObj[key][i].id)) {
|
|
725
1988
|
// Since its unordered array elements then check if the element on `oldObj` exists by id
|
|
726
1989
|
var foundObject = hashMapValue[newObj[key][i].id];
|
|
727
|
-
if (!
|
|
1990
|
+
if (!isNil(foundObject)) {
|
|
728
1991
|
var _copyEmptyArrayProps = copyEmptyArrayProps(foundObject, newObj[key][i]),
|
|
729
1992
|
_copyEmptyArrayProps2 = _slicedToArray(_copyEmptyArrayProps, 2),
|
|
730
1993
|
nestedObject = _copyEmptyArrayProps2[1];
|
|
@@ -740,10 +2003,10 @@
|
|
|
740
2003
|
return merged;
|
|
741
2004
|
}
|
|
742
2005
|
if (Array.isArray(value)) {
|
|
743
|
-
merged[key] =
|
|
2006
|
+
merged[key] = isNil(newObj[key]) ? [] : newObj[key];
|
|
744
2007
|
return merged;
|
|
745
2008
|
}
|
|
746
|
-
if (!
|
|
2009
|
+
if (!isNil(newObj[key]) && _typeof(value) === 'object' &&
|
|
747
2010
|
// Ignore Date as this will create invalid object since typeof date === 'object' return true
|
|
748
2011
|
// ex: {date: new Date()} will result {date: {}}
|
|
749
2012
|
!(value instanceof Date)) {
|
|
@@ -778,7 +2041,7 @@
|
|
|
778
2041
|
allActions.push(mapActionGroup('assets', function () {
|
|
779
2042
|
return actionsMapAssets$1(diff, oldObj, newObj);
|
|
780
2043
|
}));
|
|
781
|
-
return
|
|
2044
|
+
return flatten(allActions);
|
|
782
2045
|
};
|
|
783
2046
|
}
|
|
784
2047
|
var categories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -896,7 +2159,6 @@
|
|
|
896
2159
|
return buildReferenceActions({
|
|
897
2160
|
actions: referenceActionsList$2,
|
|
898
2161
|
diff: diff,
|
|
899
|
-
oldObj: oldObj,
|
|
900
2162
|
newObj: newObj
|
|
901
2163
|
});
|
|
902
2164
|
}
|
|
@@ -1004,7 +2266,7 @@
|
|
|
1004
2266
|
authMode: patched
|
|
1005
2267
|
}, value, newObj.password);
|
|
1006
2268
|
}).filter(function (action) {
|
|
1007
|
-
return !
|
|
2269
|
+
return !isNil(action);
|
|
1008
2270
|
});
|
|
1009
2271
|
}
|
|
1010
2272
|
|
|
@@ -1035,7 +2297,7 @@
|
|
|
1035
2297
|
allActions.push(mapActionGroup('authenticationModes', function () {
|
|
1036
2298
|
return actionsMapAuthenticationModes(diff, oldObj, newObj);
|
|
1037
2299
|
}));
|
|
1038
|
-
return
|
|
2300
|
+
return flatten(allActions);
|
|
1039
2301
|
};
|
|
1040
2302
|
}
|
|
1041
2303
|
var customers = (function (actionGroupList, syncActionConfig) {
|
|
@@ -1094,7 +2356,6 @@
|
|
|
1094
2356
|
return buildReferenceActions({
|
|
1095
2357
|
actions: referenceActionsList$1,
|
|
1096
2358
|
diff: diff,
|
|
1097
|
-
oldObj: oldObj,
|
|
1098
2359
|
newObj: newObj
|
|
1099
2360
|
});
|
|
1100
2361
|
}
|
|
@@ -1111,7 +2372,7 @@
|
|
|
1111
2372
|
allActions.push(mapActionGroup('custom', function () {
|
|
1112
2373
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
1113
2374
|
}));
|
|
1114
|
-
return
|
|
2375
|
+
return flatten(allActions);
|
|
1115
2376
|
};
|
|
1116
2377
|
}
|
|
1117
2378
|
var inventories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -1178,7 +2439,7 @@
|
|
|
1178
2439
|
var _preProcessCollection2 = preProcessCollection(now, identifier),
|
|
1179
2440
|
nowObjRefByIdentifier = _preProcessCollection2.refByIdentifier,
|
|
1180
2441
|
nowObjRefByIndex = _preProcessCollection2.refByIndex;
|
|
1181
|
-
|
|
2442
|
+
forEach(diff, function (item, key) {
|
|
1182
2443
|
if (REGEX_NUMBER$3.test(key)) {
|
|
1183
2444
|
var matchingIdentifier = nowObjRefByIndex[key];
|
|
1184
2445
|
result[key] = [beforeObjRefByIdentifier[matchingIdentifier], key];
|
|
@@ -1359,7 +2620,7 @@
|
|
|
1359
2620
|
var actions = [];
|
|
1360
2621
|
// generate a hashMap to be able to reference the right image from both ends
|
|
1361
2622
|
var matchingImagePairs = findMatchingPairs(diffedImages, oldVariant.images, newVariant.images, 'url');
|
|
1362
|
-
|
|
2623
|
+
forEach(diffedImages, function (image, key) {
|
|
1363
2624
|
var _extractMatchingPairs = extractMatchingPairs(matchingImagePairs, key, oldVariant.images, newVariant.images),
|
|
1364
2625
|
oldObj = _extractMatchingPairs.oldObj,
|
|
1365
2626
|
newObj = _extractMatchingPairs.newObj;
|
|
@@ -1416,7 +2677,7 @@
|
|
|
1416
2677
|
|
|
1417
2678
|
// generate a hashMap to be able to reference the right image from both ends
|
|
1418
2679
|
var matchingPricePairs = findMatchingPairs(diffedPrices, oldVariant.prices, newVariant.prices);
|
|
1419
|
-
|
|
2680
|
+
forEach(diffedPrices, function (price, key) {
|
|
1420
2681
|
var _extractMatchingPairs2 = extractMatchingPairs(matchingPricePairs, key, oldVariant.prices, newVariant.prices),
|
|
1421
2682
|
oldObj = _extractMatchingPairs2.oldObj,
|
|
1422
2683
|
newObj = _extractMatchingPairs2.newObj;
|
|
@@ -1464,7 +2725,7 @@
|
|
|
1464
2725
|
function _buildVariantAttributesActions(attributes, oldVariant, newVariant, sameForAllAttributeNames) {
|
|
1465
2726
|
var actions = [];
|
|
1466
2727
|
if (!attributes) return actions;
|
|
1467
|
-
|
|
2728
|
+
forEach(attributes, function (value, key) {
|
|
1468
2729
|
if (REGEX_NUMBER$2.test(key)) {
|
|
1469
2730
|
if (Array.isArray(value)) {
|
|
1470
2731
|
var id = oldVariant.id;
|
|
@@ -1529,8 +2790,8 @@
|
|
|
1529
2790
|
}).filter(function (_) {
|
|
1530
2791
|
return _ !== undefined;
|
|
1531
2792
|
});
|
|
1532
|
-
var assetIdsToKeep =
|
|
1533
|
-
var assetIdsToRemove =
|
|
2793
|
+
var assetIdsToKeep = intersection(assetIdsCurrent, assetIdsBefore);
|
|
2794
|
+
var assetIdsToRemove = without.apply(void 0, [assetIdsBefore].concat(_toConsumableArray(assetIdsToKeep)));
|
|
1534
2795
|
var changeAssetOrderAction = _objectSpread2({
|
|
1535
2796
|
action: 'changeAssetOrder',
|
|
1536
2797
|
assetOrder: assetIdsToKeep.concat(assetIdsToRemove)
|
|
@@ -1542,7 +2803,7 @@
|
|
|
1542
2803
|
|
|
1543
2804
|
// generate a hashMap to be able to reference the right asset from both ends
|
|
1544
2805
|
var matchingAssetPairs = findMatchingPairs(diffAssets, oldVariant.assets, newVariant.assets);
|
|
1545
|
-
|
|
2806
|
+
forEach(diffAssets, function (asset, key) {
|
|
1546
2807
|
var _extractMatchingPairs3 = extractMatchingPairs(matchingAssetPairs, key, oldVariant.assets, newVariant.assets),
|
|
1547
2808
|
oldAsset = _extractMatchingPairs3.oldObj,
|
|
1548
2809
|
newAsset = _extractMatchingPairs3.newObj;
|
|
@@ -1641,7 +2902,6 @@
|
|
|
1641
2902
|
return buildReferenceActions({
|
|
1642
2903
|
actions: referenceActionsList,
|
|
1643
2904
|
diff: diff,
|
|
1644
|
-
oldObj: oldObj,
|
|
1645
2905
|
newObj: newObj
|
|
1646
2906
|
});
|
|
1647
2907
|
}
|
|
@@ -1650,7 +2910,7 @@
|
|
|
1650
2910
|
if (!diff.categories) return actions;
|
|
1651
2911
|
var addToCategoryActions = [];
|
|
1652
2912
|
var removeFromCategoryActions = [];
|
|
1653
|
-
|
|
2913
|
+
forEach(diff.categories, function (category) {
|
|
1654
2914
|
if (Array.isArray(category)) {
|
|
1655
2915
|
var action = {
|
|
1656
2916
|
category: category[0]
|
|
@@ -1695,7 +2955,7 @@
|
|
|
1695
2955
|
function actionsMapAssets(diff, oldObj, newObj, variantHashMap) {
|
|
1696
2956
|
var allAssetsActions = [];
|
|
1697
2957
|
var variants = diff.variants;
|
|
1698
|
-
if (variants)
|
|
2958
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1699
2959
|
var _extractMatchingPairs4 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1700
2960
|
oldVariant = _extractMatchingPairs4.oldObj,
|
|
1701
2961
|
newVariant = _extractMatchingPairs4.newObj;
|
|
@@ -1711,7 +2971,7 @@
|
|
|
1711
2971
|
var variantHashMap = arguments.length > 4 ? arguments[4] : undefined;
|
|
1712
2972
|
var actions = [];
|
|
1713
2973
|
var variants = diff.variants;
|
|
1714
|
-
if (variants)
|
|
2974
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1715
2975
|
var _extractMatchingPairs5 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1716
2976
|
oldVariant = _extractMatchingPairs5.oldObj,
|
|
1717
2977
|
newVariant = _extractMatchingPairs5.newObj;
|
|
@@ -1728,14 +2988,14 @@
|
|
|
1728
2988
|
|
|
1729
2989
|
// Ensure that an action is unique.
|
|
1730
2990
|
// This is especially necessary for SFA attributes.
|
|
1731
|
-
return
|
|
2991
|
+
return uniqWith(actions, function (a, b) {
|
|
1732
2992
|
return a.action === b.action && a.name === b.name && a.variantId === b.variantId;
|
|
1733
2993
|
});
|
|
1734
2994
|
}
|
|
1735
2995
|
function actionsMapImages(diff, oldObj, newObj, variantHashMap) {
|
|
1736
2996
|
var actions = [];
|
|
1737
2997
|
var variants = diff.variants;
|
|
1738
|
-
if (variants)
|
|
2998
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1739
2999
|
var _extractMatchingPairs6 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1740
3000
|
oldVariant = _extractMatchingPairs6.oldObj,
|
|
1741
3001
|
newVariant = _extractMatchingPairs6.newObj;
|
|
@@ -1751,7 +3011,7 @@
|
|
|
1751
3011
|
var changePriceActions = [];
|
|
1752
3012
|
var removePriceActions = [];
|
|
1753
3013
|
var variants = diff.variants;
|
|
1754
|
-
if (variants)
|
|
3014
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1755
3015
|
var _extractMatchingPairs7 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1756
3016
|
oldVariant = _extractMatchingPairs7.oldObj,
|
|
1757
3017
|
newVariant = _extractMatchingPairs7.newObj;
|
|
@@ -1773,13 +3033,13 @@
|
|
|
1773
3033
|
function actionsMapPricesCustom(diff, oldObj, newObj, variantHashMap) {
|
|
1774
3034
|
var actions = [];
|
|
1775
3035
|
var variants = diff.variants;
|
|
1776
|
-
if (variants)
|
|
3036
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1777
3037
|
var _extractMatchingPairs8 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1778
3038
|
oldVariant = _extractMatchingPairs8.oldObj,
|
|
1779
3039
|
newVariant = _extractMatchingPairs8.newObj;
|
|
1780
3040
|
if (variant && variant.prices && (REGEX_UNDERSCORE_NUMBER$2.test(key) || REGEX_NUMBER$2.test(key))) {
|
|
1781
3041
|
var priceHashMap = findMatchingPairs(variant.prices, oldVariant.prices, newVariant.prices);
|
|
1782
|
-
|
|
3042
|
+
forEach(variant.prices, function (price, index) {
|
|
1783
3043
|
var _extractMatchingPairs9 = extractMatchingPairs(priceHashMap, index, oldVariant.prices, newVariant.prices),
|
|
1784
3044
|
oldPrice = _extractMatchingPairs9.oldObj,
|
|
1785
3045
|
newPrice = _extractMatchingPairs9.newObj;
|
|
@@ -1863,12 +3123,12 @@
|
|
|
1863
3123
|
allActions.push(mapActionGroup('assets', function () {
|
|
1864
3124
|
return actionsMapAssets(diff, oldObj, newObj, variantHashMap);
|
|
1865
3125
|
}));
|
|
1866
|
-
if (publish === true || staged === false) return
|
|
3126
|
+
if (publish === true || staged === false) return flatten(allActions).map(function (action) {
|
|
1867
3127
|
return _objectSpread2(_objectSpread2({}, action), {}, {
|
|
1868
3128
|
staged: false
|
|
1869
3129
|
});
|
|
1870
3130
|
});
|
|
1871
|
-
return
|
|
3131
|
+
return flatten(allActions);
|
|
1872
3132
|
};
|
|
1873
3133
|
}
|
|
1874
3134
|
function moveMasterVariantsIntoVariants(before, now) {
|
|
@@ -1951,7 +3211,7 @@
|
|
|
1951
3211
|
|
|
1952
3212
|
// generate a hashMap to be able to reference the right image from both ends
|
|
1953
3213
|
var matchingParcelPairs = findMatchingPairs(diffedParcels, oldDelivery.parcels, newDelivery.parcels);
|
|
1954
|
-
|
|
3214
|
+
forEach(diffedParcels, function (parcel, key) {
|
|
1955
3215
|
var _extractMatchingPairs = extractMatchingPairs(matchingParcelPairs, key, oldDelivery.parcels, newDelivery.parcels),
|
|
1956
3216
|
oldObj = _extractMatchingPairs.oldObj;
|
|
1957
3217
|
if (isAddAction(key, parcel)) {
|
|
@@ -1993,7 +3253,7 @@
|
|
|
1993
3253
|
if (!deliveries) return [];
|
|
1994
3254
|
var addParcelActions = [];
|
|
1995
3255
|
var removeParcelActions = [];
|
|
1996
|
-
if (deliveries)
|
|
3256
|
+
if (deliveries) forEach(deliveries, function (delivery, key) {
|
|
1997
3257
|
var _extractMatchingPairs2 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
|
|
1998
3258
|
oldDelivery = _extractMatchingPairs2.oldObj,
|
|
1999
3259
|
newDelivery = _extractMatchingPairs2.newObj;
|
|
@@ -2014,7 +3274,7 @@
|
|
|
2014
3274
|
var deliveries = shippingInfo.deliveries;
|
|
2015
3275
|
if (!deliveries) return [];
|
|
2016
3276
|
var setDeliveryItemsActions = [];
|
|
2017
|
-
|
|
3277
|
+
forEach(deliveries, function (delivery, key) {
|
|
2018
3278
|
var _extractMatchingPairs3 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
|
|
2019
3279
|
newDelivery = _extractMatchingPairs3.newObj;
|
|
2020
3280
|
if (REGEX_UNDERSCORE_NUMBER$1.test(key) || REGEX_NUMBER$1.test(key)) {
|
|
@@ -2083,13 +3343,13 @@
|
|
|
2083
3343
|
allActions.push(mapActionGroup('items', function () {
|
|
2084
3344
|
return actionsMapDeliveryItems(diff, oldObj, newObj, deliveryHashMap);
|
|
2085
3345
|
}));
|
|
2086
|
-
allActions.push(
|
|
3346
|
+
allActions.push(flatten(mapActionGroup('returnInfo', function () {
|
|
2087
3347
|
return actionsMapReturnsInfo(diff, oldObj, newObj);
|
|
2088
3348
|
})));
|
|
2089
3349
|
allActions.push(mapActionGroup('custom', function () {
|
|
2090
3350
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2091
3351
|
}));
|
|
2092
|
-
return
|
|
3352
|
+
return flatten(allActions);
|
|
2093
3353
|
};
|
|
2094
3354
|
}
|
|
2095
3355
|
var orders = (function (actionGroupList, syncActionConfig) {
|
|
@@ -2183,7 +3443,7 @@
|
|
|
2183
3443
|
allActions.push(mapActionGroup('base', function () {
|
|
2184
3444
|
return actionsMapBase$f(diff, oldObj, newObj, syncActionConfig);
|
|
2185
3445
|
}));
|
|
2186
|
-
return combineValidityActions(
|
|
3446
|
+
return combineValidityActions(flatten(allActions));
|
|
2187
3447
|
};
|
|
2188
3448
|
}
|
|
2189
3449
|
var productDiscounts = (function (actionGroupList) {
|
|
@@ -2252,7 +3512,7 @@
|
|
|
2252
3512
|
allActions.push(mapActionGroup('custom', function () {
|
|
2253
3513
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2254
3514
|
}));
|
|
2255
|
-
return combineValidityActions(
|
|
3515
|
+
return combineValidityActions(flatten(allActions));
|
|
2256
3516
|
};
|
|
2257
3517
|
}
|
|
2258
3518
|
var discountCodes = (function (actionGroupList) {
|
|
@@ -2305,7 +3565,7 @@
|
|
|
2305
3565
|
allActions.push(mapActionGroup('custom', function () {
|
|
2306
3566
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2307
3567
|
}));
|
|
2308
|
-
return
|
|
3568
|
+
return flatten(allActions);
|
|
2309
3569
|
};
|
|
2310
3570
|
}
|
|
2311
3571
|
var customerGroup = (function (actionGroupList) {
|
|
@@ -2377,7 +3637,7 @@
|
|
|
2377
3637
|
allActions.push(mapActionGroup('custom', function () {
|
|
2378
3638
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2379
3639
|
}));
|
|
2380
|
-
return combineValidityActions(
|
|
3640
|
+
return combineValidityActions(flatten(allActions));
|
|
2381
3641
|
};
|
|
2382
3642
|
}
|
|
2383
3643
|
var cartDiscounts = (function (actionGroupList) {
|
|
@@ -2757,7 +4017,7 @@
|
|
|
2757
4017
|
allActions.push(mapActionGroup('rates', function () {
|
|
2758
4018
|
return actionsMapRates(diff, oldObj, newObj);
|
|
2759
4019
|
}));
|
|
2760
|
-
return
|
|
4020
|
+
return flatten(allActions);
|
|
2761
4021
|
};
|
|
2762
4022
|
}
|
|
2763
4023
|
var taxCategories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -2848,10 +4108,10 @@
|
|
|
2848
4108
|
allActions.push(mapActionGroup('base', function () {
|
|
2849
4109
|
return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
|
|
2850
4110
|
}));
|
|
2851
|
-
allActions.push(
|
|
4111
|
+
allActions.push(flatten(mapActionGroup('locations', function () {
|
|
2852
4112
|
return actionsMapLocations(diff, oldObj, newObj);
|
|
2853
4113
|
})));
|
|
2854
|
-
return
|
|
4114
|
+
return flatten(allActions);
|
|
2855
4115
|
};
|
|
2856
4116
|
}
|
|
2857
4117
|
var zones = (function (actionGroupList, syncActionConfig) {
|
|
@@ -2967,7 +4227,7 @@
|
|
|
2967
4227
|
if (diff.zoneRates[key].shippingRates) return [].concat(_toConsumableArray(actions), _toConsumableArray(actionsMapZoneRatesShippingRates(diff.zoneRates[key], oldZoneRate, newZoneRate)));
|
|
2968
4228
|
return actions;
|
|
2969
4229
|
}, []);
|
|
2970
|
-
return
|
|
4230
|
+
return flatten(hasZoneActions ? [].concat(_toConsumableArray(shippingRateActions), [{
|
|
2971
4231
|
action: 'removeZone',
|
|
2972
4232
|
zone: oldZoneRate.zone
|
|
2973
4233
|
}, {
|
|
@@ -2984,13 +4244,13 @@
|
|
|
2984
4244
|
allActions.push(mapActionGroup('base', function () {
|
|
2985
4245
|
return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
|
|
2986
4246
|
}));
|
|
2987
|
-
allActions.push(
|
|
4247
|
+
allActions.push(flatten(mapActionGroup('zoneRates', function () {
|
|
2988
4248
|
return actionsMapZoneRates(diff, oldObj, newObj);
|
|
2989
4249
|
})));
|
|
2990
4250
|
allActions.push(mapActionGroup('custom', function () {
|
|
2991
4251
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2992
4252
|
}));
|
|
2993
|
-
return
|
|
4253
|
+
return flatten(allActions);
|
|
2994
4254
|
};
|
|
2995
4255
|
}
|
|
2996
4256
|
var shippingMethods = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3122,7 +4382,7 @@
|
|
|
3122
4382
|
action: 'removeAttributeDefinition',
|
|
3123
4383
|
name: attributeDef.previous.name
|
|
3124
4384
|
};
|
|
3125
|
-
})), _toConsumableArray(
|
|
4385
|
+
})), _toConsumableArray(flatten(updatedAttributeDefinitions.map(function (updatedAttributeDefinition) {
|
|
3126
4386
|
return generateBaseFieldsUpdateActions(updatedAttributeDefinition.previous, updatedAttributeDefinition.next, {
|
|
3127
4387
|
label: {
|
|
3128
4388
|
action: 'changeLabel',
|
|
@@ -3172,7 +4432,7 @@
|
|
|
3172
4432
|
return _objectSpread2(_objectSpread2({}, nextEnumUpdateActions), {}, _defineProperty({}, removedAttributeEnumValue.hint.attributeName, _objectSpread2(_objectSpread2({}, removedAttributeEnumValueOfSameAttributeName), {}, {
|
|
3173
4433
|
keys: [].concat(_toConsumableArray(removedAttributeEnumValueOfSameAttributeName.keys), [removedAttributeEnumValue.previous.key])
|
|
3174
4434
|
})));
|
|
3175
|
-
}, {}))), _toConsumableArray(
|
|
4435
|
+
}, {}))), _toConsumableArray(flatten(updatedAttributeEnumValues.map(function (updatedAttributeEnumValue) {
|
|
3176
4436
|
var updateActions = generateBaseFieldsUpdateActions(updatedAttributeEnumValue.previous, updatedAttributeEnumValue.next, {
|
|
3177
4437
|
key: {
|
|
3178
4438
|
action: 'changeEnumKey',
|
|
@@ -3246,7 +4506,7 @@
|
|
|
3246
4506
|
|
|
3247
4507
|
function createProductTypeMapActions(mapActionGroup, syncActionConfig) {
|
|
3248
4508
|
return function doMapActions(diff, next, previous, options) {
|
|
3249
|
-
return
|
|
4509
|
+
return flatten([
|
|
3250
4510
|
// we support only base fields for the product type,
|
|
3251
4511
|
// for attributes, applying hints would be recommended
|
|
3252
4512
|
mapActionGroup('base', function () {
|
|
@@ -3342,7 +4602,7 @@
|
|
|
3342
4602
|
roleActions.push(mapActionGroup('roles', function () {
|
|
3343
4603
|
return actionsMapRoles(diff, oldObj, newObj);
|
|
3344
4604
|
}));
|
|
3345
|
-
return
|
|
4605
|
+
return flatten([].concat(baseActions, _toConsumableArray(groupRoleActions(roleActions))));
|
|
3346
4606
|
};
|
|
3347
4607
|
}
|
|
3348
4608
|
var states = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3395,7 +4655,7 @@
|
|
|
3395
4655
|
allActions.push(mapActionGroup('custom', function () {
|
|
3396
4656
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
3397
4657
|
}));
|
|
3398
|
-
return
|
|
4658
|
+
return flatten(allActions);
|
|
3399
4659
|
};
|
|
3400
4660
|
}
|
|
3401
4661
|
var channels = (function (actionGroupList) {
|
|
@@ -3466,7 +4726,7 @@
|
|
|
3466
4726
|
var foundPreviousEnum = previous.values.find(function (previousEnum) {
|
|
3467
4727
|
return previousEnum.key === newEnum.key;
|
|
3468
4728
|
});
|
|
3469
|
-
var isLabelEqual =
|
|
4729
|
+
var isLabelEqual = isEqual(foundPreviousEnum.label, newEnum.label);
|
|
3470
4730
|
if (isKeyChanged) {
|
|
3471
4731
|
// these actions is then flatten in the end
|
|
3472
4732
|
changeActions.push({
|
|
@@ -3495,7 +4755,7 @@
|
|
|
3495
4755
|
// following lists are necessary to ensure that when we change the
|
|
3496
4756
|
// order of enumValues, we generate one updateAction instead of one at a time.
|
|
3497
4757
|
var newEnumValuesOrder = [];
|
|
3498
|
-
|
|
4758
|
+
flatten(buildArrayActions(attributeDiff, previous, next)).forEach(function (updateAction) {
|
|
3499
4759
|
if (updateAction.action === changeEnumOrderActionName) {
|
|
3500
4760
|
newEnumValuesOrder = next.values.map(function (enumValue) {
|
|
3501
4761
|
return enumValue.key;
|
|
@@ -3510,7 +4770,7 @@
|
|
|
3510
4770
|
}
|
|
3511
4771
|
function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPaths) {
|
|
3512
4772
|
var actions = [];
|
|
3513
|
-
|
|
4773
|
+
forEach(fieldDefinitionsDiff, function (diffValue, diffKey) {
|
|
3514
4774
|
var extractedPairs = extractMatchingPairs(diffPaths, diffKey, previous, next);
|
|
3515
4775
|
if (getIsChangedOperation(diffKey)) {
|
|
3516
4776
|
var _diffValue$type;
|
|
@@ -3561,7 +4821,7 @@
|
|
|
3561
4821
|
// in order to prevent any eventual removal of `addAction`.
|
|
3562
4822
|
// List of `removeActions` can be found here
|
|
3563
4823
|
// https://docs.commercetools.com/http-api-projects-types.html#change-key
|
|
3564
|
-
var sortedActions =
|
|
4824
|
+
var sortedActions = sortBy(actions, function (action) {
|
|
3565
4825
|
return action.action !== 'removeFieldDefinition';
|
|
3566
4826
|
});
|
|
3567
4827
|
return sortedActions;
|
|
@@ -3575,7 +4835,7 @@
|
|
|
3575
4835
|
}), mapActionGroup('fieldDefinitions', function () {
|
|
3576
4836
|
return actionsMapFieldDefinitions(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, findMatchingPairs(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, 'name'));
|
|
3577
4837
|
}));
|
|
3578
|
-
return
|
|
4838
|
+
return flatten(allActions);
|
|
3579
4839
|
};
|
|
3580
4840
|
}
|
|
3581
4841
|
var types = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3677,7 +4937,7 @@
|
|
|
3677
4937
|
allActions.push(mapActionGroup('searchIndexingConfiguration', function () {
|
|
3678
4938
|
return actionsMapSearchIndexingConfiguration(diff, oldObj, newObj);
|
|
3679
4939
|
}));
|
|
3680
|
-
return
|
|
4940
|
+
return flatten(allActions);
|
|
3681
4941
|
};
|
|
3682
4942
|
}
|
|
3683
4943
|
var projects = (function (actionGroupList) {
|
|
@@ -3725,7 +4985,7 @@
|
|
|
3725
4985
|
allActions.push(mapActionGroup('custom', function () {
|
|
3726
4986
|
return actionsMapCustom(diff, next, previous);
|
|
3727
4987
|
}));
|
|
3728
|
-
return
|
|
4988
|
+
return flatten(allActions);
|
|
3729
4989
|
};
|
|
3730
4990
|
}
|
|
3731
4991
|
var stores = (function (actionGroupList) {
|
|
@@ -3768,7 +5028,7 @@
|
|
|
3768
5028
|
allActions.push(mapActionGroup('custom', function () {
|
|
3769
5029
|
return actionsMapCustom(diff, next, previous);
|
|
3770
5030
|
}));
|
|
3771
|
-
return
|
|
5031
|
+
return flatten(allActions);
|
|
3772
5032
|
};
|
|
3773
5033
|
}
|
|
3774
5034
|
var productSelections = (function (actionGroupList) {
|
|
@@ -3903,10 +5163,10 @@
|
|
|
3903
5163
|
allActions.push(mapActionGroup('base', function () {
|
|
3904
5164
|
return actionsMapBase(diff, oldObj, newObj, syncActionConfig);
|
|
3905
5165
|
}));
|
|
3906
|
-
allActions.push(
|
|
5166
|
+
allActions.push(flatten(mapActionGroup('attributes', function () {
|
|
3907
5167
|
return actionsMapAttributes(diff, oldObj, newObj);
|
|
3908
5168
|
})));
|
|
3909
|
-
return
|
|
5169
|
+
return flatten(allActions);
|
|
3910
5170
|
};
|
|
3911
5171
|
}
|
|
3912
5172
|
var attributeGroups = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3940,6 +5200,4 @@
|
|
|
3940
5200
|
exports.createSyncTypes = types;
|
|
3941
5201
|
exports.createSyncZones = zones;
|
|
3942
5202
|
|
|
3943
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3944
|
-
|
|
3945
5203
|
}));
|