@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.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,1215 @@
|
|
|
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
|
+
|
|
1506
|
+
function create(options) {
|
|
1507
|
+
return new DiffPatcher(options);
|
|
1508
|
+
}
|
|
1509
|
+
|
|
242
1510
|
function objectHash(obj, index) {
|
|
243
1511
|
var objIndex = "$$index:".concat(index);
|
|
244
1512
|
return _typeof(obj) === 'object' && obj !== null ? obj.id || obj.name || obj.url || objIndex : objIndex;
|
|
245
1513
|
}
|
|
246
|
-
var diffpatcher =
|
|
1514
|
+
var diffpatcher = create({
|
|
247
1515
|
objectHash: objectHash,
|
|
248
1516
|
arrays: {
|
|
249
1517
|
// detect items moved inside the array
|
|
@@ -573,7 +1841,7 @@
|
|
|
573
1841
|
action: item.action
|
|
574
1842
|
}, actionKey, patched);
|
|
575
1843
|
}).filter(function (action) {
|
|
576
|
-
return !
|
|
1844
|
+
return !isNil(action);
|
|
577
1845
|
});
|
|
578
1846
|
}
|
|
579
1847
|
|
|
@@ -680,7 +1948,6 @@
|
|
|
680
1948
|
return buildReferenceActions({
|
|
681
1949
|
actions: referenceActionsList$3,
|
|
682
1950
|
diff: diff,
|
|
683
|
-
oldObj: oldObj,
|
|
684
1951
|
newObj: newObj
|
|
685
1952
|
});
|
|
686
1953
|
}
|
|
@@ -706,7 +1973,7 @@
|
|
|
706
1973
|
function copyEmptyArrayProps() {
|
|
707
1974
|
var oldObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
708
1975
|
var newObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
709
|
-
if (!
|
|
1976
|
+
if (!isNil(oldObj) && !isNil(newObj)) {
|
|
710
1977
|
var nextObjectWithEmptyArray = Object.entries(oldObj).reduce(function (merged, _ref) {
|
|
711
1978
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
712
1979
|
key = _ref2[0],
|
|
@@ -721,10 +1988,10 @@
|
|
|
721
1988
|
return acc;
|
|
722
1989
|
}, {});
|
|
723
1990
|
for (var i = 0; i < newObj[key].length; i++) {
|
|
724
|
-
if (!
|
|
1991
|
+
if (!isNil(newObj[key][i]) && _typeof(newObj[key][i]) === 'object' && !isNil(newObj[key][i].id)) {
|
|
725
1992
|
// Since its unordered array elements then check if the element on `oldObj` exists by id
|
|
726
1993
|
var foundObject = hashMapValue[newObj[key][i].id];
|
|
727
|
-
if (!
|
|
1994
|
+
if (!isNil(foundObject)) {
|
|
728
1995
|
var _copyEmptyArrayProps = copyEmptyArrayProps(foundObject, newObj[key][i]),
|
|
729
1996
|
_copyEmptyArrayProps2 = _slicedToArray(_copyEmptyArrayProps, 2),
|
|
730
1997
|
nestedObject = _copyEmptyArrayProps2[1];
|
|
@@ -740,10 +2007,10 @@
|
|
|
740
2007
|
return merged;
|
|
741
2008
|
}
|
|
742
2009
|
if (Array.isArray(value)) {
|
|
743
|
-
merged[key] =
|
|
2010
|
+
merged[key] = isNil(newObj[key]) ? [] : newObj[key];
|
|
744
2011
|
return merged;
|
|
745
2012
|
}
|
|
746
|
-
if (!
|
|
2013
|
+
if (!isNil(newObj[key]) && _typeof(value) === 'object' &&
|
|
747
2014
|
// Ignore Date as this will create invalid object since typeof date === 'object' return true
|
|
748
2015
|
// ex: {date: new Date()} will result {date: {}}
|
|
749
2016
|
!(value instanceof Date)) {
|
|
@@ -778,7 +2045,7 @@
|
|
|
778
2045
|
allActions.push(mapActionGroup('assets', function () {
|
|
779
2046
|
return actionsMapAssets$1(diff, oldObj, newObj);
|
|
780
2047
|
}));
|
|
781
|
-
return
|
|
2048
|
+
return flatten(allActions);
|
|
782
2049
|
};
|
|
783
2050
|
}
|
|
784
2051
|
var categories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -896,7 +2163,6 @@
|
|
|
896
2163
|
return buildReferenceActions({
|
|
897
2164
|
actions: referenceActionsList$2,
|
|
898
2165
|
diff: diff,
|
|
899
|
-
oldObj: oldObj,
|
|
900
2166
|
newObj: newObj
|
|
901
2167
|
});
|
|
902
2168
|
}
|
|
@@ -1004,7 +2270,7 @@
|
|
|
1004
2270
|
authMode: patched
|
|
1005
2271
|
}, value, newObj.password);
|
|
1006
2272
|
}).filter(function (action) {
|
|
1007
|
-
return !
|
|
2273
|
+
return !isNil(action);
|
|
1008
2274
|
});
|
|
1009
2275
|
}
|
|
1010
2276
|
|
|
@@ -1035,7 +2301,7 @@
|
|
|
1035
2301
|
allActions.push(mapActionGroup('authenticationModes', function () {
|
|
1036
2302
|
return actionsMapAuthenticationModes(diff, oldObj, newObj);
|
|
1037
2303
|
}));
|
|
1038
|
-
return
|
|
2304
|
+
return flatten(allActions);
|
|
1039
2305
|
};
|
|
1040
2306
|
}
|
|
1041
2307
|
var customers = (function (actionGroupList, syncActionConfig) {
|
|
@@ -1094,7 +2360,6 @@
|
|
|
1094
2360
|
return buildReferenceActions({
|
|
1095
2361
|
actions: referenceActionsList$1,
|
|
1096
2362
|
diff: diff,
|
|
1097
|
-
oldObj: oldObj,
|
|
1098
2363
|
newObj: newObj
|
|
1099
2364
|
});
|
|
1100
2365
|
}
|
|
@@ -1111,7 +2376,7 @@
|
|
|
1111
2376
|
allActions.push(mapActionGroup('custom', function () {
|
|
1112
2377
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
1113
2378
|
}));
|
|
1114
|
-
return
|
|
2379
|
+
return flatten(allActions);
|
|
1115
2380
|
};
|
|
1116
2381
|
}
|
|
1117
2382
|
var inventories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -1178,7 +2443,7 @@
|
|
|
1178
2443
|
var _preProcessCollection2 = preProcessCollection(now, identifier),
|
|
1179
2444
|
nowObjRefByIdentifier = _preProcessCollection2.refByIdentifier,
|
|
1180
2445
|
nowObjRefByIndex = _preProcessCollection2.refByIndex;
|
|
1181
|
-
|
|
2446
|
+
forEach(diff, function (item, key) {
|
|
1182
2447
|
if (REGEX_NUMBER$3.test(key)) {
|
|
1183
2448
|
var matchingIdentifier = nowObjRefByIndex[key];
|
|
1184
2449
|
result[key] = [beforeObjRefByIdentifier[matchingIdentifier], key];
|
|
@@ -1359,7 +2624,7 @@
|
|
|
1359
2624
|
var actions = [];
|
|
1360
2625
|
// generate a hashMap to be able to reference the right image from both ends
|
|
1361
2626
|
var matchingImagePairs = findMatchingPairs(diffedImages, oldVariant.images, newVariant.images, 'url');
|
|
1362
|
-
|
|
2627
|
+
forEach(diffedImages, function (image, key) {
|
|
1363
2628
|
var _extractMatchingPairs = extractMatchingPairs(matchingImagePairs, key, oldVariant.images, newVariant.images),
|
|
1364
2629
|
oldObj = _extractMatchingPairs.oldObj,
|
|
1365
2630
|
newObj = _extractMatchingPairs.newObj;
|
|
@@ -1416,7 +2681,7 @@
|
|
|
1416
2681
|
|
|
1417
2682
|
// generate a hashMap to be able to reference the right image from both ends
|
|
1418
2683
|
var matchingPricePairs = findMatchingPairs(diffedPrices, oldVariant.prices, newVariant.prices);
|
|
1419
|
-
|
|
2684
|
+
forEach(diffedPrices, function (price, key) {
|
|
1420
2685
|
var _extractMatchingPairs2 = extractMatchingPairs(matchingPricePairs, key, oldVariant.prices, newVariant.prices),
|
|
1421
2686
|
oldObj = _extractMatchingPairs2.oldObj,
|
|
1422
2687
|
newObj = _extractMatchingPairs2.newObj;
|
|
@@ -1464,7 +2729,7 @@
|
|
|
1464
2729
|
function _buildVariantAttributesActions(attributes, oldVariant, newVariant, sameForAllAttributeNames) {
|
|
1465
2730
|
var actions = [];
|
|
1466
2731
|
if (!attributes) return actions;
|
|
1467
|
-
|
|
2732
|
+
forEach(attributes, function (value, key) {
|
|
1468
2733
|
if (REGEX_NUMBER$2.test(key)) {
|
|
1469
2734
|
if (Array.isArray(value)) {
|
|
1470
2735
|
var id = oldVariant.id;
|
|
@@ -1529,8 +2794,8 @@
|
|
|
1529
2794
|
}).filter(function (_) {
|
|
1530
2795
|
return _ !== undefined;
|
|
1531
2796
|
});
|
|
1532
|
-
var assetIdsToKeep =
|
|
1533
|
-
var assetIdsToRemove =
|
|
2797
|
+
var assetIdsToKeep = intersection(assetIdsCurrent, assetIdsBefore);
|
|
2798
|
+
var assetIdsToRemove = without.apply(void 0, [assetIdsBefore].concat(_toConsumableArray(assetIdsToKeep)));
|
|
1534
2799
|
var changeAssetOrderAction = _objectSpread2({
|
|
1535
2800
|
action: 'changeAssetOrder',
|
|
1536
2801
|
assetOrder: assetIdsToKeep.concat(assetIdsToRemove)
|
|
@@ -1542,7 +2807,7 @@
|
|
|
1542
2807
|
|
|
1543
2808
|
// generate a hashMap to be able to reference the right asset from both ends
|
|
1544
2809
|
var matchingAssetPairs = findMatchingPairs(diffAssets, oldVariant.assets, newVariant.assets);
|
|
1545
|
-
|
|
2810
|
+
forEach(diffAssets, function (asset, key) {
|
|
1546
2811
|
var _extractMatchingPairs3 = extractMatchingPairs(matchingAssetPairs, key, oldVariant.assets, newVariant.assets),
|
|
1547
2812
|
oldAsset = _extractMatchingPairs3.oldObj,
|
|
1548
2813
|
newAsset = _extractMatchingPairs3.newObj;
|
|
@@ -1641,7 +2906,6 @@
|
|
|
1641
2906
|
return buildReferenceActions({
|
|
1642
2907
|
actions: referenceActionsList,
|
|
1643
2908
|
diff: diff,
|
|
1644
|
-
oldObj: oldObj,
|
|
1645
2909
|
newObj: newObj
|
|
1646
2910
|
});
|
|
1647
2911
|
}
|
|
@@ -1650,7 +2914,7 @@
|
|
|
1650
2914
|
if (!diff.categories) return actions;
|
|
1651
2915
|
var addToCategoryActions = [];
|
|
1652
2916
|
var removeFromCategoryActions = [];
|
|
1653
|
-
|
|
2917
|
+
forEach(diff.categories, function (category) {
|
|
1654
2918
|
if (Array.isArray(category)) {
|
|
1655
2919
|
var action = {
|
|
1656
2920
|
category: category[0]
|
|
@@ -1695,7 +2959,7 @@
|
|
|
1695
2959
|
function actionsMapAssets(diff, oldObj, newObj, variantHashMap) {
|
|
1696
2960
|
var allAssetsActions = [];
|
|
1697
2961
|
var variants = diff.variants;
|
|
1698
|
-
if (variants)
|
|
2962
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1699
2963
|
var _extractMatchingPairs4 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1700
2964
|
oldVariant = _extractMatchingPairs4.oldObj,
|
|
1701
2965
|
newVariant = _extractMatchingPairs4.newObj;
|
|
@@ -1711,7 +2975,7 @@
|
|
|
1711
2975
|
var variantHashMap = arguments.length > 4 ? arguments[4] : undefined;
|
|
1712
2976
|
var actions = [];
|
|
1713
2977
|
var variants = diff.variants;
|
|
1714
|
-
if (variants)
|
|
2978
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1715
2979
|
var _extractMatchingPairs5 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1716
2980
|
oldVariant = _extractMatchingPairs5.oldObj,
|
|
1717
2981
|
newVariant = _extractMatchingPairs5.newObj;
|
|
@@ -1728,14 +2992,14 @@
|
|
|
1728
2992
|
|
|
1729
2993
|
// Ensure that an action is unique.
|
|
1730
2994
|
// This is especially necessary for SFA attributes.
|
|
1731
|
-
return
|
|
2995
|
+
return uniqWith(actions, function (a, b) {
|
|
1732
2996
|
return a.action === b.action && a.name === b.name && a.variantId === b.variantId;
|
|
1733
2997
|
});
|
|
1734
2998
|
}
|
|
1735
2999
|
function actionsMapImages(diff, oldObj, newObj, variantHashMap) {
|
|
1736
3000
|
var actions = [];
|
|
1737
3001
|
var variants = diff.variants;
|
|
1738
|
-
if (variants)
|
|
3002
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1739
3003
|
var _extractMatchingPairs6 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1740
3004
|
oldVariant = _extractMatchingPairs6.oldObj,
|
|
1741
3005
|
newVariant = _extractMatchingPairs6.newObj;
|
|
@@ -1751,7 +3015,7 @@
|
|
|
1751
3015
|
var changePriceActions = [];
|
|
1752
3016
|
var removePriceActions = [];
|
|
1753
3017
|
var variants = diff.variants;
|
|
1754
|
-
if (variants)
|
|
3018
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1755
3019
|
var _extractMatchingPairs7 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1756
3020
|
oldVariant = _extractMatchingPairs7.oldObj,
|
|
1757
3021
|
newVariant = _extractMatchingPairs7.newObj;
|
|
@@ -1773,13 +3037,13 @@
|
|
|
1773
3037
|
function actionsMapPricesCustom(diff, oldObj, newObj, variantHashMap) {
|
|
1774
3038
|
var actions = [];
|
|
1775
3039
|
var variants = diff.variants;
|
|
1776
|
-
if (variants)
|
|
3040
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
1777
3041
|
var _extractMatchingPairs8 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
1778
3042
|
oldVariant = _extractMatchingPairs8.oldObj,
|
|
1779
3043
|
newVariant = _extractMatchingPairs8.newObj;
|
|
1780
3044
|
if (variant && variant.prices && (REGEX_UNDERSCORE_NUMBER$2.test(key) || REGEX_NUMBER$2.test(key))) {
|
|
1781
3045
|
var priceHashMap = findMatchingPairs(variant.prices, oldVariant.prices, newVariant.prices);
|
|
1782
|
-
|
|
3046
|
+
forEach(variant.prices, function (price, index) {
|
|
1783
3047
|
var _extractMatchingPairs9 = extractMatchingPairs(priceHashMap, index, oldVariant.prices, newVariant.prices),
|
|
1784
3048
|
oldPrice = _extractMatchingPairs9.oldObj,
|
|
1785
3049
|
newPrice = _extractMatchingPairs9.newObj;
|
|
@@ -1863,12 +3127,12 @@
|
|
|
1863
3127
|
allActions.push(mapActionGroup('assets', function () {
|
|
1864
3128
|
return actionsMapAssets(diff, oldObj, newObj, variantHashMap);
|
|
1865
3129
|
}));
|
|
1866
|
-
if (publish === true || staged === false) return
|
|
3130
|
+
if (publish === true || staged === false) return flatten(allActions).map(function (action) {
|
|
1867
3131
|
return _objectSpread2(_objectSpread2({}, action), {}, {
|
|
1868
3132
|
staged: false
|
|
1869
3133
|
});
|
|
1870
3134
|
});
|
|
1871
|
-
return
|
|
3135
|
+
return flatten(allActions);
|
|
1872
3136
|
};
|
|
1873
3137
|
}
|
|
1874
3138
|
function moveMasterVariantsIntoVariants(before, now) {
|
|
@@ -1951,7 +3215,7 @@
|
|
|
1951
3215
|
|
|
1952
3216
|
// generate a hashMap to be able to reference the right image from both ends
|
|
1953
3217
|
var matchingParcelPairs = findMatchingPairs(diffedParcels, oldDelivery.parcels, newDelivery.parcels);
|
|
1954
|
-
|
|
3218
|
+
forEach(diffedParcels, function (parcel, key) {
|
|
1955
3219
|
var _extractMatchingPairs = extractMatchingPairs(matchingParcelPairs, key, oldDelivery.parcels, newDelivery.parcels),
|
|
1956
3220
|
oldObj = _extractMatchingPairs.oldObj;
|
|
1957
3221
|
if (isAddAction(key, parcel)) {
|
|
@@ -1993,7 +3257,7 @@
|
|
|
1993
3257
|
if (!deliveries) return [];
|
|
1994
3258
|
var addParcelActions = [];
|
|
1995
3259
|
var removeParcelActions = [];
|
|
1996
|
-
if (deliveries)
|
|
3260
|
+
if (deliveries) forEach(deliveries, function (delivery, key) {
|
|
1997
3261
|
var _extractMatchingPairs2 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
|
|
1998
3262
|
oldDelivery = _extractMatchingPairs2.oldObj,
|
|
1999
3263
|
newDelivery = _extractMatchingPairs2.newObj;
|
|
@@ -2014,7 +3278,7 @@
|
|
|
2014
3278
|
var deliveries = shippingInfo.deliveries;
|
|
2015
3279
|
if (!deliveries) return [];
|
|
2016
3280
|
var setDeliveryItemsActions = [];
|
|
2017
|
-
|
|
3281
|
+
forEach(deliveries, function (delivery, key) {
|
|
2018
3282
|
var _extractMatchingPairs3 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
|
|
2019
3283
|
newDelivery = _extractMatchingPairs3.newObj;
|
|
2020
3284
|
if (REGEX_UNDERSCORE_NUMBER$1.test(key) || REGEX_NUMBER$1.test(key)) {
|
|
@@ -2083,13 +3347,13 @@
|
|
|
2083
3347
|
allActions.push(mapActionGroup('items', function () {
|
|
2084
3348
|
return actionsMapDeliveryItems(diff, oldObj, newObj, deliveryHashMap);
|
|
2085
3349
|
}));
|
|
2086
|
-
allActions.push(
|
|
3350
|
+
allActions.push(flatten(mapActionGroup('returnInfo', function () {
|
|
2087
3351
|
return actionsMapReturnsInfo(diff, oldObj, newObj);
|
|
2088
3352
|
})));
|
|
2089
3353
|
allActions.push(mapActionGroup('custom', function () {
|
|
2090
3354
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2091
3355
|
}));
|
|
2092
|
-
return
|
|
3356
|
+
return flatten(allActions);
|
|
2093
3357
|
};
|
|
2094
3358
|
}
|
|
2095
3359
|
var orders = (function (actionGroupList, syncActionConfig) {
|
|
@@ -2183,7 +3447,7 @@
|
|
|
2183
3447
|
allActions.push(mapActionGroup('base', function () {
|
|
2184
3448
|
return actionsMapBase$f(diff, oldObj, newObj, syncActionConfig);
|
|
2185
3449
|
}));
|
|
2186
|
-
return combineValidityActions(
|
|
3450
|
+
return combineValidityActions(flatten(allActions));
|
|
2187
3451
|
};
|
|
2188
3452
|
}
|
|
2189
3453
|
var productDiscounts = (function (actionGroupList) {
|
|
@@ -2252,7 +3516,7 @@
|
|
|
2252
3516
|
allActions.push(mapActionGroup('custom', function () {
|
|
2253
3517
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2254
3518
|
}));
|
|
2255
|
-
return combineValidityActions(
|
|
3519
|
+
return combineValidityActions(flatten(allActions));
|
|
2256
3520
|
};
|
|
2257
3521
|
}
|
|
2258
3522
|
var discountCodes = (function (actionGroupList) {
|
|
@@ -2305,7 +3569,7 @@
|
|
|
2305
3569
|
allActions.push(mapActionGroup('custom', function () {
|
|
2306
3570
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2307
3571
|
}));
|
|
2308
|
-
return
|
|
3572
|
+
return flatten(allActions);
|
|
2309
3573
|
};
|
|
2310
3574
|
}
|
|
2311
3575
|
var customerGroup = (function (actionGroupList) {
|
|
@@ -2377,7 +3641,7 @@
|
|
|
2377
3641
|
allActions.push(mapActionGroup('custom', function () {
|
|
2378
3642
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2379
3643
|
}));
|
|
2380
|
-
return combineValidityActions(
|
|
3644
|
+
return combineValidityActions(flatten(allActions));
|
|
2381
3645
|
};
|
|
2382
3646
|
}
|
|
2383
3647
|
var cartDiscounts = (function (actionGroupList) {
|
|
@@ -2757,7 +4021,7 @@
|
|
|
2757
4021
|
allActions.push(mapActionGroup('rates', function () {
|
|
2758
4022
|
return actionsMapRates(diff, oldObj, newObj);
|
|
2759
4023
|
}));
|
|
2760
|
-
return
|
|
4024
|
+
return flatten(allActions);
|
|
2761
4025
|
};
|
|
2762
4026
|
}
|
|
2763
4027
|
var taxCategories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -2848,10 +4112,10 @@
|
|
|
2848
4112
|
allActions.push(mapActionGroup('base', function () {
|
|
2849
4113
|
return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
|
|
2850
4114
|
}));
|
|
2851
|
-
allActions.push(
|
|
4115
|
+
allActions.push(flatten(mapActionGroup('locations', function () {
|
|
2852
4116
|
return actionsMapLocations(diff, oldObj, newObj);
|
|
2853
4117
|
})));
|
|
2854
|
-
return
|
|
4118
|
+
return flatten(allActions);
|
|
2855
4119
|
};
|
|
2856
4120
|
}
|
|
2857
4121
|
var zones = (function (actionGroupList, syncActionConfig) {
|
|
@@ -2967,7 +4231,7 @@
|
|
|
2967
4231
|
if (diff.zoneRates[key].shippingRates) return [].concat(_toConsumableArray(actions), _toConsumableArray(actionsMapZoneRatesShippingRates(diff.zoneRates[key], oldZoneRate, newZoneRate)));
|
|
2968
4232
|
return actions;
|
|
2969
4233
|
}, []);
|
|
2970
|
-
return
|
|
4234
|
+
return flatten(hasZoneActions ? [].concat(_toConsumableArray(shippingRateActions), [{
|
|
2971
4235
|
action: 'removeZone',
|
|
2972
4236
|
zone: oldZoneRate.zone
|
|
2973
4237
|
}, {
|
|
@@ -2984,13 +4248,13 @@
|
|
|
2984
4248
|
allActions.push(mapActionGroup('base', function () {
|
|
2985
4249
|
return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
|
|
2986
4250
|
}));
|
|
2987
|
-
allActions.push(
|
|
4251
|
+
allActions.push(flatten(mapActionGroup('zoneRates', function () {
|
|
2988
4252
|
return actionsMapZoneRates(diff, oldObj, newObj);
|
|
2989
4253
|
})));
|
|
2990
4254
|
allActions.push(mapActionGroup('custom', function () {
|
|
2991
4255
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
2992
4256
|
}));
|
|
2993
|
-
return
|
|
4257
|
+
return flatten(allActions);
|
|
2994
4258
|
};
|
|
2995
4259
|
}
|
|
2996
4260
|
var shippingMethods = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3122,7 +4386,7 @@
|
|
|
3122
4386
|
action: 'removeAttributeDefinition',
|
|
3123
4387
|
name: attributeDef.previous.name
|
|
3124
4388
|
};
|
|
3125
|
-
})), _toConsumableArray(
|
|
4389
|
+
})), _toConsumableArray(flatten(updatedAttributeDefinitions.map(function (updatedAttributeDefinition) {
|
|
3126
4390
|
return generateBaseFieldsUpdateActions(updatedAttributeDefinition.previous, updatedAttributeDefinition.next, {
|
|
3127
4391
|
label: {
|
|
3128
4392
|
action: 'changeLabel',
|
|
@@ -3172,7 +4436,7 @@
|
|
|
3172
4436
|
return _objectSpread2(_objectSpread2({}, nextEnumUpdateActions), {}, _defineProperty({}, removedAttributeEnumValue.hint.attributeName, _objectSpread2(_objectSpread2({}, removedAttributeEnumValueOfSameAttributeName), {}, {
|
|
3173
4437
|
keys: [].concat(_toConsumableArray(removedAttributeEnumValueOfSameAttributeName.keys), [removedAttributeEnumValue.previous.key])
|
|
3174
4438
|
})));
|
|
3175
|
-
}, {}))), _toConsumableArray(
|
|
4439
|
+
}, {}))), _toConsumableArray(flatten(updatedAttributeEnumValues.map(function (updatedAttributeEnumValue) {
|
|
3176
4440
|
var updateActions = generateBaseFieldsUpdateActions(updatedAttributeEnumValue.previous, updatedAttributeEnumValue.next, {
|
|
3177
4441
|
key: {
|
|
3178
4442
|
action: 'changeEnumKey',
|
|
@@ -3246,7 +4510,7 @@
|
|
|
3246
4510
|
|
|
3247
4511
|
function createProductTypeMapActions(mapActionGroup, syncActionConfig) {
|
|
3248
4512
|
return function doMapActions(diff, next, previous, options) {
|
|
3249
|
-
return
|
|
4513
|
+
return flatten([
|
|
3250
4514
|
// we support only base fields for the product type,
|
|
3251
4515
|
// for attributes, applying hints would be recommended
|
|
3252
4516
|
mapActionGroup('base', function () {
|
|
@@ -3342,7 +4606,7 @@
|
|
|
3342
4606
|
roleActions.push(mapActionGroup('roles', function () {
|
|
3343
4607
|
return actionsMapRoles(diff, oldObj, newObj);
|
|
3344
4608
|
}));
|
|
3345
|
-
return
|
|
4609
|
+
return flatten([].concat(baseActions, _toConsumableArray(groupRoleActions(roleActions))));
|
|
3346
4610
|
};
|
|
3347
4611
|
}
|
|
3348
4612
|
var states = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3395,7 +4659,7 @@
|
|
|
3395
4659
|
allActions.push(mapActionGroup('custom', function () {
|
|
3396
4660
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
3397
4661
|
}));
|
|
3398
|
-
return
|
|
4662
|
+
return flatten(allActions);
|
|
3399
4663
|
};
|
|
3400
4664
|
}
|
|
3401
4665
|
var channels = (function (actionGroupList) {
|
|
@@ -3466,7 +4730,7 @@
|
|
|
3466
4730
|
var foundPreviousEnum = previous.values.find(function (previousEnum) {
|
|
3467
4731
|
return previousEnum.key === newEnum.key;
|
|
3468
4732
|
});
|
|
3469
|
-
var isLabelEqual =
|
|
4733
|
+
var isLabelEqual = isEqual(foundPreviousEnum.label, newEnum.label);
|
|
3470
4734
|
if (isKeyChanged) {
|
|
3471
4735
|
// these actions is then flatten in the end
|
|
3472
4736
|
changeActions.push({
|
|
@@ -3495,7 +4759,7 @@
|
|
|
3495
4759
|
// following lists are necessary to ensure that when we change the
|
|
3496
4760
|
// order of enumValues, we generate one updateAction instead of one at a time.
|
|
3497
4761
|
var newEnumValuesOrder = [];
|
|
3498
|
-
|
|
4762
|
+
flatten(buildArrayActions(attributeDiff, previous, next)).forEach(function (updateAction) {
|
|
3499
4763
|
if (updateAction.action === changeEnumOrderActionName) {
|
|
3500
4764
|
newEnumValuesOrder = next.values.map(function (enumValue) {
|
|
3501
4765
|
return enumValue.key;
|
|
@@ -3510,7 +4774,7 @@
|
|
|
3510
4774
|
}
|
|
3511
4775
|
function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPaths) {
|
|
3512
4776
|
var actions = [];
|
|
3513
|
-
|
|
4777
|
+
forEach(fieldDefinitionsDiff, function (diffValue, diffKey) {
|
|
3514
4778
|
var extractedPairs = extractMatchingPairs(diffPaths, diffKey, previous, next);
|
|
3515
4779
|
if (getIsChangedOperation(diffKey)) {
|
|
3516
4780
|
var _diffValue$type;
|
|
@@ -3561,7 +4825,7 @@
|
|
|
3561
4825
|
// in order to prevent any eventual removal of `addAction`.
|
|
3562
4826
|
// List of `removeActions` can be found here
|
|
3563
4827
|
// https://docs.commercetools.com/http-api-projects-types.html#change-key
|
|
3564
|
-
var sortedActions =
|
|
4828
|
+
var sortedActions = sortBy(actions, function (action) {
|
|
3565
4829
|
return action.action !== 'removeFieldDefinition';
|
|
3566
4830
|
});
|
|
3567
4831
|
return sortedActions;
|
|
@@ -3575,7 +4839,7 @@
|
|
|
3575
4839
|
}), mapActionGroup('fieldDefinitions', function () {
|
|
3576
4840
|
return actionsMapFieldDefinitions(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, findMatchingPairs(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, 'name'));
|
|
3577
4841
|
}));
|
|
3578
|
-
return
|
|
4842
|
+
return flatten(allActions);
|
|
3579
4843
|
};
|
|
3580
4844
|
}
|
|
3581
4845
|
var types = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3677,7 +4941,7 @@
|
|
|
3677
4941
|
allActions.push(mapActionGroup('searchIndexingConfiguration', function () {
|
|
3678
4942
|
return actionsMapSearchIndexingConfiguration(diff, oldObj, newObj);
|
|
3679
4943
|
}));
|
|
3680
|
-
return
|
|
4944
|
+
return flatten(allActions);
|
|
3681
4945
|
};
|
|
3682
4946
|
}
|
|
3683
4947
|
var projects = (function (actionGroupList) {
|
|
@@ -3725,7 +4989,7 @@
|
|
|
3725
4989
|
allActions.push(mapActionGroup('custom', function () {
|
|
3726
4990
|
return actionsMapCustom(diff, next, previous);
|
|
3727
4991
|
}));
|
|
3728
|
-
return
|
|
4992
|
+
return flatten(allActions);
|
|
3729
4993
|
};
|
|
3730
4994
|
}
|
|
3731
4995
|
var stores = (function (actionGroupList) {
|
|
@@ -3768,7 +5032,7 @@
|
|
|
3768
5032
|
allActions.push(mapActionGroup('custom', function () {
|
|
3769
5033
|
return actionsMapCustom(diff, next, previous);
|
|
3770
5034
|
}));
|
|
3771
|
-
return
|
|
5035
|
+
return flatten(allActions);
|
|
3772
5036
|
};
|
|
3773
5037
|
}
|
|
3774
5038
|
var productSelections = (function (actionGroupList) {
|
|
@@ -3903,10 +5167,10 @@
|
|
|
3903
5167
|
allActions.push(mapActionGroup('base', function () {
|
|
3904
5168
|
return actionsMapBase(diff, oldObj, newObj, syncActionConfig);
|
|
3905
5169
|
}));
|
|
3906
|
-
allActions.push(
|
|
5170
|
+
allActions.push(flatten(mapActionGroup('attributes', function () {
|
|
3907
5171
|
return actionsMapAttributes(diff, oldObj, newObj);
|
|
3908
5172
|
})));
|
|
3909
|
-
return
|
|
5173
|
+
return flatten(allActions);
|
|
3910
5174
|
};
|
|
3911
5175
|
}
|
|
3912
5176
|
var attributeGroups = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3940,6 +5204,4 @@
|
|
|
3940
5204
|
exports.createSyncTypes = types;
|
|
3941
5205
|
exports.createSyncZones = zones;
|
|
3942
5206
|
|
|
3943
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3944
|
-
|
|
3945
5207
|
}));
|