datum-merge 1.3.0 → 1.5.0
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/README.md +4 -5
- package/dist/cjs/datum-utils.js +14 -11
- package/dist/cjs/diff-high.js +6 -7
- package/dist/cjs/diff-lib/deep-diff.js +10 -11
- package/dist/cjs/index.js +6 -2
- package/dist/cjs/merge-conf.js +7 -7
- package/dist/cjs/merge-high.js +7 -8
- package/dist/cjs/merge-low.js +23 -6
- package/dist/cjs/merge-patch.js +4 -5
- package/dist/cjs/patch-low.js +39 -15
- package/dist/cjs/type-utils.js +15 -16
- package/dist/dts/datum-utils.d.ts +1 -0
- package/dist/dts/datum-utils.d.ts.map +1 -1
- package/dist/dts/index.d.ts +3 -1
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/merge-low.d.ts +1 -0
- package/dist/dts/merge-low.d.ts.map +1 -1
- package/dist/dts/patch-low.d.ts +5 -1
- package/dist/dts/patch-low.d.ts.map +1 -1
- package/dist/esm/datum-utils.js +3 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/merge-low.js +21 -5
- package/dist/esm/patch-low.js +31 -7
- package/dist/umd/datum-merge.min.js +1 -1
- package/dist/umd/datum-merge.min.js.map +4 -4
- package/package.json +11 -11
- package/src/datum-utils.ts +4 -0
- package/src/diff-lib/README.md +19 -17
- package/src/diff-lib/dd-README.md +238 -0
- package/src/diff-lib/package-lock.json +26 -16
- package/src/diff-lib/package.json +5 -5
- package/src/index.ts +3 -1
- package/src/merge-low.ts +27 -5
- package/src/patch-low.ts +38 -7
package/README.md
CHANGED
|
@@ -61,7 +61,8 @@ import { customMergePatch, MergeResult, revertPatchLog } from "datum-merge";
|
|
|
61
61
|
const conf = { scalar: "I", vector: "XM", nested: "B" };
|
|
62
62
|
const patch: MergeResult[] = customMergePatch(target, source, conf);
|
|
63
63
|
const changed = revertPatchLog(patch, target);
|
|
64
|
-
applyPatchLog(patch,
|
|
64
|
+
applyPatchLog(patch, otherTarget); //op replayed, exact paths
|
|
65
|
+
forcePatchLog(patch, anotherTarget); //op ignored, nulls deleted
|
|
65
66
|
```
|
|
66
67
|
---
|
|
67
68
|
|
|
@@ -73,11 +74,9 @@ applyPatchLog(patch, anotherTarget);
|
|
|
73
74
|
|
|
74
75
|
3. option to ignore errors for datatype mismatch during merge.
|
|
75
76
|
|
|
76
|
-
4. support custom equality check
|
|
77
|
+
4. support custom equality check for vector labels.
|
|
77
78
|
|
|
78
|
-
5.
|
|
79
|
-
|
|
80
|
-
6. better anti-diff function that retains deep similarities.
|
|
79
|
+
5. better anti-diff function that retains deep similarities.
|
|
81
80
|
|
|
82
81
|
Code contributions are welcome via issues and pull requests.
|
|
83
82
|
|
package/dist/cjs/datum-utils.js
CHANGED
|
@@ -3,7 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getObjectKeys = getObjectKeys;
|
|
7
|
+
exports.createValueKeys = createValueKeys;
|
|
8
|
+
exports.shallowEquals = shallowEquals;
|
|
9
|
+
exports.deepEquals = deepEquals;
|
|
10
|
+
exports.deepEqualsPath = deepEqualsPath;
|
|
11
|
+
exports.deepClone = deepClone;
|
|
12
|
+
exports.toUniqueArray = toUniqueArray;
|
|
13
|
+
exports.areArraysEqual = areArraysEqual;
|
|
14
|
+
exports.fastGlobMatch = fastGlobMatch;
|
|
15
|
+
exports.getGlobKeys = getGlobKeys;
|
|
16
|
+
exports.selectObjKeys = selectObjKeys;
|
|
7
17
|
const lodash_es_1 = require("lodash-es");
|
|
8
18
|
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
9
19
|
function getObjectKeys(obj, excludeKeys, includeKeys) {
|
|
@@ -20,30 +30,27 @@ function getObjectKeys(obj, excludeKeys, includeKeys) {
|
|
|
20
30
|
}
|
|
21
31
|
return sourceKeys;
|
|
22
32
|
}
|
|
23
|
-
exports.getObjectKeys = getObjectKeys;
|
|
24
33
|
;
|
|
25
34
|
function createValueKeys(keys, value) {
|
|
26
35
|
return Object.fromEntries(keys.map((k) => [k, value]));
|
|
27
36
|
}
|
|
28
|
-
|
|
37
|
+
function shallowEquals(lhs, rhs) {
|
|
38
|
+
return lhs === rhs;
|
|
39
|
+
}
|
|
29
40
|
function deepEquals(lhs, rhs) {
|
|
30
41
|
if (lhs === rhs)
|
|
31
42
|
return true;
|
|
32
43
|
return (0, fast_deep_equal_1.default)(lhs, rhs);
|
|
33
44
|
}
|
|
34
|
-
exports.deepEquals = deepEquals;
|
|
35
45
|
function deepEqualsPath(lhs, rhs, atPath) {
|
|
36
46
|
return (0, fast_deep_equal_1.default)((0, lodash_es_1.get)(lhs, atPath), (0, lodash_es_1.get)(rhs, atPath));
|
|
37
47
|
}
|
|
38
|
-
exports.deepEqualsPath = deepEqualsPath;
|
|
39
48
|
function deepClone(val) {
|
|
40
49
|
return (0, lodash_es_1.cloneDeep)(val);
|
|
41
50
|
}
|
|
42
|
-
exports.deepClone = deepClone;
|
|
43
51
|
function toUniqueArray(arr) {
|
|
44
52
|
return [...new Set(arr)];
|
|
45
53
|
}
|
|
46
|
-
exports.toUniqueArray = toUniqueArray;
|
|
47
54
|
function areArraysEqual(arr1, arr2) {
|
|
48
55
|
if (arr1 == null && arr2 == null)
|
|
49
56
|
return true;
|
|
@@ -58,7 +65,6 @@ function areArraysEqual(arr1, arr2) {
|
|
|
58
65
|
}
|
|
59
66
|
return true;
|
|
60
67
|
}
|
|
61
|
-
exports.areArraysEqual = areArraysEqual;
|
|
62
68
|
function fastGlobMatch(glob, text) {
|
|
63
69
|
if (!glob.includes("*"))
|
|
64
70
|
return text === glob;
|
|
@@ -85,17 +91,14 @@ function fastGlobMatch(glob, text) {
|
|
|
85
91
|
return false;
|
|
86
92
|
return true;
|
|
87
93
|
}
|
|
88
|
-
exports.fastGlobMatch = fastGlobMatch;
|
|
89
94
|
function getGlobKeys(obj, inclPats = ["*"], exclPats) {
|
|
90
95
|
return Object.keys(obj)
|
|
91
96
|
.filter((k) => !inclPats || inclPats.some((g) => fastGlobMatch(g, k)))
|
|
92
97
|
.filter((k) => !(exclPats === null || exclPats === void 0 ? void 0 : exclPats.length) || !exclPats.some((g) => fastGlobMatch(g, k)));
|
|
93
98
|
}
|
|
94
|
-
exports.getGlobKeys = getGlobKeys;
|
|
95
99
|
function selectObjKeys(obj, includeKeys) {
|
|
96
100
|
if (!(includeKeys === null || includeKeys === void 0 ? void 0 : includeKeys.length))
|
|
97
101
|
return Object.assign({}, obj);
|
|
98
102
|
return Object.fromEntries(Object.entries(obj)
|
|
99
103
|
.filter(([k, _]) => includeKeys.includes(k)));
|
|
100
104
|
}
|
|
101
|
-
exports.selectObjKeys = selectObjKeys;
|
package/dist/cjs/diff-high.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.deepDiffTyped = deepDiffTyped;
|
|
4
|
+
exports.antiDiffTyped = antiDiffTyped;
|
|
5
|
+
exports.deepDiffLow = deepDiffLow;
|
|
6
|
+
exports.deepDiffFlat = deepDiffFlat;
|
|
7
|
+
exports.flattenObject = flattenObject;
|
|
8
|
+
exports.unflattenObject = unflattenObject;
|
|
4
9
|
const type_utils_1 = require("./type-utils");
|
|
5
10
|
const deep_diff_1 = require("./diff-lib/deep-diff");
|
|
6
11
|
function deepDiffTyped(lhsObj, rhsObj, orderInd = false) {
|
|
@@ -21,7 +26,6 @@ function deepDiffTyped(lhsObj, rhsObj, orderInd = false) {
|
|
|
21
26
|
cleanupObjArrays(deltaObj);
|
|
22
27
|
return deltaObj;
|
|
23
28
|
}
|
|
24
|
-
exports.deepDiffTyped = deepDiffTyped;
|
|
25
29
|
;
|
|
26
30
|
function cleanupObjArrays(obj) {
|
|
27
31
|
var _a;
|
|
@@ -48,7 +52,6 @@ function antiDiffTyped(lhsObj, rhsObj, orderInd = false) {
|
|
|
48
52
|
.filter(([k, _]) => !modFields.has(k)));
|
|
49
53
|
return shareObj;
|
|
50
54
|
}
|
|
51
|
-
exports.antiDiffTyped = antiDiffTyped;
|
|
52
55
|
function deepDiffLow(lhsObj, rhsObj, orderInd = false) {
|
|
53
56
|
const differences = !orderInd
|
|
54
57
|
? (0, deep_diff_1.diff)(lhsObj, rhsObj)
|
|
@@ -57,7 +60,6 @@ function deepDiffLow(lhsObj, rhsObj, orderInd = false) {
|
|
|
57
60
|
? false
|
|
58
61
|
: differences;
|
|
59
62
|
}
|
|
60
|
-
exports.deepDiffLow = deepDiffLow;
|
|
61
63
|
;
|
|
62
64
|
function deepDiffFlat(oldFlat, newFlat, flatten = true) {
|
|
63
65
|
if (flatten) {
|
|
@@ -74,7 +76,6 @@ function deepDiffFlat(oldFlat, newFlat, flatten = true) {
|
|
|
74
76
|
}
|
|
75
77
|
return [updated, removed];
|
|
76
78
|
}
|
|
77
|
-
exports.deepDiffFlat = deepDiffFlat;
|
|
78
79
|
function flattenObject(obj) {
|
|
79
80
|
const flatObj = {};
|
|
80
81
|
const path = [];
|
|
@@ -94,7 +95,6 @@ function flattenObject(obj) {
|
|
|
94
95
|
dig(obj);
|
|
95
96
|
return flatObj;
|
|
96
97
|
}
|
|
97
|
-
exports.flattenObject = flattenObject;
|
|
98
98
|
function unflattenObject(flatObj) {
|
|
99
99
|
const unflatObj = {};
|
|
100
100
|
for (const [path, value] of Object.entries(flatObj)) {
|
|
@@ -112,4 +112,3 @@ function unflattenObject(flatObj) {
|
|
|
112
112
|
}
|
|
113
113
|
return unflatObj;
|
|
114
114
|
}
|
|
115
|
-
exports.unflattenObject = unflattenObject;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.diff = diff;
|
|
4
|
+
exports.orderIndependentDiff = orderIndependentDiff;
|
|
5
|
+
exports.accumulateDiff = accumulateDiff;
|
|
6
|
+
exports.observableDiff = observableDiff;
|
|
7
|
+
exports.orderIndependentDeepDiff = orderIndependentDeepDiff;
|
|
8
|
+
exports.applyChange = applyChange;
|
|
9
|
+
exports.revertChange = revertChange;
|
|
10
|
+
exports.applyDiff = applyDiff;
|
|
11
|
+
exports.realTypeOf = realTypeOf;
|
|
12
|
+
exports.getOrderIndependentHash = getOrderIndependentHash;
|
|
4
13
|
const typeNormalizer = {
|
|
5
14
|
normalize: function (currentPath, key, lhs, rhs) {
|
|
6
15
|
if (realTypeOf(lhs) === 'regexp' && realTypeOf(rhs) === 'regexp') {
|
|
@@ -19,12 +28,10 @@ function diff(lhs, rhs, prefilter) {
|
|
|
19
28
|
deepDiff(lhs, rhs, changes, prefilter);
|
|
20
29
|
return (changes === null || changes === void 0 ? void 0 : changes.length) ? changes : undefined;
|
|
21
30
|
}
|
|
22
|
-
exports.diff = diff;
|
|
23
31
|
function orderIndependentDiff(lhs, rhs, prefilter) {
|
|
24
32
|
const changes = observableDiff(lhs, rhs, undefined, prefilter, true);
|
|
25
33
|
return (changes === null || changes === void 0 ? void 0 : changes.length) ? changes : undefined;
|
|
26
34
|
}
|
|
27
|
-
exports.orderIndependentDiff = orderIndependentDiff;
|
|
28
35
|
function observableDiff(lhs, rhs, observer, prefilter, orderIndependent) {
|
|
29
36
|
const changes = [];
|
|
30
37
|
deepDiff(lhs, rhs, changes, prefilter, undefined, undefined, undefined, orderIndependent);
|
|
@@ -33,7 +40,6 @@ function observableDiff(lhs, rhs, observer, prefilter, orderIndependent) {
|
|
|
33
40
|
}
|
|
34
41
|
return changes;
|
|
35
42
|
}
|
|
36
|
-
exports.observableDiff = observableDiff;
|
|
37
43
|
function accumulateDiff(lhs, rhs, prefilter, accum, orderIndependent) {
|
|
38
44
|
const observer = (accum) ?
|
|
39
45
|
function (difference) {
|
|
@@ -44,11 +50,9 @@ function accumulateDiff(lhs, rhs, prefilter, accum, orderIndependent) {
|
|
|
44
50
|
const changes = observableDiff(lhs, rhs, observer, prefilter, orderIndependent);
|
|
45
51
|
return accum ? accum : (changes.length) ? changes : undefined;
|
|
46
52
|
}
|
|
47
|
-
exports.accumulateDiff = accumulateDiff;
|
|
48
53
|
function orderIndependentDeepDiff(lhs, rhs, changes, prefilter, path, key, stack) {
|
|
49
54
|
deepDiff(lhs, rhs, changes, prefilter, path, key, stack, true);
|
|
50
55
|
}
|
|
51
|
-
exports.orderIndependentDeepDiff = orderIndependentDeepDiff;
|
|
52
56
|
function deepDiff(lhs, rhs, changes, prefilter, path, key, stack, orderIndependent = false) {
|
|
53
57
|
changes = changes || [];
|
|
54
58
|
path = path || [];
|
|
@@ -221,7 +225,6 @@ function applyDiff(target, source, filter) {
|
|
|
221
225
|
observableDiff(target, source, onChange);
|
|
222
226
|
return target;
|
|
223
227
|
}
|
|
224
|
-
exports.applyDiff = applyDiff;
|
|
225
228
|
function applyChange(target, unused, change) {
|
|
226
229
|
var _a;
|
|
227
230
|
if (!target || !change || !change.kind) {
|
|
@@ -254,7 +257,6 @@ function applyChange(target, unused, change) {
|
|
|
254
257
|
break;
|
|
255
258
|
}
|
|
256
259
|
}
|
|
257
|
-
exports.applyChange = applyChange;
|
|
258
260
|
function applyArrayChange(arr, index, change) {
|
|
259
261
|
if (change.path && change.path.length > 0) {
|
|
260
262
|
const last = change.path.length - 1;
|
|
@@ -322,7 +324,6 @@ function revertChange(target, unused, change) {
|
|
|
322
324
|
break;
|
|
323
325
|
}
|
|
324
326
|
}
|
|
325
|
-
exports.revertChange = revertChange;
|
|
326
327
|
function revertArrayChange(arr, index, change) {
|
|
327
328
|
if (change.path && change.path.length > 0) {
|
|
328
329
|
const last = change.path.length - 1;
|
|
@@ -391,7 +392,6 @@ function realTypeOf(val) {
|
|
|
391
392
|
}
|
|
392
393
|
return 'object';
|
|
393
394
|
}
|
|
394
|
-
exports.realTypeOf = realTypeOf;
|
|
395
395
|
function getOrderIndependentHash(val) {
|
|
396
396
|
let accum = 0;
|
|
397
397
|
const type = realTypeOf(val);
|
|
@@ -415,7 +415,6 @@ function getOrderIndependentHash(val) {
|
|
|
415
415
|
const stringToHash = `[ type: ${type} ; value: ${val}]`;
|
|
416
416
|
return accum + hashThisString(stringToHash);
|
|
417
417
|
}
|
|
418
|
-
exports.getOrderIndependentHash = getOrderIndependentHash;
|
|
419
418
|
function hashThisString(str) {
|
|
420
419
|
let hash = 0;
|
|
421
420
|
if (str.length === 0) {
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.deepDiff = exports.mergeDiff = exports.merge = exports.selectPathCode = exports.deepMergeLog = exports.bypassMergePatch = exports.customMergePatch = exports.bypassMerge = exports.immutableCustomMerge = exports.customMerge = exports.fillUpdateCodes = exports.immutableDetailMerge = exports.detailMerge = exports.patchFromMerge = exports.diffFromMerge = exports.immutableDeepMerge = exports.deepMerge = exports.immutableMerge = exports.shallowMerge = exports.updateCodeInfo = exports.MC = exports.UpdateCode = exports.getPointerValue = exports.
|
|
17
|
+
exports.deepDiff = exports.mergeDiff = exports.merge = exports.selectPathCode = exports.deepMergeLog = exports.bypassMergePatch = exports.customMergePatch = exports.bypassMerge = exports.immutableCustomMerge = exports.customMerge = exports.fillUpdateCodes = exports.immutableDetailMerge = exports.detailMerge = exports.patchFromMerge = exports.diffFromMerge = exports.immutableDeepMerge = exports.deepMerge = exports.immutableMerge = exports.shallowMerge = exports.mergeVectors = exports.updateCodeInfo = exports.MC = exports.UpdateCode = exports.immutablePatch = exports.getPointerValue = exports.forcePatchLog = exports.revertPatchLog = exports.applyPatchLog = exports.deepPatchLog = exports.diffToPatchLog = exports.unflattenObject = exports.flattenObject = exports.deepDiffFlat = exports.antiDiffTyped = exports.deepDiffTyped = exports.deepDiffLow = exports.deepClone = exports.deepEquals = void 0;
|
|
18
18
|
var datum_utils_1 = require("./datum-utils");
|
|
19
19
|
Object.defineProperty(exports, "deepEquals", { enumerable: true, get: function () { return datum_utils_1.deepEquals; } });
|
|
20
20
|
var datum_utils_2 = require("./datum-utils");
|
|
@@ -36,14 +36,18 @@ var patch_low_2 = require("./patch-low");
|
|
|
36
36
|
Object.defineProperty(exports, "applyPatchLog", { enumerable: true, get: function () { return patch_low_2.applyPatchLog; } });
|
|
37
37
|
Object.defineProperty(exports, "revertPatchLog", { enumerable: true, get: function () { return patch_low_2.revertPatchLog; } });
|
|
38
38
|
var patch_low_3 = require("./patch-low");
|
|
39
|
-
Object.defineProperty(exports, "
|
|
39
|
+
Object.defineProperty(exports, "forcePatchLog", { enumerable: true, get: function () { return patch_low_3.forcePatchLog; } });
|
|
40
40
|
Object.defineProperty(exports, "getPointerValue", { enumerable: true, get: function () { return patch_low_3.getPointerValue; } });
|
|
41
|
+
var patch_low_4 = require("./patch-low");
|
|
42
|
+
Object.defineProperty(exports, "immutablePatch", { enumerable: true, get: function () { return patch_low_4.immutablePatch; } });
|
|
41
43
|
var merge_low_1 = require("./merge-low");
|
|
42
44
|
Object.defineProperty(exports, "UpdateCode", { enumerable: true, get: function () { return merge_low_1.UpdateCode; } });
|
|
43
45
|
var merge_low_2 = require("./merge-low");
|
|
44
46
|
Object.defineProperty(exports, "MC", { enumerable: true, get: function () { return merge_low_2.UpdateCode; } });
|
|
45
47
|
var merge_high_1 = require("./merge-high");
|
|
46
48
|
Object.defineProperty(exports, "updateCodeInfo", { enumerable: true, get: function () { return merge_high_1.updateCodeInfo; } });
|
|
49
|
+
var merge_low_3 = require("./merge-low");
|
|
50
|
+
Object.defineProperty(exports, "mergeVectors", { enumerable: true, get: function () { return merge_low_3.mergeVectors; } });
|
|
47
51
|
var merge_high_2 = require("./merge-high");
|
|
48
52
|
Object.defineProperty(exports, "shallowMerge", { enumerable: true, get: function () { return merge_high_2.shallowMerge; } });
|
|
49
53
|
Object.defineProperty(exports, "immutableMerge", { enumerable: true, get: function () { return merge_high_2.immutableMerge; } });
|
package/dist/cjs/merge-conf.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fillUpdateCodes =
|
|
3
|
+
exports.fillUpdateCodes = void 0;
|
|
4
|
+
exports.detailMerge = detailMerge;
|
|
5
|
+
exports.immutableDetailMerge = immutableDetailMerge;
|
|
6
|
+
exports.getDetailKeys = getDetailKeys;
|
|
7
|
+
exports.customMerge = customMerge;
|
|
8
|
+
exports.bypassMerge = bypassMerge;
|
|
9
|
+
exports.immutableCustomMerge = immutableCustomMerge;
|
|
4
10
|
const type_utils_1 = require("./type-utils");
|
|
5
11
|
const datum_utils_1 = require("./datum-utils");
|
|
6
12
|
const diff_high_1 = require("./diff-high");
|
|
@@ -36,13 +42,11 @@ function detailMerge(target, source, mergeCodes) {
|
|
|
36
42
|
}
|
|
37
43
|
return changed;
|
|
38
44
|
}
|
|
39
|
-
exports.detailMerge = detailMerge;
|
|
40
45
|
function immutableDetailMerge(target, source, mergeCodes) {
|
|
41
46
|
const targetCopy = (0, datum_utils_1.deepClone)(target);
|
|
42
47
|
detailMerge(targetCopy, source, mergeCodes);
|
|
43
48
|
return targetCopy;
|
|
44
49
|
}
|
|
45
|
-
exports.immutableDetailMerge = immutableDetailMerge;
|
|
46
50
|
function getDetailKeys(obj, mergeCodes, excludeKeys) {
|
|
47
51
|
const includeKeys = [];
|
|
48
52
|
if (!obj || !mergeCodes) {
|
|
@@ -57,7 +61,6 @@ function getDetailKeys(obj, mergeCodes, excludeKeys) {
|
|
|
57
61
|
}
|
|
58
62
|
return includeKeys;
|
|
59
63
|
}
|
|
60
|
-
exports.getDetailKeys = getDetailKeys;
|
|
61
64
|
function customMerge(target, source, mergeConf, excludeKeys) {
|
|
62
65
|
switch (mergeConf) {
|
|
63
66
|
case merge_low_1.UpdateCode.C:
|
|
@@ -81,7 +84,6 @@ function customMerge(target, source, mergeConf, excludeKeys) {
|
|
|
81
84
|
}
|
|
82
85
|
return false;
|
|
83
86
|
}
|
|
84
|
-
exports.customMerge = customMerge;
|
|
85
87
|
function bypassMerge(target, source) {
|
|
86
88
|
if ((0, type_utils_1.emptyObject)(source)) {
|
|
87
89
|
return false;
|
|
@@ -91,7 +93,6 @@ function bypassMerge(target, source) {
|
|
|
91
93
|
delta = (0, datum_utils_1.selectObjKeys)(delta, (0, datum_utils_1.getObjectKeys)(source));
|
|
92
94
|
return (0, type_utils_1.emptyObject)(delta) ? false : delta;
|
|
93
95
|
}
|
|
94
|
-
exports.bypassMerge = bypassMerge;
|
|
95
96
|
function immutableCustomMerge(target, source, mergeConf, skipFill = false) {
|
|
96
97
|
const mergeCodes = !skipFill
|
|
97
98
|
? (0, exports.fillUpdateCodes)(source, mergeConf)
|
|
@@ -100,7 +101,6 @@ function immutableCustomMerge(target, source, mergeConf, skipFill = false) {
|
|
|
100
101
|
detailMerge(targetCopy, source, mergeCodes);
|
|
101
102
|
return targetCopy;
|
|
102
103
|
}
|
|
103
|
-
exports.immutableCustomMerge = immutableCustomMerge;
|
|
104
104
|
const fillUpdateCodes = (source, mergeConf, blockUnset = false, excludeKeys) => {
|
|
105
105
|
if ((0, type_utils_1.isString)(mergeConf)) {
|
|
106
106
|
mergeConf = { scalar: mergeConf };
|
package/dist/cjs/merge-high.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.updateCodeInfo = updateCodeInfo;
|
|
4
|
+
exports.shallowMerge = shallowMerge;
|
|
5
|
+
exports.immutableMerge = immutableMerge;
|
|
6
|
+
exports.deepMerge = deepMerge;
|
|
7
|
+
exports.immutableDeepMerge = immutableDeepMerge;
|
|
8
|
+
exports.diffFromMerge = diffFromMerge;
|
|
9
|
+
exports.patchFromMerge = patchFromMerge;
|
|
4
10
|
const type_utils_1 = require("./type-utils");
|
|
5
11
|
const datum_utils_1 = require("./datum-utils");
|
|
6
12
|
const merge_low_1 = require("./merge-low");
|
|
@@ -30,7 +36,6 @@ function updateCodeInfo(mergeCode) {
|
|
|
30
36
|
enable: allowInsert || allowUpdate || allowUnset,
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
|
-
exports.updateCodeInfo = updateCodeInfo;
|
|
34
39
|
function shallowMerge(target, source, scalarCode, vectorCode, excludeKeys, includeKeys) {
|
|
35
40
|
const sourceKeys = (0, datum_utils_1.getObjectKeys)(source, excludeKeys, includeKeys);
|
|
36
41
|
if (!(sourceKeys === null || sourceKeys === void 0 ? void 0 : sourceKeys.length)) {
|
|
@@ -50,13 +55,11 @@ function shallowMerge(target, source, scalarCode, vectorCode, excludeKeys, inclu
|
|
|
50
55
|
}
|
|
51
56
|
return changed;
|
|
52
57
|
}
|
|
53
|
-
exports.shallowMerge = shallowMerge;
|
|
54
58
|
function immutableMerge(target, source, scalarCode, vectorCode) {
|
|
55
59
|
const targetCopy = (0, datum_utils_1.deepClone)(target);
|
|
56
60
|
shallowMerge(targetCopy, source, scalarCode, vectorCode);
|
|
57
61
|
return targetCopy;
|
|
58
62
|
}
|
|
59
|
-
exports.immutableMerge = immutableMerge;
|
|
60
63
|
;
|
|
61
64
|
function deepMerge(target, source, scalarCode, vectorCode, nestedCode) {
|
|
62
65
|
const sourceKeys = (0, datum_utils_1.getObjectKeys)(source);
|
|
@@ -83,23 +86,19 @@ function deepMerge(target, source, scalarCode, vectorCode, nestedCode) {
|
|
|
83
86
|
}
|
|
84
87
|
return changed;
|
|
85
88
|
}
|
|
86
|
-
exports.deepMerge = deepMerge;
|
|
87
89
|
function immutableDeepMerge(target, source, scalarCode, vectorCode, nestedCode) {
|
|
88
90
|
const targetCopy = (0, datum_utils_1.deepClone)(target);
|
|
89
91
|
deepMerge(targetCopy, source, scalarCode, vectorCode !== null && vectorCode !== void 0 ? vectorCode : scalarCode, nestedCode !== null && nestedCode !== void 0 ? nestedCode : scalarCode);
|
|
90
92
|
return targetCopy;
|
|
91
93
|
}
|
|
92
|
-
exports.immutableDeepMerge = immutableDeepMerge;
|
|
93
94
|
;
|
|
94
95
|
function diffFromMerge(target, source, scalarCode, vectorCode, nestedCode, orderInd = false) {
|
|
95
96
|
const targetCopy = immutableDeepMerge(target, source, scalarCode, vectorCode, nestedCode);
|
|
96
97
|
const delta = (0, diff_high_1.deepDiffTyped)(target, targetCopy, orderInd);
|
|
97
98
|
return (0, type_utils_1.emptyObject)(delta) ? false : delta;
|
|
98
99
|
}
|
|
99
|
-
exports.diffFromMerge = diffFromMerge;
|
|
100
100
|
function patchFromMerge(target, source, scalarCode, vectorCode, nestedCode, orderInd = false) {
|
|
101
101
|
const targetCopy = immutableDeepMerge(target, source, scalarCode, vectorCode, nestedCode);
|
|
102
102
|
const patch = (0, patch_low_1.deepPatchLog)(target, targetCopy, orderInd, true);
|
|
103
103
|
return !(patch === null || patch === void 0 ? void 0 : patch.length) ? false : patch;
|
|
104
104
|
}
|
|
105
|
-
exports.patchFromMerge = patchFromMerge;
|
package/dist/cjs/merge-low.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.UpdateCode = void 0;
|
|
4
|
+
exports.mergeScalarField = mergeScalarField;
|
|
5
|
+
exports.mergeVectorField = mergeVectorField;
|
|
6
|
+
exports.mergeVectors = mergeVectors;
|
|
4
7
|
const lodash_es_1 = require("lodash-es");
|
|
5
8
|
const type_utils_1 = require("./type-utils");
|
|
6
9
|
const datum_utils_1 = require("./datum-utils");
|
|
@@ -83,7 +86,6 @@ function mergeScalarField(target, source, label, mergeCode) {
|
|
|
83
86
|
}
|
|
84
87
|
return true;
|
|
85
88
|
}
|
|
86
|
-
exports.mergeScalarField = mergeScalarField;
|
|
87
89
|
;
|
|
88
90
|
function mergeVectorField(target, source, label, mergeCode) {
|
|
89
91
|
var _a, _b;
|
|
@@ -120,13 +122,13 @@ function mergeVectorField(target, source, label, mergeCode) {
|
|
|
120
122
|
break;
|
|
121
123
|
case exports.UpdateCode.B:
|
|
122
124
|
case exports.UpdateCode.XM:
|
|
123
|
-
targetVals = (0, lodash_es_1.unionWith)(target[label], sourceVals,
|
|
125
|
+
targetVals = (0, lodash_es_1.unionWith)(target[label], sourceVals, datum_utils_1.deepEquals);
|
|
124
126
|
break;
|
|
125
127
|
case exports.UpdateCode.XD:
|
|
126
|
-
targetVals = (0, lodash_es_1.differenceWith)(target[label], sourceVals,
|
|
128
|
+
targetVals = (0, lodash_es_1.differenceWith)(target[label], sourceVals, datum_utils_1.deepEquals);
|
|
127
129
|
break;
|
|
128
130
|
case exports.UpdateCode.XI:
|
|
129
|
-
targetVals = (0, lodash_es_1.intersectionWith)(target[label], sourceVals,
|
|
131
|
+
targetVals = (0, lodash_es_1.intersectionWith)(target[label], sourceVals, datum_utils_1.deepEquals);
|
|
130
132
|
break;
|
|
131
133
|
default:
|
|
132
134
|
return false;
|
|
@@ -139,5 +141,20 @@ function mergeVectorField(target, source, label, mergeCode) {
|
|
|
139
141
|
target[label] = !changed ? targetVals : (0, datum_utils_1.deepClone)(targetVals);
|
|
140
142
|
return changed;
|
|
141
143
|
}
|
|
142
|
-
exports.mergeVectorField = mergeVectorField;
|
|
143
144
|
;
|
|
145
|
+
function mergeVectors(mergeCode, arr1, arr2, equalsCond) {
|
|
146
|
+
if (!(arr1 === null || arr1 === void 0 ? void 0 : arr1.length) && !(arr2 === null || arr2 === void 0 ? void 0 : arr2.length))
|
|
147
|
+
return [];
|
|
148
|
+
equalsCond = equalsCond !== null && equalsCond !== void 0 ? equalsCond : datum_utils_1.deepEquals;
|
|
149
|
+
switch (mergeCode) {
|
|
150
|
+
case exports.UpdateCode.XM:
|
|
151
|
+
return (0, lodash_es_1.unionWith)(arr1, arr2, equalsCond);
|
|
152
|
+
case exports.UpdateCode.XI:
|
|
153
|
+
return (0, lodash_es_1.intersectionWith)(arr1, arr2, equalsCond);
|
|
154
|
+
case exports.UpdateCode.XD:
|
|
155
|
+
return (0, lodash_es_1.differenceWith)(arr1, arr2, equalsCond);
|
|
156
|
+
case exports.UpdateCode.XS:
|
|
157
|
+
return (0, lodash_es_1.concat)(arr1 !== null && arr1 !== void 0 ? arr1 : [], arr2 !== null && arr2 !== void 0 ? arr2 : []);
|
|
158
|
+
}
|
|
159
|
+
throw new Error("invalid merge code " + mergeCode);
|
|
160
|
+
}
|
package/dist/cjs/merge-patch.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.customMergePatch = customMergePatch;
|
|
4
|
+
exports.bypassMergePatch = bypassMergePatch;
|
|
5
|
+
exports.deepMergeLog = deepMergeLog;
|
|
6
|
+
exports.selectPathCode = selectPathCode;
|
|
4
7
|
const type_utils_1 = require("./type-utils");
|
|
5
8
|
const datum_utils_1 = require("./datum-utils");
|
|
6
9
|
const patch_low_1 = require("./patch-low");
|
|
@@ -29,7 +32,6 @@ function customMergePatch(target, source, mergeConf, excludeKeys) {
|
|
|
29
32
|
}
|
|
30
33
|
return false;
|
|
31
34
|
}
|
|
32
|
-
exports.customMergePatch = customMergePatch;
|
|
33
35
|
function bypassMergePatch(target, source) {
|
|
34
36
|
const sourceKeys = (0, datum_utils_1.getObjectKeys)(source !== null && source !== void 0 ? source : {});
|
|
35
37
|
if (!source || !sourceKeys.length) {
|
|
@@ -41,7 +43,6 @@ function bypassMergePatch(target, source) {
|
|
|
41
43
|
const patch = deepMergeLog(targetBkp, target, mergeCodes);
|
|
42
44
|
return !(patch === null || patch === void 0 ? void 0 : patch.length) ? false : patch;
|
|
43
45
|
}
|
|
44
|
-
exports.bypassMergePatch = bypassMergePatch;
|
|
45
46
|
function deepMergeLog(lhsObj, rhsObj, mergeCodes) {
|
|
46
47
|
const mergeLog = (0, patch_low_1.deepPatchLog)(lhsObj, rhsObj, false, true);
|
|
47
48
|
if (!(mergeLog === null || mergeLog === void 0 ? void 0 : mergeLog.length)) {
|
|
@@ -61,7 +62,6 @@ function deepMergeLog(lhsObj, rhsObj, mergeCodes) {
|
|
|
61
62
|
}
|
|
62
63
|
return mergeLog;
|
|
63
64
|
}
|
|
64
|
-
exports.deepMergeLog = deepMergeLog;
|
|
65
65
|
;
|
|
66
66
|
function selectPathCode(mergeCodes, pathParts) {
|
|
67
67
|
if (!mergeCodes || (0, type_utils_1.emptyObject)(mergeCodes)) {
|
|
@@ -84,4 +84,3 @@ function selectPathCode(mergeCodes, pathParts) {
|
|
|
84
84
|
}
|
|
85
85
|
return merge_low_1.UpdateCode.N;
|
|
86
86
|
}
|
|
87
|
-
exports.selectPathCode = selectPathCode;
|
package/dist/cjs/patch-low.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.diffToPatchLog = diffToPatchLog;
|
|
4
|
+
exports.deepPatchLog = deepPatchLog;
|
|
5
|
+
exports.applyPatchLog = applyPatchLog;
|
|
6
|
+
exports.revertPatchLog = revertPatchLog;
|
|
7
|
+
exports.forcePatchLog = forcePatchLog;
|
|
8
|
+
exports.immutablePatch = immutablePatch;
|
|
9
|
+
exports.asLodashPath = asLodashPath;
|
|
10
|
+
exports.getPointerValue = getPointerValue;
|
|
4
11
|
const lodash_es_1 = require("lodash-es");
|
|
12
|
+
const type_utils_1 = require("./type-utils");
|
|
5
13
|
const datum_utils_1 = require("./datum-utils");
|
|
6
14
|
const diff_high_1 = require("./diff-high");
|
|
7
15
|
function diffToPatchLog(differences, storePrev = false) {
|
|
@@ -35,12 +43,10 @@ function diffToPatchLog(differences, storePrev = false) {
|
|
|
35
43
|
}
|
|
36
44
|
return jsonPatch;
|
|
37
45
|
}
|
|
38
|
-
exports.diffToPatchLog = diffToPatchLog;
|
|
39
46
|
function deepPatchLog(lhsObj, rhsObj, orderInd = false, storePrev = false) {
|
|
40
47
|
const differences = (0, diff_high_1.deepDiffLow)(lhsObj, rhsObj, orderInd);
|
|
41
48
|
return !differences ? [] : diffToPatchLog(differences, storePrev);
|
|
42
49
|
}
|
|
43
|
-
exports.deepPatchLog = deepPatchLog;
|
|
44
50
|
;
|
|
45
51
|
function applyPatchLog(patchLog, target) {
|
|
46
52
|
if (!target || !(patchLog === null || patchLog === void 0 ? void 0 : patchLog.length))
|
|
@@ -55,44 +61,64 @@ function applyPatchLog(patchLog, target) {
|
|
|
55
61
|
continue;
|
|
56
62
|
}
|
|
57
63
|
const targetVal = (0, lodash_es_1.get)(target, difPath);
|
|
58
|
-
|
|
64
|
+
const sourceVal = patchItem.value;
|
|
65
|
+
if ((0, type_utils_1.isNullish)(targetVal) && (0, type_utils_1.isNullish)(sourceVal))
|
|
59
66
|
continue;
|
|
60
|
-
if (
|
|
61
|
-
(0, lodash_es_1.set)(target, difPath,
|
|
67
|
+
if ((0, type_utils_1.isNullish)(targetVal) || !(0, datum_utils_1.deepEquals)(targetVal, sourceVal)) {
|
|
68
|
+
(0, lodash_es_1.set)(target, difPath, (0, datum_utils_1.deepClone)(sourceVal));
|
|
62
69
|
changed = true;
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
return changed;
|
|
66
73
|
}
|
|
67
|
-
exports.applyPatchLog = applyPatchLog;
|
|
68
74
|
function revertPatchLog(patchLog, target) {
|
|
69
75
|
if (!target || !(patchLog === null || patchLog === void 0 ? void 0 : patchLog.length))
|
|
70
76
|
return false;
|
|
71
77
|
let changed = false;
|
|
72
78
|
for (const patchItem of patchLog) {
|
|
73
79
|
const difPath = asLodashPath(patchItem.path);
|
|
80
|
+
if (patchItem.op === "test")
|
|
81
|
+
continue;
|
|
74
82
|
if (patchItem.op === "add") {
|
|
75
83
|
changed = (0, lodash_es_1.unset)(target, difPath) || changed;
|
|
84
|
+
continue;
|
|
76
85
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
changed = true;
|
|
80
|
-
}
|
|
86
|
+
(0, lodash_es_1.set)(target, difPath, patchItem.prev);
|
|
87
|
+
changed = true;
|
|
81
88
|
}
|
|
82
89
|
return changed;
|
|
83
90
|
}
|
|
84
|
-
|
|
91
|
+
function forcePatchLog(patchLog, target = {}) {
|
|
92
|
+
for (const patchItem of patchLog) {
|
|
93
|
+
const difPath = patchItem.path.startsWith("/")
|
|
94
|
+
? asLodashPath(patchItem.path) : (0, lodash_es_1.toPath)(patchItem.path);
|
|
95
|
+
if (!(difPath === null || difPath === void 0 ? void 0 : difPath.length))
|
|
96
|
+
continue;
|
|
97
|
+
const value = patchItem.value;
|
|
98
|
+
if ((0, type_utils_1.isNullish)(value)) {
|
|
99
|
+
(0, lodash_es_1.unset)(target, difPath);
|
|
100
|
+
}
|
|
101
|
+
if ((0, type_utils_1.isPrimitive)(value)) {
|
|
102
|
+
(0, lodash_es_1.set)(target, difPath, value);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
(0, lodash_es_1.set)(target, difPath, (0, datum_utils_1.deepClone)(value));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
85
109
|
function immutablePatch(target, patchSrc, patchDir) {
|
|
86
110
|
const targetCopy = (0, datum_utils_1.deepClone)(target !== null && target !== void 0 ? target : {});
|
|
87
111
|
if (patchDir === "revert") {
|
|
88
112
|
revertPatchLog(patchSrc, targetCopy);
|
|
89
113
|
}
|
|
114
|
+
else if (patchDir === "force") {
|
|
115
|
+
forcePatchLog(patchSrc, targetCopy);
|
|
116
|
+
}
|
|
90
117
|
else {
|
|
91
118
|
applyPatchLog(patchSrc, targetCopy);
|
|
92
119
|
}
|
|
93
120
|
return targetCopy;
|
|
94
121
|
}
|
|
95
|
-
exports.immutablePatch = immutablePatch;
|
|
96
122
|
;
|
|
97
123
|
function escapePathPart(path) {
|
|
98
124
|
if (typeof path === 'number')
|
|
@@ -117,9 +143,7 @@ function asLodashPath(pointer) {
|
|
|
117
143
|
.map((s) => unescapePathPart(s));
|
|
118
144
|
return !(parts === null || parts === void 0 ? void 0 : parts.length) ? [] : (0, lodash_es_1.toPath)(parts.join("."));
|
|
119
145
|
}
|
|
120
|
-
exports.asLodashPath = asLodashPath;
|
|
121
146
|
function getPointerValue(document, pointer) {
|
|
122
147
|
return pointer === "" ? document
|
|
123
148
|
: (0, lodash_es_1.get)(document, asLodashPath(pointer));
|
|
124
149
|
}
|
|
125
|
-
exports.getPointerValue = getPointerValue;
|