object-diagram-js-differ 1.0.2 → 1.0.3
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.
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
return obj === undefined;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function isNil(obj) {
|
|
25
|
+
return obj == null;
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
function isArray(obj) {
|
|
25
29
|
return nativeToString.call(obj) === '[object Array]';
|
|
26
30
|
}
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
* @return {Boolean}
|
|
35
39
|
*/
|
|
36
40
|
function has(target, key) {
|
|
37
|
-
return nativeHasOwnProperty.call(target, key);
|
|
41
|
+
return !isNil(target) && nativeHasOwnProperty.call(target, key);
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
|
|
@@ -104,66 +108,137 @@
|
|
|
104
108
|
return Number(arg);
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
function cloneRegExp(re) {
|
|
112
|
+
var _a;
|
|
113
|
+
const regexMatch = /^\/(.*)\/([gimyu]*)$/.exec(re.toString());
|
|
114
|
+
if (!regexMatch) {
|
|
115
|
+
throw new Error("Invalid RegExp");
|
|
111
116
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
117
|
+
return new RegExp((_a = regexMatch[1]) !== null && _a !== void 0 ? _a : "", regexMatch[2]);
|
|
118
|
+
}
|
|
119
|
+
function clone(arg) {
|
|
120
|
+
if (typeof arg !== "object") {
|
|
121
|
+
return arg;
|
|
122
|
+
}
|
|
123
|
+
if (arg === null) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
if (Array.isArray(arg)) {
|
|
127
|
+
return arg.map(clone);
|
|
128
|
+
}
|
|
129
|
+
if (arg instanceof Date) {
|
|
130
|
+
return new Date(arg.getTime());
|
|
131
|
+
}
|
|
132
|
+
if (arg instanceof RegExp) {
|
|
133
|
+
return cloneRegExp(arg);
|
|
134
|
+
}
|
|
135
|
+
const cloned = {};
|
|
136
|
+
for (const name in arg) {
|
|
137
|
+
if (Object.prototype.hasOwnProperty.call(arg, name)) {
|
|
138
|
+
cloned[name] = clone(arg[name]);
|
|
115
139
|
}
|
|
116
|
-
return this.selfOptions;
|
|
117
140
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
141
|
+
return cloned;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function assertNonEmptyArray(arr, message) {
|
|
145
|
+
if (arr.length === 0) {
|
|
146
|
+
throw new Error("Expected a non-empty array");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* type-safe version of `arr[arr.length - 1]`
|
|
151
|
+
* @param arr a non empty array
|
|
152
|
+
* @returns the last element of the array
|
|
153
|
+
*/
|
|
154
|
+
const lastNonEmpty = (arr) => arr[arr.length - 1];
|
|
155
|
+
|
|
156
|
+
class Context {
|
|
157
|
+
setResult(result) {
|
|
158
|
+
this.result = result;
|
|
159
|
+
this.hasResult = true;
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
exit() {
|
|
163
|
+
this.exiting = true;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
push(child, name) {
|
|
167
|
+
child.parent = this;
|
|
168
|
+
if (typeof name !== "undefined") {
|
|
169
|
+
child.childName = name;
|
|
128
170
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.pipes[pipe.name] = pipe;
|
|
171
|
+
child.root = this.root || this;
|
|
172
|
+
child.options = child.options || this.options;
|
|
173
|
+
if (!this.children) {
|
|
174
|
+
this.children = [child];
|
|
175
|
+
this.nextAfterChildren = this.next || null;
|
|
176
|
+
this.next = child;
|
|
136
177
|
}
|
|
137
|
-
|
|
138
|
-
|
|
178
|
+
else {
|
|
179
|
+
assertNonEmptyArray(this.children);
|
|
180
|
+
lastNonEmpty(this.children).next = child;
|
|
181
|
+
this.children.push(child);
|
|
182
|
+
}
|
|
183
|
+
child.next = this;
|
|
184
|
+
return this;
|
|
139
185
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (
|
|
153
|
-
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
class DiffContext extends Context {
|
|
189
|
+
constructor(left, right) {
|
|
190
|
+
super();
|
|
191
|
+
this.left = left;
|
|
192
|
+
this.right = right;
|
|
193
|
+
this.pipe = "diff";
|
|
194
|
+
}
|
|
195
|
+
prepareDeltaResult(result) {
|
|
196
|
+
var _a, _b, _c, _d;
|
|
197
|
+
if (typeof result === "object") {
|
|
198
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.omitRemovedValues) &&
|
|
199
|
+
Array.isArray(result) &&
|
|
200
|
+
result.length > 1 &&
|
|
201
|
+
(result.length === 2 || // modified
|
|
202
|
+
result[2] === 0 || // deleted
|
|
203
|
+
result[2] === 3) // moved
|
|
204
|
+
) {
|
|
205
|
+
// omit the left/old value (this delta will be more compact but irreversible)
|
|
206
|
+
result[0] = 0;
|
|
154
207
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
208
|
+
if ((_b = this.options) === null || _b === void 0 ? void 0 : _b.cloneDiffValues) {
|
|
209
|
+
const clone$1 = typeof ((_c = this.options) === null || _c === void 0 ? void 0 : _c.cloneDiffValues) === "function"
|
|
210
|
+
? (_d = this.options) === null || _d === void 0 ? void 0 : _d.cloneDiffValues
|
|
211
|
+
: clone;
|
|
212
|
+
if (typeof result[0] === "object") {
|
|
213
|
+
result[0] = clone$1(result[0]);
|
|
214
|
+
}
|
|
215
|
+
if (typeof result[1] === "object") {
|
|
216
|
+
result[1] = clone$1(result[1]);
|
|
162
217
|
}
|
|
163
218
|
}
|
|
164
219
|
}
|
|
165
|
-
|
|
166
|
-
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
setResult(result) {
|
|
223
|
+
this.prepareDeltaResult(result);
|
|
224
|
+
return super.setResult(result);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
class PatchContext extends Context {
|
|
229
|
+
constructor(left, delta) {
|
|
230
|
+
super();
|
|
231
|
+
this.left = left;
|
|
232
|
+
this.delta = delta;
|
|
233
|
+
this.pipe = "patch";
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
class ReverseContext extends Context {
|
|
238
|
+
constructor(delta) {
|
|
239
|
+
super();
|
|
240
|
+
this.delta = delta;
|
|
241
|
+
this.pipe = "reverse";
|
|
167
242
|
}
|
|
168
243
|
}
|
|
169
244
|
|
|
@@ -175,18 +250,20 @@
|
|
|
175
250
|
}
|
|
176
251
|
process(input) {
|
|
177
252
|
if (!this.processor) {
|
|
178
|
-
throw new Error(
|
|
253
|
+
throw new Error("add this pipe to a processor before using it");
|
|
179
254
|
}
|
|
180
255
|
const debug = this.debug;
|
|
181
256
|
const length = this.filters.length;
|
|
182
257
|
const context = input;
|
|
183
258
|
for (let index = 0; index < length; index++) {
|
|
184
259
|
const filter = this.filters[index];
|
|
260
|
+
if (!filter)
|
|
261
|
+
continue;
|
|
185
262
|
if (debug) {
|
|
186
263
|
this.log(`filter: ${filter.filterName}`);
|
|
187
264
|
}
|
|
188
265
|
filter(context);
|
|
189
|
-
if (typeof context ===
|
|
266
|
+
if (typeof context === "object" && context.exiting) {
|
|
190
267
|
context.exiting = false;
|
|
191
268
|
break;
|
|
192
269
|
}
|
|
@@ -208,11 +285,11 @@
|
|
|
208
285
|
}
|
|
209
286
|
indexOf(filterName) {
|
|
210
287
|
if (!filterName) {
|
|
211
|
-
throw new Error(
|
|
288
|
+
throw new Error("a filter name is required");
|
|
212
289
|
}
|
|
213
290
|
for (let index = 0; index < this.filters.length; index++) {
|
|
214
291
|
const filter = this.filters[index];
|
|
215
|
-
if (filter.filterName === filterName) {
|
|
292
|
+
if ((filter === null || filter === void 0 ? void 0 : filter.filterName) === filterName) {
|
|
216
293
|
return index;
|
|
217
294
|
}
|
|
218
295
|
}
|
|
@@ -248,10 +325,10 @@
|
|
|
248
325
|
shouldHaveResult(should) {
|
|
249
326
|
if (should === false) {
|
|
250
327
|
this.resultCheck = null;
|
|
251
|
-
return;
|
|
328
|
+
return this;
|
|
252
329
|
}
|
|
253
330
|
if (this.resultCheck) {
|
|
254
|
-
return;
|
|
331
|
+
return this;
|
|
255
332
|
}
|
|
256
333
|
this.resultCheck = (context) => {
|
|
257
334
|
if (!context.hasResult) {
|
|
@@ -265,353 +342,67 @@
|
|
|
265
342
|
}
|
|
266
343
|
}
|
|
267
344
|
|
|
268
|
-
class
|
|
269
|
-
|
|
270
|
-
this.
|
|
271
|
-
this.
|
|
272
|
-
return this;
|
|
273
|
-
}
|
|
274
|
-
exit() {
|
|
275
|
-
this.exiting = true;
|
|
276
|
-
return this;
|
|
277
|
-
}
|
|
278
|
-
push(child, name) {
|
|
279
|
-
child.parent = this;
|
|
280
|
-
if (typeof name !== 'undefined') {
|
|
281
|
-
child.childName = name;
|
|
282
|
-
}
|
|
283
|
-
child.root = this.root || this;
|
|
284
|
-
child.options = child.options || this.options;
|
|
285
|
-
if (!this.children) {
|
|
286
|
-
this.children = [child];
|
|
287
|
-
this.nextAfterChildren = this.next || null;
|
|
288
|
-
this.next = child;
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
this.children[this.children.length - 1].next = child;
|
|
292
|
-
this.children.push(child);
|
|
293
|
-
}
|
|
294
|
-
child.next = this;
|
|
295
|
-
return this;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function cloneRegExp(re) {
|
|
300
|
-
const regexMatch = /^\/(.*)\/([gimyu]*)$/.exec(re.toString());
|
|
301
|
-
return new RegExp(regexMatch[1], regexMatch[2]);
|
|
302
|
-
}
|
|
303
|
-
function clone(arg) {
|
|
304
|
-
if (typeof arg !== 'object') {
|
|
305
|
-
return arg;
|
|
306
|
-
}
|
|
307
|
-
if (arg === null) {
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
if (Array.isArray(arg)) {
|
|
311
|
-
return arg.map(clone);
|
|
312
|
-
}
|
|
313
|
-
if (arg instanceof Date) {
|
|
314
|
-
return new Date(arg.getTime());
|
|
315
|
-
}
|
|
316
|
-
if (arg instanceof RegExp) {
|
|
317
|
-
return cloneRegExp(arg);
|
|
345
|
+
class Processor {
|
|
346
|
+
constructor(options) {
|
|
347
|
+
this.selfOptions = options || {};
|
|
348
|
+
this.pipes = {};
|
|
318
349
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
cloned[name] = clone(arg[name]);
|
|
350
|
+
options(options) {
|
|
351
|
+
if (options) {
|
|
352
|
+
this.selfOptions = options;
|
|
323
353
|
}
|
|
354
|
+
return this.selfOptions;
|
|
324
355
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
super();
|
|
331
|
-
this.left = left;
|
|
332
|
-
this.right = right;
|
|
333
|
-
this.pipe = 'diff';
|
|
334
|
-
}
|
|
335
|
-
setResult(result) {
|
|
336
|
-
if (this.options.cloneDiffValues && typeof result === 'object') {
|
|
337
|
-
const clone$1 = typeof this.options.cloneDiffValues === 'function'
|
|
338
|
-
? this.options.cloneDiffValues
|
|
339
|
-
: clone;
|
|
340
|
-
if (typeof result[0] === 'object') {
|
|
341
|
-
result[0] = clone$1(result[0]);
|
|
342
|
-
}
|
|
343
|
-
if (typeof result[1] === 'object') {
|
|
344
|
-
result[1] = clone$1(result[1]);
|
|
356
|
+
pipe(name, pipeArg) {
|
|
357
|
+
let pipe = pipeArg;
|
|
358
|
+
if (typeof name === "string") {
|
|
359
|
+
if (typeof pipe === "undefined") {
|
|
360
|
+
return this.pipes[name];
|
|
345
361
|
}
|
|
362
|
+
this.pipes[name] = pipe;
|
|
346
363
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
class PatchContext extends Context {
|
|
352
|
-
constructor(left, delta) {
|
|
353
|
-
super();
|
|
354
|
-
this.left = left;
|
|
355
|
-
this.delta = delta;
|
|
356
|
-
this.pipe = 'patch';
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
class ReverseContext extends Context {
|
|
361
|
-
constructor(delta) {
|
|
362
|
-
super();
|
|
363
|
-
this.delta = delta;
|
|
364
|
-
this.pipe = 'reverse';
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
const diffFilter$3 = function trivialMatchesDiffFilter(context) {
|
|
369
|
-
if (context.left === context.right) {
|
|
370
|
-
context.setResult(undefined).exit();
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
if (typeof context.left === 'undefined') {
|
|
374
|
-
if (typeof context.right === 'function') {
|
|
375
|
-
throw new Error('functions are not supported');
|
|
376
|
-
}
|
|
377
|
-
context.setResult([context.right]).exit();
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
if (typeof context.right === 'undefined') {
|
|
381
|
-
context.setResult([context.left, 0, 0]).exit();
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
if (typeof context.left === 'function' ||
|
|
385
|
-
typeof context.right === 'function') {
|
|
386
|
-
throw new Error('functions are not supported');
|
|
387
|
-
}
|
|
388
|
-
context.leftType = context.left === null ? 'null' : typeof context.left;
|
|
389
|
-
context.rightType = context.right === null ? 'null' : typeof context.right;
|
|
390
|
-
if (context.leftType !== context.rightType) {
|
|
391
|
-
context.setResult([context.left, context.right]).exit();
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
if (context.leftType === 'boolean' || context.leftType === 'number') {
|
|
395
|
-
context.setResult([context.left, context.right]).exit();
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
if (context.leftType === 'object') {
|
|
399
|
-
context.leftIsArray = Array.isArray(context.left);
|
|
400
|
-
}
|
|
401
|
-
if (context.rightType === 'object') {
|
|
402
|
-
context.rightIsArray = Array.isArray(context.right);
|
|
403
|
-
}
|
|
404
|
-
if (context.leftIsArray !== context.rightIsArray) {
|
|
405
|
-
context.setResult([context.left, context.right]).exit();
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
if (context.left instanceof RegExp) {
|
|
409
|
-
if (context.right instanceof RegExp) {
|
|
410
|
-
context
|
|
411
|
-
.setResult([context.left.toString(), context.right.toString()])
|
|
412
|
-
.exit();
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
context.setResult([context.left, context.right]).exit();
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
diffFilter$3.filterName = 'trivial';
|
|
420
|
-
const patchFilter$3 = function trivialMatchesPatchFilter(context) {
|
|
421
|
-
if (typeof context.delta === 'undefined') {
|
|
422
|
-
context.setResult(context.left).exit();
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
context.nested = !Array.isArray(context.delta);
|
|
426
|
-
if (context.nested) {
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
const nonNestedDelta = context.delta;
|
|
430
|
-
if (nonNestedDelta.length === 1) {
|
|
431
|
-
context.setResult(nonNestedDelta[0]).exit();
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
if (nonNestedDelta.length === 2) {
|
|
435
|
-
if (context.left instanceof RegExp) {
|
|
436
|
-
const regexArgs = /^\/(.*)\/([gimyu]+)$/.exec(nonNestedDelta[1]);
|
|
437
|
-
if (regexArgs) {
|
|
438
|
-
context.setResult(new RegExp(regexArgs[1], regexArgs[2])).exit();
|
|
439
|
-
return;
|
|
364
|
+
if (name && name.name) {
|
|
365
|
+
pipe = name;
|
|
366
|
+
if (pipe.processor === this) {
|
|
367
|
+
return pipe;
|
|
440
368
|
}
|
|
369
|
+
this.pipes[pipe.name] = pipe;
|
|
441
370
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
|
|
446
|
-
context.setResult(undefined).exit();
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
patchFilter$3.filterName = 'trivial';
|
|
450
|
-
const reverseFilter$3 = function trivialReferseFilter(context) {
|
|
451
|
-
if (typeof context.delta === 'undefined') {
|
|
452
|
-
context.setResult(context.delta).exit();
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
context.nested = !Array.isArray(context.delta);
|
|
456
|
-
if (context.nested) {
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
const nonNestedDelta = context.delta;
|
|
460
|
-
if (nonNestedDelta.length === 1) {
|
|
461
|
-
context.setResult([nonNestedDelta[0], 0, 0]).exit();
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
if (nonNestedDelta.length === 2) {
|
|
465
|
-
context.setResult([nonNestedDelta[1], nonNestedDelta[0]]).exit();
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
|
|
469
|
-
context.setResult([nonNestedDelta[0]]).exit();
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
reverseFilter$3.filterName = 'trivial';
|
|
473
|
-
|
|
474
|
-
const collectChildrenDiffFilter = (context) => {
|
|
475
|
-
if (!context || !context.children) {
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
const length = context.children.length;
|
|
479
|
-
let child;
|
|
480
|
-
let result = context.result;
|
|
481
|
-
for (let index = 0; index < length; index++) {
|
|
482
|
-
child = context.children[index];
|
|
483
|
-
if (typeof child.result === 'undefined') {
|
|
484
|
-
continue;
|
|
485
|
-
}
|
|
486
|
-
result = result || {};
|
|
487
|
-
result[child.childName] = child.result;
|
|
488
|
-
}
|
|
489
|
-
if (result && context.leftIsArray) {
|
|
490
|
-
result._t = 'a';
|
|
491
|
-
}
|
|
492
|
-
context.setResult(result).exit();
|
|
493
|
-
};
|
|
494
|
-
collectChildrenDiffFilter.filterName = 'collectChildren';
|
|
495
|
-
const objectsDiffFilter = (context) => {
|
|
496
|
-
if (context.leftIsArray || context.leftType !== 'object') {
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
const left = context.left;
|
|
500
|
-
const right = context.right;
|
|
501
|
-
let name;
|
|
502
|
-
let child;
|
|
503
|
-
const propertyFilter = context.options.propertyFilter;
|
|
504
|
-
for (name in left) {
|
|
505
|
-
if (!Object.prototype.hasOwnProperty.call(left, name)) {
|
|
506
|
-
continue;
|
|
507
|
-
}
|
|
508
|
-
if (propertyFilter && !propertyFilter(name, context)) {
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
child = new DiffContext(left[name], right[name]);
|
|
512
|
-
context.push(child, name);
|
|
513
|
-
}
|
|
514
|
-
for (name in right) {
|
|
515
|
-
if (!Object.prototype.hasOwnProperty.call(right, name)) {
|
|
516
|
-
continue;
|
|
517
|
-
}
|
|
518
|
-
if (propertyFilter && !propertyFilter(name, context)) {
|
|
519
|
-
continue;
|
|
520
|
-
}
|
|
521
|
-
if (typeof left[name] === 'undefined') {
|
|
522
|
-
child = new DiffContext(undefined, right[name]);
|
|
523
|
-
context.push(child, name);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
if (!context.children || context.children.length === 0) {
|
|
527
|
-
context.setResult(undefined).exit();
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
context.exit();
|
|
531
|
-
};
|
|
532
|
-
objectsDiffFilter.filterName = 'objects';
|
|
533
|
-
const patchFilter$2 = function nestedPatchFilter(context) {
|
|
534
|
-
if (!context.nested) {
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
const nestedDelta = context.delta;
|
|
538
|
-
if (nestedDelta._t) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
const objectDelta = nestedDelta;
|
|
542
|
-
let name;
|
|
543
|
-
let child;
|
|
544
|
-
for (name in objectDelta) {
|
|
545
|
-
child = new PatchContext(context.left[name], objectDelta[name]);
|
|
546
|
-
context.push(child, name);
|
|
547
|
-
}
|
|
548
|
-
context.exit();
|
|
549
|
-
};
|
|
550
|
-
patchFilter$2.filterName = 'objects';
|
|
551
|
-
const collectChildrenPatchFilter$1 = function collectChildrenPatchFilter(context) {
|
|
552
|
-
if (!context || !context.children) {
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
const deltaWithChildren = context.delta;
|
|
556
|
-
if (deltaWithChildren._t) {
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
const object = context.left;
|
|
560
|
-
const length = context.children.length;
|
|
561
|
-
let child;
|
|
562
|
-
for (let index = 0; index < length; index++) {
|
|
563
|
-
child = context.children[index];
|
|
564
|
-
const property = child.childName;
|
|
565
|
-
if (Object.prototype.hasOwnProperty.call(context.left, property) &&
|
|
566
|
-
child.result === undefined) {
|
|
567
|
-
delete object[property];
|
|
568
|
-
}
|
|
569
|
-
else if (object[property] !== child.result) {
|
|
570
|
-
object[property] = child.result;
|
|
371
|
+
if (!pipe) {
|
|
372
|
+
throw new Error(`pipe is not defined: ${name}`);
|
|
571
373
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
if (deltaWithChildren._t) {
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
const length = context.children.length;
|
|
603
|
-
let child;
|
|
604
|
-
const delta = {};
|
|
605
|
-
for (let index = 0; index < length; index++) {
|
|
606
|
-
child = context.children[index];
|
|
607
|
-
const property = child.childName;
|
|
608
|
-
if (delta[property] !== child.result) {
|
|
609
|
-
delta[property] = child.result;
|
|
374
|
+
pipe.processor = this;
|
|
375
|
+
return pipe;
|
|
376
|
+
}
|
|
377
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
378
|
+
process(input, pipe) {
|
|
379
|
+
let context = input;
|
|
380
|
+
context.options = this.options();
|
|
381
|
+
let nextPipe = pipe || input.pipe || "default";
|
|
382
|
+
let lastPipe = undefined;
|
|
383
|
+
while (nextPipe) {
|
|
384
|
+
if (typeof context.nextAfterChildren !== "undefined") {
|
|
385
|
+
// children processed and coming back to parent
|
|
386
|
+
context.next = context.nextAfterChildren;
|
|
387
|
+
context.nextAfterChildren = null;
|
|
388
|
+
}
|
|
389
|
+
if (typeof nextPipe === "string") {
|
|
390
|
+
nextPipe = this.pipe(nextPipe);
|
|
391
|
+
}
|
|
392
|
+
nextPipe.process(context);
|
|
393
|
+
lastPipe = nextPipe;
|
|
394
|
+
nextPipe = null;
|
|
395
|
+
if (context) {
|
|
396
|
+
if (context.next) {
|
|
397
|
+
context = context.next;
|
|
398
|
+
nextPipe = context.pipe || lastPipe;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
610
401
|
}
|
|
402
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
403
|
+
return context.hasResult ? context.result : undefined;
|
|
611
404
|
}
|
|
612
|
-
|
|
613
|
-
};
|
|
614
|
-
collectChildrenReverseFilter$1.filterName = 'collectChildren';
|
|
405
|
+
}
|
|
615
406
|
|
|
616
407
|
/*
|
|
617
408
|
|
|
@@ -620,36 +411,45 @@
|
|
|
620
411
|
reference: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
|
|
621
412
|
|
|
622
413
|
*/
|
|
623
|
-
const defaultMatch =
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
const lengthMatrix = function (array1, array2, match, context) {
|
|
414
|
+
const defaultMatch = (array1, array2, index1, index2) => array1[index1] === array2[index2];
|
|
415
|
+
const lengthMatrix = (array1, array2, match, context) => {
|
|
416
|
+
var _a, _b, _c;
|
|
627
417
|
const len1 = array1.length;
|
|
628
418
|
const len2 = array2.length;
|
|
629
|
-
let x
|
|
419
|
+
let x;
|
|
420
|
+
let y;
|
|
630
421
|
// initialize empty matrix of len1+1 x len2+1
|
|
631
422
|
const matrix = new Array(len1 + 1);
|
|
632
423
|
for (x = 0; x < len1 + 1; x++) {
|
|
633
|
-
|
|
424
|
+
const matrixNewRow = new Array(len2 + 1);
|
|
634
425
|
for (y = 0; y < len2 + 1; y++) {
|
|
635
|
-
|
|
426
|
+
matrixNewRow[y] = 0;
|
|
636
427
|
}
|
|
428
|
+
matrix[x] = matrixNewRow;
|
|
637
429
|
}
|
|
638
430
|
matrix.match = match;
|
|
639
431
|
// save sequence lengths for each coordinate
|
|
640
432
|
for (x = 1; x < len1 + 1; x++) {
|
|
433
|
+
const matrixRowX = matrix[x];
|
|
434
|
+
if (matrixRowX === undefined) {
|
|
435
|
+
throw new Error("LCS matrix row is undefined");
|
|
436
|
+
}
|
|
437
|
+
const matrixRowBeforeX = matrix[x - 1];
|
|
438
|
+
if (matrixRowBeforeX === undefined) {
|
|
439
|
+
throw new Error("LCS matrix row is undefined");
|
|
440
|
+
}
|
|
641
441
|
for (y = 1; y < len2 + 1; y++) {
|
|
642
442
|
if (match(array1, array2, x - 1, y - 1, context)) {
|
|
643
|
-
|
|
443
|
+
matrixRowX[y] = ((_a = matrixRowBeforeX[y - 1]) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
644
444
|
}
|
|
645
445
|
else {
|
|
646
|
-
|
|
446
|
+
matrixRowX[y] = Math.max((_b = matrixRowBeforeX[y]) !== null && _b !== void 0 ? _b : 0, (_c = matrixRowX[y - 1]) !== null && _c !== void 0 ? _c : 0);
|
|
647
447
|
}
|
|
648
448
|
}
|
|
649
449
|
}
|
|
650
450
|
return matrix;
|
|
651
451
|
};
|
|
652
|
-
const backtrack =
|
|
452
|
+
const backtrack = (matrix, array1, array2, context) => {
|
|
653
453
|
let index1 = array1.length;
|
|
654
454
|
let index2 = array2.length;
|
|
655
455
|
const subsequence = {
|
|
@@ -658,6 +458,9 @@
|
|
|
658
458
|
indices2: [],
|
|
659
459
|
};
|
|
660
460
|
while (index1 !== 0 && index2 !== 0) {
|
|
461
|
+
if (matrix.match === undefined) {
|
|
462
|
+
throw new Error("LCS matrix match function is undefined");
|
|
463
|
+
}
|
|
661
464
|
const sameLetter = matrix.match(array1, array2, index1 - 1, index2 - 1, context);
|
|
662
465
|
if (sameLetter) {
|
|
663
466
|
subsequence.sequence.unshift(array1[index1 - 1]);
|
|
@@ -667,8 +470,22 @@
|
|
|
667
470
|
--index2;
|
|
668
471
|
}
|
|
669
472
|
else {
|
|
670
|
-
const
|
|
671
|
-
|
|
473
|
+
const matrixRowIndex1 = matrix[index1];
|
|
474
|
+
if (matrixRowIndex1 === undefined) {
|
|
475
|
+
throw new Error("LCS matrix row is undefined");
|
|
476
|
+
}
|
|
477
|
+
const valueAtMatrixAbove = matrixRowIndex1[index2 - 1];
|
|
478
|
+
if (valueAtMatrixAbove === undefined) {
|
|
479
|
+
throw new Error("LCS matrix value is undefined");
|
|
480
|
+
}
|
|
481
|
+
const matrixRowBeforeIndex1 = matrix[index1 - 1];
|
|
482
|
+
if (matrixRowBeforeIndex1 === undefined) {
|
|
483
|
+
throw new Error("LCS matrix row is undefined");
|
|
484
|
+
}
|
|
485
|
+
const valueAtMatrixLeft = matrixRowBeforeIndex1[index2];
|
|
486
|
+
if (valueAtMatrixLeft === undefined) {
|
|
487
|
+
throw new Error("LCS matrix value is undefined");
|
|
488
|
+
}
|
|
672
489
|
if (valueAtMatrixAbove > valueAtMatrixLeft) {
|
|
673
490
|
--index2;
|
|
674
491
|
}
|
|
@@ -679,7 +496,7 @@
|
|
|
679
496
|
}
|
|
680
497
|
return subsequence;
|
|
681
498
|
};
|
|
682
|
-
const get =
|
|
499
|
+
const get = (array1, array2, match, context) => {
|
|
683
500
|
const innerContext = context || {};
|
|
684
501
|
const matrix = lengthMatrix(array1, array2, match || defaultMatch, innerContext);
|
|
685
502
|
return backtrack(matrix, array1, array2, innerContext);
|
|
@@ -699,6 +516,7 @@
|
|
|
699
516
|
}
|
|
700
517
|
}
|
|
701
518
|
}
|
|
519
|
+
return false;
|
|
702
520
|
}
|
|
703
521
|
function matchItems(array1, array2, index1, index2, context) {
|
|
704
522
|
const value1 = array1[index1];
|
|
@@ -706,7 +524,7 @@
|
|
|
706
524
|
if (value1 === value2) {
|
|
707
525
|
return true;
|
|
708
526
|
}
|
|
709
|
-
if (typeof value1 !==
|
|
527
|
+
if (typeof value1 !== "object" || typeof value2 !== "object") {
|
|
710
528
|
return false;
|
|
711
529
|
}
|
|
712
530
|
const objectHash = context.objectHash;
|
|
@@ -716,29 +534,30 @@
|
|
|
716
534
|
}
|
|
717
535
|
context.hashCache1 = context.hashCache1 || [];
|
|
718
536
|
let hash1 = context.hashCache1[index1];
|
|
719
|
-
if (typeof hash1 ===
|
|
537
|
+
if (typeof hash1 === "undefined") {
|
|
720
538
|
context.hashCache1[index1] = hash1 = objectHash(value1, index1);
|
|
721
539
|
}
|
|
722
|
-
if (typeof hash1 ===
|
|
540
|
+
if (typeof hash1 === "undefined") {
|
|
723
541
|
return false;
|
|
724
542
|
}
|
|
725
543
|
context.hashCache2 = context.hashCache2 || [];
|
|
726
544
|
let hash2 = context.hashCache2[index2];
|
|
727
|
-
if (typeof hash2 ===
|
|
545
|
+
if (typeof hash2 === "undefined") {
|
|
728
546
|
context.hashCache2[index2] = hash2 = objectHash(value2, index2);
|
|
729
547
|
}
|
|
730
|
-
if (typeof hash2 ===
|
|
548
|
+
if (typeof hash2 === "undefined") {
|
|
731
549
|
return false;
|
|
732
550
|
}
|
|
733
551
|
return hash1 === hash2;
|
|
734
552
|
}
|
|
735
|
-
const diffFilter$
|
|
553
|
+
const diffFilter$3 = function arraysDiffFilter(context) {
|
|
554
|
+
var _a, _b, _c, _d, _e;
|
|
736
555
|
if (!context.leftIsArray) {
|
|
737
556
|
return;
|
|
738
557
|
}
|
|
739
558
|
const matchContext = {
|
|
740
|
-
objectHash: context.options
|
|
741
|
-
matchByPosition: context.options
|
|
559
|
+
objectHash: (_a = context.options) === null || _a === void 0 ? void 0 : _a.objectHash,
|
|
560
|
+
matchByPosition: (_b = context.options) === null || _b === void 0 ? void 0 : _b.matchByPosition,
|
|
742
561
|
};
|
|
743
562
|
let commonHead = 0;
|
|
744
563
|
let commonTail = 0;
|
|
@@ -753,7 +572,7 @@
|
|
|
753
572
|
if (len1 > 0 &&
|
|
754
573
|
len2 > 0 &&
|
|
755
574
|
!matchContext.objectHash &&
|
|
756
|
-
typeof matchContext.matchByPosition !==
|
|
575
|
+
typeof matchContext.matchByPosition !== "boolean") {
|
|
757
576
|
matchContext.matchByPosition = !arraysHaveMatchByRef(array1, array2, len1, len2);
|
|
758
577
|
}
|
|
759
578
|
// separate common head
|
|
@@ -784,10 +603,11 @@
|
|
|
784
603
|
}
|
|
785
604
|
// trivial case, a block (1 or more consecutive items) was added
|
|
786
605
|
result = result || {
|
|
787
|
-
_t:
|
|
606
|
+
_t: "a",
|
|
788
607
|
};
|
|
789
608
|
for (index = commonHead; index < len2 - commonTail; index++) {
|
|
790
609
|
result[index] = [array2[index]];
|
|
610
|
+
context.prepareDeltaResult(result[index]);
|
|
791
611
|
}
|
|
792
612
|
context.setResult(result).exit();
|
|
793
613
|
return;
|
|
@@ -795,42 +615,42 @@
|
|
|
795
615
|
if (commonHead + commonTail === len2) {
|
|
796
616
|
// trivial case, a block (1 or more consecutive items) was removed
|
|
797
617
|
result = result || {
|
|
798
|
-
_t:
|
|
618
|
+
_t: "a",
|
|
799
619
|
};
|
|
800
620
|
for (index = commonHead; index < len1 - commonTail; index++) {
|
|
801
|
-
|
|
621
|
+
const key = `_${index}`;
|
|
622
|
+
result[key] = [array1[index], 0, 0];
|
|
623
|
+
context.prepareDeltaResult(result[key]);
|
|
802
624
|
}
|
|
803
625
|
context.setResult(result).exit();
|
|
804
626
|
return;
|
|
805
627
|
}
|
|
806
628
|
// reset hash cache
|
|
807
|
-
|
|
808
|
-
|
|
629
|
+
matchContext.hashCache1 = undefined;
|
|
630
|
+
matchContext.hashCache2 = undefined;
|
|
809
631
|
// diff is not trivial, find the LCS (Longest Common Subsequence)
|
|
810
632
|
const trimmed1 = array1.slice(commonHead, len1 - commonTail);
|
|
811
633
|
const trimmed2 = array2.slice(commonHead, len2 - commonTail);
|
|
812
634
|
const seq = lcs.get(trimmed1, trimmed2, matchItems, matchContext);
|
|
813
635
|
const removedItems = [];
|
|
814
636
|
result = result || {
|
|
815
|
-
_t:
|
|
637
|
+
_t: "a",
|
|
816
638
|
};
|
|
817
639
|
for (index = commonHead; index < len1 - commonTail; index++) {
|
|
818
640
|
if (seq.indices1.indexOf(index - commonHead) < 0) {
|
|
819
641
|
// removed
|
|
820
|
-
|
|
642
|
+
const key = `_${index}`;
|
|
643
|
+
result[key] = [array1[index], 0, 0];
|
|
644
|
+
context.prepareDeltaResult(result[key]);
|
|
821
645
|
removedItems.push(index);
|
|
822
646
|
}
|
|
823
647
|
}
|
|
824
648
|
let detectMove = true;
|
|
825
|
-
if (context.options &&
|
|
826
|
-
context.options.arrays &&
|
|
827
|
-
context.options.arrays.detectMove === false) {
|
|
649
|
+
if (((_c = context.options) === null || _c === void 0 ? void 0 : _c.arrays) && context.options.arrays.detectMove === false) {
|
|
828
650
|
detectMove = false;
|
|
829
651
|
}
|
|
830
652
|
let includeValueOnMove = false;
|
|
831
|
-
if (context.options
|
|
832
|
-
context.options.arrays &&
|
|
833
|
-
context.options.arrays.includeValueOnMove) {
|
|
653
|
+
if ((_e = (_d = context.options) === null || _d === void 0 ? void 0 : _d.arrays) === null || _e === void 0 ? void 0 : _e.includeValueOnMove) {
|
|
834
654
|
includeValueOnMove = true;
|
|
835
655
|
}
|
|
836
656
|
const removedItemsLength = removedItems.length;
|
|
@@ -842,12 +662,16 @@
|
|
|
842
662
|
if (detectMove && removedItemsLength > 0) {
|
|
843
663
|
for (let removeItemIndex1 = 0; removeItemIndex1 < removedItemsLength; removeItemIndex1++) {
|
|
844
664
|
index1 = removedItems[removeItemIndex1];
|
|
845
|
-
|
|
665
|
+
const resultItem = index1 === undefined ? undefined : result[`_${index1}`];
|
|
666
|
+
if (index1 !== undefined &&
|
|
667
|
+
resultItem &&
|
|
668
|
+
matchItems(trimmed1, trimmed2, index1 - commonHead, index - commonHead, matchContext)) {
|
|
846
669
|
// store position move as: [originalValue, newPosition, ARRAY_MOVE]
|
|
847
|
-
|
|
670
|
+
resultItem.splice(1, 2, index, ARRAY_MOVE);
|
|
671
|
+
resultItem.splice(1, 2, index, ARRAY_MOVE);
|
|
848
672
|
if (!includeValueOnMove) {
|
|
849
673
|
// don't include moved value on diff, to save bytes
|
|
850
|
-
|
|
674
|
+
resultItem[0] = "";
|
|
851
675
|
}
|
|
852
676
|
index2 = index;
|
|
853
677
|
child = new DiffContext(array1[index1], array2[index2]);
|
|
@@ -861,11 +685,18 @@
|
|
|
861
685
|
if (!isMove) {
|
|
862
686
|
// added
|
|
863
687
|
result[index] = [array2[index]];
|
|
688
|
+
context.prepareDeltaResult(result[index]);
|
|
864
689
|
}
|
|
865
690
|
}
|
|
866
691
|
else {
|
|
867
692
|
// match, do inner diff
|
|
693
|
+
if (seq.indices1[indexOnArray2] === undefined) {
|
|
694
|
+
throw new Error(`Invalid indexOnArray2: ${indexOnArray2}, seq.indices1: ${seq.indices1}`);
|
|
695
|
+
}
|
|
868
696
|
index1 = seq.indices1[indexOnArray2] + commonHead;
|
|
697
|
+
if (seq.indices2[indexOnArray2] === undefined) {
|
|
698
|
+
throw new Error(`Invalid indexOnArray2: ${indexOnArray2}, seq.indices2: ${seq.indices2}`);
|
|
699
|
+
}
|
|
869
700
|
index2 = seq.indices2[indexOnArray2] + commonHead;
|
|
870
701
|
child = new DiffContext(array1[index1], array2[index2]);
|
|
871
702
|
context.push(child, index2);
|
|
@@ -873,7 +704,7 @@
|
|
|
873
704
|
}
|
|
874
705
|
context.setResult(result).exit();
|
|
875
706
|
};
|
|
876
|
-
diffFilter$
|
|
707
|
+
diffFilter$3.filterName = "arrays";
|
|
877
708
|
const compare = {
|
|
878
709
|
numerically(a, b) {
|
|
879
710
|
return a - b;
|
|
@@ -882,12 +713,13 @@
|
|
|
882
713
|
return (a, b) => a[name] - b[name];
|
|
883
714
|
},
|
|
884
715
|
};
|
|
885
|
-
const patchFilter$
|
|
716
|
+
const patchFilter$3 = function nestedPatchFilter(context) {
|
|
717
|
+
var _a;
|
|
886
718
|
if (!context.nested) {
|
|
887
719
|
return;
|
|
888
720
|
}
|
|
889
721
|
const nestedDelta = context.delta;
|
|
890
|
-
if (nestedDelta._t !==
|
|
722
|
+
if (nestedDelta._t !== "a") {
|
|
891
723
|
return;
|
|
892
724
|
}
|
|
893
725
|
let index;
|
|
@@ -899,17 +731,17 @@
|
|
|
899
731
|
let toInsert = [];
|
|
900
732
|
const toModify = [];
|
|
901
733
|
for (index in delta) {
|
|
902
|
-
if (index !==
|
|
903
|
-
if (index[0] ===
|
|
734
|
+
if (index !== "_t") {
|
|
735
|
+
if (index[0] === "_") {
|
|
904
736
|
const removedOrMovedIndex = index;
|
|
905
737
|
// removed item from original array
|
|
906
|
-
if (delta[removedOrMovedIndex]
|
|
907
|
-
delta[removedOrMovedIndex][2] ===
|
|
908
|
-
|
|
738
|
+
if (delta[removedOrMovedIndex] !== undefined &&
|
|
739
|
+
(delta[removedOrMovedIndex][2] === 0 ||
|
|
740
|
+
delta[removedOrMovedIndex][2] === ARRAY_MOVE)) {
|
|
741
|
+
toRemove.push(Number.parseInt(index.slice(1), 10));
|
|
909
742
|
}
|
|
910
743
|
else {
|
|
911
|
-
throw new Error(
|
|
912
|
-
` invalid diff type: ${delta[removedOrMovedIndex][2]}`);
|
|
744
|
+
throw new Error(`only removal or move can be applied at original array indices, invalid diff type: ${(_a = delta[removedOrMovedIndex]) === null || _a === void 0 ? void 0 : _a[2]}`);
|
|
913
745
|
}
|
|
914
746
|
}
|
|
915
747
|
else {
|
|
@@ -917,14 +749,14 @@
|
|
|
917
749
|
if (delta[numberIndex].length === 1) {
|
|
918
750
|
// added item at new array
|
|
919
751
|
toInsert.push({
|
|
920
|
-
index: parseInt(numberIndex, 10),
|
|
752
|
+
index: Number.parseInt(numberIndex, 10),
|
|
921
753
|
value: delta[numberIndex][0],
|
|
922
754
|
});
|
|
923
755
|
}
|
|
924
756
|
else {
|
|
925
757
|
// modified item at new array
|
|
926
758
|
toModify.push({
|
|
927
|
-
index: parseInt(numberIndex, 10),
|
|
759
|
+
index: Number.parseInt(numberIndex, 10),
|
|
928
760
|
delta: delta[numberIndex],
|
|
929
761
|
});
|
|
930
762
|
}
|
|
@@ -935,9 +767,11 @@
|
|
|
935
767
|
toRemove = toRemove.sort(compare.numerically);
|
|
936
768
|
for (index = toRemove.length - 1; index >= 0; index--) {
|
|
937
769
|
index1 = toRemove[index];
|
|
770
|
+
if (index1 === undefined)
|
|
771
|
+
continue;
|
|
938
772
|
const indexDiff = delta[`_${index1}`];
|
|
939
773
|
const removedValue = array.splice(index1, 1)[0];
|
|
940
|
-
if (indexDiff[2] === ARRAY_MOVE) {
|
|
774
|
+
if ((indexDiff === null || indexDiff === void 0 ? void 0 : indexDiff[2]) === ARRAY_MOVE) {
|
|
941
775
|
// reinsert later
|
|
942
776
|
toInsert.push({
|
|
943
777
|
index: indexDiff[1],
|
|
@@ -946,19 +780,22 @@
|
|
|
946
780
|
}
|
|
947
781
|
}
|
|
948
782
|
// insert items, in reverse order to avoid moving our own floor
|
|
949
|
-
toInsert = toInsert.sort(compare.numericallyBy(
|
|
783
|
+
toInsert = toInsert.sort(compare.numericallyBy("index"));
|
|
950
784
|
const toInsertLength = toInsert.length;
|
|
951
785
|
for (index = 0; index < toInsertLength; index++) {
|
|
952
786
|
const insertion = toInsert[index];
|
|
787
|
+
if (insertion === undefined)
|
|
788
|
+
continue;
|
|
953
789
|
array.splice(insertion.index, 0, insertion.value);
|
|
954
790
|
}
|
|
955
791
|
// apply modifications
|
|
956
792
|
const toModifyLength = toModify.length;
|
|
957
|
-
let child;
|
|
958
793
|
if (toModifyLength > 0) {
|
|
959
794
|
for (index = 0; index < toModifyLength; index++) {
|
|
960
795
|
const modification = toModify[index];
|
|
961
|
-
|
|
796
|
+
if (modification === undefined)
|
|
797
|
+
continue;
|
|
798
|
+
const child = new PatchContext(array[modification.index], modification.delta);
|
|
962
799
|
context.push(child, modification.index);
|
|
963
800
|
}
|
|
964
801
|
}
|
|
@@ -968,27 +805,28 @@
|
|
|
968
805
|
}
|
|
969
806
|
context.exit();
|
|
970
807
|
};
|
|
971
|
-
patchFilter$
|
|
972
|
-
const collectChildrenPatchFilter = function collectChildrenPatchFilter(context) {
|
|
808
|
+
patchFilter$3.filterName = "arrays";
|
|
809
|
+
const collectChildrenPatchFilter$1 = function collectChildrenPatchFilter(context) {
|
|
973
810
|
if (!context || !context.children) {
|
|
974
811
|
return;
|
|
975
812
|
}
|
|
976
813
|
const deltaWithChildren = context.delta;
|
|
977
|
-
if (deltaWithChildren._t !==
|
|
814
|
+
if (deltaWithChildren._t !== "a") {
|
|
978
815
|
return;
|
|
979
816
|
}
|
|
980
817
|
const array = context.left;
|
|
981
818
|
const length = context.children.length;
|
|
982
|
-
let child;
|
|
983
819
|
for (let index = 0; index < length; index++) {
|
|
984
|
-
child = context.children[index];
|
|
820
|
+
const child = context.children[index];
|
|
821
|
+
if (child === undefined)
|
|
822
|
+
continue;
|
|
985
823
|
const arrayIndex = child.childName;
|
|
986
824
|
array[arrayIndex] = child.result;
|
|
987
825
|
}
|
|
988
826
|
context.setResult(array).exit();
|
|
989
827
|
};
|
|
990
|
-
collectChildrenPatchFilter.filterName =
|
|
991
|
-
const reverseFilter$
|
|
828
|
+
collectChildrenPatchFilter$1.filterName = "arraysCollectChildren";
|
|
829
|
+
const reverseFilter$3 = function arraysReverseFilter(context) {
|
|
992
830
|
if (!context.nested) {
|
|
993
831
|
const nonNestedDelta = context.delta;
|
|
994
832
|
if (nonNestedDelta[2] === ARRAY_MOVE) {
|
|
@@ -997,7 +835,7 @@
|
|
|
997
835
|
context
|
|
998
836
|
.setResult([
|
|
999
837
|
arrayMoveDelta[0],
|
|
1000
|
-
parseInt(context.childName.substring(1), 10),
|
|
838
|
+
Number.parseInt(context.childName.substring(1), 10),
|
|
1001
839
|
ARRAY_MOVE,
|
|
1002
840
|
])
|
|
1003
841
|
.exit();
|
|
@@ -1005,27 +843,25 @@
|
|
|
1005
843
|
return;
|
|
1006
844
|
}
|
|
1007
845
|
const nestedDelta = context.delta;
|
|
1008
|
-
if (nestedDelta._t !==
|
|
846
|
+
if (nestedDelta._t !== "a") {
|
|
1009
847
|
return;
|
|
1010
848
|
}
|
|
1011
849
|
const arrayDelta = nestedDelta;
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
for (name in arrayDelta) {
|
|
1015
|
-
if (name === '_t') {
|
|
850
|
+
for (const name in arrayDelta) {
|
|
851
|
+
if (name === "_t") {
|
|
1016
852
|
continue;
|
|
1017
853
|
}
|
|
1018
|
-
child = new ReverseContext(arrayDelta[name]);
|
|
854
|
+
const child = new ReverseContext(arrayDelta[name]);
|
|
1019
855
|
context.push(child, name);
|
|
1020
856
|
}
|
|
1021
857
|
context.exit();
|
|
1022
858
|
};
|
|
1023
|
-
reverseFilter$
|
|
859
|
+
reverseFilter$3.filterName = "arrays";
|
|
1024
860
|
const reverseArrayDeltaIndex = (delta, index, itemDelta) => {
|
|
1025
|
-
if (typeof index ===
|
|
1026
|
-
return parseInt(index.substring(1), 10);
|
|
861
|
+
if (typeof index === "string" && index[0] === "_") {
|
|
862
|
+
return Number.parseInt(index.substring(1), 10);
|
|
1027
863
|
}
|
|
1028
|
-
|
|
864
|
+
if (Array.isArray(itemDelta) && itemDelta[2] === 0) {
|
|
1029
865
|
return `_${index}`;
|
|
1030
866
|
}
|
|
1031
867
|
let reverseIndex = +index;
|
|
@@ -1033,7 +869,7 @@
|
|
|
1033
869
|
const deltaItem = delta[deltaIndex];
|
|
1034
870
|
if (Array.isArray(deltaItem)) {
|
|
1035
871
|
if (deltaItem[2] === ARRAY_MOVE) {
|
|
1036
|
-
const moveFromIndex = parseInt(deltaIndex.substring(1), 10);
|
|
872
|
+
const moveFromIndex = Number.parseInt(deltaIndex.substring(1), 10);
|
|
1037
873
|
const moveToIndex = deltaItem[1];
|
|
1038
874
|
if (moveToIndex === +index) {
|
|
1039
875
|
return moveFromIndex;
|
|
@@ -1047,37 +883,41 @@
|
|
|
1047
883
|
}
|
|
1048
884
|
}
|
|
1049
885
|
else if (deltaItem[2] === 0) {
|
|
1050
|
-
const deleteIndex = parseInt(deltaIndex.substring(1), 10);
|
|
886
|
+
const deleteIndex = Number.parseInt(deltaIndex.substring(1), 10);
|
|
1051
887
|
if (deleteIndex <= reverseIndex) {
|
|
1052
888
|
reverseIndex++;
|
|
1053
889
|
}
|
|
1054
890
|
}
|
|
1055
891
|
else if (deltaItem.length === 1 &&
|
|
1056
|
-
parseInt(deltaIndex, 10) <= reverseIndex) {
|
|
892
|
+
Number.parseInt(deltaIndex, 10) <= reverseIndex) {
|
|
1057
893
|
reverseIndex--;
|
|
1058
894
|
}
|
|
1059
895
|
}
|
|
1060
896
|
}
|
|
1061
897
|
return reverseIndex;
|
|
1062
898
|
};
|
|
1063
|
-
const collectChildrenReverseFilter = (context) => {
|
|
899
|
+
const collectChildrenReverseFilter$1 = (context) => {
|
|
1064
900
|
if (!context || !context.children) {
|
|
1065
901
|
return;
|
|
1066
902
|
}
|
|
1067
903
|
const deltaWithChildren = context.delta;
|
|
1068
|
-
if (deltaWithChildren._t !==
|
|
904
|
+
if (deltaWithChildren._t !== "a") {
|
|
1069
905
|
return;
|
|
1070
906
|
}
|
|
1071
907
|
const arrayDelta = deltaWithChildren;
|
|
1072
908
|
const length = context.children.length;
|
|
1073
|
-
let child;
|
|
1074
909
|
const delta = {
|
|
1075
|
-
_t:
|
|
910
|
+
_t: "a",
|
|
1076
911
|
};
|
|
1077
912
|
for (let index = 0; index < length; index++) {
|
|
1078
|
-
child = context.children[index];
|
|
913
|
+
const child = context.children[index];
|
|
914
|
+
if (child === undefined)
|
|
915
|
+
continue;
|
|
1079
916
|
let name = child.newName;
|
|
1080
|
-
if (typeof name ===
|
|
917
|
+
if (typeof name === "undefined") {
|
|
918
|
+
if (child.childName === undefined) {
|
|
919
|
+
throw new Error("child.childName is undefined");
|
|
920
|
+
}
|
|
1081
921
|
name = reverseArrayDeltaIndex(arrayDelta, child.childName, child.result);
|
|
1082
922
|
}
|
|
1083
923
|
if (delta[name] !== child.result) {
|
|
@@ -1087,9 +927,9 @@
|
|
|
1087
927
|
}
|
|
1088
928
|
context.setResult(delta).exit();
|
|
1089
929
|
};
|
|
1090
|
-
collectChildrenReverseFilter.filterName =
|
|
930
|
+
collectChildrenReverseFilter$1.filterName = "arraysCollectChildren";
|
|
1091
931
|
|
|
1092
|
-
const diffFilter$
|
|
932
|
+
const diffFilter$2 = function datesDiffFilter(context) {
|
|
1093
933
|
if (context.left instanceof Date) {
|
|
1094
934
|
if (context.right instanceof Date) {
|
|
1095
935
|
if (context.left.getTime() !== context.right.getTime()) {
|
|
@@ -1108,7 +948,150 @@
|
|
|
1108
948
|
context.setResult([context.left, context.right]).exit();
|
|
1109
949
|
}
|
|
1110
950
|
};
|
|
1111
|
-
diffFilter$
|
|
951
|
+
diffFilter$2.filterName = "dates";
|
|
952
|
+
|
|
953
|
+
const collectChildrenDiffFilter = (context) => {
|
|
954
|
+
if (!context || !context.children) {
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
const length = context.children.length;
|
|
958
|
+
let result = context.result;
|
|
959
|
+
for (let index = 0; index < length; index++) {
|
|
960
|
+
const child = context.children[index];
|
|
961
|
+
if (child === undefined)
|
|
962
|
+
continue;
|
|
963
|
+
if (typeof child.result === "undefined") {
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
result = result || {};
|
|
967
|
+
if (child.childName === undefined) {
|
|
968
|
+
throw new Error("diff child.childName is undefined");
|
|
969
|
+
}
|
|
970
|
+
result[child.childName] = child.result;
|
|
971
|
+
}
|
|
972
|
+
if (result && context.leftIsArray) {
|
|
973
|
+
result._t = "a";
|
|
974
|
+
}
|
|
975
|
+
context.setResult(result).exit();
|
|
976
|
+
};
|
|
977
|
+
collectChildrenDiffFilter.filterName = "collectChildren";
|
|
978
|
+
const objectsDiffFilter = (context) => {
|
|
979
|
+
var _a;
|
|
980
|
+
if (context.leftIsArray || context.leftType !== "object") {
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
const left = context.left;
|
|
984
|
+
const right = context.right;
|
|
985
|
+
const propertyFilter = (_a = context.options) === null || _a === void 0 ? void 0 : _a.propertyFilter;
|
|
986
|
+
for (const name in left) {
|
|
987
|
+
if (!Object.prototype.hasOwnProperty.call(left, name)) {
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
if (propertyFilter && !propertyFilter(name, context)) {
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
const child = new DiffContext(left[name], right[name]);
|
|
994
|
+
context.push(child, name);
|
|
995
|
+
}
|
|
996
|
+
for (const name in right) {
|
|
997
|
+
if (!Object.prototype.hasOwnProperty.call(right, name)) {
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
1000
|
+
if (propertyFilter && !propertyFilter(name, context)) {
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
if (typeof left[name] === "undefined") {
|
|
1004
|
+
const child = new DiffContext(undefined, right[name]);
|
|
1005
|
+
context.push(child, name);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
if (!context.children || context.children.length === 0) {
|
|
1009
|
+
context.setResult(undefined).exit();
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
context.exit();
|
|
1013
|
+
};
|
|
1014
|
+
objectsDiffFilter.filterName = "objects";
|
|
1015
|
+
const patchFilter$2 = function nestedPatchFilter(context) {
|
|
1016
|
+
if (!context.nested) {
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
const nestedDelta = context.delta;
|
|
1020
|
+
if (nestedDelta._t) {
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
const objectDelta = nestedDelta;
|
|
1024
|
+
for (const name in objectDelta) {
|
|
1025
|
+
const child = new PatchContext(context.left[name], objectDelta[name]);
|
|
1026
|
+
context.push(child, name);
|
|
1027
|
+
}
|
|
1028
|
+
context.exit();
|
|
1029
|
+
};
|
|
1030
|
+
patchFilter$2.filterName = "objects";
|
|
1031
|
+
const collectChildrenPatchFilter = function collectChildrenPatchFilter(context) {
|
|
1032
|
+
if (!context || !context.children) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
const deltaWithChildren = context.delta;
|
|
1036
|
+
if (deltaWithChildren._t) {
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
const object = context.left;
|
|
1040
|
+
const length = context.children.length;
|
|
1041
|
+
for (let index = 0; index < length; index++) {
|
|
1042
|
+
const child = context.children[index];
|
|
1043
|
+
if (child === undefined)
|
|
1044
|
+
continue;
|
|
1045
|
+
const property = child.childName;
|
|
1046
|
+
if (Object.prototype.hasOwnProperty.call(context.left, property) &&
|
|
1047
|
+
child.result === undefined) {
|
|
1048
|
+
delete object[property];
|
|
1049
|
+
}
|
|
1050
|
+
else if (object[property] !== child.result) {
|
|
1051
|
+
object[property] = child.result;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
context.setResult(object).exit();
|
|
1055
|
+
};
|
|
1056
|
+
collectChildrenPatchFilter.filterName = "collectChildren";
|
|
1057
|
+
const reverseFilter$2 = function nestedReverseFilter(context) {
|
|
1058
|
+
if (!context.nested) {
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
const nestedDelta = context.delta;
|
|
1062
|
+
if (nestedDelta._t) {
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
const objectDelta = context.delta;
|
|
1066
|
+
for (const name in objectDelta) {
|
|
1067
|
+
const child = new ReverseContext(objectDelta[name]);
|
|
1068
|
+
context.push(child, name);
|
|
1069
|
+
}
|
|
1070
|
+
context.exit();
|
|
1071
|
+
};
|
|
1072
|
+
reverseFilter$2.filterName = "objects";
|
|
1073
|
+
const collectChildrenReverseFilter = (context) => {
|
|
1074
|
+
if (!context || !context.children) {
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
const deltaWithChildren = context.delta;
|
|
1078
|
+
if (deltaWithChildren._t) {
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
const length = context.children.length;
|
|
1082
|
+
const delta = {};
|
|
1083
|
+
for (let index = 0; index < length; index++) {
|
|
1084
|
+
const child = context.children[index];
|
|
1085
|
+
if (child === undefined)
|
|
1086
|
+
continue;
|
|
1087
|
+
const property = child.childName;
|
|
1088
|
+
if (delta[property] !== child.result) {
|
|
1089
|
+
delta[property] = child.result;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
context.setResult(delta).exit();
|
|
1093
|
+
};
|
|
1094
|
+
collectChildrenReverseFilter.filterName = "collectChildren";
|
|
1112
1095
|
|
|
1113
1096
|
const TEXT_DIFF = 2;
|
|
1114
1097
|
const DEFAULT_MIN_LENGTH = 60;
|
|
@@ -1124,21 +1107,20 @@
|
|
|
1124
1107
|
if (!required) {
|
|
1125
1108
|
return null;
|
|
1126
1109
|
}
|
|
1127
|
-
const error = new Error(
|
|
1110
|
+
const 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.");
|
|
1128
1111
|
// eslint-disable-next-line camelcase
|
|
1129
1112
|
error.diff_match_patch_not_found = true;
|
|
1130
1113
|
throw error;
|
|
1131
1114
|
}
|
|
1132
1115
|
cachedDiffPatch = {
|
|
1133
|
-
diff:
|
|
1134
|
-
|
|
1135
|
-
},
|
|
1136
|
-
patch: function (txt1, patch) {
|
|
1116
|
+
diff: (txt1, txt2) => instance.patch_toText(instance.patch_make(txt1, txt2)),
|
|
1117
|
+
patch: (txt1, patch) => {
|
|
1137
1118
|
const results = instance.patch_apply(instance.patch_fromText(patch), txt1);
|
|
1138
|
-
for (
|
|
1139
|
-
if (!
|
|
1140
|
-
const error = new Error(
|
|
1119
|
+
for (const resultOk of results[1]) {
|
|
1120
|
+
if (!resultOk) {
|
|
1121
|
+
const error = new Error("text patch failed");
|
|
1141
1122
|
error.textPatchFailed = true;
|
|
1123
|
+
throw error;
|
|
1142
1124
|
}
|
|
1143
1125
|
}
|
|
1144
1126
|
return results[0];
|
|
@@ -1147,16 +1129,14 @@
|
|
|
1147
1129
|
}
|
|
1148
1130
|
return cachedDiffPatch;
|
|
1149
1131
|
}
|
|
1150
|
-
const diffFilter = function textsDiffFilter(context) {
|
|
1151
|
-
|
|
1132
|
+
const diffFilter$1 = function textsDiffFilter(context) {
|
|
1133
|
+
var _a, _b;
|
|
1134
|
+
if (context.leftType !== "string") {
|
|
1152
1135
|
return;
|
|
1153
1136
|
}
|
|
1154
1137
|
const left = context.left;
|
|
1155
1138
|
const right = context.right;
|
|
1156
|
-
const minLength = (context.options
|
|
1157
|
-
context.options.textDiff &&
|
|
1158
|
-
context.options.textDiff.minLength) ||
|
|
1159
|
-
DEFAULT_MIN_LENGTH;
|
|
1139
|
+
const minLength = ((_b = (_a = context.options) === null || _a === void 0 ? void 0 : _a.textDiff) === null || _b === void 0 ? void 0 : _b.minLength) || DEFAULT_MIN_LENGTH;
|
|
1160
1140
|
if (left.length < minLength || right.length < minLength) {
|
|
1161
1141
|
context.setResult([left, right]).exit();
|
|
1162
1142
|
return;
|
|
@@ -1172,8 +1152,8 @@
|
|
|
1172
1152
|
const diff = diffMatchPatch.diff;
|
|
1173
1153
|
context.setResult([diff(left, right), 0, TEXT_DIFF]).exit();
|
|
1174
1154
|
};
|
|
1175
|
-
diffFilter.filterName =
|
|
1176
|
-
const patchFilter = function textsPatchFilter(context) {
|
|
1155
|
+
diffFilter$1.filterName = "texts";
|
|
1156
|
+
const patchFilter$1 = function textsPatchFilter(context) {
|
|
1177
1157
|
if (context.nested) {
|
|
1178
1158
|
return;
|
|
1179
1159
|
}
|
|
@@ -1186,50 +1166,41 @@
|
|
|
1186
1166
|
const patch = getDiffMatchPatch(context.options, true).patch;
|
|
1187
1167
|
context.setResult(patch(context.left, textDiffDelta[0])).exit();
|
|
1188
1168
|
};
|
|
1189
|
-
patchFilter.filterName =
|
|
1190
|
-
const textDeltaReverse =
|
|
1191
|
-
|
|
1192
|
-
let l;
|
|
1193
|
-
let line;
|
|
1194
|
-
let lineTmp;
|
|
1195
|
-
let header = null;
|
|
1169
|
+
patchFilter$1.filterName = "texts";
|
|
1170
|
+
const textDeltaReverse = (delta) => {
|
|
1171
|
+
var _a, _b, _c;
|
|
1196
1172
|
const headerRegex = /^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/;
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
line
|
|
1173
|
+
const lines = delta.split("\n");
|
|
1174
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1175
|
+
const line = lines[i];
|
|
1176
|
+
if (line === undefined)
|
|
1177
|
+
continue;
|
|
1201
1178
|
const lineStart = line.slice(0, 1);
|
|
1202
|
-
if (lineStart ===
|
|
1203
|
-
header = headerRegex.exec(line);
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
header[3]
|
|
1209
|
-
|
|
1210
|
-
header[4] +
|
|
1211
|
-
' +' +
|
|
1212
|
-
header[1] +
|
|
1213
|
-
',' +
|
|
1214
|
-
header[2] +
|
|
1215
|
-
' @@';
|
|
1179
|
+
if (lineStart === "@") {
|
|
1180
|
+
const header = headerRegex.exec(line);
|
|
1181
|
+
if (header !== null) {
|
|
1182
|
+
const lineHeader = i;
|
|
1183
|
+
// fix header
|
|
1184
|
+
lines[lineHeader] =
|
|
1185
|
+
`@@ -${header[3]},${header[4]} +${header[1]},${header[2]} @@`;
|
|
1186
|
+
}
|
|
1216
1187
|
}
|
|
1217
|
-
else if (lineStart ===
|
|
1218
|
-
lines[i] =
|
|
1219
|
-
if (lines[i - 1].slice(0, 1) ===
|
|
1188
|
+
else if (lineStart === "+") {
|
|
1189
|
+
lines[i] = `-${(_a = lines[i]) === null || _a === void 0 ? void 0 : _a.slice(1)}`;
|
|
1190
|
+
if (((_b = lines[i - 1]) === null || _b === void 0 ? void 0 : _b.slice(0, 1)) === "+") {
|
|
1220
1191
|
// swap lines to keep default order (-+)
|
|
1221
|
-
lineTmp = lines[i];
|
|
1192
|
+
const lineTmp = lines[i];
|
|
1222
1193
|
lines[i] = lines[i - 1];
|
|
1223
1194
|
lines[i - 1] = lineTmp;
|
|
1224
1195
|
}
|
|
1225
1196
|
}
|
|
1226
|
-
else if (lineStart ===
|
|
1227
|
-
lines[i] =
|
|
1197
|
+
else if (lineStart === "-") {
|
|
1198
|
+
lines[i] = `+${(_c = lines[i]) === null || _c === void 0 ? void 0 : _c.slice(1)}`;
|
|
1228
1199
|
}
|
|
1229
1200
|
}
|
|
1230
|
-
return lines.join(
|
|
1201
|
+
return lines.join("\n");
|
|
1231
1202
|
};
|
|
1232
|
-
const reverseFilter = function textsReverseFilter(context) {
|
|
1203
|
+
const reverseFilter$1 = function textsReverseFilter(context) {
|
|
1233
1204
|
if (context.nested) {
|
|
1234
1205
|
return;
|
|
1235
1206
|
}
|
|
@@ -1243,19 +1214,125 @@
|
|
|
1243
1214
|
.setResult([textDeltaReverse(textDiffDelta[0]), 0, TEXT_DIFF])
|
|
1244
1215
|
.exit();
|
|
1245
1216
|
};
|
|
1246
|
-
reverseFilter.filterName =
|
|
1217
|
+
reverseFilter$1.filterName = "texts";
|
|
1218
|
+
|
|
1219
|
+
const diffFilter = function trivialMatchesDiffFilter(context) {
|
|
1220
|
+
if (context.left === context.right) {
|
|
1221
|
+
context.setResult(undefined).exit();
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
if (typeof context.left === "undefined") {
|
|
1225
|
+
if (typeof context.right === "function") {
|
|
1226
|
+
throw new Error("functions are not supported");
|
|
1227
|
+
}
|
|
1228
|
+
context.setResult([context.right]).exit();
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
if (typeof context.right === "undefined") {
|
|
1232
|
+
context.setResult([context.left, 0, 0]).exit();
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
if (typeof context.left === "function" ||
|
|
1236
|
+
typeof context.right === "function") {
|
|
1237
|
+
throw new Error("functions are not supported");
|
|
1238
|
+
}
|
|
1239
|
+
context.leftType = context.left === null ? "null" : typeof context.left;
|
|
1240
|
+
context.rightType = context.right === null ? "null" : typeof context.right;
|
|
1241
|
+
if (context.leftType !== context.rightType) {
|
|
1242
|
+
context.setResult([context.left, context.right]).exit();
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
if (context.leftType === "boolean" || context.leftType === "number") {
|
|
1246
|
+
context.setResult([context.left, context.right]).exit();
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1249
|
+
if (context.leftType === "object") {
|
|
1250
|
+
context.leftIsArray = Array.isArray(context.left);
|
|
1251
|
+
}
|
|
1252
|
+
if (context.rightType === "object") {
|
|
1253
|
+
context.rightIsArray = Array.isArray(context.right);
|
|
1254
|
+
}
|
|
1255
|
+
if (context.leftIsArray !== context.rightIsArray) {
|
|
1256
|
+
context.setResult([context.left, context.right]).exit();
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
if (context.left instanceof RegExp) {
|
|
1260
|
+
if (context.right instanceof RegExp) {
|
|
1261
|
+
context
|
|
1262
|
+
.setResult([context.left.toString(), context.right.toString()])
|
|
1263
|
+
.exit();
|
|
1264
|
+
}
|
|
1265
|
+
else {
|
|
1266
|
+
context.setResult([context.left, context.right]).exit();
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
diffFilter.filterName = "trivial";
|
|
1271
|
+
const patchFilter = function trivialMatchesPatchFilter(context) {
|
|
1272
|
+
if (typeof context.delta === "undefined") {
|
|
1273
|
+
context.setResult(context.left).exit();
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
context.nested = !Array.isArray(context.delta);
|
|
1277
|
+
if (context.nested) {
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
const nonNestedDelta = context.delta;
|
|
1281
|
+
if (nonNestedDelta.length === 1) {
|
|
1282
|
+
context.setResult(nonNestedDelta[0]).exit();
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
if (nonNestedDelta.length === 2) {
|
|
1286
|
+
if (context.left instanceof RegExp) {
|
|
1287
|
+
const regexArgs = /^\/(.*)\/([gimyu]+)$/.exec(nonNestedDelta[1]);
|
|
1288
|
+
if (regexArgs === null || regexArgs === void 0 ? void 0 : regexArgs[1]) {
|
|
1289
|
+
context.setResult(new RegExp(regexArgs[1], regexArgs[2])).exit();
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
context.setResult(nonNestedDelta[1]).exit();
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
|
|
1297
|
+
context.setResult(undefined).exit();
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
patchFilter.filterName = "trivial";
|
|
1301
|
+
const reverseFilter = function trivialReferseFilter(context) {
|
|
1302
|
+
if (typeof context.delta === "undefined") {
|
|
1303
|
+
context.setResult(context.delta).exit();
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
context.nested = !Array.isArray(context.delta);
|
|
1307
|
+
if (context.nested) {
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
const nonNestedDelta = context.delta;
|
|
1311
|
+
if (nonNestedDelta.length === 1) {
|
|
1312
|
+
context.setResult([nonNestedDelta[0], 0, 0]).exit();
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
if (nonNestedDelta.length === 2) {
|
|
1316
|
+
context.setResult([nonNestedDelta[1], nonNestedDelta[0]]).exit();
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
if (nonNestedDelta.length === 3 && nonNestedDelta[2] === 0) {
|
|
1320
|
+
context.setResult([nonNestedDelta[0]]).exit();
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
reverseFilter.filterName = "trivial";
|
|
1247
1324
|
|
|
1248
1325
|
class DiffPatcher {
|
|
1249
1326
|
constructor(options) {
|
|
1250
1327
|
this.processor = new Processor(options);
|
|
1251
|
-
this.processor.pipe(new Pipe(
|
|
1252
|
-
.append(collectChildrenDiffFilter, diffFilter
|
|
1328
|
+
this.processor.pipe(new Pipe("diff")
|
|
1329
|
+
.append(collectChildrenDiffFilter, diffFilter, diffFilter$2, diffFilter$1, objectsDiffFilter, diffFilter$3)
|
|
1253
1330
|
.shouldHaveResult());
|
|
1254
|
-
this.processor.pipe(new Pipe(
|
|
1255
|
-
.append(collectChildrenPatchFilter
|
|
1331
|
+
this.processor.pipe(new Pipe("patch")
|
|
1332
|
+
.append(collectChildrenPatchFilter, collectChildrenPatchFilter$1, patchFilter, patchFilter$1, patchFilter$2, patchFilter$3)
|
|
1256
1333
|
.shouldHaveResult());
|
|
1257
|
-
this.processor.pipe(new Pipe(
|
|
1258
|
-
.append(collectChildrenReverseFilter
|
|
1334
|
+
this.processor.pipe(new Pipe("reverse")
|
|
1335
|
+
.append(collectChildrenReverseFilter, collectChildrenReverseFilter$1, reverseFilter, reverseFilter$1, reverseFilter$2, reverseFilter$3)
|
|
1259
1336
|
.shouldHaveResult());
|
|
1260
1337
|
}
|
|
1261
1338
|
options(options) {
|