@commercetools/sync-actions 6.1.0 → 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 +477 -1665
- package/dist/sync-actions.es.js +419 -1592
- package/dist/sync-actions.umd.js +480 -1666
- 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 -203
package/dist/sync-actions.umd.js
CHANGED
|
@@ -1,21 +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 dmp__default = /*#__PURE__*/_interopDefaultLegacy(dmp);
|
|
13
|
-
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
|
14
|
-
var forEach__default = /*#__PURE__*/_interopDefaultLegacy(forEach);
|
|
15
|
-
var uniqWith__default = /*#__PURE__*/_interopDefaultLegacy(uniqWith);
|
|
16
|
-
var intersection__default = /*#__PURE__*/_interopDefaultLegacy(intersection);
|
|
17
|
-
var without__default = /*#__PURE__*/_interopDefaultLegacy(without);
|
|
18
|
-
var sortBy__default = /*#__PURE__*/_interopDefaultLegacy(sortBy$1);
|
|
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';
|
|
19
6
|
|
|
20
7
|
function _arrayLikeToArray(r, a) {
|
|
21
8
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -28,14 +15,69 @@
|
|
|
28
15
|
function _arrayWithoutHoles(r) {
|
|
29
16
|
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
30
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
|
+
}
|
|
31
39
|
function _defineProperty(e, r, t) {
|
|
32
40
|
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
33
41
|
value: t,
|
|
34
|
-
enumerable:
|
|
35
|
-
configurable:
|
|
36
|
-
writable:
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true
|
|
37
45
|
}) : e[r] = t, e;
|
|
38
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
|
+
}
|
|
39
81
|
function _iterableToArray(r) {
|
|
40
82
|
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
41
83
|
}
|
|
@@ -47,15 +89,15 @@
|
|
|
47
89
|
i,
|
|
48
90
|
u,
|
|
49
91
|
a = [],
|
|
50
|
-
f =
|
|
51
|
-
o =
|
|
92
|
+
f = true,
|
|
93
|
+
o = false;
|
|
52
94
|
try {
|
|
53
95
|
if (i = (t = t.call(r)).next, 0 === l) {
|
|
54
96
|
if (Object(t) !== t) return;
|
|
55
97
|
f = !1;
|
|
56
98
|
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
57
99
|
} catch (r) {
|
|
58
|
-
o =
|
|
100
|
+
o = true, n = r;
|
|
59
101
|
} finally {
|
|
60
102
|
try {
|
|
61
103
|
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
@@ -85,7 +127,7 @@
|
|
|
85
127
|
function _objectSpread2(e) {
|
|
86
128
|
for (var r = 1; r < arguments.length; r++) {
|
|
87
129
|
var t = null != arguments[r] ? arguments[r] : {};
|
|
88
|
-
r % 2 ? ownKeys(Object(t),
|
|
130
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
89
131
|
_defineProperty(e, r, t[r]);
|
|
90
132
|
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
91
133
|
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
@@ -99,8 +141,8 @@
|
|
|
99
141
|
r,
|
|
100
142
|
i = _objectWithoutPropertiesLoose(e, t);
|
|
101
143
|
if (Object.getOwnPropertySymbols) {
|
|
102
|
-
var
|
|
103
|
-
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]);
|
|
104
146
|
}
|
|
105
147
|
return i;
|
|
106
148
|
}
|
|
@@ -108,14 +150,34 @@
|
|
|
108
150
|
if (null == r) return {};
|
|
109
151
|
var t = {};
|
|
110
152
|
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
111
|
-
if (e.
|
|
153
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
112
154
|
t[n] = r[n];
|
|
113
155
|
}
|
|
114
156
|
return t;
|
|
115
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
|
+
}
|
|
116
168
|
function _slicedToArray(r, e) {
|
|
117
169
|
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
118
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
|
+
}
|
|
119
181
|
function _toConsumableArray(r) {
|
|
120
182
|
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
121
183
|
}
|
|
@@ -123,24 +185,24 @@
|
|
|
123
185
|
if ("object" != typeof t || !t) return t;
|
|
124
186
|
var e = t[Symbol.toPrimitive];
|
|
125
187
|
if (void 0 !== e) {
|
|
126
|
-
var i = e.call(t, r
|
|
188
|
+
var i = e.call(t, r);
|
|
127
189
|
if ("object" != typeof i) return i;
|
|
128
190
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
129
191
|
}
|
|
130
|
-
return (
|
|
192
|
+
return (String )(t);
|
|
131
193
|
}
|
|
132
194
|
function _toPropertyKey(t) {
|
|
133
195
|
var i = _toPrimitive(t, "string");
|
|
134
196
|
return "symbol" == typeof i ? i : i + "";
|
|
135
197
|
}
|
|
136
|
-
function _typeof
|
|
198
|
+
function _typeof(o) {
|
|
137
199
|
"@babel/helpers - typeof";
|
|
138
200
|
|
|
139
|
-
return _typeof
|
|
201
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
140
202
|
return typeof o;
|
|
141
203
|
} : function (o) {
|
|
142
204
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
143
|
-
}, _typeof
|
|
205
|
+
}, _typeof(o);
|
|
144
206
|
}
|
|
145
207
|
function _unsupportedIterableToArray(r, a) {
|
|
146
208
|
if (r) {
|
|
@@ -169,7 +231,7 @@
|
|
|
169
231
|
function arePricesStructurallyEqual(oldPrice, newPrice) {
|
|
170
232
|
var oldPriceComparison = createPriceComparator(oldPrice);
|
|
171
233
|
var newPriceComparison = createPriceComparator(newPrice);
|
|
172
|
-
return
|
|
234
|
+
return isEqual(newPriceComparison, oldPriceComparison);
|
|
173
235
|
}
|
|
174
236
|
function extractPriceFromPreviousVariant(newPrice, previousVariant) {
|
|
175
237
|
if (!previousVariant) return null;
|
|
@@ -184,7 +246,7 @@
|
|
|
184
246
|
restOfVariant = _objectWithoutProperties(newVariant, _excluded$2);
|
|
185
247
|
if (!prices) return restOfVariant;
|
|
186
248
|
var oldVariant = previousVariants.find(function (previousVariant) {
|
|
187
|
-
return !
|
|
249
|
+
return !isNil(previousVariant.id) && previousVariant.id === newVariant.id || !isNil(previousVariant.key) && previousVariant.key === newVariant.key || !isNil(previousVariant.sku) && previousVariant.sku === newVariant.sku;
|
|
188
250
|
});
|
|
189
251
|
return _objectSpread2(_objectSpread2({}, restOfVariant), {}, {
|
|
190
252
|
prices: prices.map(function (price) {
|
|
@@ -193,8 +255,8 @@
|
|
|
193
255
|
if (oldPrice) {
|
|
194
256
|
// copy ID if not provided
|
|
195
257
|
if (!newPrice.id) newPrice.id = oldPrice.id;
|
|
196
|
-
if (
|
|
197
|
-
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;
|
|
198
260
|
}
|
|
199
261
|
return newPrice;
|
|
200
262
|
})
|
|
@@ -241,129 +303,23 @@
|
|
|
241
303
|
};
|
|
242
304
|
}
|
|
243
305
|
|
|
244
|
-
var
|
|
245
|
-
return _typeof$1(obj);
|
|
246
|
-
} : function (obj) {
|
|
247
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof$1(obj);
|
|
248
|
-
};
|
|
249
|
-
var classCallCheck = function classCallCheck(instance, Constructor) {
|
|
250
|
-
if (!(instance instanceof Constructor)) {
|
|
251
|
-
throw new TypeError("Cannot call a class as a function");
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
var createClass = function () {
|
|
255
|
-
function defineProperties(target, props) {
|
|
256
|
-
for (var i = 0; i < props.length; i++) {
|
|
257
|
-
var descriptor = props[i];
|
|
258
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
259
|
-
descriptor.configurable = true;
|
|
260
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
261
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return function (Constructor, protoProps, staticProps) {
|
|
265
|
-
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
|
266
|
-
if (staticProps) defineProperties(Constructor, staticProps);
|
|
267
|
-
return Constructor;
|
|
268
|
-
};
|
|
269
|
-
}();
|
|
270
|
-
var get = function get(object, property, receiver) {
|
|
271
|
-
if (object === null) object = Function.prototype;
|
|
272
|
-
var desc = Object.getOwnPropertyDescriptor(object, property);
|
|
273
|
-
if (desc === undefined) {
|
|
274
|
-
var parent = Object.getPrototypeOf(object);
|
|
275
|
-
if (parent === null) {
|
|
276
|
-
return undefined;
|
|
277
|
-
} else {
|
|
278
|
-
return get(parent, property, receiver);
|
|
279
|
-
}
|
|
280
|
-
} else if ("value" in desc) {
|
|
281
|
-
return desc.value;
|
|
282
|
-
} else {
|
|
283
|
-
var getter = desc.get;
|
|
284
|
-
if (getter === undefined) {
|
|
285
|
-
return undefined;
|
|
286
|
-
}
|
|
287
|
-
return getter.call(receiver);
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
var inherits = function inherits(subClass, superClass) {
|
|
291
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
292
|
-
throw new TypeError("Super expression must either be null or a function, not " + _typeof$1(superClass));
|
|
293
|
-
}
|
|
294
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
295
|
-
constructor: {
|
|
296
|
-
value: subClass,
|
|
297
|
-
enumerable: false,
|
|
298
|
-
writable: true,
|
|
299
|
-
configurable: true
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
|
303
|
-
};
|
|
304
|
-
var possibleConstructorReturn = function possibleConstructorReturn(self, call) {
|
|
305
|
-
if (!self) {
|
|
306
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
307
|
-
}
|
|
308
|
-
return call && (_typeof$1(call) === "object" || typeof call === "function") ? call : self;
|
|
309
|
-
};
|
|
310
|
-
var slicedToArray = function () {
|
|
311
|
-
function sliceIterator(arr, i) {
|
|
312
|
-
var _arr = [];
|
|
313
|
-
var _n = true;
|
|
314
|
-
var _d = false;
|
|
315
|
-
var _e = undefined;
|
|
316
|
-
try {
|
|
317
|
-
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
318
|
-
_arr.push(_s.value);
|
|
319
|
-
if (i && _arr.length === i) break;
|
|
320
|
-
}
|
|
321
|
-
} catch (err) {
|
|
322
|
-
_d = true;
|
|
323
|
-
_e = err;
|
|
324
|
-
} finally {
|
|
325
|
-
try {
|
|
326
|
-
if (!_n && _i["return"]) _i["return"]();
|
|
327
|
-
} finally {
|
|
328
|
-
if (_d) throw _e;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return _arr;
|
|
332
|
-
}
|
|
333
|
-
return function (arr, i) {
|
|
334
|
-
if (Array.isArray(arr)) {
|
|
335
|
-
return arr;
|
|
336
|
-
} else if (Symbol.iterator in Object(arr)) {
|
|
337
|
-
return sliceIterator(arr, i);
|
|
338
|
-
} else {
|
|
339
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
}();
|
|
343
|
-
var toConsumableArray = function toConsumableArray(arr) {
|
|
344
|
-
if (Array.isArray(arr)) {
|
|
345
|
-
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
|
346
|
-
return arr2;
|
|
347
|
-
} else {
|
|
348
|
-
return Array.from(arr);
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
var Processor = function () {
|
|
306
|
+
var Processor = /*#__PURE__*/function () {
|
|
352
307
|
function Processor(options) {
|
|
353
|
-
|
|
308
|
+
_classCallCheck(this, Processor);
|
|
354
309
|
this.selfOptions = options || {};
|
|
355
310
|
this.pipes = {};
|
|
356
311
|
}
|
|
357
|
-
|
|
358
|
-
key:
|
|
312
|
+
return _createClass(Processor, [{
|
|
313
|
+
key: "options",
|
|
359
314
|
value: function options(_options) {
|
|
360
315
|
if (_options) {
|
|
361
316
|
this.selfOptions = _options;
|
|
362
317
|
}
|
|
363
318
|
return this.selfOptions;
|
|
364
319
|
}
|
|
320
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
365
321
|
}, {
|
|
366
|
-
key:
|
|
322
|
+
key: "pipe",
|
|
367
323
|
value: function pipe(name, pipeArg) {
|
|
368
324
|
var pipe = pipeArg;
|
|
369
325
|
if (typeof name === 'string') {
|
|
@@ -374,6 +330,7 @@
|
|
|
374
330
|
}
|
|
375
331
|
}
|
|
376
332
|
if (name && name.name) {
|
|
333
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
377
334
|
pipe = name;
|
|
378
335
|
if (pipe.processor === this) {
|
|
379
336
|
return pipe;
|
|
@@ -383,14 +340,14 @@
|
|
|
383
340
|
pipe.processor = this;
|
|
384
341
|
return pipe;
|
|
385
342
|
}
|
|
343
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
386
344
|
}, {
|
|
387
|
-
key:
|
|
345
|
+
key: "process",
|
|
388
346
|
value: function process(input, pipe) {
|
|
389
347
|
var context = input;
|
|
390
348
|
context.options = this.options();
|
|
391
349
|
var nextPipe = pipe || input.pipe || 'default';
|
|
392
|
-
var lastPipe
|
|
393
|
-
var lastContext = void 0;
|
|
350
|
+
var lastPipe;
|
|
394
351
|
while (nextPipe) {
|
|
395
352
|
if (typeof context.nextAfterChildren !== 'undefined') {
|
|
396
353
|
// children processed and coming back to parent
|
|
@@ -401,29 +358,30 @@
|
|
|
401
358
|
nextPipe = this.pipe(nextPipe);
|
|
402
359
|
}
|
|
403
360
|
nextPipe.process(context);
|
|
404
|
-
lastContext = context;
|
|
405
361
|
lastPipe = nextPipe;
|
|
406
362
|
nextPipe = null;
|
|
407
363
|
if (context) {
|
|
408
364
|
if (context.next) {
|
|
409
365
|
context = context.next;
|
|
410
|
-
nextPipe =
|
|
366
|
+
nextPipe = context.pipe || lastPipe;
|
|
411
367
|
}
|
|
412
368
|
}
|
|
413
369
|
}
|
|
370
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
414
371
|
return context.hasResult ? context.result : undefined;
|
|
415
372
|
}
|
|
416
373
|
}]);
|
|
417
|
-
return Processor;
|
|
418
374
|
}();
|
|
419
|
-
|
|
375
|
+
|
|
376
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
377
|
+
var Pipe = /*#__PURE__*/function () {
|
|
420
378
|
function Pipe(name) {
|
|
421
|
-
|
|
379
|
+
_classCallCheck(this, Pipe);
|
|
422
380
|
this.name = name;
|
|
423
381
|
this.filters = [];
|
|
424
382
|
}
|
|
425
|
-
|
|
426
|
-
key:
|
|
383
|
+
return _createClass(Pipe, [{
|
|
384
|
+
key: "process",
|
|
427
385
|
value: function process(input) {
|
|
428
386
|
if (!this.processor) {
|
|
429
387
|
throw new Error('add this pipe to a processor before using it');
|
|
@@ -434,10 +392,10 @@
|
|
|
434
392
|
for (var index = 0; index < length; index++) {
|
|
435
393
|
var filter = this.filters[index];
|
|
436
394
|
if (debug) {
|
|
437
|
-
this.log(
|
|
395
|
+
this.log("filter: ".concat(filter.filterName));
|
|
438
396
|
}
|
|
439
397
|
filter(context);
|
|
440
|
-
if (
|
|
398
|
+
if (_typeof(context) === 'object' && context.exiting) {
|
|
441
399
|
context.exiting = false;
|
|
442
400
|
break;
|
|
443
401
|
}
|
|
@@ -447,26 +405,26 @@
|
|
|
447
405
|
}
|
|
448
406
|
}
|
|
449
407
|
}, {
|
|
450
|
-
key:
|
|
408
|
+
key: "log",
|
|
451
409
|
value: function log(msg) {
|
|
452
|
-
console.log(
|
|
410
|
+
console.log("[jsondiffpatch] ".concat(this.name, " pipe, ").concat(msg));
|
|
453
411
|
}
|
|
454
412
|
}, {
|
|
455
|
-
key:
|
|
413
|
+
key: "append",
|
|
456
414
|
value: function append() {
|
|
457
|
-
var
|
|
458
|
-
(
|
|
415
|
+
var _this$filters;
|
|
416
|
+
(_this$filters = this.filters).push.apply(_this$filters, arguments);
|
|
459
417
|
return this;
|
|
460
418
|
}
|
|
461
419
|
}, {
|
|
462
|
-
key:
|
|
420
|
+
key: "prepend",
|
|
463
421
|
value: function prepend() {
|
|
464
|
-
var
|
|
465
|
-
(
|
|
422
|
+
var _this$filters2;
|
|
423
|
+
(_this$filters2 = this.filters).unshift.apply(_this$filters2, arguments);
|
|
466
424
|
return this;
|
|
467
425
|
}
|
|
468
426
|
}, {
|
|
469
|
-
key:
|
|
427
|
+
key: "indexOf",
|
|
470
428
|
value: function indexOf(filterName) {
|
|
471
429
|
if (!filterName) {
|
|
472
430
|
throw new Error('a filter name is required');
|
|
@@ -477,67 +435,65 @@
|
|
|
477
435
|
return index;
|
|
478
436
|
}
|
|
479
437
|
}
|
|
480
|
-
throw new Error(
|
|
438
|
+
throw new Error("filter not found: ".concat(filterName));
|
|
481
439
|
}
|
|
482
440
|
}, {
|
|
483
|
-
key:
|
|
441
|
+
key: "list",
|
|
484
442
|
value: function list() {
|
|
485
443
|
return this.filters.map(function (f) {
|
|
486
444
|
return f.filterName;
|
|
487
445
|
});
|
|
488
446
|
}
|
|
489
447
|
}, {
|
|
490
|
-
key:
|
|
448
|
+
key: "after",
|
|
491
449
|
value: function after(filterName) {
|
|
450
|
+
var _this$filters3;
|
|
492
451
|
var index = this.indexOf(filterName);
|
|
493
|
-
var params = Array
|
|
494
|
-
|
|
495
|
-
throw new Error('a filter is required');
|
|
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];
|
|
496
454
|
}
|
|
497
|
-
|
|
498
|
-
Array.prototype.splice.apply(this.filters, params);
|
|
455
|
+
(_this$filters3 = this.filters).splice.apply(_this$filters3, [index + 1, 0].concat(params));
|
|
499
456
|
return this;
|
|
500
457
|
}
|
|
501
458
|
}, {
|
|
502
|
-
key:
|
|
459
|
+
key: "before",
|
|
503
460
|
value: function before(filterName) {
|
|
461
|
+
var _this$filters4;
|
|
504
462
|
var index = this.indexOf(filterName);
|
|
505
|
-
var params = Array
|
|
506
|
-
|
|
507
|
-
throw new Error('a filter is required');
|
|
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];
|
|
508
465
|
}
|
|
509
|
-
|
|
510
|
-
Array.prototype.splice.apply(this.filters, params);
|
|
466
|
+
(_this$filters4 = this.filters).splice.apply(_this$filters4, [index, 0].concat(params));
|
|
511
467
|
return this;
|
|
512
468
|
}
|
|
513
469
|
}, {
|
|
514
|
-
key:
|
|
470
|
+
key: "replace",
|
|
515
471
|
value: function replace(filterName) {
|
|
472
|
+
var _this$filters5;
|
|
516
473
|
var index = this.indexOf(filterName);
|
|
517
|
-
var params = Array
|
|
518
|
-
|
|
519
|
-
throw new Error('a filter is required');
|
|
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];
|
|
520
476
|
}
|
|
521
|
-
|
|
522
|
-
Array.prototype.splice.apply(this.filters, params);
|
|
477
|
+
(_this$filters5 = this.filters).splice.apply(_this$filters5, [index, 1].concat(params));
|
|
523
478
|
return this;
|
|
524
479
|
}
|
|
525
480
|
}, {
|
|
526
|
-
key:
|
|
481
|
+
key: "remove",
|
|
527
482
|
value: function remove(filterName) {
|
|
528
483
|
var index = this.indexOf(filterName);
|
|
529
484
|
this.filters.splice(index, 1);
|
|
530
485
|
return this;
|
|
531
486
|
}
|
|
532
487
|
}, {
|
|
533
|
-
key:
|
|
488
|
+
key: "clear",
|
|
534
489
|
value: function clear() {
|
|
535
490
|
this.filters.length = 0;
|
|
536
491
|
return this;
|
|
537
492
|
}
|
|
538
493
|
}, {
|
|
539
|
-
key:
|
|
494
|
+
key: "shouldHaveResult",
|
|
540
495
|
value: function shouldHaveResult(should) {
|
|
496
|
+
var _this = this;
|
|
541
497
|
if (should === false) {
|
|
542
498
|
this.resultCheck = null;
|
|
543
499
|
return;
|
|
@@ -545,11 +501,10 @@
|
|
|
545
501
|
if (this.resultCheck) {
|
|
546
502
|
return;
|
|
547
503
|
}
|
|
548
|
-
var pipe = this;
|
|
549
504
|
this.resultCheck = function (context) {
|
|
550
505
|
if (!context.hasResult) {
|
|
551
506
|
console.log(context);
|
|
552
|
-
var error = new Error(
|
|
507
|
+
var error = new Error("".concat(_this.name, " failed"));
|
|
553
508
|
error.noResult = true;
|
|
554
509
|
throw error;
|
|
555
510
|
}
|
|
@@ -557,40 +512,27 @@
|
|
|
557
512
|
return this;
|
|
558
513
|
}
|
|
559
514
|
}]);
|
|
560
|
-
return Pipe;
|
|
561
515
|
}();
|
|
562
|
-
|
|
516
|
+
|
|
517
|
+
var Context = /*#__PURE__*/function () {
|
|
563
518
|
function Context() {
|
|
564
|
-
|
|
519
|
+
_classCallCheck(this, Context);
|
|
565
520
|
}
|
|
566
|
-
|
|
567
|
-
key:
|
|
521
|
+
return _createClass(Context, [{
|
|
522
|
+
key: "setResult",
|
|
568
523
|
value: function setResult(result) {
|
|
569
524
|
this.result = result;
|
|
570
525
|
this.hasResult = true;
|
|
571
526
|
return this;
|
|
572
527
|
}
|
|
573
528
|
}, {
|
|
574
|
-
key:
|
|
529
|
+
key: "exit",
|
|
575
530
|
value: function exit() {
|
|
576
531
|
this.exiting = true;
|
|
577
532
|
return this;
|
|
578
533
|
}
|
|
579
534
|
}, {
|
|
580
|
-
key:
|
|
581
|
-
value: function switchTo(next, pipe) {
|
|
582
|
-
if (typeof next === 'string' || next instanceof Pipe) {
|
|
583
|
-
this.nextPipe = next;
|
|
584
|
-
} else {
|
|
585
|
-
this.next = next;
|
|
586
|
-
if (pipe) {
|
|
587
|
-
this.nextPipe = pipe;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
return this;
|
|
591
|
-
}
|
|
592
|
-
}, {
|
|
593
|
-
key: 'push',
|
|
535
|
+
key: "push",
|
|
594
536
|
value: function push(child, name) {
|
|
595
537
|
child.parent = this;
|
|
596
538
|
if (typeof name !== 'undefined') {
|
|
@@ -610,23 +552,20 @@
|
|
|
610
552
|
return this;
|
|
611
553
|
}
|
|
612
554
|
}]);
|
|
613
|
-
return Context;
|
|
614
555
|
}();
|
|
615
|
-
|
|
616
|
-
return a instanceof Array;
|
|
617
|
-
};
|
|
556
|
+
|
|
618
557
|
function cloneRegExp(re) {
|
|
619
558
|
var regexMatch = /^\/(.*)\/([gimyu]*)$/.exec(re.toString());
|
|
620
559
|
return new RegExp(regexMatch[1], regexMatch[2]);
|
|
621
560
|
}
|
|
622
561
|
function clone$1(arg) {
|
|
623
|
-
if (
|
|
562
|
+
if (_typeof(arg) !== 'object') {
|
|
624
563
|
return arg;
|
|
625
564
|
}
|
|
626
565
|
if (arg === null) {
|
|
627
566
|
return null;
|
|
628
567
|
}
|
|
629
|
-
if (isArray(arg)) {
|
|
568
|
+
if (Array.isArray(arg)) {
|
|
630
569
|
return arg.map(clone$1);
|
|
631
570
|
}
|
|
632
571
|
if (arg instanceof Date) {
|
|
@@ -643,60 +582,63 @@
|
|
|
643
582
|
}
|
|
644
583
|
return cloned;
|
|
645
584
|
}
|
|
646
|
-
|
|
647
|
-
|
|
585
|
+
|
|
586
|
+
var DiffContext = /*#__PURE__*/function (_Context) {
|
|
648
587
|
function DiffContext(left, right) {
|
|
649
|
-
|
|
650
|
-
|
|
588
|
+
var _this;
|
|
589
|
+
_classCallCheck(this, DiffContext);
|
|
590
|
+
_this = _callSuper(this, DiffContext);
|
|
651
591
|
_this.left = left;
|
|
652
592
|
_this.right = right;
|
|
653
593
|
_this.pipe = 'diff';
|
|
654
594
|
return _this;
|
|
655
595
|
}
|
|
656
|
-
|
|
657
|
-
|
|
596
|
+
_inherits(DiffContext, _Context);
|
|
597
|
+
return _createClass(DiffContext, [{
|
|
598
|
+
key: "setResult",
|
|
658
599
|
value: function setResult(result) {
|
|
659
|
-
if (this.options.cloneDiffValues &&
|
|
660
|
-
var clone
|
|
600
|
+
if (this.options.cloneDiffValues && _typeof(result) === 'object') {
|
|
601
|
+
var clone = typeof this.options.cloneDiffValues === 'function' ? this.options.cloneDiffValues : clone$1;
|
|
661
602
|
if (_typeof(result[0]) === 'object') {
|
|
662
|
-
result[0] = clone
|
|
603
|
+
result[0] = clone(result[0]);
|
|
663
604
|
}
|
|
664
605
|
if (_typeof(result[1]) === 'object') {
|
|
665
|
-
result[1] = clone
|
|
606
|
+
result[1] = clone(result[1]);
|
|
666
607
|
}
|
|
667
608
|
}
|
|
668
|
-
return
|
|
609
|
+
return _superPropGet(DiffContext, "setResult", this, 3)([result]);
|
|
669
610
|
}
|
|
670
611
|
}]);
|
|
671
|
-
return DiffContext;
|
|
672
612
|
}(Context);
|
|
673
|
-
|
|
674
|
-
|
|
613
|
+
|
|
614
|
+
var PatchContext = /*#__PURE__*/function (_Context) {
|
|
675
615
|
function PatchContext(left, delta) {
|
|
676
|
-
|
|
677
|
-
|
|
616
|
+
var _this;
|
|
617
|
+
_classCallCheck(this, PatchContext);
|
|
618
|
+
_this = _callSuper(this, PatchContext);
|
|
678
619
|
_this.left = left;
|
|
679
620
|
_this.delta = delta;
|
|
680
621
|
_this.pipe = 'patch';
|
|
681
622
|
return _this;
|
|
682
623
|
}
|
|
683
|
-
|
|
624
|
+
_inherits(PatchContext, _Context);
|
|
625
|
+
return _createClass(PatchContext);
|
|
684
626
|
}(Context);
|
|
685
|
-
|
|
686
|
-
|
|
627
|
+
|
|
628
|
+
var ReverseContext = /*#__PURE__*/function (_Context) {
|
|
687
629
|
function ReverseContext(delta) {
|
|
688
|
-
|
|
689
|
-
|
|
630
|
+
var _this;
|
|
631
|
+
_classCallCheck(this, ReverseContext);
|
|
632
|
+
_this = _callSuper(this, ReverseContext);
|
|
690
633
|
_this.delta = delta;
|
|
691
634
|
_this.pipe = 'reverse';
|
|
692
635
|
return _this;
|
|
693
636
|
}
|
|
694
|
-
|
|
637
|
+
_inherits(ReverseContext, _Context);
|
|
638
|
+
return _createClass(ReverseContext);
|
|
695
639
|
}(Context);
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
};
|
|
699
|
-
var diffFilter = function trivialMatchesDiffFilter(context) {
|
|
640
|
+
|
|
641
|
+
var diffFilter$3 = function trivialMatchesDiffFilter(context) {
|
|
700
642
|
if (context.left === context.right) {
|
|
701
643
|
context.setResult(undefined).exit();
|
|
702
644
|
return;
|
|
@@ -726,10 +668,10 @@
|
|
|
726
668
|
return;
|
|
727
669
|
}
|
|
728
670
|
if (context.leftType === 'object') {
|
|
729
|
-
context.leftIsArray = isArray
|
|
671
|
+
context.leftIsArray = Array.isArray(context.left);
|
|
730
672
|
}
|
|
731
673
|
if (context.rightType === 'object') {
|
|
732
|
-
context.rightIsArray = isArray
|
|
674
|
+
context.rightIsArray = Array.isArray(context.right);
|
|
733
675
|
}
|
|
734
676
|
if (context.leftIsArray !== context.rightIsArray) {
|
|
735
677
|
context.setResult([context.left, context.right]).exit();
|
|
@@ -743,64 +685,67 @@
|
|
|
743
685
|
}
|
|
744
686
|
}
|
|
745
687
|
};
|
|
746
|
-
diffFilter.filterName = 'trivial';
|
|
747
|
-
var patchFilter = function trivialMatchesPatchFilter(context) {
|
|
688
|
+
diffFilter$3.filterName = 'trivial';
|
|
689
|
+
var patchFilter$3 = function trivialMatchesPatchFilter(context) {
|
|
748
690
|
if (typeof context.delta === 'undefined') {
|
|
749
691
|
context.setResult(context.left).exit();
|
|
750
692
|
return;
|
|
751
693
|
}
|
|
752
|
-
context.nested = !isArray
|
|
694
|
+
context.nested = !Array.isArray(context.delta);
|
|
753
695
|
if (context.nested) {
|
|
754
696
|
return;
|
|
755
697
|
}
|
|
756
|
-
|
|
757
|
-
|
|
698
|
+
var nonNestedDelta = context.delta;
|
|
699
|
+
if (nonNestedDelta.length === 1) {
|
|
700
|
+
context.setResult(nonNestedDelta[0]).exit();
|
|
758
701
|
return;
|
|
759
702
|
}
|
|
760
|
-
if (
|
|
703
|
+
if (nonNestedDelta.length === 2) {
|
|
761
704
|
if (context.left instanceof RegExp) {
|
|
762
|
-
var regexArgs = /^\/(.*)\/([gimyu]+)$/.exec(
|
|
705
|
+
var regexArgs = /^\/(.*)\/([gimyu]+)$/.exec(nonNestedDelta[1]);
|
|
763
706
|
if (regexArgs) {
|
|
764
707
|
context.setResult(new RegExp(regexArgs[1], regexArgs[2])).exit();
|
|
765
708
|
return;
|
|
766
709
|
}
|
|
767
710
|
}
|
|
768
|
-
context.setResult(
|
|
711
|
+
context.setResult(nonNestedDelta[1]).exit();
|
|
769
712
|
return;
|
|
770
713
|
}
|
|
771
|
-
if (
|
|
714
|
+
if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
|
|
772
715
|
context.setResult(undefined).exit();
|
|
773
716
|
}
|
|
774
717
|
};
|
|
775
|
-
patchFilter.filterName = 'trivial';
|
|
776
|
-
var reverseFilter = function trivialReferseFilter(context) {
|
|
718
|
+
patchFilter$3.filterName = 'trivial';
|
|
719
|
+
var reverseFilter$3 = function trivialReferseFilter(context) {
|
|
777
720
|
if (typeof context.delta === 'undefined') {
|
|
778
721
|
context.setResult(context.delta).exit();
|
|
779
722
|
return;
|
|
780
723
|
}
|
|
781
|
-
context.nested = !isArray
|
|
724
|
+
context.nested = !Array.isArray(context.delta);
|
|
782
725
|
if (context.nested) {
|
|
783
726
|
return;
|
|
784
727
|
}
|
|
785
|
-
|
|
786
|
-
|
|
728
|
+
var nonNestedDelta = context.delta;
|
|
729
|
+
if (nonNestedDelta.length === 1) {
|
|
730
|
+
context.setResult([nonNestedDelta[0], 0, 0]).exit();
|
|
787
731
|
return;
|
|
788
732
|
}
|
|
789
|
-
if (
|
|
790
|
-
context.setResult([
|
|
733
|
+
if (nonNestedDelta.length === 2) {
|
|
734
|
+
context.setResult([nonNestedDelta[1], nonNestedDelta[0]]).exit();
|
|
791
735
|
return;
|
|
792
736
|
}
|
|
793
|
-
if (
|
|
794
|
-
context.setResult([
|
|
737
|
+
if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
|
|
738
|
+
context.setResult([nonNestedDelta[0]]).exit();
|
|
795
739
|
}
|
|
796
740
|
};
|
|
797
|
-
reverseFilter.filterName = 'trivial';
|
|
798
|
-
|
|
741
|
+
reverseFilter$3.filterName = 'trivial';
|
|
742
|
+
|
|
743
|
+
var collectChildrenDiffFilter = function collectChildrenDiffFilter(context) {
|
|
799
744
|
if (!context || !context.children) {
|
|
800
745
|
return;
|
|
801
746
|
}
|
|
802
747
|
var length = context.children.length;
|
|
803
|
-
var child
|
|
748
|
+
var child;
|
|
804
749
|
var result = context.result;
|
|
805
750
|
for (var index = 0; index < length; index++) {
|
|
806
751
|
child = context.children[index];
|
|
@@ -814,34 +759,36 @@
|
|
|
814
759
|
result._t = 'a';
|
|
815
760
|
}
|
|
816
761
|
context.setResult(result).exit();
|
|
817
|
-
}
|
|
762
|
+
};
|
|
818
763
|
collectChildrenDiffFilter.filterName = 'collectChildren';
|
|
819
|
-
function objectsDiffFilter(context) {
|
|
764
|
+
var objectsDiffFilter = function objectsDiffFilter(context) {
|
|
820
765
|
if (context.leftIsArray || context.leftType !== 'object') {
|
|
821
766
|
return;
|
|
822
767
|
}
|
|
823
|
-
var
|
|
824
|
-
var
|
|
768
|
+
var left = context.left;
|
|
769
|
+
var right = context.right;
|
|
770
|
+
var name;
|
|
771
|
+
var child;
|
|
825
772
|
var propertyFilter = context.options.propertyFilter;
|
|
826
|
-
for (name in
|
|
827
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
773
|
+
for (name in left) {
|
|
774
|
+
if (!Object.prototype.hasOwnProperty.call(left, name)) {
|
|
828
775
|
continue;
|
|
829
776
|
}
|
|
830
777
|
if (propertyFilter && !propertyFilter(name, context)) {
|
|
831
778
|
continue;
|
|
832
779
|
}
|
|
833
|
-
child = new DiffContext(
|
|
780
|
+
child = new DiffContext(left[name], right[name]);
|
|
834
781
|
context.push(child, name);
|
|
835
782
|
}
|
|
836
|
-
for (name in
|
|
837
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
783
|
+
for (name in right) {
|
|
784
|
+
if (!Object.prototype.hasOwnProperty.call(right, name)) {
|
|
838
785
|
continue;
|
|
839
786
|
}
|
|
840
787
|
if (propertyFilter && !propertyFilter(name, context)) {
|
|
841
788
|
continue;
|
|
842
789
|
}
|
|
843
|
-
if (typeof
|
|
844
|
-
child = new DiffContext(undefined,
|
|
790
|
+
if (typeof left[name] === 'undefined') {
|
|
791
|
+
child = new DiffContext(undefined, right[name]);
|
|
845
792
|
context.push(child, name);
|
|
846
793
|
}
|
|
847
794
|
}
|
|
@@ -850,79 +797,88 @@
|
|
|
850
797
|
return;
|
|
851
798
|
}
|
|
852
799
|
context.exit();
|
|
853
|
-
}
|
|
800
|
+
};
|
|
854
801
|
objectsDiffFilter.filterName = 'objects';
|
|
855
|
-
var patchFilter$
|
|
802
|
+
var patchFilter$2 = function nestedPatchFilter(context) {
|
|
856
803
|
if (!context.nested) {
|
|
857
804
|
return;
|
|
858
805
|
}
|
|
859
|
-
|
|
806
|
+
var nestedDelta = context.delta;
|
|
807
|
+
if (nestedDelta._t) {
|
|
860
808
|
return;
|
|
861
809
|
}
|
|
862
|
-
var
|
|
863
|
-
var
|
|
864
|
-
|
|
865
|
-
|
|
810
|
+
var objectDelta = nestedDelta;
|
|
811
|
+
var name;
|
|
812
|
+
var child;
|
|
813
|
+
for (name in objectDelta) {
|
|
814
|
+
child = new PatchContext(context.left[name], objectDelta[name]);
|
|
866
815
|
context.push(child, name);
|
|
867
816
|
}
|
|
868
817
|
context.exit();
|
|
869
818
|
};
|
|
870
|
-
patchFilter$
|
|
871
|
-
var collectChildrenPatchFilter = function collectChildrenPatchFilter(context) {
|
|
819
|
+
patchFilter$2.filterName = 'objects';
|
|
820
|
+
var collectChildrenPatchFilter$1 = function collectChildrenPatchFilter(context) {
|
|
872
821
|
if (!context || !context.children) {
|
|
873
822
|
return;
|
|
874
823
|
}
|
|
875
|
-
|
|
824
|
+
var deltaWithChildren = context.delta;
|
|
825
|
+
if (deltaWithChildren._t) {
|
|
876
826
|
return;
|
|
877
827
|
}
|
|
828
|
+
var object = context.left;
|
|
878
829
|
var length = context.children.length;
|
|
879
|
-
var child
|
|
830
|
+
var child;
|
|
880
831
|
for (var index = 0; index < length; index++) {
|
|
881
832
|
child = context.children[index];
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
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;
|
|
886
838
|
}
|
|
887
839
|
}
|
|
888
|
-
context.setResult(
|
|
840
|
+
context.setResult(object).exit();
|
|
889
841
|
};
|
|
890
|
-
collectChildrenPatchFilter.filterName = 'collectChildren';
|
|
891
|
-
var reverseFilter$
|
|
842
|
+
collectChildrenPatchFilter$1.filterName = 'collectChildren';
|
|
843
|
+
var reverseFilter$2 = function nestedReverseFilter(context) {
|
|
892
844
|
if (!context.nested) {
|
|
893
845
|
return;
|
|
894
846
|
}
|
|
895
|
-
|
|
847
|
+
var nestedDelta = context.delta;
|
|
848
|
+
if (nestedDelta._t) {
|
|
896
849
|
return;
|
|
897
850
|
}
|
|
898
|
-
var
|
|
899
|
-
var
|
|
900
|
-
|
|
901
|
-
|
|
851
|
+
var objectDelta = context.delta;
|
|
852
|
+
var name;
|
|
853
|
+
var child;
|
|
854
|
+
for (name in objectDelta) {
|
|
855
|
+
child = new ReverseContext(objectDelta[name]);
|
|
902
856
|
context.push(child, name);
|
|
903
857
|
}
|
|
904
858
|
context.exit();
|
|
905
859
|
};
|
|
906
|
-
reverseFilter$
|
|
907
|
-
function collectChildrenReverseFilter(context) {
|
|
860
|
+
reverseFilter$2.filterName = 'objects';
|
|
861
|
+
var collectChildrenReverseFilter$1 = function collectChildrenReverseFilter(context) {
|
|
908
862
|
if (!context || !context.children) {
|
|
909
863
|
return;
|
|
910
864
|
}
|
|
911
|
-
|
|
865
|
+
var deltaWithChildren = context.delta;
|
|
866
|
+
if (deltaWithChildren._t) {
|
|
912
867
|
return;
|
|
913
868
|
}
|
|
914
869
|
var length = context.children.length;
|
|
915
|
-
var child
|
|
870
|
+
var child;
|
|
916
871
|
var delta = {};
|
|
917
872
|
for (var index = 0; index < length; index++) {
|
|
918
873
|
child = context.children[index];
|
|
919
|
-
|
|
920
|
-
|
|
874
|
+
var property = child.childName;
|
|
875
|
+
if (delta[property] !== child.result) {
|
|
876
|
+
delta[property] = child.result;
|
|
921
877
|
}
|
|
922
878
|
}
|
|
923
879
|
context.setResult(delta).exit();
|
|
924
|
-
}
|
|
925
|
-
collectChildrenReverseFilter.filterName = 'collectChildren';
|
|
880
|
+
};
|
|
881
|
+
collectChildrenReverseFilter$1.filterName = 'collectChildren';
|
|
926
882
|
|
|
927
883
|
/*
|
|
928
884
|
|
|
@@ -931,20 +887,17 @@
|
|
|
931
887
|
reference: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
|
|
932
888
|
|
|
933
889
|
*/
|
|
934
|
-
|
|
935
890
|
var defaultMatch = function defaultMatch(array1, array2, index1, index2) {
|
|
936
891
|
return array1[index1] === array2[index2];
|
|
937
892
|
};
|
|
938
893
|
var lengthMatrix = function lengthMatrix(array1, array2, match, context) {
|
|
939
894
|
var len1 = array1.length;
|
|
940
895
|
var len2 = array2.length;
|
|
941
|
-
var x
|
|
942
|
-
y = void 0;
|
|
943
|
-
|
|
896
|
+
var x, y;
|
|
944
897
|
// initialize empty matrix of len1+1 x len2+1
|
|
945
|
-
var matrix =
|
|
898
|
+
var matrix = new Array(len1 + 1);
|
|
946
899
|
for (x = 0; x < len1 + 1; x++) {
|
|
947
|
-
matrix[x] =
|
|
900
|
+
matrix[x] = new Array(len2 + 1);
|
|
948
901
|
for (y = 0; y < len2 + 1; y++) {
|
|
949
902
|
matrix[x][y] = 0;
|
|
950
903
|
}
|
|
@@ -990,33 +943,16 @@
|
|
|
990
943
|
}
|
|
991
944
|
return subsequence;
|
|
992
945
|
};
|
|
993
|
-
var get
|
|
946
|
+
var get = function get(array1, array2, match, context) {
|
|
994
947
|
var innerContext = context || {};
|
|
995
948
|
var matrix = lengthMatrix(array1, array2, match || defaultMatch, innerContext);
|
|
996
|
-
|
|
997
|
-
if (typeof array1 === 'string' && typeof array2 === 'string') {
|
|
998
|
-
result.sequence = result.sequence.join('');
|
|
999
|
-
}
|
|
1000
|
-
return result;
|
|
949
|
+
return backtrack(matrix, array1, array2, innerContext);
|
|
1001
950
|
};
|
|
1002
951
|
var lcs = {
|
|
1003
|
-
get: get
|
|
952
|
+
get: get
|
|
1004
953
|
};
|
|
954
|
+
|
|
1005
955
|
var ARRAY_MOVE = 3;
|
|
1006
|
-
var isArray$2 = typeof Array.isArray === 'function' ? Array.isArray : function (a) {
|
|
1007
|
-
return a instanceof Array;
|
|
1008
|
-
};
|
|
1009
|
-
var arrayIndexOf = typeof Array.prototype.indexOf === 'function' ? function (array, item) {
|
|
1010
|
-
return array.indexOf(item);
|
|
1011
|
-
} : function (array, item) {
|
|
1012
|
-
var length = array.length;
|
|
1013
|
-
for (var i = 0; i < length; i++) {
|
|
1014
|
-
if (array[i] === item) {
|
|
1015
|
-
return i;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
return -1;
|
|
1019
|
-
};
|
|
1020
956
|
function arraysHaveMatchByRef(array1, array2, len1, len2) {
|
|
1021
957
|
for (var index1 = 0; index1 < len1; index1++) {
|
|
1022
958
|
var val1 = array1[index1];
|
|
@@ -1034,7 +970,7 @@
|
|
|
1034
970
|
if (value1 === value2) {
|
|
1035
971
|
return true;
|
|
1036
972
|
}
|
|
1037
|
-
if (
|
|
973
|
+
if (_typeof(value1) !== 'object' || _typeof(value2) !== 'object') {
|
|
1038
974
|
return false;
|
|
1039
975
|
}
|
|
1040
976
|
var objectHash = context.objectHash;
|
|
@@ -1042,35 +978,25 @@
|
|
|
1042
978
|
// no way to match objects was provided, try match by position
|
|
1043
979
|
return context.matchByPosition && index1 === index2;
|
|
1044
980
|
}
|
|
1045
|
-
|
|
1046
|
-
var
|
|
1047
|
-
if (typeof
|
|
1048
|
-
context.hashCache1 =
|
|
1049
|
-
hash1 = context.hashCache1[index1];
|
|
1050
|
-
if (typeof hash1 === 'undefined') {
|
|
1051
|
-
context.hashCache1[index1] = hash1 = objectHash(value1, index1);
|
|
1052
|
-
}
|
|
1053
|
-
} else {
|
|
1054
|
-
hash1 = objectHash(value1);
|
|
981
|
+
context.hashCache1 = context.hashCache1 || [];
|
|
982
|
+
var hash1 = context.hashCache1[index1];
|
|
983
|
+
if (typeof hash1 === 'undefined') {
|
|
984
|
+
context.hashCache1[index1] = hash1 = objectHash(value1, index1);
|
|
1055
985
|
}
|
|
1056
986
|
if (typeof hash1 === 'undefined') {
|
|
1057
987
|
return false;
|
|
1058
988
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
context.hashCache2[index2] = hash2 = objectHash(value2, index2);
|
|
1064
|
-
}
|
|
1065
|
-
} else {
|
|
1066
|
-
hash2 = objectHash(value2);
|
|
989
|
+
context.hashCache2 = context.hashCache2 || [];
|
|
990
|
+
var hash2 = context.hashCache2[index2];
|
|
991
|
+
if (typeof hash2 === 'undefined') {
|
|
992
|
+
context.hashCache2[index2] = hash2 = objectHash(value2, index2);
|
|
1067
993
|
}
|
|
1068
994
|
if (typeof hash2 === 'undefined') {
|
|
1069
995
|
return false;
|
|
1070
996
|
}
|
|
1071
997
|
return hash1 === hash2;
|
|
1072
998
|
}
|
|
1073
|
-
var diffFilter$
|
|
999
|
+
var diffFilter$2 = function arraysDiffFilter(context) {
|
|
1074
1000
|
if (!context.leftIsArray) {
|
|
1075
1001
|
return;
|
|
1076
1002
|
}
|
|
@@ -1080,22 +1006,21 @@
|
|
|
1080
1006
|
};
|
|
1081
1007
|
var commonHead = 0;
|
|
1082
1008
|
var commonTail = 0;
|
|
1083
|
-
var index
|
|
1084
|
-
var index1
|
|
1085
|
-
var index2
|
|
1009
|
+
var index;
|
|
1010
|
+
var index1;
|
|
1011
|
+
var index2;
|
|
1086
1012
|
var array1 = context.left;
|
|
1087
1013
|
var array2 = context.right;
|
|
1088
1014
|
var len1 = array1.length;
|
|
1089
1015
|
var len2 = array2.length;
|
|
1090
|
-
var child
|
|
1016
|
+
var child;
|
|
1091
1017
|
if (len1 > 0 && len2 > 0 && !matchContext.objectHash && typeof matchContext.matchByPosition !== 'boolean') {
|
|
1092
1018
|
matchContext.matchByPosition = !arraysHaveMatchByRef(array1, array2, len1, len2);
|
|
1093
1019
|
}
|
|
1094
|
-
|
|
1095
1020
|
// separate common head
|
|
1096
1021
|
while (commonHead < len1 && commonHead < len2 && matchItems(array1, array2, commonHead, commonHead, matchContext)) {
|
|
1097
1022
|
index = commonHead;
|
|
1098
|
-
child = new DiffContext(
|
|
1023
|
+
child = new DiffContext(array1[index], array2[index]);
|
|
1099
1024
|
context.push(child, index);
|
|
1100
1025
|
commonHead++;
|
|
1101
1026
|
}
|
|
@@ -1103,11 +1028,11 @@
|
|
|
1103
1028
|
while (commonTail + commonHead < len1 && commonTail + commonHead < len2 && matchItems(array1, array2, len1 - 1 - commonTail, len2 - 1 - commonTail, matchContext)) {
|
|
1104
1029
|
index1 = len1 - 1 - commonTail;
|
|
1105
1030
|
index2 = len2 - 1 - commonTail;
|
|
1106
|
-
child = new DiffContext(
|
|
1031
|
+
child = new DiffContext(array1[index1], array2[index2]);
|
|
1107
1032
|
context.push(child, index2);
|
|
1108
1033
|
commonTail++;
|
|
1109
1034
|
}
|
|
1110
|
-
var result
|
|
1035
|
+
var result;
|
|
1111
1036
|
if (commonHead + commonTail === len1) {
|
|
1112
1037
|
if (len1 === len2) {
|
|
1113
1038
|
// arrays are identical
|
|
@@ -1130,7 +1055,7 @@
|
|
|
1130
1055
|
_t: 'a'
|
|
1131
1056
|
};
|
|
1132
1057
|
for (index = commonHead; index < len1 - commonTail; index++) {
|
|
1133
|
-
result[
|
|
1058
|
+
result["_".concat(index)] = [array1[index], 0, 0];
|
|
1134
1059
|
}
|
|
1135
1060
|
context.setResult(result).exit();
|
|
1136
1061
|
return;
|
|
@@ -1138,7 +1063,6 @@
|
|
|
1138
1063
|
// reset hash cache
|
|
1139
1064
|
delete matchContext.hashCache1;
|
|
1140
1065
|
delete matchContext.hashCache2;
|
|
1141
|
-
|
|
1142
1066
|
// diff is not trivial, find the LCS (Longest Common Subsequence)
|
|
1143
1067
|
var trimmed1 = array1.slice(commonHead, len1 - commonTail);
|
|
1144
1068
|
var trimmed2 = array2.slice(commonHead, len2 - commonTail);
|
|
@@ -1148,9 +1072,9 @@
|
|
|
1148
1072
|
_t: 'a'
|
|
1149
1073
|
};
|
|
1150
1074
|
for (index = commonHead; index < len1 - commonTail; index++) {
|
|
1151
|
-
if (
|
|
1075
|
+
if (seq.indices1.indexOf(index - commonHead) < 0) {
|
|
1152
1076
|
// removed
|
|
1153
|
-
result[
|
|
1077
|
+
result["_".concat(index)] = [array1[index], 0, 0];
|
|
1154
1078
|
removedItems.push(index);
|
|
1155
1079
|
}
|
|
1156
1080
|
}
|
|
@@ -1164,7 +1088,7 @@
|
|
|
1164
1088
|
}
|
|
1165
1089
|
var removedItemsLength = removedItems.length;
|
|
1166
1090
|
for (index = commonHead; index < len2 - commonTail; index++) {
|
|
1167
|
-
var indexOnArray2 =
|
|
1091
|
+
var indexOnArray2 = seq.indices2.indexOf(index - commonHead);
|
|
1168
1092
|
if (indexOnArray2 < 0) {
|
|
1169
1093
|
// added, try to match with a removed item and register as position move
|
|
1170
1094
|
var isMove = false;
|
|
@@ -1173,13 +1097,13 @@
|
|
|
1173
1097
|
index1 = removedItems[removeItemIndex1];
|
|
1174
1098
|
if (matchItems(trimmed1, trimmed2, index1 - commonHead, index - commonHead, matchContext)) {
|
|
1175
1099
|
// store position move as: [originalValue, newPosition, ARRAY_MOVE]
|
|
1176
|
-
result[
|
|
1100
|
+
result["_".concat(index1)].splice(1, 2, index, ARRAY_MOVE);
|
|
1177
1101
|
if (!includeValueOnMove) {
|
|
1178
1102
|
// don't include moved value on diff, to save bytes
|
|
1179
|
-
result[
|
|
1103
|
+
result["_".concat(index1)][0] = '';
|
|
1180
1104
|
}
|
|
1181
1105
|
index2 = index;
|
|
1182
|
-
child = new DiffContext(
|
|
1106
|
+
child = new DiffContext(array1[index1], array2[index2]);
|
|
1183
1107
|
context.push(child, index2);
|
|
1184
1108
|
removedItems.splice(removeItemIndex1, 1);
|
|
1185
1109
|
isMove = true;
|
|
@@ -1195,13 +1119,13 @@
|
|
|
1195
1119
|
// match, do inner diff
|
|
1196
1120
|
index1 = seq.indices1[indexOnArray2] + commonHead;
|
|
1197
1121
|
index2 = seq.indices2[indexOnArray2] + commonHead;
|
|
1198
|
-
child = new DiffContext(
|
|
1122
|
+
child = new DiffContext(array1[index1], array2[index2]);
|
|
1199
1123
|
context.push(child, index2);
|
|
1200
1124
|
}
|
|
1201
1125
|
}
|
|
1202
1126
|
context.setResult(result).exit();
|
|
1203
1127
|
};
|
|
1204
|
-
diffFilter$
|
|
1128
|
+
diffFilter$2.filterName = 'arrays';
|
|
1205
1129
|
var compare = {
|
|
1206
1130
|
numerically: function numerically(a, b) {
|
|
1207
1131
|
return a - b;
|
|
@@ -1212,18 +1136,18 @@
|
|
|
1212
1136
|
};
|
|
1213
1137
|
}
|
|
1214
1138
|
};
|
|
1215
|
-
var patchFilter$
|
|
1139
|
+
var patchFilter$1 = function nestedPatchFilter(context) {
|
|
1216
1140
|
if (!context.nested) {
|
|
1217
1141
|
return;
|
|
1218
1142
|
}
|
|
1219
|
-
|
|
1143
|
+
var nestedDelta = context.delta;
|
|
1144
|
+
if (nestedDelta._t !== 'a') {
|
|
1220
1145
|
return;
|
|
1221
1146
|
}
|
|
1222
|
-
var index
|
|
1223
|
-
var index1
|
|
1224
|
-
var delta =
|
|
1147
|
+
var index;
|
|
1148
|
+
var index1;
|
|
1149
|
+
var delta = nestedDelta;
|
|
1225
1150
|
var array = context.left;
|
|
1226
|
-
|
|
1227
1151
|
// first, separate removals, insertions and modifications
|
|
1228
1152
|
var toRemove = [];
|
|
1229
1153
|
var toInsert = [];
|
|
@@ -1231,35 +1155,36 @@
|
|
|
1231
1155
|
for (index in delta) {
|
|
1232
1156
|
if (index !== '_t') {
|
|
1233
1157
|
if (index[0] === '_') {
|
|
1158
|
+
var removedOrMovedIndex = index;
|
|
1234
1159
|
// removed item from original array
|
|
1235
|
-
if (delta[
|
|
1160
|
+
if (delta[removedOrMovedIndex][2] === 0 || delta[removedOrMovedIndex][2] === ARRAY_MOVE) {
|
|
1236
1161
|
toRemove.push(parseInt(index.slice(1), 10));
|
|
1237
1162
|
} else {
|
|
1238
|
-
throw new Error('only removal or move can be applied at original array indices,' +
|
|
1163
|
+
throw new Error('only removal or move can be applied at original array indices,' + " invalid diff type: ".concat(delta[removedOrMovedIndex][2]));
|
|
1239
1164
|
}
|
|
1240
1165
|
} else {
|
|
1241
|
-
|
|
1166
|
+
var numberIndex = index;
|
|
1167
|
+
if (delta[numberIndex].length === 1) {
|
|
1242
1168
|
// added item at new array
|
|
1243
1169
|
toInsert.push({
|
|
1244
|
-
index: parseInt(
|
|
1245
|
-
value: delta[
|
|
1170
|
+
index: parseInt(numberIndex, 10),
|
|
1171
|
+
value: delta[numberIndex][0]
|
|
1246
1172
|
});
|
|
1247
1173
|
} else {
|
|
1248
1174
|
// modified item at new array
|
|
1249
1175
|
toModify.push({
|
|
1250
|
-
index: parseInt(
|
|
1251
|
-
delta: delta[
|
|
1176
|
+
index: parseInt(numberIndex, 10),
|
|
1177
|
+
delta: delta[numberIndex]
|
|
1252
1178
|
});
|
|
1253
1179
|
}
|
|
1254
1180
|
}
|
|
1255
1181
|
}
|
|
1256
1182
|
}
|
|
1257
|
-
|
|
1258
1183
|
// remove items, in reverse order to avoid sawing our own floor
|
|
1259
1184
|
toRemove = toRemove.sort(compare.numerically);
|
|
1260
1185
|
for (index = toRemove.length - 1; index >= 0; index--) {
|
|
1261
1186
|
index1 = toRemove[index];
|
|
1262
|
-
var indexDiff = delta[
|
|
1187
|
+
var indexDiff = delta["_".concat(index1)];
|
|
1263
1188
|
var removedValue = array.splice(index1, 1)[0];
|
|
1264
1189
|
if (indexDiff[2] === ARRAY_MOVE) {
|
|
1265
1190
|
// reinsert later
|
|
@@ -1269,7 +1194,6 @@
|
|
|
1269
1194
|
});
|
|
1270
1195
|
}
|
|
1271
1196
|
}
|
|
1272
|
-
|
|
1273
1197
|
// insert items, in reverse order to avoid moving our own floor
|
|
1274
1198
|
toInsert = toInsert.sort(compare.numericallyBy('index'));
|
|
1275
1199
|
var toInsertLength = toInsert.length;
|
|
@@ -1277,75 +1201,81 @@
|
|
|
1277
1201
|
var insertion = toInsert[index];
|
|
1278
1202
|
array.splice(insertion.index, 0, insertion.value);
|
|
1279
1203
|
}
|
|
1280
|
-
|
|
1281
1204
|
// apply modifications
|
|
1282
1205
|
var toModifyLength = toModify.length;
|
|
1283
|
-
var child
|
|
1206
|
+
var child;
|
|
1284
1207
|
if (toModifyLength > 0) {
|
|
1285
1208
|
for (index = 0; index < toModifyLength; index++) {
|
|
1286
1209
|
var modification = toModify[index];
|
|
1287
|
-
child = new PatchContext(
|
|
1210
|
+
child = new PatchContext(array[modification.index], modification.delta);
|
|
1288
1211
|
context.push(child, modification.index);
|
|
1289
1212
|
}
|
|
1290
1213
|
}
|
|
1291
1214
|
if (!context.children) {
|
|
1292
|
-
context.setResult(
|
|
1215
|
+
context.setResult(array).exit();
|
|
1293
1216
|
return;
|
|
1294
1217
|
}
|
|
1295
1218
|
context.exit();
|
|
1296
1219
|
};
|
|
1297
|
-
patchFilter$
|
|
1298
|
-
var collectChildrenPatchFilter
|
|
1220
|
+
patchFilter$1.filterName = 'arrays';
|
|
1221
|
+
var collectChildrenPatchFilter = function collectChildrenPatchFilter(context) {
|
|
1299
1222
|
if (!context || !context.children) {
|
|
1300
1223
|
return;
|
|
1301
1224
|
}
|
|
1302
|
-
|
|
1225
|
+
var deltaWithChildren = context.delta;
|
|
1226
|
+
if (deltaWithChildren._t !== 'a') {
|
|
1303
1227
|
return;
|
|
1304
1228
|
}
|
|
1229
|
+
var array = context.left;
|
|
1305
1230
|
var length = context.children.length;
|
|
1306
|
-
var child
|
|
1231
|
+
var child;
|
|
1307
1232
|
for (var index = 0; index < length; index++) {
|
|
1308
1233
|
child = context.children[index];
|
|
1309
|
-
|
|
1234
|
+
var arrayIndex = child.childName;
|
|
1235
|
+
array[arrayIndex] = child.result;
|
|
1310
1236
|
}
|
|
1311
|
-
context.setResult(
|
|
1237
|
+
context.setResult(array).exit();
|
|
1312
1238
|
};
|
|
1313
|
-
collectChildrenPatchFilter
|
|
1314
|
-
var reverseFilter$
|
|
1239
|
+
collectChildrenPatchFilter.filterName = 'arraysCollectChildren';
|
|
1240
|
+
var reverseFilter$1 = function arraysReverseFilter(context) {
|
|
1315
1241
|
if (!context.nested) {
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
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();
|
|
1319
1247
|
}
|
|
1320
1248
|
return;
|
|
1321
1249
|
}
|
|
1322
|
-
|
|
1250
|
+
var nestedDelta = context.delta;
|
|
1251
|
+
if (nestedDelta._t !== 'a') {
|
|
1323
1252
|
return;
|
|
1324
1253
|
}
|
|
1325
|
-
var
|
|
1326
|
-
var
|
|
1327
|
-
|
|
1254
|
+
var arrayDelta = nestedDelta;
|
|
1255
|
+
var name;
|
|
1256
|
+
var child;
|
|
1257
|
+
for (name in arrayDelta) {
|
|
1328
1258
|
if (name === '_t') {
|
|
1329
1259
|
continue;
|
|
1330
1260
|
}
|
|
1331
|
-
child = new ReverseContext(
|
|
1261
|
+
child = new ReverseContext(arrayDelta[name]);
|
|
1332
1262
|
context.push(child, name);
|
|
1333
1263
|
}
|
|
1334
1264
|
context.exit();
|
|
1335
1265
|
};
|
|
1336
|
-
reverseFilter$
|
|
1266
|
+
reverseFilter$1.filterName = 'arrays';
|
|
1337
1267
|
var reverseArrayDeltaIndex = function reverseArrayDeltaIndex(delta, index, itemDelta) {
|
|
1338
1268
|
if (typeof index === 'string' && index[0] === '_') {
|
|
1339
|
-
return parseInt(index.
|
|
1340
|
-
} else if (isArray
|
|
1341
|
-
return
|
|
1269
|
+
return parseInt(index.substring(1), 10);
|
|
1270
|
+
} else if (Array.isArray(itemDelta) && itemDelta[2] === 0) {
|
|
1271
|
+
return "_".concat(index);
|
|
1342
1272
|
}
|
|
1343
1273
|
var reverseIndex = +index;
|
|
1344
1274
|
for (var deltaIndex in delta) {
|
|
1345
1275
|
var deltaItem = delta[deltaIndex];
|
|
1346
|
-
if (isArray
|
|
1276
|
+
if (Array.isArray(deltaItem)) {
|
|
1347
1277
|
if (deltaItem[2] === ARRAY_MOVE) {
|
|
1348
|
-
var moveFromIndex = parseInt(deltaIndex.
|
|
1278
|
+
var moveFromIndex = parseInt(deltaIndex.substring(1), 10);
|
|
1349
1279
|
var moveToIndex = deltaItem[1];
|
|
1350
1280
|
if (moveToIndex === +index) {
|
|
1351
1281
|
return moveFromIndex;
|
|
@@ -1356,26 +1286,28 @@
|
|
|
1356
1286
|
reverseIndex--;
|
|
1357
1287
|
}
|
|
1358
1288
|
} else if (deltaItem[2] === 0) {
|
|
1359
|
-
var deleteIndex = parseInt(deltaIndex.
|
|
1289
|
+
var deleteIndex = parseInt(deltaIndex.substring(1), 10);
|
|
1360
1290
|
if (deleteIndex <= reverseIndex) {
|
|
1361
1291
|
reverseIndex++;
|
|
1362
1292
|
}
|
|
1363
|
-
} else if (deltaItem.length === 1 && deltaIndex <= reverseIndex) {
|
|
1293
|
+
} else if (deltaItem.length === 1 && parseInt(deltaIndex, 10) <= reverseIndex) {
|
|
1364
1294
|
reverseIndex--;
|
|
1365
1295
|
}
|
|
1366
1296
|
}
|
|
1367
1297
|
}
|
|
1368
1298
|
return reverseIndex;
|
|
1369
1299
|
};
|
|
1370
|
-
function collectChildrenReverseFilter
|
|
1300
|
+
var collectChildrenReverseFilter = function collectChildrenReverseFilter(context) {
|
|
1371
1301
|
if (!context || !context.children) {
|
|
1372
1302
|
return;
|
|
1373
1303
|
}
|
|
1374
|
-
|
|
1304
|
+
var deltaWithChildren = context.delta;
|
|
1305
|
+
if (deltaWithChildren._t !== 'a') {
|
|
1375
1306
|
return;
|
|
1376
1307
|
}
|
|
1308
|
+
var arrayDelta = deltaWithChildren;
|
|
1377
1309
|
var length = context.children.length;
|
|
1378
|
-
var child
|
|
1310
|
+
var child;
|
|
1379
1311
|
var delta = {
|
|
1380
1312
|
_t: 'a'
|
|
1381
1313
|
};
|
|
@@ -1383,16 +1315,18 @@
|
|
|
1383
1315
|
child = context.children[index];
|
|
1384
1316
|
var name = child.newName;
|
|
1385
1317
|
if (typeof name === 'undefined') {
|
|
1386
|
-
name = reverseArrayDeltaIndex(
|
|
1318
|
+
name = reverseArrayDeltaIndex(arrayDelta, child.childName, child.result);
|
|
1387
1319
|
}
|
|
1388
1320
|
if (delta[name] !== child.result) {
|
|
1321
|
+
// There's no way to type this well.
|
|
1389
1322
|
delta[name] = child.result;
|
|
1390
1323
|
}
|
|
1391
1324
|
}
|
|
1392
1325
|
context.setResult(delta).exit();
|
|
1393
|
-
}
|
|
1394
|
-
collectChildrenReverseFilter
|
|
1395
|
-
|
|
1326
|
+
};
|
|
1327
|
+
collectChildrenReverseFilter.filterName = 'arraysCollectChildren';
|
|
1328
|
+
|
|
1329
|
+
var diffFilter$1 = function datesDiffFilter(context) {
|
|
1396
1330
|
if (context.left instanceof Date) {
|
|
1397
1331
|
if (context.right instanceof Date) {
|
|
1398
1332
|
if (context.left.getTime() !== context.right.getTime()) {
|
|
@@ -1408,34 +1342,22 @@
|
|
|
1408
1342
|
context.setResult([context.left, context.right]).exit();
|
|
1409
1343
|
}
|
|
1410
1344
|
};
|
|
1411
|
-
diffFilter$
|
|
1345
|
+
diffFilter$1.filterName = 'dates';
|
|
1412
1346
|
|
|
1413
|
-
/* global diff_match_patch */
|
|
1414
1347
|
var TEXT_DIFF = 2;
|
|
1415
1348
|
var DEFAULT_MIN_LENGTH = 60;
|
|
1416
1349
|
var cachedDiffPatch = null;
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1350
|
+
function getDiffMatchPatch(options, required) {
|
|
1351
|
+
var _a;
|
|
1420
1352
|
if (!cachedDiffPatch) {
|
|
1421
|
-
var instance
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
instance = typeof diff_match_patch === 'function' ? new diff_match_patch() : new diff_match_patch.diff_match_patch();
|
|
1426
|
-
} else if (dmp__default["default"]) {
|
|
1427
|
-
try {
|
|
1428
|
-
instance = dmp__default["default"] && new dmp__default["default"]();
|
|
1429
|
-
} catch (err) {
|
|
1430
|
-
instance = null;
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
/* eslint-enable camelcase, new-cap */
|
|
1434
|
-
if (!instance) {
|
|
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 {
|
|
1435
1357
|
if (!required) {
|
|
1436
1358
|
return null;
|
|
1437
1359
|
}
|
|
1438
|
-
var error = new Error('
|
|
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.');
|
|
1439
1361
|
// eslint-disable-next-line camelcase
|
|
1440
1362
|
error.diff_match_patch_not_found = true;
|
|
1441
1363
|
throw error;
|
|
@@ -1457,58 +1379,59 @@
|
|
|
1457
1379
|
};
|
|
1458
1380
|
}
|
|
1459
1381
|
return cachedDiffPatch;
|
|
1460
|
-
}
|
|
1461
|
-
var diffFilter
|
|
1382
|
+
}
|
|
1383
|
+
var diffFilter = function textsDiffFilter(context) {
|
|
1462
1384
|
if (context.leftType !== 'string') {
|
|
1463
1385
|
return;
|
|
1464
1386
|
}
|
|
1387
|
+
var left = context.left;
|
|
1388
|
+
var right = context.right;
|
|
1465
1389
|
var minLength = context.options && context.options.textDiff && context.options.textDiff.minLength || DEFAULT_MIN_LENGTH;
|
|
1466
|
-
if (
|
|
1467
|
-
context.setResult([
|
|
1390
|
+
if (left.length < minLength || right.length < minLength) {
|
|
1391
|
+
context.setResult([left, right]).exit();
|
|
1468
1392
|
return;
|
|
1469
1393
|
}
|
|
1470
1394
|
// large text, try to use a text-diff algorithm
|
|
1471
|
-
var diffMatchPatch = getDiffMatchPatch();
|
|
1395
|
+
var diffMatchPatch = getDiffMatchPatch(context.options);
|
|
1472
1396
|
if (!diffMatchPatch) {
|
|
1473
1397
|
// diff-match-patch library not available,
|
|
1474
1398
|
// fallback to regular string replace
|
|
1475
|
-
context.setResult([
|
|
1399
|
+
context.setResult([left, right]).exit();
|
|
1476
1400
|
return;
|
|
1477
1401
|
}
|
|
1478
1402
|
var diff = diffMatchPatch.diff;
|
|
1479
|
-
context.setResult([diff(
|
|
1403
|
+
context.setResult([diff(left, right), 0, TEXT_DIFF]).exit();
|
|
1480
1404
|
};
|
|
1481
|
-
diffFilter
|
|
1482
|
-
var patchFilter
|
|
1405
|
+
diffFilter.filterName = 'texts';
|
|
1406
|
+
var patchFilter = function textsPatchFilter(context) {
|
|
1483
1407
|
if (context.nested) {
|
|
1484
1408
|
return;
|
|
1485
1409
|
}
|
|
1486
|
-
|
|
1410
|
+
var nonNestedDelta = context.delta;
|
|
1411
|
+
if (nonNestedDelta[2] !== TEXT_DIFF) {
|
|
1487
1412
|
return;
|
|
1488
1413
|
}
|
|
1489
|
-
|
|
1414
|
+
var textDiffDelta = nonNestedDelta;
|
|
1490
1415
|
// text-diff, use a text-patch algorithm
|
|
1491
|
-
var patch = getDiffMatchPatch(true).patch;
|
|
1492
|
-
context.setResult(patch(context.left,
|
|
1416
|
+
var patch = getDiffMatchPatch(context.options, true).patch;
|
|
1417
|
+
context.setResult(patch(context.left, textDiffDelta[0])).exit();
|
|
1493
1418
|
};
|
|
1494
|
-
patchFilter
|
|
1419
|
+
patchFilter.filterName = 'texts';
|
|
1495
1420
|
var textDeltaReverse = function textDeltaReverse(delta) {
|
|
1496
|
-
var i
|
|
1497
|
-
var l
|
|
1498
|
-
var
|
|
1499
|
-
var
|
|
1500
|
-
var lineTmp = void 0;
|
|
1421
|
+
var i;
|
|
1422
|
+
var l;
|
|
1423
|
+
var line;
|
|
1424
|
+
var lineTmp;
|
|
1501
1425
|
var header = null;
|
|
1502
1426
|
var headerRegex = /^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/;
|
|
1503
|
-
var lineHeader
|
|
1504
|
-
lines = delta.split('\n');
|
|
1427
|
+
var lineHeader;
|
|
1428
|
+
var lines = delta.split('\n');
|
|
1505
1429
|
for (i = 0, l = lines.length; i < l; i++) {
|
|
1506
1430
|
line = lines[i];
|
|
1507
1431
|
var lineStart = line.slice(0, 1);
|
|
1508
1432
|
if (lineStart === '@') {
|
|
1509
1433
|
header = headerRegex.exec(line);
|
|
1510
1434
|
lineHeader = i;
|
|
1511
|
-
|
|
1512
1435
|
// fix header
|
|
1513
1436
|
lines[lineHeader] = '@@ -' + header[3] + ',' + header[4] + ' +' + header[1] + ',' + header[2] + ' @@';
|
|
1514
1437
|
} else if (lineStart === '+') {
|
|
@@ -1525,1167 +1448,64 @@
|
|
|
1525
1448
|
}
|
|
1526
1449
|
return lines.join('\n');
|
|
1527
1450
|
};
|
|
1528
|
-
var reverseFilter
|
|
1451
|
+
var reverseFilter = function textsReverseFilter(context) {
|
|
1529
1452
|
if (context.nested) {
|
|
1530
1453
|
return;
|
|
1531
1454
|
}
|
|
1532
|
-
|
|
1455
|
+
var nonNestedDelta = context.delta;
|
|
1456
|
+
if (nonNestedDelta[2] !== TEXT_DIFF) {
|
|
1533
1457
|
return;
|
|
1534
1458
|
}
|
|
1535
|
-
|
|
1459
|
+
var textDiffDelta = nonNestedDelta;
|
|
1536
1460
|
// text-diff, use a text-diff algorithm
|
|
1537
|
-
context.setResult([textDeltaReverse(
|
|
1461
|
+
context.setResult([textDeltaReverse(textDiffDelta[0]), 0, TEXT_DIFF]).exit();
|
|
1538
1462
|
};
|
|
1539
|
-
reverseFilter
|
|
1540
|
-
|
|
1463
|
+
reverseFilter.filterName = 'texts';
|
|
1464
|
+
|
|
1465
|
+
var DiffPatcher = /*#__PURE__*/function () {
|
|
1541
1466
|
function DiffPatcher(options) {
|
|
1542
|
-
|
|
1467
|
+
_classCallCheck(this, DiffPatcher);
|
|
1543
1468
|
this.processor = new Processor(options);
|
|
1544
|
-
this.processor.pipe(new Pipe('diff').append(collectChildrenDiffFilter, diffFilter, diffFilter$
|
|
1545
|
-
this.processor.pipe(new Pipe('patch').append(collectChildrenPatchFilter
|
|
1546
|
-
this.processor.pipe(new Pipe('reverse').append(collectChildrenReverseFilter
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
key:
|
|
1550
|
-
value: function options() {
|
|
1551
|
-
|
|
1552
|
-
return (_processor = this.processor).options.apply(_processor, arguments);
|
|
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);
|
|
1553
1477
|
}
|
|
1554
1478
|
}, {
|
|
1555
|
-
key:
|
|
1479
|
+
key: "diff",
|
|
1556
1480
|
value: function diff(left, right) {
|
|
1557
1481
|
return this.processor.process(new DiffContext(left, right));
|
|
1558
1482
|
}
|
|
1559
1483
|
}, {
|
|
1560
|
-
key:
|
|
1484
|
+
key: "patch",
|
|
1561
1485
|
value: function patch(left, delta) {
|
|
1562
1486
|
return this.processor.process(new PatchContext(left, delta));
|
|
1563
1487
|
}
|
|
1564
1488
|
}, {
|
|
1565
|
-
key:
|
|
1489
|
+
key: "reverse",
|
|
1566
1490
|
value: function reverse(delta) {
|
|
1567
1491
|
return this.processor.process(new ReverseContext(delta));
|
|
1568
1492
|
}
|
|
1569
1493
|
}, {
|
|
1570
|
-
key:
|
|
1494
|
+
key: "unpatch",
|
|
1571
1495
|
value: function unpatch(right, delta) {
|
|
1572
1496
|
return this.patch(right, this.reverse(delta));
|
|
1573
1497
|
}
|
|
1574
1498
|
}, {
|
|
1575
|
-
key:
|
|
1576
|
-
value: function clone
|
|
1499
|
+
key: "clone",
|
|
1500
|
+
value: function clone(value) {
|
|
1577
1501
|
return clone$1(value);
|
|
1578
1502
|
}
|
|
1579
1503
|
}]);
|
|
1580
|
-
return DiffPatcher;
|
|
1581
1504
|
}();
|
|
1582
|
-
var isArray$3 = typeof Array.isArray === 'function' ? Array.isArray : function (a) {
|
|
1583
|
-
return a instanceof Array;
|
|
1584
|
-
};
|
|
1585
|
-
var getObjectKeys = typeof Object.keys === 'function' ? function (obj) {
|
|
1586
|
-
return Object.keys(obj);
|
|
1587
|
-
} : function (obj) {
|
|
1588
|
-
var names = [];
|
|
1589
|
-
for (var property in obj) {
|
|
1590
|
-
if (Object.prototype.hasOwnProperty.call(obj, property)) {
|
|
1591
|
-
names.push(property);
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
return names;
|
|
1595
|
-
};
|
|
1596
|
-
var trimUnderscore = function trimUnderscore(str) {
|
|
1597
|
-
if (str.substr(0, 1) === '_') {
|
|
1598
|
-
return str.slice(1);
|
|
1599
|
-
}
|
|
1600
|
-
return str;
|
|
1601
|
-
};
|
|
1602
|
-
var arrayKeyToSortNumber = function arrayKeyToSortNumber(key) {
|
|
1603
|
-
if (key === '_t') {
|
|
1604
|
-
return -1;
|
|
1605
|
-
} else {
|
|
1606
|
-
if (key.substr(0, 1) === '_') {
|
|
1607
|
-
return parseInt(key.slice(1), 10);
|
|
1608
|
-
} else {
|
|
1609
|
-
return parseInt(key, 10) + 0.1;
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
};
|
|
1613
|
-
var arrayKeyComparer = function arrayKeyComparer(key1, key2) {
|
|
1614
|
-
return arrayKeyToSortNumber(key1) - arrayKeyToSortNumber(key2);
|
|
1615
|
-
};
|
|
1616
|
-
var BaseFormatter = function () {
|
|
1617
|
-
function BaseFormatter() {
|
|
1618
|
-
classCallCheck(this, BaseFormatter);
|
|
1619
|
-
}
|
|
1620
|
-
createClass(BaseFormatter, [{
|
|
1621
|
-
key: 'format',
|
|
1622
|
-
value: function format(delta, left) {
|
|
1623
|
-
var context = {};
|
|
1624
|
-
this.prepareContext(context);
|
|
1625
|
-
this.recurse(context, delta, left);
|
|
1626
|
-
return this.finalize(context);
|
|
1627
|
-
}
|
|
1628
|
-
}, {
|
|
1629
|
-
key: 'prepareContext',
|
|
1630
|
-
value: function prepareContext(context) {
|
|
1631
|
-
context.buffer = [];
|
|
1632
|
-
context.out = function () {
|
|
1633
|
-
var _buffer;
|
|
1634
|
-
(_buffer = this.buffer).push.apply(_buffer, arguments);
|
|
1635
|
-
};
|
|
1636
|
-
}
|
|
1637
|
-
}, {
|
|
1638
|
-
key: 'typeFormattterNotFound',
|
|
1639
|
-
value: function typeFormattterNotFound(context, deltaType) {
|
|
1640
|
-
throw new Error('cannot format delta type: ' + deltaType);
|
|
1641
|
-
}
|
|
1642
|
-
}, {
|
|
1643
|
-
key: 'typeFormattterErrorFormatter',
|
|
1644
|
-
value: function typeFormattterErrorFormatter(context, err) {
|
|
1645
|
-
return err.toString();
|
|
1646
|
-
}
|
|
1647
|
-
}, {
|
|
1648
|
-
key: 'finalize',
|
|
1649
|
-
value: function finalize(_ref) {
|
|
1650
|
-
var buffer = _ref.buffer;
|
|
1651
|
-
if (isArray$3(buffer)) {
|
|
1652
|
-
return buffer.join('');
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
}, {
|
|
1656
|
-
key: 'recurse',
|
|
1657
|
-
value: function recurse(context, delta, left, key, leftKey, movedFrom, isLast) {
|
|
1658
|
-
var useMoveOriginHere = delta && movedFrom;
|
|
1659
|
-
var leftValue = useMoveOriginHere ? movedFrom.value : left;
|
|
1660
|
-
if (typeof delta === 'undefined' && typeof key === 'undefined') {
|
|
1661
|
-
return undefined;
|
|
1662
|
-
}
|
|
1663
|
-
var type = this.getDeltaType(delta, movedFrom);
|
|
1664
|
-
var nodeType = type === 'node' ? delta._t === 'a' ? 'array' : 'object' : '';
|
|
1665
|
-
if (typeof key !== 'undefined') {
|
|
1666
|
-
this.nodeBegin(context, key, leftKey, type, nodeType, isLast);
|
|
1667
|
-
} else {
|
|
1668
|
-
this.rootBegin(context, type, nodeType);
|
|
1669
|
-
}
|
|
1670
|
-
var typeFormattter = void 0;
|
|
1671
|
-
try {
|
|
1672
|
-
typeFormattter = this['format_' + type] || this.typeFormattterNotFound(context, type);
|
|
1673
|
-
typeFormattter.call(this, context, delta, leftValue, key, leftKey, movedFrom);
|
|
1674
|
-
} catch (err) {
|
|
1675
|
-
this.typeFormattterErrorFormatter(context, err, delta, leftValue, key, leftKey, movedFrom);
|
|
1676
|
-
if (typeof console !== 'undefined' && console.error) {
|
|
1677
|
-
console.error(err.stack);
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
if (typeof key !== 'undefined') {
|
|
1681
|
-
this.nodeEnd(context, key, leftKey, type, nodeType, isLast);
|
|
1682
|
-
} else {
|
|
1683
|
-
this.rootEnd(context, type, nodeType);
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
}, {
|
|
1687
|
-
key: 'formatDeltaChildren',
|
|
1688
|
-
value: function formatDeltaChildren(context, delta, left) {
|
|
1689
|
-
var self = this;
|
|
1690
|
-
this.forEachDeltaKey(delta, left, function (key, leftKey, movedFrom, isLast) {
|
|
1691
|
-
self.recurse(context, delta[key], left ? left[leftKey] : undefined, key, leftKey, movedFrom, isLast);
|
|
1692
|
-
});
|
|
1693
|
-
}
|
|
1694
|
-
}, {
|
|
1695
|
-
key: 'forEachDeltaKey',
|
|
1696
|
-
value: function forEachDeltaKey(delta, left, fn) {
|
|
1697
|
-
var keys = getObjectKeys(delta);
|
|
1698
|
-
var arrayKeys = delta._t === 'a';
|
|
1699
|
-
var moveDestinations = {};
|
|
1700
|
-
var name = void 0;
|
|
1701
|
-
if (typeof left !== 'undefined') {
|
|
1702
|
-
for (name in left) {
|
|
1703
|
-
if (Object.prototype.hasOwnProperty.call(left, name)) {
|
|
1704
|
-
if (typeof delta[name] === 'undefined' && (!arrayKeys || typeof delta['_' + name] === 'undefined')) {
|
|
1705
|
-
keys.push(name);
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
// look for move destinations
|
|
1711
|
-
for (name in delta) {
|
|
1712
|
-
if (Object.prototype.hasOwnProperty.call(delta, name)) {
|
|
1713
|
-
var value = delta[name];
|
|
1714
|
-
if (isArray$3(value) && value[2] === 3) {
|
|
1715
|
-
moveDestinations[value[1].toString()] = {
|
|
1716
|
-
key: name,
|
|
1717
|
-
value: left && left[parseInt(name.substr(1))]
|
|
1718
|
-
};
|
|
1719
|
-
if (this.includeMoveDestinations !== false) {
|
|
1720
|
-
if (typeof left === 'undefined' && typeof delta[value[1]] === 'undefined') {
|
|
1721
|
-
keys.push(value[1].toString());
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
if (arrayKeys) {
|
|
1728
|
-
keys.sort(arrayKeyComparer);
|
|
1729
|
-
} else {
|
|
1730
|
-
keys.sort();
|
|
1731
|
-
}
|
|
1732
|
-
for (var index = 0, length = keys.length; index < length; index++) {
|
|
1733
|
-
var key = keys[index];
|
|
1734
|
-
if (arrayKeys && key === '_t') {
|
|
1735
|
-
continue;
|
|
1736
|
-
}
|
|
1737
|
-
var leftKey = arrayKeys ? typeof key === 'number' ? key : parseInt(trimUnderscore(key), 10) : key;
|
|
1738
|
-
var isLast = index === length - 1;
|
|
1739
|
-
fn(key, leftKey, moveDestinations[leftKey], isLast);
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
}, {
|
|
1743
|
-
key: 'getDeltaType',
|
|
1744
|
-
value: function getDeltaType(delta, movedFrom) {
|
|
1745
|
-
if (typeof delta === 'undefined') {
|
|
1746
|
-
if (typeof movedFrom !== 'undefined') {
|
|
1747
|
-
return 'movedestination';
|
|
1748
|
-
}
|
|
1749
|
-
return 'unchanged';
|
|
1750
|
-
}
|
|
1751
|
-
if (isArray$3(delta)) {
|
|
1752
|
-
if (delta.length === 1) {
|
|
1753
|
-
return 'added';
|
|
1754
|
-
}
|
|
1755
|
-
if (delta.length === 2) {
|
|
1756
|
-
return 'modified';
|
|
1757
|
-
}
|
|
1758
|
-
if (delta.length === 3 && delta[2] === 0) {
|
|
1759
|
-
return 'deleted';
|
|
1760
|
-
}
|
|
1761
|
-
if (delta.length === 3 && delta[2] === 2) {
|
|
1762
|
-
return 'textdiff';
|
|
1763
|
-
}
|
|
1764
|
-
if (delta.length === 3 && delta[2] === 3) {
|
|
1765
|
-
return 'moved';
|
|
1766
|
-
}
|
|
1767
|
-
} else if ((typeof delta === 'undefined' ? 'undefined' : _typeof(delta)) === 'object') {
|
|
1768
|
-
return 'node';
|
|
1769
|
-
}
|
|
1770
|
-
return 'unknown';
|
|
1771
|
-
}
|
|
1772
|
-
}, {
|
|
1773
|
-
key: 'parseTextDiff',
|
|
1774
|
-
value: function parseTextDiff(value) {
|
|
1775
|
-
var output = [];
|
|
1776
|
-
var lines = value.split('\n@@ ');
|
|
1777
|
-
for (var i = 0, l = lines.length; i < l; i++) {
|
|
1778
|
-
var line = lines[i];
|
|
1779
|
-
var lineOutput = {
|
|
1780
|
-
pieces: []
|
|
1781
|
-
};
|
|
1782
|
-
var location = /^(?:@@ )?[-+]?(\d+),(\d+)/.exec(line).slice(1);
|
|
1783
|
-
lineOutput.location = {
|
|
1784
|
-
line: location[0],
|
|
1785
|
-
chr: location[1]
|
|
1786
|
-
};
|
|
1787
|
-
var pieces = line.split('\n').slice(1);
|
|
1788
|
-
for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
|
|
1789
|
-
var piece = pieces[pieceIndex];
|
|
1790
|
-
if (!piece.length) {
|
|
1791
|
-
continue;
|
|
1792
|
-
}
|
|
1793
|
-
var pieceOutput = {
|
|
1794
|
-
type: 'context'
|
|
1795
|
-
};
|
|
1796
|
-
if (piece.substr(0, 1) === '+') {
|
|
1797
|
-
pieceOutput.type = 'added';
|
|
1798
|
-
} else if (piece.substr(0, 1) === '-') {
|
|
1799
|
-
pieceOutput.type = 'deleted';
|
|
1800
|
-
}
|
|
1801
|
-
pieceOutput.text = piece.slice(1);
|
|
1802
|
-
lineOutput.pieces.push(pieceOutput);
|
|
1803
|
-
}
|
|
1804
|
-
output.push(lineOutput);
|
|
1805
|
-
}
|
|
1806
|
-
return output;
|
|
1807
|
-
}
|
|
1808
|
-
}]);
|
|
1809
|
-
return BaseFormatter;
|
|
1810
|
-
}();
|
|
1811
|
-
var base = Object.freeze({
|
|
1812
|
-
default: BaseFormatter
|
|
1813
|
-
});
|
|
1814
|
-
var HtmlFormatter = function (_BaseFormatter) {
|
|
1815
|
-
inherits(HtmlFormatter, _BaseFormatter);
|
|
1816
|
-
function HtmlFormatter() {
|
|
1817
|
-
classCallCheck(this, HtmlFormatter);
|
|
1818
|
-
return possibleConstructorReturn(this, (HtmlFormatter.__proto__ || Object.getPrototypeOf(HtmlFormatter)).apply(this, arguments));
|
|
1819
|
-
}
|
|
1820
|
-
createClass(HtmlFormatter, [{
|
|
1821
|
-
key: 'typeFormattterErrorFormatter',
|
|
1822
|
-
value: function typeFormattterErrorFormatter(context, err) {
|
|
1823
|
-
context.out('<pre class="jsondiffpatch-error">' + err + '</pre>');
|
|
1824
|
-
}
|
|
1825
|
-
}, {
|
|
1826
|
-
key: 'formatValue',
|
|
1827
|
-
value: function formatValue(context, value) {
|
|
1828
|
-
context.out('<pre>' + htmlEscape(JSON.stringify(value, null, 2)) + '</pre>');
|
|
1829
|
-
}
|
|
1830
|
-
}, {
|
|
1831
|
-
key: 'formatTextDiffString',
|
|
1832
|
-
value: function formatTextDiffString(context, value) {
|
|
1833
|
-
var lines = this.parseTextDiff(value);
|
|
1834
|
-
context.out('<ul class="jsondiffpatch-textdiff">');
|
|
1835
|
-
for (var i = 0, l = lines.length; i < l; i++) {
|
|
1836
|
-
var line = lines[i];
|
|
1837
|
-
context.out('<li><div class="jsondiffpatch-textdiff-location">' + ('<span class="jsondiffpatch-textdiff-line-number">' + line.location.line + '</span><span class="jsondiffpatch-textdiff-char">' + line.location.chr + '</span></div><div class="jsondiffpatch-textdiff-line">'));
|
|
1838
|
-
var pieces = line.pieces;
|
|
1839
|
-
for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
|
|
1840
|
-
/* global decodeURI */
|
|
1841
|
-
var piece = pieces[pieceIndex];
|
|
1842
|
-
context.out('<span class="jsondiffpatch-textdiff-' + piece.type + '">' + htmlEscape(decodeURI(piece.text)) + '</span>');
|
|
1843
|
-
}
|
|
1844
|
-
context.out('</div></li>');
|
|
1845
|
-
}
|
|
1846
|
-
context.out('</ul>');
|
|
1847
|
-
}
|
|
1848
|
-
}, {
|
|
1849
|
-
key: 'rootBegin',
|
|
1850
|
-
value: function rootBegin(context, type, nodeType) {
|
|
1851
|
-
var nodeClass = 'jsondiffpatch-' + type + (nodeType ? ' jsondiffpatch-child-node-type-' + nodeType : '');
|
|
1852
|
-
context.out('<div class="jsondiffpatch-delta ' + nodeClass + '">');
|
|
1853
|
-
}
|
|
1854
|
-
}, {
|
|
1855
|
-
key: 'rootEnd',
|
|
1856
|
-
value: function rootEnd(context) {
|
|
1857
|
-
context.out('</div>' + (context.hasArrows ? '<script type="text/javascript">setTimeout(' + (adjustArrows.toString() + ',10);</script>') : ''));
|
|
1858
|
-
}
|
|
1859
|
-
}, {
|
|
1860
|
-
key: 'nodeBegin',
|
|
1861
|
-
value: function nodeBegin(context, key, leftKey, type, nodeType) {
|
|
1862
|
-
var nodeClass = 'jsondiffpatch-' + type + (nodeType ? ' jsondiffpatch-child-node-type-' + nodeType : '');
|
|
1863
|
-
context.out('<li class="' + nodeClass + '" data-key="' + leftKey + '">' + ('<div class="jsondiffpatch-property-name">' + leftKey + '</div>'));
|
|
1864
|
-
}
|
|
1865
|
-
}, {
|
|
1866
|
-
key: 'nodeEnd',
|
|
1867
|
-
value: function nodeEnd(context) {
|
|
1868
|
-
context.out('</li>');
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
/* jshint camelcase: false */
|
|
1872
|
-
/* eslint-disable camelcase */
|
|
1873
|
-
}, {
|
|
1874
|
-
key: 'format_unchanged',
|
|
1875
|
-
value: function format_unchanged(context, delta, left) {
|
|
1876
|
-
if (typeof left === 'undefined') {
|
|
1877
|
-
return;
|
|
1878
|
-
}
|
|
1879
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1880
|
-
this.formatValue(context, left);
|
|
1881
|
-
context.out('</div>');
|
|
1882
|
-
}
|
|
1883
|
-
}, {
|
|
1884
|
-
key: 'format_movedestination',
|
|
1885
|
-
value: function format_movedestination(context, delta, left) {
|
|
1886
|
-
if (typeof left === 'undefined') {
|
|
1887
|
-
return;
|
|
1888
|
-
}
|
|
1889
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1890
|
-
this.formatValue(context, left);
|
|
1891
|
-
context.out('</div>');
|
|
1892
|
-
}
|
|
1893
|
-
}, {
|
|
1894
|
-
key: 'format_node',
|
|
1895
|
-
value: function format_node(context, delta, left) {
|
|
1896
|
-
// recurse
|
|
1897
|
-
var nodeType = delta._t === 'a' ? 'array' : 'object';
|
|
1898
|
-
context.out('<ul class="jsondiffpatch-node jsondiffpatch-node-type-' + nodeType + '">');
|
|
1899
|
-
this.formatDeltaChildren(context, delta, left);
|
|
1900
|
-
context.out('</ul>');
|
|
1901
|
-
}
|
|
1902
|
-
}, {
|
|
1903
|
-
key: 'format_added',
|
|
1904
|
-
value: function format_added(context, delta) {
|
|
1905
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1906
|
-
this.formatValue(context, delta[0]);
|
|
1907
|
-
context.out('</div>');
|
|
1908
|
-
}
|
|
1909
|
-
}, {
|
|
1910
|
-
key: 'format_modified',
|
|
1911
|
-
value: function format_modified(context, delta) {
|
|
1912
|
-
context.out('<div class="jsondiffpatch-value jsondiffpatch-left-value">');
|
|
1913
|
-
this.formatValue(context, delta[0]);
|
|
1914
|
-
context.out('</div>' + '<div class="jsondiffpatch-value jsondiffpatch-right-value">');
|
|
1915
|
-
this.formatValue(context, delta[1]);
|
|
1916
|
-
context.out('</div>');
|
|
1917
|
-
}
|
|
1918
|
-
}, {
|
|
1919
|
-
key: 'format_deleted',
|
|
1920
|
-
value: function format_deleted(context, delta) {
|
|
1921
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1922
|
-
this.formatValue(context, delta[0]);
|
|
1923
|
-
context.out('</div>');
|
|
1924
|
-
}
|
|
1925
|
-
}, {
|
|
1926
|
-
key: 'format_moved',
|
|
1927
|
-
value: function format_moved(context, delta) {
|
|
1928
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1929
|
-
this.formatValue(context, delta[0]);
|
|
1930
|
-
context.out('</div><div class="jsondiffpatch-moved-destination">' + delta[1] + '</div>');
|
|
1931
|
-
|
|
1932
|
-
// draw an SVG arrow from here to move destination
|
|
1933
|
-
context.out( /* jshint multistr: true */
|
|
1934
|
-
'<div class="jsondiffpatch-arrow" ' + 'style="position: relative; left: -34px;">\n <svg width="30" height="60" ' + 'style="position: absolute; display: none;">\n <defs>\n <marker id="markerArrow" markerWidth="8" markerHeight="8"\n refx="2" refy="4"\n orient="auto" markerUnits="userSpaceOnUse">\n <path d="M1,1 L1,7 L7,4 L1,1" style="fill: #339;" />\n </marker>\n </defs>\n <path d="M30,0 Q-10,25 26,50"\n style="stroke: #88f; stroke-width: 2px; fill: none; ' + 'stroke-opacity: 0.5; marker-end: url(#markerArrow);"\n ></path>\n </svg>\n </div>');
|
|
1935
|
-
context.hasArrows = true;
|
|
1936
|
-
}
|
|
1937
|
-
}, {
|
|
1938
|
-
key: 'format_textdiff',
|
|
1939
|
-
value: function format_textdiff(context, delta) {
|
|
1940
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1941
|
-
this.formatTextDiffString(context, delta[0]);
|
|
1942
|
-
context.out('</div>');
|
|
1943
|
-
}
|
|
1944
|
-
}]);
|
|
1945
|
-
return HtmlFormatter;
|
|
1946
|
-
}(BaseFormatter);
|
|
1947
|
-
function htmlEscape(text) {
|
|
1948
|
-
var html = text;
|
|
1949
|
-
var replacements = [[/&/g, '&'], [/</g, '<'], [/>/g, '>'], [/'/g, '''], [/"/g, '"']];
|
|
1950
|
-
for (var i = 0; i < replacements.length; i++) {
|
|
1951
|
-
html = html.replace(replacements[i][0], replacements[i][1]);
|
|
1952
|
-
}
|
|
1953
|
-
return html;
|
|
1954
|
-
}
|
|
1955
|
-
var adjustArrows = function jsondiffpatchHtmlFormatterAdjustArrows(nodeArg) {
|
|
1956
|
-
var node = nodeArg || document;
|
|
1957
|
-
var getElementText = function getElementText(_ref) {
|
|
1958
|
-
var textContent = _ref.textContent,
|
|
1959
|
-
innerText = _ref.innerText;
|
|
1960
|
-
return textContent || innerText;
|
|
1961
|
-
};
|
|
1962
|
-
var eachByQuery = function eachByQuery(el, query, fn) {
|
|
1963
|
-
var elems = el.querySelectorAll(query);
|
|
1964
|
-
for (var i = 0, l = elems.length; i < l; i++) {
|
|
1965
|
-
fn(elems[i]);
|
|
1966
|
-
}
|
|
1967
|
-
};
|
|
1968
|
-
var eachChildren = function eachChildren(_ref2, fn) {
|
|
1969
|
-
var children = _ref2.children;
|
|
1970
|
-
for (var i = 0, l = children.length; i < l; i++) {
|
|
1971
|
-
fn(children[i], i);
|
|
1972
|
-
}
|
|
1973
|
-
};
|
|
1974
|
-
eachByQuery(node, '.jsondiffpatch-arrow', function (_ref3) {
|
|
1975
|
-
var parentNode = _ref3.parentNode,
|
|
1976
|
-
children = _ref3.children,
|
|
1977
|
-
style = _ref3.style;
|
|
1978
|
-
var arrowParent = parentNode;
|
|
1979
|
-
var svg = children[0];
|
|
1980
|
-
var path = svg.children[1];
|
|
1981
|
-
svg.style.display = 'none';
|
|
1982
|
-
var destination = getElementText(arrowParent.querySelector('.jsondiffpatch-moved-destination'));
|
|
1983
|
-
var container = arrowParent.parentNode;
|
|
1984
|
-
var destinationElem = void 0;
|
|
1985
|
-
eachChildren(container, function (child) {
|
|
1986
|
-
if (child.getAttribute('data-key') === destination) {
|
|
1987
|
-
destinationElem = child;
|
|
1988
|
-
}
|
|
1989
|
-
});
|
|
1990
|
-
if (!destinationElem) {
|
|
1991
|
-
return;
|
|
1992
|
-
}
|
|
1993
|
-
try {
|
|
1994
|
-
var distance = destinationElem.offsetTop - arrowParent.offsetTop;
|
|
1995
|
-
svg.setAttribute('height', Math.abs(distance) + 6);
|
|
1996
|
-
style.top = -8 + (distance > 0 ? 0 : distance) + 'px';
|
|
1997
|
-
var curve = distance > 0 ? 'M30,0 Q-10,' + Math.round(distance / 2) + ' 26,' + (distance - 4) : 'M30,' + -distance + ' Q-10,' + Math.round(-distance / 2) + ' 26,4';
|
|
1998
|
-
path.setAttribute('d', curve);
|
|
1999
|
-
svg.style.display = '';
|
|
2000
|
-
} catch (err) {}
|
|
2001
|
-
});
|
|
2002
|
-
};
|
|
2003
|
-
|
|
2004
|
-
/* jshint camelcase: true */
|
|
2005
|
-
/* eslint-enable camelcase */
|
|
2006
|
-
|
|
2007
|
-
var showUnchanged = function showUnchanged(show, node, delay) {
|
|
2008
|
-
var el = node || document.body;
|
|
2009
|
-
var prefix = 'jsondiffpatch-unchanged-';
|
|
2010
|
-
var classes = {
|
|
2011
|
-
showing: prefix + 'showing',
|
|
2012
|
-
hiding: prefix + 'hiding',
|
|
2013
|
-
visible: prefix + 'visible',
|
|
2014
|
-
hidden: prefix + 'hidden'
|
|
2015
|
-
};
|
|
2016
|
-
var list = el.classList;
|
|
2017
|
-
if (!list) {
|
|
2018
|
-
return;
|
|
2019
|
-
}
|
|
2020
|
-
if (!delay) {
|
|
2021
|
-
list.remove(classes.showing);
|
|
2022
|
-
list.remove(classes.hiding);
|
|
2023
|
-
list.remove(classes.visible);
|
|
2024
|
-
list.remove(classes.hidden);
|
|
2025
|
-
if (show === false) {
|
|
2026
|
-
list.add(classes.hidden);
|
|
2027
|
-
}
|
|
2028
|
-
return;
|
|
2029
|
-
}
|
|
2030
|
-
if (show === false) {
|
|
2031
|
-
list.remove(classes.showing);
|
|
2032
|
-
list.add(classes.visible);
|
|
2033
|
-
setTimeout(function () {
|
|
2034
|
-
list.add(classes.hiding);
|
|
2035
|
-
}, 10);
|
|
2036
|
-
} else {
|
|
2037
|
-
list.remove(classes.hiding);
|
|
2038
|
-
list.add(classes.showing);
|
|
2039
|
-
list.remove(classes.hidden);
|
|
2040
|
-
}
|
|
2041
|
-
var intervalId = setInterval(function () {
|
|
2042
|
-
adjustArrows(el);
|
|
2043
|
-
}, 100);
|
|
2044
|
-
setTimeout(function () {
|
|
2045
|
-
list.remove(classes.showing);
|
|
2046
|
-
list.remove(classes.hiding);
|
|
2047
|
-
if (show === false) {
|
|
2048
|
-
list.add(classes.hidden);
|
|
2049
|
-
list.remove(classes.visible);
|
|
2050
|
-
} else {
|
|
2051
|
-
list.add(classes.visible);
|
|
2052
|
-
list.remove(classes.hidden);
|
|
2053
|
-
}
|
|
2054
|
-
setTimeout(function () {
|
|
2055
|
-
list.remove(classes.visible);
|
|
2056
|
-
clearInterval(intervalId);
|
|
2057
|
-
}, delay + 400);
|
|
2058
|
-
}, delay);
|
|
2059
|
-
};
|
|
2060
|
-
var hideUnchanged = function hideUnchanged(node, delay) {
|
|
2061
|
-
return showUnchanged(false, node, delay);
|
|
2062
|
-
};
|
|
2063
|
-
var defaultInstance = void 0;
|
|
2064
|
-
function format(delta, left) {
|
|
2065
|
-
if (!defaultInstance) {
|
|
2066
|
-
defaultInstance = new HtmlFormatter();
|
|
2067
|
-
}
|
|
2068
|
-
return defaultInstance.format(delta, left);
|
|
2069
|
-
}
|
|
2070
|
-
var html = Object.freeze({
|
|
2071
|
-
showUnchanged: showUnchanged,
|
|
2072
|
-
hideUnchanged: hideUnchanged,
|
|
2073
|
-
default: HtmlFormatter,
|
|
2074
|
-
format: format
|
|
2075
|
-
});
|
|
2076
|
-
var AnnotatedFormatter = function (_BaseFormatter) {
|
|
2077
|
-
inherits(AnnotatedFormatter, _BaseFormatter);
|
|
2078
|
-
function AnnotatedFormatter() {
|
|
2079
|
-
classCallCheck(this, AnnotatedFormatter);
|
|
2080
|
-
var _this = possibleConstructorReturn(this, (AnnotatedFormatter.__proto__ || Object.getPrototypeOf(AnnotatedFormatter)).call(this));
|
|
2081
|
-
_this.includeMoveDestinations = false;
|
|
2082
|
-
return _this;
|
|
2083
|
-
}
|
|
2084
|
-
createClass(AnnotatedFormatter, [{
|
|
2085
|
-
key: 'prepareContext',
|
|
2086
|
-
value: function prepareContext(context) {
|
|
2087
|
-
get(AnnotatedFormatter.prototype.__proto__ || Object.getPrototypeOf(AnnotatedFormatter.prototype), 'prepareContext', this).call(this, context);
|
|
2088
|
-
context.indent = function (levels) {
|
|
2089
|
-
this.indentLevel = (this.indentLevel || 0) + (typeof levels === 'undefined' ? 1 : levels);
|
|
2090
|
-
this.indentPad = new Array(this.indentLevel + 1).join(' ');
|
|
2091
|
-
};
|
|
2092
|
-
context.row = function (json, htmlNote) {
|
|
2093
|
-
context.out('<tr><td style="white-space: nowrap;">' + '<pre class="jsondiffpatch-annotated-indent"' + ' style="display: inline-block">');
|
|
2094
|
-
context.out(context.indentPad);
|
|
2095
|
-
context.out('</pre><pre style="display: inline-block">');
|
|
2096
|
-
context.out(json);
|
|
2097
|
-
context.out('</pre></td><td class="jsondiffpatch-delta-note"><div>');
|
|
2098
|
-
context.out(htmlNote);
|
|
2099
|
-
context.out('</div></td></tr>');
|
|
2100
|
-
};
|
|
2101
|
-
}
|
|
2102
|
-
}, {
|
|
2103
|
-
key: 'typeFormattterErrorFormatter',
|
|
2104
|
-
value: function typeFormattterErrorFormatter(context, err) {
|
|
2105
|
-
context.row('', '<pre class="jsondiffpatch-error">' + err + '</pre>');
|
|
2106
|
-
}
|
|
2107
|
-
}, {
|
|
2108
|
-
key: 'formatTextDiffString',
|
|
2109
|
-
value: function formatTextDiffString(context, value) {
|
|
2110
|
-
var lines = this.parseTextDiff(value);
|
|
2111
|
-
context.out('<ul class="jsondiffpatch-textdiff">');
|
|
2112
|
-
for (var i = 0, l = lines.length; i < l; i++) {
|
|
2113
|
-
var line = lines[i];
|
|
2114
|
-
context.out('<li><div class="jsondiffpatch-textdiff-location">' + ('<span class="jsondiffpatch-textdiff-line-number">' + line.location.line + '</span><span class="jsondiffpatch-textdiff-char">' + line.location.chr + '</span></div><div class="jsondiffpatch-textdiff-line">'));
|
|
2115
|
-
var pieces = line.pieces;
|
|
2116
|
-
for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
|
|
2117
|
-
var piece = pieces[pieceIndex];
|
|
2118
|
-
context.out('<span class="jsondiffpatch-textdiff-' + piece.type + '">' + piece.text + '</span>');
|
|
2119
|
-
}
|
|
2120
|
-
context.out('</div></li>');
|
|
2121
|
-
}
|
|
2122
|
-
context.out('</ul>');
|
|
2123
|
-
}
|
|
2124
|
-
}, {
|
|
2125
|
-
key: 'rootBegin',
|
|
2126
|
-
value: function rootBegin(context, type, nodeType) {
|
|
2127
|
-
context.out('<table class="jsondiffpatch-annotated-delta">');
|
|
2128
|
-
if (type === 'node') {
|
|
2129
|
-
context.row('{');
|
|
2130
|
-
context.indent();
|
|
2131
|
-
}
|
|
2132
|
-
if (nodeType === 'array') {
|
|
2133
|
-
context.row('"_t": "a",', 'Array delta (member names indicate array indices)');
|
|
2134
|
-
}
|
|
2135
|
-
}
|
|
2136
|
-
}, {
|
|
2137
|
-
key: 'rootEnd',
|
|
2138
|
-
value: function rootEnd(context, type) {
|
|
2139
|
-
if (type === 'node') {
|
|
2140
|
-
context.indent(-1);
|
|
2141
|
-
context.row('}');
|
|
2142
|
-
}
|
|
2143
|
-
context.out('</table>');
|
|
2144
|
-
}
|
|
2145
|
-
}, {
|
|
2146
|
-
key: 'nodeBegin',
|
|
2147
|
-
value: function nodeBegin(context, key, leftKey, type, nodeType) {
|
|
2148
|
-
context.row('"' + key + '": {');
|
|
2149
|
-
if (type === 'node') {
|
|
2150
|
-
context.indent();
|
|
2151
|
-
}
|
|
2152
|
-
if (nodeType === 'array') {
|
|
2153
|
-
context.row('"_t": "a",', 'Array delta (member names indicate array indices)');
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
}, {
|
|
2157
|
-
key: 'nodeEnd',
|
|
2158
|
-
value: function nodeEnd(context, key, leftKey, type, nodeType, isLast) {
|
|
2159
|
-
if (type === 'node') {
|
|
2160
|
-
context.indent(-1);
|
|
2161
|
-
}
|
|
2162
|
-
context.row('}' + (isLast ? '' : ','));
|
|
2163
|
-
}
|
|
2164
|
-
|
|
2165
|
-
/* jshint camelcase: false */
|
|
2166
|
-
|
|
2167
|
-
/* eslint-disable camelcase */
|
|
2168
|
-
}, {
|
|
2169
|
-
key: 'format_unchanged',
|
|
2170
|
-
value: function format_unchanged() {}
|
|
2171
|
-
}, {
|
|
2172
|
-
key: 'format_movedestination',
|
|
2173
|
-
value: function format_movedestination() {}
|
|
2174
|
-
}, {
|
|
2175
|
-
key: 'format_node',
|
|
2176
|
-
value: function format_node(context, delta, left) {
|
|
2177
|
-
// recurse
|
|
2178
|
-
this.formatDeltaChildren(context, delta, left);
|
|
2179
|
-
}
|
|
2180
|
-
}]);
|
|
2181
|
-
return AnnotatedFormatter;
|
|
2182
|
-
}(BaseFormatter);
|
|
2183
|
-
|
|
2184
|
-
/* eslint-enable camelcase */
|
|
2185
|
-
|
|
2186
|
-
var wrapPropertyName = function wrapPropertyName(name) {
|
|
2187
|
-
return '<pre style="display:inline-block">"' + name + '"</pre>';
|
|
2188
|
-
};
|
|
2189
|
-
var deltaAnnotations = {
|
|
2190
|
-
added: function added(delta, left, key, leftKey) {
|
|
2191
|
-
var formatLegend = ' <pre>([newValue])</pre>';
|
|
2192
|
-
if (typeof leftKey === 'undefined') {
|
|
2193
|
-
return 'new value' + formatLegend;
|
|
2194
|
-
}
|
|
2195
|
-
if (typeof leftKey === 'number') {
|
|
2196
|
-
return 'insert at index ' + leftKey + formatLegend;
|
|
2197
|
-
}
|
|
2198
|
-
return 'add property ' + wrapPropertyName(leftKey) + formatLegend;
|
|
2199
|
-
},
|
|
2200
|
-
modified: function modified(delta, left, key, leftKey) {
|
|
2201
|
-
var formatLegend = ' <pre>([previousValue, newValue])</pre>';
|
|
2202
|
-
if (typeof leftKey === 'undefined') {
|
|
2203
|
-
return 'modify value' + formatLegend;
|
|
2204
|
-
}
|
|
2205
|
-
if (typeof leftKey === 'number') {
|
|
2206
|
-
return 'modify at index ' + leftKey + formatLegend;
|
|
2207
|
-
}
|
|
2208
|
-
return 'modify property ' + wrapPropertyName(leftKey) + formatLegend;
|
|
2209
|
-
},
|
|
2210
|
-
deleted: function deleted(delta, left, key, leftKey) {
|
|
2211
|
-
var formatLegend = ' <pre>([previousValue, 0, 0])</pre>';
|
|
2212
|
-
if (typeof leftKey === 'undefined') {
|
|
2213
|
-
return 'delete value' + formatLegend;
|
|
2214
|
-
}
|
|
2215
|
-
if (typeof leftKey === 'number') {
|
|
2216
|
-
return 'remove index ' + leftKey + formatLegend;
|
|
2217
|
-
}
|
|
2218
|
-
return 'delete property ' + wrapPropertyName(leftKey) + formatLegend;
|
|
2219
|
-
},
|
|
2220
|
-
moved: function moved(delta, left, key, leftKey) {
|
|
2221
|
-
return 'move from <span title="(position to remove at original state)">' + ('index ' + leftKey + '</span> to <span title="(position to insert at final') + (' state)">index ' + delta[1] + '</span>');
|
|
2222
|
-
},
|
|
2223
|
-
textdiff: function textdiff(delta, left, key, leftKey) {
|
|
2224
|
-
var location = typeof leftKey === 'undefined' ? '' : typeof leftKey === 'number' ? ' at index ' + leftKey : ' at property ' + wrapPropertyName(leftKey);
|
|
2225
|
-
return 'text diff' + location + ', format is <a href="https://code.google.com/' + 'p/google-diff-match-patch/wiki/Unidiff">a variation of Unidiff</a>';
|
|
2226
|
-
}
|
|
2227
|
-
};
|
|
2228
|
-
var formatAnyChange = function formatAnyChange(context, delta) {
|
|
2229
|
-
var deltaType = this.getDeltaType(delta);
|
|
2230
|
-
var annotator = deltaAnnotations[deltaType];
|
|
2231
|
-
var htmlNote = annotator && annotator.apply(annotator, Array.prototype.slice.call(arguments, 1));
|
|
2232
|
-
var json = JSON.stringify(delta, null, 2);
|
|
2233
|
-
if (deltaType === 'textdiff') {
|
|
2234
|
-
// split text diffs lines
|
|
2235
|
-
json = json.split('\\n').join('\\n"+\n "');
|
|
2236
|
-
}
|
|
2237
|
-
context.indent();
|
|
2238
|
-
context.row(json, htmlNote);
|
|
2239
|
-
context.indent(-1);
|
|
2240
|
-
};
|
|
2241
|
-
|
|
2242
|
-
/* eslint-disable camelcase */
|
|
2243
|
-
AnnotatedFormatter.prototype.format_added = formatAnyChange;
|
|
2244
|
-
AnnotatedFormatter.prototype.format_modified = formatAnyChange;
|
|
2245
|
-
AnnotatedFormatter.prototype.format_deleted = formatAnyChange;
|
|
2246
|
-
AnnotatedFormatter.prototype.format_moved = formatAnyChange;
|
|
2247
|
-
AnnotatedFormatter.prototype.format_textdiff = formatAnyChange;
|
|
2248
|
-
var defaultInstance$1 = void 0;
|
|
2249
|
-
function format$1(delta, left) {
|
|
2250
|
-
if (!defaultInstance$1) {
|
|
2251
|
-
defaultInstance$1 = new AnnotatedFormatter();
|
|
2252
|
-
}
|
|
2253
|
-
return defaultInstance$1.format(delta, left);
|
|
2254
|
-
}
|
|
2255
|
-
var annotated = Object.freeze({
|
|
2256
|
-
default: AnnotatedFormatter,
|
|
2257
|
-
format: format$1
|
|
2258
|
-
});
|
|
2259
|
-
var OPERATIONS = {
|
|
2260
|
-
add: 'add',
|
|
2261
|
-
remove: 'remove',
|
|
2262
|
-
replace: 'replace',
|
|
2263
|
-
move: 'move'
|
|
2264
|
-
};
|
|
2265
|
-
var JSONFormatter = function (_BaseFormatter) {
|
|
2266
|
-
inherits(JSONFormatter, _BaseFormatter);
|
|
2267
|
-
function JSONFormatter() {
|
|
2268
|
-
classCallCheck(this, JSONFormatter);
|
|
2269
|
-
var _this = possibleConstructorReturn(this, (JSONFormatter.__proto__ || Object.getPrototypeOf(JSONFormatter)).call(this));
|
|
2270
|
-
_this.includeMoveDestinations = true;
|
|
2271
|
-
return _this;
|
|
2272
|
-
}
|
|
2273
|
-
createClass(JSONFormatter, [{
|
|
2274
|
-
key: 'prepareContext',
|
|
2275
|
-
value: function prepareContext(context) {
|
|
2276
|
-
get(JSONFormatter.prototype.__proto__ || Object.getPrototypeOf(JSONFormatter.prototype), 'prepareContext', this).call(this, context);
|
|
2277
|
-
context.result = [];
|
|
2278
|
-
context.path = [];
|
|
2279
|
-
context.pushCurrentOp = function (obj) {
|
|
2280
|
-
var op = obj.op,
|
|
2281
|
-
value = obj.value;
|
|
2282
|
-
var val = {
|
|
2283
|
-
op: op,
|
|
2284
|
-
path: this.currentPath()
|
|
2285
|
-
};
|
|
2286
|
-
if (typeof value !== 'undefined') {
|
|
2287
|
-
val.value = value;
|
|
2288
|
-
}
|
|
2289
|
-
this.result.push(val);
|
|
2290
|
-
};
|
|
2291
|
-
context.pushMoveOp = function (to) {
|
|
2292
|
-
var from = this.currentPath();
|
|
2293
|
-
this.result.push({
|
|
2294
|
-
op: OPERATIONS.move,
|
|
2295
|
-
from: from,
|
|
2296
|
-
path: this.toPath(to)
|
|
2297
|
-
});
|
|
2298
|
-
};
|
|
2299
|
-
context.currentPath = function () {
|
|
2300
|
-
return '/' + this.path.join('/');
|
|
2301
|
-
};
|
|
2302
|
-
context.toPath = function (toPath) {
|
|
2303
|
-
var to = this.path.slice();
|
|
2304
|
-
to[to.length - 1] = toPath;
|
|
2305
|
-
return '/' + to.join('/');
|
|
2306
|
-
};
|
|
2307
|
-
}
|
|
2308
|
-
}, {
|
|
2309
|
-
key: 'typeFormattterErrorFormatter',
|
|
2310
|
-
value: function typeFormattterErrorFormatter(context, err) {
|
|
2311
|
-
context.out('[ERROR] ' + err);
|
|
2312
|
-
}
|
|
2313
|
-
}, {
|
|
2314
|
-
key: 'rootBegin',
|
|
2315
|
-
value: function rootBegin() {}
|
|
2316
|
-
}, {
|
|
2317
|
-
key: 'rootEnd',
|
|
2318
|
-
value: function rootEnd() {}
|
|
2319
|
-
}, {
|
|
2320
|
-
key: 'nodeBegin',
|
|
2321
|
-
value: function nodeBegin(_ref, key, leftKey) {
|
|
2322
|
-
var path = _ref.path;
|
|
2323
|
-
path.push(leftKey);
|
|
2324
|
-
}
|
|
2325
|
-
}, {
|
|
2326
|
-
key: 'nodeEnd',
|
|
2327
|
-
value: function nodeEnd(_ref2) {
|
|
2328
|
-
var path = _ref2.path;
|
|
2329
|
-
path.pop();
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
/* jshint camelcase: false */
|
|
2333
|
-
/* eslint-disable camelcase */
|
|
2334
|
-
}, {
|
|
2335
|
-
key: 'format_unchanged',
|
|
2336
|
-
value: function format_unchanged() {}
|
|
2337
|
-
}, {
|
|
2338
|
-
key: 'format_movedestination',
|
|
2339
|
-
value: function format_movedestination() {}
|
|
2340
|
-
}, {
|
|
2341
|
-
key: 'format_node',
|
|
2342
|
-
value: function format_node(context, delta, left) {
|
|
2343
|
-
this.formatDeltaChildren(context, delta, left);
|
|
2344
|
-
}
|
|
2345
|
-
}, {
|
|
2346
|
-
key: 'format_added',
|
|
2347
|
-
value: function format_added(context, delta) {
|
|
2348
|
-
context.pushCurrentOp({
|
|
2349
|
-
op: OPERATIONS.add,
|
|
2350
|
-
value: delta[0]
|
|
2351
|
-
});
|
|
2352
|
-
}
|
|
2353
|
-
}, {
|
|
2354
|
-
key: 'format_modified',
|
|
2355
|
-
value: function format_modified(context, delta) {
|
|
2356
|
-
context.pushCurrentOp({
|
|
2357
|
-
op: OPERATIONS.replace,
|
|
2358
|
-
value: delta[1]
|
|
2359
|
-
});
|
|
2360
|
-
}
|
|
2361
|
-
}, {
|
|
2362
|
-
key: 'format_deleted',
|
|
2363
|
-
value: function format_deleted(context) {
|
|
2364
|
-
context.pushCurrentOp({
|
|
2365
|
-
op: OPERATIONS.remove
|
|
2366
|
-
});
|
|
2367
|
-
}
|
|
2368
|
-
}, {
|
|
2369
|
-
key: 'format_moved',
|
|
2370
|
-
value: function format_moved(context, delta) {
|
|
2371
|
-
var to = delta[1];
|
|
2372
|
-
context.pushMoveOp(to);
|
|
2373
|
-
}
|
|
2374
|
-
}, {
|
|
2375
|
-
key: 'format_textdiff',
|
|
2376
|
-
value: function format_textdiff() {
|
|
2377
|
-
throw new Error('Not implemented');
|
|
2378
|
-
}
|
|
2379
|
-
}, {
|
|
2380
|
-
key: 'format',
|
|
2381
|
-
value: function format(delta, left) {
|
|
2382
|
-
var context = {};
|
|
2383
|
-
this.prepareContext(context);
|
|
2384
|
-
this.recurse(context, delta, left);
|
|
2385
|
-
return context.result;
|
|
2386
|
-
}
|
|
2387
|
-
}]);
|
|
2388
|
-
return JSONFormatter;
|
|
2389
|
-
}(BaseFormatter);
|
|
2390
|
-
var last = function last(arr) {
|
|
2391
|
-
return arr[arr.length - 1];
|
|
2392
|
-
};
|
|
2393
|
-
var sortBy = function sortBy(arr, pred) {
|
|
2394
|
-
arr.sort(pred);
|
|
2395
|
-
return arr;
|
|
2396
|
-
};
|
|
2397
|
-
var compareByIndexDesc = function compareByIndexDesc(indexA, indexB) {
|
|
2398
|
-
var lastA = parseInt(indexA, 10);
|
|
2399
|
-
var lastB = parseInt(indexB, 10);
|
|
2400
|
-
if (!(isNaN(lastA) || isNaN(lastB))) {
|
|
2401
|
-
return lastB - lastA;
|
|
2402
|
-
} else {
|
|
2403
|
-
return 0;
|
|
2404
|
-
}
|
|
2405
|
-
};
|
|
2406
|
-
var opsByDescendingOrder = function opsByDescendingOrder(removeOps) {
|
|
2407
|
-
return sortBy(removeOps, function (a, b) {
|
|
2408
|
-
var splitA = a.path.split('/');
|
|
2409
|
-
var splitB = b.path.split('/');
|
|
2410
|
-
if (splitA.length !== splitB.length) {
|
|
2411
|
-
return splitA.length - splitB.length;
|
|
2412
|
-
} else {
|
|
2413
|
-
return compareByIndexDesc(last(splitA), last(splitB));
|
|
2414
|
-
}
|
|
2415
|
-
});
|
|
2416
|
-
};
|
|
2417
|
-
var partitionOps = function partitionOps(arr, fns) {
|
|
2418
|
-
var initArr = Array(fns.length + 1).fill().map(function () {
|
|
2419
|
-
return [];
|
|
2420
|
-
});
|
|
2421
|
-
return arr.map(function (item) {
|
|
2422
|
-
var position = fns.map(function (fn) {
|
|
2423
|
-
return fn(item);
|
|
2424
|
-
}).indexOf(true);
|
|
2425
|
-
if (position < 0) {
|
|
2426
|
-
position = fns.length;
|
|
2427
|
-
}
|
|
2428
|
-
return {
|
|
2429
|
-
item: item,
|
|
2430
|
-
position: position
|
|
2431
|
-
};
|
|
2432
|
-
}).reduce(function (acc, item) {
|
|
2433
|
-
acc[item.position].push(item.item);
|
|
2434
|
-
return acc;
|
|
2435
|
-
}, initArr);
|
|
2436
|
-
};
|
|
2437
|
-
var isMoveOp = function isMoveOp(_ref3) {
|
|
2438
|
-
var op = _ref3.op;
|
|
2439
|
-
return op === 'move';
|
|
2440
|
-
};
|
|
2441
|
-
var isRemoveOp = function isRemoveOp(_ref4) {
|
|
2442
|
-
var op = _ref4.op;
|
|
2443
|
-
return op === 'remove';
|
|
2444
|
-
};
|
|
2445
|
-
var reorderOps = function reorderOps(diff) {
|
|
2446
|
-
var _partitionOps = partitionOps(diff, [isMoveOp, isRemoveOp]),
|
|
2447
|
-
_partitionOps2 = slicedToArray(_partitionOps, 3),
|
|
2448
|
-
moveOps = _partitionOps2[0],
|
|
2449
|
-
removedOps = _partitionOps2[1],
|
|
2450
|
-
restOps = _partitionOps2[2];
|
|
2451
|
-
var removeOpsReverse = opsByDescendingOrder(removedOps);
|
|
2452
|
-
return [].concat(toConsumableArray(removeOpsReverse), toConsumableArray(moveOps), toConsumableArray(restOps));
|
|
2453
|
-
};
|
|
2454
|
-
var defaultInstance$2 = void 0;
|
|
2455
|
-
var format$2 = function format(delta, left) {
|
|
2456
|
-
if (!defaultInstance$2) {
|
|
2457
|
-
defaultInstance$2 = new JSONFormatter();
|
|
2458
|
-
}
|
|
2459
|
-
return reorderOps(defaultInstance$2.format(delta, left));
|
|
2460
|
-
};
|
|
2461
|
-
var log = function log(delta, left) {
|
|
2462
|
-
console.log(format$2(delta, left));
|
|
2463
|
-
};
|
|
2464
|
-
var jsonpatch = Object.freeze({
|
|
2465
|
-
default: JSONFormatter,
|
|
2466
|
-
partitionOps: partitionOps,
|
|
2467
|
-
format: format$2,
|
|
2468
|
-
log: log
|
|
2469
|
-
});
|
|
2470
|
-
function chalkColor(name) {
|
|
2471
|
-
return chalk__default["default"] && chalk__default["default"][name] || function () {
|
|
2472
|
-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
2473
|
-
args[_key] = arguments[_key];
|
|
2474
|
-
}
|
|
2475
|
-
return args;
|
|
2476
|
-
};
|
|
2477
|
-
}
|
|
2478
|
-
var colors = {
|
|
2479
|
-
added: chalkColor('green'),
|
|
2480
|
-
deleted: chalkColor('red'),
|
|
2481
|
-
movedestination: chalkColor('gray'),
|
|
2482
|
-
moved: chalkColor('yellow'),
|
|
2483
|
-
unchanged: chalkColor('gray'),
|
|
2484
|
-
error: chalkColor('white.bgRed'),
|
|
2485
|
-
textDiffLine: chalkColor('gray')
|
|
2486
|
-
};
|
|
2487
|
-
var ConsoleFormatter = function (_BaseFormatter) {
|
|
2488
|
-
inherits(ConsoleFormatter, _BaseFormatter);
|
|
2489
|
-
function ConsoleFormatter() {
|
|
2490
|
-
classCallCheck(this, ConsoleFormatter);
|
|
2491
|
-
var _this = possibleConstructorReturn(this, (ConsoleFormatter.__proto__ || Object.getPrototypeOf(ConsoleFormatter)).call(this));
|
|
2492
|
-
_this.includeMoveDestinations = false;
|
|
2493
|
-
return _this;
|
|
2494
|
-
}
|
|
2495
|
-
createClass(ConsoleFormatter, [{
|
|
2496
|
-
key: 'prepareContext',
|
|
2497
|
-
value: function prepareContext(context) {
|
|
2498
|
-
get(ConsoleFormatter.prototype.__proto__ || Object.getPrototypeOf(ConsoleFormatter.prototype), 'prepareContext', this).call(this, context);
|
|
2499
|
-
context.indent = function (levels) {
|
|
2500
|
-
this.indentLevel = (this.indentLevel || 0) + (typeof levels === 'undefined' ? 1 : levels);
|
|
2501
|
-
this.indentPad = new Array(this.indentLevel + 1).join(' ');
|
|
2502
|
-
this.outLine();
|
|
2503
|
-
};
|
|
2504
|
-
context.outLine = function () {
|
|
2505
|
-
this.buffer.push('\n' + (this.indentPad || ''));
|
|
2506
|
-
};
|
|
2507
|
-
context.out = function () {
|
|
2508
|
-
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2509
|
-
args[_key2] = arguments[_key2];
|
|
2510
|
-
}
|
|
2511
|
-
for (var i = 0, l = args.length; i < l; i++) {
|
|
2512
|
-
var lines = args[i].split('\n');
|
|
2513
|
-
var text = lines.join('\n' + (this.indentPad || ''));
|
|
2514
|
-
if (this.color && this.color[0]) {
|
|
2515
|
-
text = this.color[0](text);
|
|
2516
|
-
}
|
|
2517
|
-
this.buffer.push(text);
|
|
2518
|
-
}
|
|
2519
|
-
};
|
|
2520
|
-
context.pushColor = function (color) {
|
|
2521
|
-
this.color = this.color || [];
|
|
2522
|
-
this.color.unshift(color);
|
|
2523
|
-
};
|
|
2524
|
-
context.popColor = function () {
|
|
2525
|
-
this.color = this.color || [];
|
|
2526
|
-
this.color.shift();
|
|
2527
|
-
};
|
|
2528
|
-
}
|
|
2529
|
-
}, {
|
|
2530
|
-
key: 'typeFormattterErrorFormatter',
|
|
2531
|
-
value: function typeFormattterErrorFormatter(context, err) {
|
|
2532
|
-
context.pushColor(colors.error);
|
|
2533
|
-
context.out('[ERROR]' + err);
|
|
2534
|
-
context.popColor();
|
|
2535
|
-
}
|
|
2536
|
-
}, {
|
|
2537
|
-
key: 'formatValue',
|
|
2538
|
-
value: function formatValue(context, value) {
|
|
2539
|
-
context.out(JSON.stringify(value, null, 2));
|
|
2540
|
-
}
|
|
2541
|
-
}, {
|
|
2542
|
-
key: 'formatTextDiffString',
|
|
2543
|
-
value: function formatTextDiffString(context, value) {
|
|
2544
|
-
var lines = this.parseTextDiff(value);
|
|
2545
|
-
context.indent();
|
|
2546
|
-
for (var i = 0, l = lines.length; i < l; i++) {
|
|
2547
|
-
var line = lines[i];
|
|
2548
|
-
context.pushColor(colors.textDiffLine);
|
|
2549
|
-
context.out(line.location.line + ',' + line.location.chr + ' ');
|
|
2550
|
-
context.popColor();
|
|
2551
|
-
var pieces = line.pieces;
|
|
2552
|
-
for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
|
|
2553
|
-
var piece = pieces[pieceIndex];
|
|
2554
|
-
context.pushColor(colors[piece.type]);
|
|
2555
|
-
context.out(piece.text);
|
|
2556
|
-
context.popColor();
|
|
2557
|
-
}
|
|
2558
|
-
if (i < l - 1) {
|
|
2559
|
-
context.outLine();
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
context.indent(-1);
|
|
2563
|
-
}
|
|
2564
|
-
}, {
|
|
2565
|
-
key: 'rootBegin',
|
|
2566
|
-
value: function rootBegin(context, type, nodeType) {
|
|
2567
|
-
context.pushColor(colors[type]);
|
|
2568
|
-
if (type === 'node') {
|
|
2569
|
-
context.out(nodeType === 'array' ? '[' : '{');
|
|
2570
|
-
context.indent();
|
|
2571
|
-
}
|
|
2572
|
-
}
|
|
2573
|
-
}, {
|
|
2574
|
-
key: 'rootEnd',
|
|
2575
|
-
value: function rootEnd(context, type, nodeType) {
|
|
2576
|
-
if (type === 'node') {
|
|
2577
|
-
context.indent(-1);
|
|
2578
|
-
context.out(nodeType === 'array' ? ']' : '}');
|
|
2579
|
-
}
|
|
2580
|
-
context.popColor();
|
|
2581
|
-
}
|
|
2582
|
-
}, {
|
|
2583
|
-
key: 'nodeBegin',
|
|
2584
|
-
value: function nodeBegin(context, key, leftKey, type, nodeType) {
|
|
2585
|
-
context.pushColor(colors[type]);
|
|
2586
|
-
context.out(leftKey + ': ');
|
|
2587
|
-
if (type === 'node') {
|
|
2588
|
-
context.out(nodeType === 'array' ? '[' : '{');
|
|
2589
|
-
context.indent();
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
}, {
|
|
2593
|
-
key: 'nodeEnd',
|
|
2594
|
-
value: function nodeEnd(context, key, leftKey, type, nodeType, isLast) {
|
|
2595
|
-
if (type === 'node') {
|
|
2596
|
-
context.indent(-1);
|
|
2597
|
-
context.out(nodeType === 'array' ? ']' : '}' + (isLast ? '' : ','));
|
|
2598
|
-
}
|
|
2599
|
-
if (!isLast) {
|
|
2600
|
-
context.outLine();
|
|
2601
|
-
}
|
|
2602
|
-
context.popColor();
|
|
2603
|
-
}
|
|
2604
|
-
|
|
2605
|
-
/* jshint camelcase: false */
|
|
2606
|
-
/* eslint-disable camelcase */
|
|
2607
|
-
}, {
|
|
2608
|
-
key: 'format_unchanged',
|
|
2609
|
-
value: function format_unchanged(context, delta, left) {
|
|
2610
|
-
if (typeof left === 'undefined') {
|
|
2611
|
-
return;
|
|
2612
|
-
}
|
|
2613
|
-
this.formatValue(context, left);
|
|
2614
|
-
}
|
|
2615
|
-
}, {
|
|
2616
|
-
key: 'format_movedestination',
|
|
2617
|
-
value: function format_movedestination(context, delta, left) {
|
|
2618
|
-
if (typeof left === 'undefined') {
|
|
2619
|
-
return;
|
|
2620
|
-
}
|
|
2621
|
-
this.formatValue(context, left);
|
|
2622
|
-
}
|
|
2623
|
-
}, {
|
|
2624
|
-
key: 'format_node',
|
|
2625
|
-
value: function format_node(context, delta, left) {
|
|
2626
|
-
// recurse
|
|
2627
|
-
this.formatDeltaChildren(context, delta, left);
|
|
2628
|
-
}
|
|
2629
|
-
}, {
|
|
2630
|
-
key: 'format_added',
|
|
2631
|
-
value: function format_added(context, delta) {
|
|
2632
|
-
this.formatValue(context, delta[0]);
|
|
2633
|
-
}
|
|
2634
|
-
}, {
|
|
2635
|
-
key: 'format_modified',
|
|
2636
|
-
value: function format_modified(context, delta) {
|
|
2637
|
-
context.pushColor(colors.deleted);
|
|
2638
|
-
this.formatValue(context, delta[0]);
|
|
2639
|
-
context.popColor();
|
|
2640
|
-
context.out(' => ');
|
|
2641
|
-
context.pushColor(colors.added);
|
|
2642
|
-
this.formatValue(context, delta[1]);
|
|
2643
|
-
context.popColor();
|
|
2644
|
-
}
|
|
2645
|
-
}, {
|
|
2646
|
-
key: 'format_deleted',
|
|
2647
|
-
value: function format_deleted(context, delta) {
|
|
2648
|
-
this.formatValue(context, delta[0]);
|
|
2649
|
-
}
|
|
2650
|
-
}, {
|
|
2651
|
-
key: 'format_moved',
|
|
2652
|
-
value: function format_moved(context, delta) {
|
|
2653
|
-
context.out('==> ' + delta[1]);
|
|
2654
|
-
}
|
|
2655
|
-
}, {
|
|
2656
|
-
key: 'format_textdiff',
|
|
2657
|
-
value: function format_textdiff(context, delta) {
|
|
2658
|
-
this.formatTextDiffString(context, delta[0]);
|
|
2659
|
-
}
|
|
2660
|
-
}]);
|
|
2661
|
-
return ConsoleFormatter;
|
|
2662
|
-
}(BaseFormatter);
|
|
2663
|
-
var defaultInstance$3 = void 0;
|
|
2664
|
-
var format$3 = function format(delta, left) {
|
|
2665
|
-
if (!defaultInstance$3) {
|
|
2666
|
-
defaultInstance$3 = new ConsoleFormatter();
|
|
2667
|
-
}
|
|
2668
|
-
return defaultInstance$3.format(delta, left);
|
|
2669
|
-
};
|
|
2670
|
-
function log$1(delta, left) {
|
|
2671
|
-
console.log(format$3(delta, left));
|
|
2672
|
-
}
|
|
2673
|
-
var console$1 = Object.freeze({
|
|
2674
|
-
default: ConsoleFormatter,
|
|
2675
|
-
format: format$3,
|
|
2676
|
-
log: log$1
|
|
2677
|
-
});
|
|
2678
|
-
Object.freeze({
|
|
2679
|
-
base: base,
|
|
2680
|
-
html: html,
|
|
2681
|
-
annotated: annotated,
|
|
2682
|
-
jsonpatch: jsonpatch,
|
|
2683
|
-
console: console$1
|
|
2684
|
-
});
|
|
2685
1505
|
|
|
2686
1506
|
function objectHash(obj, index) {
|
|
2687
1507
|
var objIndex = "$$index:".concat(index);
|
|
2688
|
-
return _typeof
|
|
1508
|
+
return _typeof(obj) === 'object' && obj !== null ? obj.id || obj.name || obj.url || objIndex : objIndex;
|
|
2689
1509
|
}
|
|
2690
1510
|
var diffpatcher = new DiffPatcher({
|
|
2691
1511
|
objectHash: objectHash,
|
|
@@ -2849,7 +1669,7 @@
|
|
|
2849
1669
|
* false otherwise
|
|
2850
1670
|
*/
|
|
2851
1671
|
function isChangeAction(obj, key) {
|
|
2852
|
-
return REGEX_NUMBER$4.test(key) && (_typeof
|
|
1672
|
+
return REGEX_NUMBER$4.test(key) && (_typeof(obj[key]) === 'object' || typeof obj[key] === 'string');
|
|
2853
1673
|
}
|
|
2854
1674
|
|
|
2855
1675
|
/**
|
|
@@ -2865,7 +1685,7 @@
|
|
|
2865
1685
|
* false otherwise
|
|
2866
1686
|
*/
|
|
2867
1687
|
function isRemoveAction$1(obj, key) {
|
|
2868
|
-
return REGEX_UNDERSCORE_NUMBER$4.test(key) && Array.isArray(obj[key]) && obj[key].length === 3 && (_typeof
|
|
1688
|
+
return REGEX_UNDERSCORE_NUMBER$4.test(key) && Array.isArray(obj[key]) && obj[key].length === 3 && (_typeof(obj[key][0]) === 'object' || typeof obj[key][0] === 'string') && obj[key][1] === 0 && obj[key][2] === 0;
|
|
2869
1689
|
}
|
|
2870
1690
|
|
|
2871
1691
|
/**
|
|
@@ -3017,7 +1837,7 @@
|
|
|
3017
1837
|
action: item.action
|
|
3018
1838
|
}, actionKey, patched);
|
|
3019
1839
|
}).filter(function (action) {
|
|
3020
|
-
return !
|
|
1840
|
+
return !isNil(action);
|
|
3021
1841
|
});
|
|
3022
1842
|
}
|
|
3023
1843
|
|
|
@@ -3124,7 +1944,6 @@
|
|
|
3124
1944
|
return buildReferenceActions({
|
|
3125
1945
|
actions: referenceActionsList$3,
|
|
3126
1946
|
diff: diff,
|
|
3127
|
-
oldObj: oldObj,
|
|
3128
1947
|
newObj: newObj
|
|
3129
1948
|
});
|
|
3130
1949
|
}
|
|
@@ -3150,7 +1969,7 @@
|
|
|
3150
1969
|
function copyEmptyArrayProps() {
|
|
3151
1970
|
var oldObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3152
1971
|
var newObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3153
|
-
if (!
|
|
1972
|
+
if (!isNil(oldObj) && !isNil(newObj)) {
|
|
3154
1973
|
var nextObjectWithEmptyArray = Object.entries(oldObj).reduce(function (merged, _ref) {
|
|
3155
1974
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
3156
1975
|
key = _ref2[0],
|
|
@@ -3165,10 +1984,10 @@
|
|
|
3165
1984
|
return acc;
|
|
3166
1985
|
}, {});
|
|
3167
1986
|
for (var i = 0; i < newObj[key].length; i++) {
|
|
3168
|
-
if (!
|
|
1987
|
+
if (!isNil(newObj[key][i]) && _typeof(newObj[key][i]) === 'object' && !isNil(newObj[key][i].id)) {
|
|
3169
1988
|
// Since its unordered array elements then check if the element on `oldObj` exists by id
|
|
3170
1989
|
var foundObject = hashMapValue[newObj[key][i].id];
|
|
3171
|
-
if (!
|
|
1990
|
+
if (!isNil(foundObject)) {
|
|
3172
1991
|
var _copyEmptyArrayProps = copyEmptyArrayProps(foundObject, newObj[key][i]),
|
|
3173
1992
|
_copyEmptyArrayProps2 = _slicedToArray(_copyEmptyArrayProps, 2),
|
|
3174
1993
|
nestedObject = _copyEmptyArrayProps2[1];
|
|
@@ -3184,10 +2003,10 @@
|
|
|
3184
2003
|
return merged;
|
|
3185
2004
|
}
|
|
3186
2005
|
if (Array.isArray(value)) {
|
|
3187
|
-
merged[key] =
|
|
2006
|
+
merged[key] = isNil(newObj[key]) ? [] : newObj[key];
|
|
3188
2007
|
return merged;
|
|
3189
2008
|
}
|
|
3190
|
-
if (!
|
|
2009
|
+
if (!isNil(newObj[key]) && _typeof(value) === 'object' &&
|
|
3191
2010
|
// Ignore Date as this will create invalid object since typeof date === 'object' return true
|
|
3192
2011
|
// ex: {date: new Date()} will result {date: {}}
|
|
3193
2012
|
!(value instanceof Date)) {
|
|
@@ -3222,7 +2041,7 @@
|
|
|
3222
2041
|
allActions.push(mapActionGroup('assets', function () {
|
|
3223
2042
|
return actionsMapAssets$1(diff, oldObj, newObj);
|
|
3224
2043
|
}));
|
|
3225
|
-
return
|
|
2044
|
+
return flatten(allActions);
|
|
3226
2045
|
};
|
|
3227
2046
|
}
|
|
3228
2047
|
var categories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3340,7 +2159,6 @@
|
|
|
3340
2159
|
return buildReferenceActions({
|
|
3341
2160
|
actions: referenceActionsList$2,
|
|
3342
2161
|
diff: diff,
|
|
3343
|
-
oldObj: oldObj,
|
|
3344
2162
|
newObj: newObj
|
|
3345
2163
|
});
|
|
3346
2164
|
}
|
|
@@ -3448,7 +2266,7 @@
|
|
|
3448
2266
|
authMode: patched
|
|
3449
2267
|
}, value, newObj.password);
|
|
3450
2268
|
}).filter(function (action) {
|
|
3451
|
-
return !
|
|
2269
|
+
return !isNil(action);
|
|
3452
2270
|
});
|
|
3453
2271
|
}
|
|
3454
2272
|
|
|
@@ -3479,7 +2297,7 @@
|
|
|
3479
2297
|
allActions.push(mapActionGroup('authenticationModes', function () {
|
|
3480
2298
|
return actionsMapAuthenticationModes(diff, oldObj, newObj);
|
|
3481
2299
|
}));
|
|
3482
|
-
return
|
|
2300
|
+
return flatten(allActions);
|
|
3483
2301
|
};
|
|
3484
2302
|
}
|
|
3485
2303
|
var customers = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3538,7 +2356,6 @@
|
|
|
3538
2356
|
return buildReferenceActions({
|
|
3539
2357
|
actions: referenceActionsList$1,
|
|
3540
2358
|
diff: diff,
|
|
3541
|
-
oldObj: oldObj,
|
|
3542
2359
|
newObj: newObj
|
|
3543
2360
|
});
|
|
3544
2361
|
}
|
|
@@ -3555,7 +2372,7 @@
|
|
|
3555
2372
|
allActions.push(mapActionGroup('custom', function () {
|
|
3556
2373
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
3557
2374
|
}));
|
|
3558
|
-
return
|
|
2375
|
+
return flatten(allActions);
|
|
3559
2376
|
};
|
|
3560
2377
|
}
|
|
3561
2378
|
var inventories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -3622,7 +2439,7 @@
|
|
|
3622
2439
|
var _preProcessCollection2 = preProcessCollection(now, identifier),
|
|
3623
2440
|
nowObjRefByIdentifier = _preProcessCollection2.refByIdentifier,
|
|
3624
2441
|
nowObjRefByIndex = _preProcessCollection2.refByIndex;
|
|
3625
|
-
|
|
2442
|
+
forEach(diff, function (item, key) {
|
|
3626
2443
|
if (REGEX_NUMBER$3.test(key)) {
|
|
3627
2444
|
var matchingIdentifier = nowObjRefByIndex[key];
|
|
3628
2445
|
result[key] = [beforeObjRefByIdentifier[matchingIdentifier], key];
|
|
@@ -3781,7 +2598,7 @@
|
|
|
3781
2598
|
currencyCode: diffedValue.currencyCode ? getDeltaValue(diffedValue.currencyCode) : attribute.value.currencyCode
|
|
3782
2599
|
};else if (diffedValue.key)
|
|
3783
2600
|
// Enum / LEnum (use only the key)
|
|
3784
|
-
action.value = getDeltaValue(diffedValue.key);else if (_typeof
|
|
2601
|
+
action.value = getDeltaValue(diffedValue.key);else if (_typeof(diffedValue) === 'object') if ({}.hasOwnProperty.call(diffedValue, '_t') && diffedValue._t === 'a') {
|
|
3785
2602
|
// set-typed attribute
|
|
3786
2603
|
action = _objectSpread2(_objectSpread2({}, action), {}, {
|
|
3787
2604
|
value: attribute.value
|
|
@@ -3803,7 +2620,7 @@
|
|
|
3803
2620
|
var actions = [];
|
|
3804
2621
|
// generate a hashMap to be able to reference the right image from both ends
|
|
3805
2622
|
var matchingImagePairs = findMatchingPairs(diffedImages, oldVariant.images, newVariant.images, 'url');
|
|
3806
|
-
|
|
2623
|
+
forEach(diffedImages, function (image, key) {
|
|
3807
2624
|
var _extractMatchingPairs = extractMatchingPairs(matchingImagePairs, key, oldVariant.images, newVariant.images),
|
|
3808
2625
|
oldObj = _extractMatchingPairs.oldObj,
|
|
3809
2626
|
newObj = _extractMatchingPairs.newObj;
|
|
@@ -3813,7 +2630,7 @@
|
|
|
3813
2630
|
action: 'addExternalImage',
|
|
3814
2631
|
variantId: oldVariant.id,
|
|
3815
2632
|
image: getDeltaValue(image)
|
|
3816
|
-
});else if (_typeof
|
|
2633
|
+
});else if (_typeof(image) === 'object') if ({}.hasOwnProperty.call(image, 'url') && image.url.length === 2) {
|
|
3817
2634
|
// There is a new image, remove the old one first.
|
|
3818
2635
|
actions.push({
|
|
3819
2636
|
action: 'removeImage',
|
|
@@ -3860,7 +2677,7 @@
|
|
|
3860
2677
|
|
|
3861
2678
|
// generate a hashMap to be able to reference the right image from both ends
|
|
3862
2679
|
var matchingPricePairs = findMatchingPairs(diffedPrices, oldVariant.prices, newVariant.prices);
|
|
3863
|
-
|
|
2680
|
+
forEach(diffedPrices, function (price, key) {
|
|
3864
2681
|
var _extractMatchingPairs2 = extractMatchingPairs(matchingPricePairs, key, oldVariant.prices, newVariant.prices),
|
|
3865
2682
|
oldObj = _extractMatchingPairs2.oldObj,
|
|
3866
2683
|
newObj = _extractMatchingPairs2.newObj;
|
|
@@ -3908,7 +2725,7 @@
|
|
|
3908
2725
|
function _buildVariantAttributesActions(attributes, oldVariant, newVariant, sameForAllAttributeNames) {
|
|
3909
2726
|
var actions = [];
|
|
3910
2727
|
if (!attributes) return actions;
|
|
3911
|
-
|
|
2728
|
+
forEach(attributes, function (value, key) {
|
|
3912
2729
|
if (REGEX_NUMBER$2.test(key)) {
|
|
3913
2730
|
if (Array.isArray(value)) {
|
|
3914
2731
|
var id = oldVariant.id;
|
|
@@ -3973,8 +2790,8 @@
|
|
|
3973
2790
|
}).filter(function (_) {
|
|
3974
2791
|
return _ !== undefined;
|
|
3975
2792
|
});
|
|
3976
|
-
var assetIdsToKeep =
|
|
3977
|
-
var assetIdsToRemove =
|
|
2793
|
+
var assetIdsToKeep = intersection(assetIdsCurrent, assetIdsBefore);
|
|
2794
|
+
var assetIdsToRemove = without.apply(void 0, [assetIdsBefore].concat(_toConsumableArray(assetIdsToKeep)));
|
|
3978
2795
|
var changeAssetOrderAction = _objectSpread2({
|
|
3979
2796
|
action: 'changeAssetOrder',
|
|
3980
2797
|
assetOrder: assetIdsToKeep.concat(assetIdsToRemove)
|
|
@@ -3986,7 +2803,7 @@
|
|
|
3986
2803
|
|
|
3987
2804
|
// generate a hashMap to be able to reference the right asset from both ends
|
|
3988
2805
|
var matchingAssetPairs = findMatchingPairs(diffAssets, oldVariant.assets, newVariant.assets);
|
|
3989
|
-
|
|
2806
|
+
forEach(diffAssets, function (asset, key) {
|
|
3990
2807
|
var _extractMatchingPairs3 = extractMatchingPairs(matchingAssetPairs, key, oldVariant.assets, newVariant.assets),
|
|
3991
2808
|
oldAsset = _extractMatchingPairs3.oldObj,
|
|
3992
2809
|
newAsset = _extractMatchingPairs3.newObj;
|
|
@@ -4085,7 +2902,6 @@
|
|
|
4085
2902
|
return buildReferenceActions({
|
|
4086
2903
|
actions: referenceActionsList,
|
|
4087
2904
|
diff: diff,
|
|
4088
|
-
oldObj: oldObj,
|
|
4089
2905
|
newObj: newObj
|
|
4090
2906
|
});
|
|
4091
2907
|
}
|
|
@@ -4094,7 +2910,7 @@
|
|
|
4094
2910
|
if (!diff.categories) return actions;
|
|
4095
2911
|
var addToCategoryActions = [];
|
|
4096
2912
|
var removeFromCategoryActions = [];
|
|
4097
|
-
|
|
2913
|
+
forEach(diff.categories, function (category) {
|
|
4098
2914
|
if (Array.isArray(category)) {
|
|
4099
2915
|
var action = {
|
|
4100
2916
|
category: category[0]
|
|
@@ -4139,7 +2955,7 @@
|
|
|
4139
2955
|
function actionsMapAssets(diff, oldObj, newObj, variantHashMap) {
|
|
4140
2956
|
var allAssetsActions = [];
|
|
4141
2957
|
var variants = diff.variants;
|
|
4142
|
-
if (variants)
|
|
2958
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
4143
2959
|
var _extractMatchingPairs4 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
4144
2960
|
oldVariant = _extractMatchingPairs4.oldObj,
|
|
4145
2961
|
newVariant = _extractMatchingPairs4.newObj;
|
|
@@ -4155,7 +2971,7 @@
|
|
|
4155
2971
|
var variantHashMap = arguments.length > 4 ? arguments[4] : undefined;
|
|
4156
2972
|
var actions = [];
|
|
4157
2973
|
var variants = diff.variants;
|
|
4158
|
-
if (variants)
|
|
2974
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
4159
2975
|
var _extractMatchingPairs5 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
4160
2976
|
oldVariant = _extractMatchingPairs5.oldObj,
|
|
4161
2977
|
newVariant = _extractMatchingPairs5.newObj;
|
|
@@ -4172,14 +2988,14 @@
|
|
|
4172
2988
|
|
|
4173
2989
|
// Ensure that an action is unique.
|
|
4174
2990
|
// This is especially necessary for SFA attributes.
|
|
4175
|
-
return
|
|
2991
|
+
return uniqWith(actions, function (a, b) {
|
|
4176
2992
|
return a.action === b.action && a.name === b.name && a.variantId === b.variantId;
|
|
4177
2993
|
});
|
|
4178
2994
|
}
|
|
4179
2995
|
function actionsMapImages(diff, oldObj, newObj, variantHashMap) {
|
|
4180
2996
|
var actions = [];
|
|
4181
2997
|
var variants = diff.variants;
|
|
4182
|
-
if (variants)
|
|
2998
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
4183
2999
|
var _extractMatchingPairs6 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
4184
3000
|
oldVariant = _extractMatchingPairs6.oldObj,
|
|
4185
3001
|
newVariant = _extractMatchingPairs6.newObj;
|
|
@@ -4195,7 +3011,7 @@
|
|
|
4195
3011
|
var changePriceActions = [];
|
|
4196
3012
|
var removePriceActions = [];
|
|
4197
3013
|
var variants = diff.variants;
|
|
4198
|
-
if (variants)
|
|
3014
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
4199
3015
|
var _extractMatchingPairs7 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
4200
3016
|
oldVariant = _extractMatchingPairs7.oldObj,
|
|
4201
3017
|
newVariant = _extractMatchingPairs7.newObj;
|
|
@@ -4217,13 +3033,13 @@
|
|
|
4217
3033
|
function actionsMapPricesCustom(diff, oldObj, newObj, variantHashMap) {
|
|
4218
3034
|
var actions = [];
|
|
4219
3035
|
var variants = diff.variants;
|
|
4220
|
-
if (variants)
|
|
3036
|
+
if (variants) forEach(variants, function (variant, key) {
|
|
4221
3037
|
var _extractMatchingPairs8 = extractMatchingPairs(variantHashMap, key, oldObj.variants, newObj.variants),
|
|
4222
3038
|
oldVariant = _extractMatchingPairs8.oldObj,
|
|
4223
3039
|
newVariant = _extractMatchingPairs8.newObj;
|
|
4224
3040
|
if (variant && variant.prices && (REGEX_UNDERSCORE_NUMBER$2.test(key) || REGEX_NUMBER$2.test(key))) {
|
|
4225
3041
|
var priceHashMap = findMatchingPairs(variant.prices, oldVariant.prices, newVariant.prices);
|
|
4226
|
-
|
|
3042
|
+
forEach(variant.prices, function (price, index) {
|
|
4227
3043
|
var _extractMatchingPairs9 = extractMatchingPairs(priceHashMap, index, oldVariant.prices, newVariant.prices),
|
|
4228
3044
|
oldPrice = _extractMatchingPairs9.oldObj,
|
|
4229
3045
|
newPrice = _extractMatchingPairs9.newObj;
|
|
@@ -4307,12 +3123,12 @@
|
|
|
4307
3123
|
allActions.push(mapActionGroup('assets', function () {
|
|
4308
3124
|
return actionsMapAssets(diff, oldObj, newObj, variantHashMap);
|
|
4309
3125
|
}));
|
|
4310
|
-
if (publish === true || staged === false) return
|
|
3126
|
+
if (publish === true || staged === false) return flatten(allActions).map(function (action) {
|
|
4311
3127
|
return _objectSpread2(_objectSpread2({}, action), {}, {
|
|
4312
3128
|
staged: false
|
|
4313
3129
|
});
|
|
4314
3130
|
});
|
|
4315
|
-
return
|
|
3131
|
+
return flatten(allActions);
|
|
4316
3132
|
};
|
|
4317
3133
|
}
|
|
4318
3134
|
function moveMasterVariantsIntoVariants(before, now) {
|
|
@@ -4395,7 +3211,7 @@
|
|
|
4395
3211
|
|
|
4396
3212
|
// generate a hashMap to be able to reference the right image from both ends
|
|
4397
3213
|
var matchingParcelPairs = findMatchingPairs(diffedParcels, oldDelivery.parcels, newDelivery.parcels);
|
|
4398
|
-
|
|
3214
|
+
forEach(diffedParcels, function (parcel, key) {
|
|
4399
3215
|
var _extractMatchingPairs = extractMatchingPairs(matchingParcelPairs, key, oldDelivery.parcels, newDelivery.parcels),
|
|
4400
3216
|
oldObj = _extractMatchingPairs.oldObj;
|
|
4401
3217
|
if (isAddAction(key, parcel)) {
|
|
@@ -4437,7 +3253,7 @@
|
|
|
4437
3253
|
if (!deliveries) return [];
|
|
4438
3254
|
var addParcelActions = [];
|
|
4439
3255
|
var removeParcelActions = [];
|
|
4440
|
-
if (deliveries)
|
|
3256
|
+
if (deliveries) forEach(deliveries, function (delivery, key) {
|
|
4441
3257
|
var _extractMatchingPairs2 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
|
|
4442
3258
|
oldDelivery = _extractMatchingPairs2.oldObj,
|
|
4443
3259
|
newDelivery = _extractMatchingPairs2.newObj;
|
|
@@ -4458,7 +3274,7 @@
|
|
|
4458
3274
|
var deliveries = shippingInfo.deliveries;
|
|
4459
3275
|
if (!deliveries) return [];
|
|
4460
3276
|
var setDeliveryItemsActions = [];
|
|
4461
|
-
|
|
3277
|
+
forEach(deliveries, function (delivery, key) {
|
|
4462
3278
|
var _extractMatchingPairs3 = extractMatchingPairs(deliveryHashMap, key, oldObj.shippingInfo.deliveries, newObj.shippingInfo.deliveries),
|
|
4463
3279
|
newDelivery = _extractMatchingPairs3.newObj;
|
|
4464
3280
|
if (REGEX_UNDERSCORE_NUMBER$1.test(key) || REGEX_NUMBER$1.test(key)) {
|
|
@@ -4527,13 +3343,13 @@
|
|
|
4527
3343
|
allActions.push(mapActionGroup('items', function () {
|
|
4528
3344
|
return actionsMapDeliveryItems(diff, oldObj, newObj, deliveryHashMap);
|
|
4529
3345
|
}));
|
|
4530
|
-
allActions.push(
|
|
3346
|
+
allActions.push(flatten(mapActionGroup('returnInfo', function () {
|
|
4531
3347
|
return actionsMapReturnsInfo(diff, oldObj, newObj);
|
|
4532
3348
|
})));
|
|
4533
3349
|
allActions.push(mapActionGroup('custom', function () {
|
|
4534
3350
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
4535
3351
|
}));
|
|
4536
|
-
return
|
|
3352
|
+
return flatten(allActions);
|
|
4537
3353
|
};
|
|
4538
3354
|
}
|
|
4539
3355
|
var orders = (function (actionGroupList, syncActionConfig) {
|
|
@@ -4627,7 +3443,7 @@
|
|
|
4627
3443
|
allActions.push(mapActionGroup('base', function () {
|
|
4628
3444
|
return actionsMapBase$f(diff, oldObj, newObj, syncActionConfig);
|
|
4629
3445
|
}));
|
|
4630
|
-
return combineValidityActions(
|
|
3446
|
+
return combineValidityActions(flatten(allActions));
|
|
4631
3447
|
};
|
|
4632
3448
|
}
|
|
4633
3449
|
var productDiscounts = (function (actionGroupList) {
|
|
@@ -4696,7 +3512,7 @@
|
|
|
4696
3512
|
allActions.push(mapActionGroup('custom', function () {
|
|
4697
3513
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
4698
3514
|
}));
|
|
4699
|
-
return combineValidityActions(
|
|
3515
|
+
return combineValidityActions(flatten(allActions));
|
|
4700
3516
|
};
|
|
4701
3517
|
}
|
|
4702
3518
|
var discountCodes = (function (actionGroupList) {
|
|
@@ -4749,7 +3565,7 @@
|
|
|
4749
3565
|
allActions.push(mapActionGroup('custom', function () {
|
|
4750
3566
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
4751
3567
|
}));
|
|
4752
|
-
return
|
|
3568
|
+
return flatten(allActions);
|
|
4753
3569
|
};
|
|
4754
3570
|
}
|
|
4755
3571
|
var customerGroup = (function (actionGroupList) {
|
|
@@ -4821,7 +3637,7 @@
|
|
|
4821
3637
|
allActions.push(mapActionGroup('custom', function () {
|
|
4822
3638
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
4823
3639
|
}));
|
|
4824
|
-
return combineValidityActions(
|
|
3640
|
+
return combineValidityActions(flatten(allActions));
|
|
4825
3641
|
};
|
|
4826
3642
|
}
|
|
4827
3643
|
var cartDiscounts = (function (actionGroupList) {
|
|
@@ -4916,8 +3732,8 @@
|
|
|
4916
3732
|
if (cache === void 0) {
|
|
4917
3733
|
cache = getNewCache();
|
|
4918
3734
|
}
|
|
4919
|
-
var isCacheableA = !!a && _typeof
|
|
4920
|
-
var isCacheableB = !!b && _typeof
|
|
3735
|
+
var isCacheableA = !!a && _typeof(a) === 'object';
|
|
3736
|
+
var isCacheableB = !!b && _typeof(b) === 'object';
|
|
4921
3737
|
if (isCacheableA || isCacheableB) {
|
|
4922
3738
|
var hasA = isCacheableA && cache.has(a);
|
|
4923
3739
|
var hasB = isCacheableB && cache.has(b);
|
|
@@ -5083,7 +3899,7 @@
|
|
|
5083
3899
|
if (a === b) {
|
|
5084
3900
|
return true;
|
|
5085
3901
|
}
|
|
5086
|
-
if (a && b && _typeof
|
|
3902
|
+
if (a && b && _typeof(a) === 'object' && _typeof(b) === 'object') {
|
|
5087
3903
|
if (isPlainObject(a) && isPlainObject(b)) {
|
|
5088
3904
|
return areObjectsEqual(a, b, isEqual, meta);
|
|
5089
3905
|
}
|
|
@@ -5201,7 +4017,7 @@
|
|
|
5201
4017
|
allActions.push(mapActionGroup('rates', function () {
|
|
5202
4018
|
return actionsMapRates(diff, oldObj, newObj);
|
|
5203
4019
|
}));
|
|
5204
|
-
return
|
|
4020
|
+
return flatten(allActions);
|
|
5205
4021
|
};
|
|
5206
4022
|
}
|
|
5207
4023
|
var taxCategories = (function (actionGroupList, syncActionConfig) {
|
|
@@ -5292,10 +4108,10 @@
|
|
|
5292
4108
|
allActions.push(mapActionGroup('base', function () {
|
|
5293
4109
|
return actionsMapBase$a(diff, oldObj, newObj, syncActionConfig);
|
|
5294
4110
|
}));
|
|
5295
|
-
allActions.push(
|
|
4111
|
+
allActions.push(flatten(mapActionGroup('locations', function () {
|
|
5296
4112
|
return actionsMapLocations(diff, oldObj, newObj);
|
|
5297
4113
|
})));
|
|
5298
|
-
return
|
|
4114
|
+
return flatten(allActions);
|
|
5299
4115
|
};
|
|
5300
4116
|
}
|
|
5301
4117
|
var zones = (function (actionGroupList, syncActionConfig) {
|
|
@@ -5411,7 +4227,7 @@
|
|
|
5411
4227
|
if (diff.zoneRates[key].shippingRates) return [].concat(_toConsumableArray(actions), _toConsumableArray(actionsMapZoneRatesShippingRates(diff.zoneRates[key], oldZoneRate, newZoneRate)));
|
|
5412
4228
|
return actions;
|
|
5413
4229
|
}, []);
|
|
5414
|
-
return
|
|
4230
|
+
return flatten(hasZoneActions ? [].concat(_toConsumableArray(shippingRateActions), [{
|
|
5415
4231
|
action: 'removeZone',
|
|
5416
4232
|
zone: oldZoneRate.zone
|
|
5417
4233
|
}, {
|
|
@@ -5428,13 +4244,13 @@
|
|
|
5428
4244
|
allActions.push(mapActionGroup('base', function () {
|
|
5429
4245
|
return actionsMapBase$9(diff, oldObj, newObj, syncActionConfig);
|
|
5430
4246
|
}));
|
|
5431
|
-
allActions.push(
|
|
4247
|
+
allActions.push(flatten(mapActionGroup('zoneRates', function () {
|
|
5432
4248
|
return actionsMapZoneRates(diff, oldObj, newObj);
|
|
5433
4249
|
})));
|
|
5434
4250
|
allActions.push(mapActionGroup('custom', function () {
|
|
5435
4251
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
5436
4252
|
}));
|
|
5437
|
-
return
|
|
4253
|
+
return flatten(allActions);
|
|
5438
4254
|
};
|
|
5439
4255
|
}
|
|
5440
4256
|
var shippingMethods = (function (actionGroupList, syncActionConfig) {
|
|
@@ -5566,7 +4382,7 @@
|
|
|
5566
4382
|
action: 'removeAttributeDefinition',
|
|
5567
4383
|
name: attributeDef.previous.name
|
|
5568
4384
|
};
|
|
5569
|
-
})), _toConsumableArray(
|
|
4385
|
+
})), _toConsumableArray(flatten(updatedAttributeDefinitions.map(function (updatedAttributeDefinition) {
|
|
5570
4386
|
return generateBaseFieldsUpdateActions(updatedAttributeDefinition.previous, updatedAttributeDefinition.next, {
|
|
5571
4387
|
label: {
|
|
5572
4388
|
action: 'changeLabel',
|
|
@@ -5616,7 +4432,7 @@
|
|
|
5616
4432
|
return _objectSpread2(_objectSpread2({}, nextEnumUpdateActions), {}, _defineProperty({}, removedAttributeEnumValue.hint.attributeName, _objectSpread2(_objectSpread2({}, removedAttributeEnumValueOfSameAttributeName), {}, {
|
|
5617
4433
|
keys: [].concat(_toConsumableArray(removedAttributeEnumValueOfSameAttributeName.keys), [removedAttributeEnumValue.previous.key])
|
|
5618
4434
|
})));
|
|
5619
|
-
}, {}))), _toConsumableArray(
|
|
4435
|
+
}, {}))), _toConsumableArray(flatten(updatedAttributeEnumValues.map(function (updatedAttributeEnumValue) {
|
|
5620
4436
|
var updateActions = generateBaseFieldsUpdateActions(updatedAttributeEnumValue.previous, updatedAttributeEnumValue.next, {
|
|
5621
4437
|
key: {
|
|
5622
4438
|
action: 'changeEnumKey',
|
|
@@ -5690,7 +4506,7 @@
|
|
|
5690
4506
|
|
|
5691
4507
|
function createProductTypeMapActions(mapActionGroup, syncActionConfig) {
|
|
5692
4508
|
return function doMapActions(diff, next, previous, options) {
|
|
5693
|
-
return
|
|
4509
|
+
return flatten([
|
|
5694
4510
|
// we support only base fields for the product type,
|
|
5695
4511
|
// for attributes, applying hints would be recommended
|
|
5696
4512
|
mapActionGroup('base', function () {
|
|
@@ -5786,7 +4602,7 @@
|
|
|
5786
4602
|
roleActions.push(mapActionGroup('roles', function () {
|
|
5787
4603
|
return actionsMapRoles(diff, oldObj, newObj);
|
|
5788
4604
|
}));
|
|
5789
|
-
return
|
|
4605
|
+
return flatten([].concat(baseActions, _toConsumableArray(groupRoleActions(roleActions))));
|
|
5790
4606
|
};
|
|
5791
4607
|
}
|
|
5792
4608
|
var states = (function (actionGroupList, syncActionConfig) {
|
|
@@ -5839,7 +4655,7 @@
|
|
|
5839
4655
|
allActions.push(mapActionGroup('custom', function () {
|
|
5840
4656
|
return actionsMapCustom(diff, newObj, oldObj);
|
|
5841
4657
|
}));
|
|
5842
|
-
return
|
|
4658
|
+
return flatten(allActions);
|
|
5843
4659
|
};
|
|
5844
4660
|
}
|
|
5845
4661
|
var channels = (function (actionGroupList) {
|
|
@@ -5910,7 +4726,7 @@
|
|
|
5910
4726
|
var foundPreviousEnum = previous.values.find(function (previousEnum) {
|
|
5911
4727
|
return previousEnum.key === newEnum.key;
|
|
5912
4728
|
});
|
|
5913
|
-
var isLabelEqual =
|
|
4729
|
+
var isLabelEqual = isEqual(foundPreviousEnum.label, newEnum.label);
|
|
5914
4730
|
if (isKeyChanged) {
|
|
5915
4731
|
// these actions is then flatten in the end
|
|
5916
4732
|
changeActions.push({
|
|
@@ -5939,7 +4755,7 @@
|
|
|
5939
4755
|
// following lists are necessary to ensure that when we change the
|
|
5940
4756
|
// order of enumValues, we generate one updateAction instead of one at a time.
|
|
5941
4757
|
var newEnumValuesOrder = [];
|
|
5942
|
-
|
|
4758
|
+
flatten(buildArrayActions(attributeDiff, previous, next)).forEach(function (updateAction) {
|
|
5943
4759
|
if (updateAction.action === changeEnumOrderActionName) {
|
|
5944
4760
|
newEnumValuesOrder = next.values.map(function (enumValue) {
|
|
5945
4761
|
return enumValue.key;
|
|
@@ -5954,7 +4770,7 @@
|
|
|
5954
4770
|
}
|
|
5955
4771
|
function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPaths) {
|
|
5956
4772
|
var actions = [];
|
|
5957
|
-
|
|
4773
|
+
forEach(fieldDefinitionsDiff, function (diffValue, diffKey) {
|
|
5958
4774
|
var extractedPairs = extractMatchingPairs(diffPaths, diffKey, previous, next);
|
|
5959
4775
|
if (getIsChangedOperation(diffKey)) {
|
|
5960
4776
|
var _diffValue$type;
|
|
@@ -6005,7 +4821,7 @@
|
|
|
6005
4821
|
// in order to prevent any eventual removal of `addAction`.
|
|
6006
4822
|
// List of `removeActions` can be found here
|
|
6007
4823
|
// https://docs.commercetools.com/http-api-projects-types.html#change-key
|
|
6008
|
-
var sortedActions =
|
|
4824
|
+
var sortedActions = sortBy(actions, function (action) {
|
|
6009
4825
|
return action.action !== 'removeFieldDefinition';
|
|
6010
4826
|
});
|
|
6011
4827
|
return sortedActions;
|
|
@@ -6019,7 +4835,7 @@
|
|
|
6019
4835
|
}), mapActionGroup('fieldDefinitions', function () {
|
|
6020
4836
|
return actionsMapFieldDefinitions(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, findMatchingPairs(diff.fieldDefinitions, previous.fieldDefinitions, next.fieldDefinitions, 'name'));
|
|
6021
4837
|
}));
|
|
6022
|
-
return
|
|
4838
|
+
return flatten(allActions);
|
|
6023
4839
|
};
|
|
6024
4840
|
}
|
|
6025
4841
|
var types = (function (actionGroupList, syncActionConfig) {
|
|
@@ -6121,7 +4937,7 @@
|
|
|
6121
4937
|
allActions.push(mapActionGroup('searchIndexingConfiguration', function () {
|
|
6122
4938
|
return actionsMapSearchIndexingConfiguration(diff, oldObj, newObj);
|
|
6123
4939
|
}));
|
|
6124
|
-
return
|
|
4940
|
+
return flatten(allActions);
|
|
6125
4941
|
};
|
|
6126
4942
|
}
|
|
6127
4943
|
var projects = (function (actionGroupList) {
|
|
@@ -6169,7 +4985,7 @@
|
|
|
6169
4985
|
allActions.push(mapActionGroup('custom', function () {
|
|
6170
4986
|
return actionsMapCustom(diff, next, previous);
|
|
6171
4987
|
}));
|
|
6172
|
-
return
|
|
4988
|
+
return flatten(allActions);
|
|
6173
4989
|
};
|
|
6174
4990
|
}
|
|
6175
4991
|
var stores = (function (actionGroupList) {
|
|
@@ -6212,7 +5028,7 @@
|
|
|
6212
5028
|
allActions.push(mapActionGroup('custom', function () {
|
|
6213
5029
|
return actionsMapCustom(diff, next, previous);
|
|
6214
5030
|
}));
|
|
6215
|
-
return
|
|
5031
|
+
return flatten(allActions);
|
|
6216
5032
|
};
|
|
6217
5033
|
}
|
|
6218
5034
|
var productSelections = (function (actionGroupList) {
|
|
@@ -6347,10 +5163,10 @@
|
|
|
6347
5163
|
allActions.push(mapActionGroup('base', function () {
|
|
6348
5164
|
return actionsMapBase(diff, oldObj, newObj, syncActionConfig);
|
|
6349
5165
|
}));
|
|
6350
|
-
allActions.push(
|
|
5166
|
+
allActions.push(flatten(mapActionGroup('attributes', function () {
|
|
6351
5167
|
return actionsMapAttributes(diff, oldObj, newObj);
|
|
6352
5168
|
})));
|
|
6353
|
-
return
|
|
5169
|
+
return flatten(allActions);
|
|
6354
5170
|
};
|
|
6355
5171
|
}
|
|
6356
5172
|
var attributeGroups = (function (actionGroupList, syncActionConfig) {
|
|
@@ -6384,6 +5200,4 @@
|
|
|
6384
5200
|
exports.createSyncTypes = types;
|
|
6385
5201
|
exports.createSyncZones = zones;
|
|
6386
5202
|
|
|
6387
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6388
|
-
|
|
6389
5203
|
}));
|