datum-merge 1.0.3 → 1.2.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 +14 -3
- package/dist/cjs/datum-utils.js +2 -0
- package/dist/cjs/index.js +17 -7
- package/dist/cjs/merge-high.js +15 -14
- package/dist/cjs/merge-patch.js +87 -0
- package/dist/cjs/patch-low.js +51 -13
- package/dist/dts/datum-utils.d.ts.map +1 -1
- package/dist/dts/index.d.ts +8 -4
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/merge-high.d.ts +6 -0
- package/dist/dts/merge-high.d.ts.map +1 -1
- package/dist/dts/merge-patch.d.ts +18 -0
- package/dist/dts/merge-patch.d.ts.map +1 -0
- package/dist/dts/patch-low.d.ts +5 -3
- package/dist/dts/patch-low.d.ts.map +1 -1
- package/dist/esm/datum-utils.js +2 -0
- package/dist/esm/index.js +6 -3
- package/dist/esm/merge-high.js +13 -13
- package/dist/esm/merge-patch.js +80 -0
- package/dist/esm/patch-low.js +46 -10
- package/dist/umd/datum-merge.min.js +1 -1
- package/dist/umd/datum-merge.min.js.map +4 -4
- package/package.json +1 -1
- package/src/datum-utils.ts +2 -0
- package/src/diff-lib/README.md +9 -2
- package/src/index.ts +9 -4
- package/src/merge-conf.ts +1 -1
- package/src/merge-high.ts +28 -16
- package/src/merge-patch.ts +134 -0
- package/src/patch-low.ts +63 -17
package/README.md
CHANGED
|
@@ -52,13 +52,22 @@ const conf: MergeConfig = {
|
|
|
52
52
|
vector: UpdateCode.XM,
|
|
53
53
|
},
|
|
54
54
|
};
|
|
55
|
-
const diff = customMerge(target, source, conf);
|
|
55
|
+
const diff: Partial<T> = customMerge<T>(target, source, conf);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Reversible deep merge with changelog in json-patch format:
|
|
59
|
+
```
|
|
60
|
+
import { customMergePatch, MergeResult, revertPatchLog } from "datum-merge";
|
|
61
|
+
const conf = { scalar: "I", vector: "XM", nested: "B" };
|
|
62
|
+
const patch: MergeResult[] = customMergePatch(target, source, conf);
|
|
63
|
+
const changed = revertPatchLog(patch, target);
|
|
64
|
+
applyPatchLog(patch, anotherTarget);
|
|
56
65
|
```
|
|
57
66
|
---
|
|
58
67
|
|
|
59
68
|
## Upcoming Features
|
|
60
69
|
|
|
61
|
-
1. publish
|
|
70
|
+
1. publish diff module as a standalone package ([available](/src/diff-lib/README.md)).
|
|
62
71
|
|
|
63
72
|
2. formalize config schema for deeply nested objects (for v1).
|
|
64
73
|
|
|
@@ -68,6 +77,8 @@ const diff = customMerge(target, source, conf);
|
|
|
68
77
|
|
|
69
78
|
5. support merging for top level arrays or primitives.
|
|
70
79
|
|
|
80
|
+
6. better anti-diff function that retains deep similarities.
|
|
81
|
+
|
|
71
82
|
Code contributions are welcome via issues and pull requests.
|
|
72
83
|
|
|
73
84
|
---
|
|
@@ -110,6 +121,6 @@ Applying the merge results in one of these transitions per primitive value in th
|
|
|
110
121
|
| `add` | new / insert | I | `null <-- non-null` |
|
|
111
122
|
| `replace` | edit / update | H | `non-null <-- non-null` |
|
|
112
123
|
| `remove` | unset / delete | D | `non-null <-- null` |
|
|
113
|
-
| `test` | noop / skip / ignore
|
|
124
|
+
| `test` | noop / skip / ignore | N | `null <-- null` or `non-null == non-null` |
|
|
114
125
|
|
|
115
126
|
---
|
package/dist/cjs/datum-utils.js
CHANGED
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.
|
|
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.immutablePatch = 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");
|
|
@@ -29,6 +29,15 @@ Object.defineProperty(exports, "deepDiffFlat", { enumerable: true, get: function
|
|
|
29
29
|
var diff_high_4 = require("./diff-high");
|
|
30
30
|
Object.defineProperty(exports, "flattenObject", { enumerable: true, get: function () { return diff_high_4.flattenObject; } });
|
|
31
31
|
Object.defineProperty(exports, "unflattenObject", { enumerable: true, get: function () { return diff_high_4.unflattenObject; } });
|
|
32
|
+
var patch_low_1 = require("./patch-low");
|
|
33
|
+
Object.defineProperty(exports, "diffToPatchLog", { enumerable: true, get: function () { return patch_low_1.diffToPatchLog; } });
|
|
34
|
+
Object.defineProperty(exports, "deepPatchLog", { enumerable: true, get: function () { return patch_low_1.deepPatchLog; } });
|
|
35
|
+
var patch_low_2 = require("./patch-low");
|
|
36
|
+
Object.defineProperty(exports, "applyPatchLog", { enumerable: true, get: function () { return patch_low_2.applyPatchLog; } });
|
|
37
|
+
Object.defineProperty(exports, "revertPatchLog", { enumerable: true, get: function () { return patch_low_2.revertPatchLog; } });
|
|
38
|
+
var patch_low_3 = require("./patch-low");
|
|
39
|
+
Object.defineProperty(exports, "immutablePatch", { enumerable: true, get: function () { return patch_low_3.immutablePatch; } });
|
|
40
|
+
Object.defineProperty(exports, "getPointerValue", { enumerable: true, get: function () { return patch_low_3.getPointerValue; } });
|
|
32
41
|
var merge_low_1 = require("./merge-low");
|
|
33
42
|
Object.defineProperty(exports, "UpdateCode", { enumerable: true, get: function () { return merge_low_1.UpdateCode; } });
|
|
34
43
|
var merge_low_2 = require("./merge-low");
|
|
@@ -43,6 +52,7 @@ Object.defineProperty(exports, "deepMerge", { enumerable: true, get: function ()
|
|
|
43
52
|
Object.defineProperty(exports, "immutableDeepMerge", { enumerable: true, get: function () { return merge_high_3.immutableDeepMerge; } });
|
|
44
53
|
var merge_high_4 = require("./merge-high");
|
|
45
54
|
Object.defineProperty(exports, "diffFromMerge", { enumerable: true, get: function () { return merge_high_4.diffFromMerge; } });
|
|
55
|
+
Object.defineProperty(exports, "patchFromMerge", { enumerable: true, get: function () { return merge_high_4.patchFromMerge; } });
|
|
46
56
|
var merge_conf_1 = require("./merge-conf");
|
|
47
57
|
Object.defineProperty(exports, "detailMerge", { enumerable: true, get: function () { return merge_conf_1.detailMerge; } });
|
|
48
58
|
Object.defineProperty(exports, "immutableDetailMerge", { enumerable: true, get: function () { return merge_conf_1.immutableDetailMerge; } });
|
|
@@ -53,12 +63,12 @@ Object.defineProperty(exports, "customMerge", { enumerable: true, get: function
|
|
|
53
63
|
Object.defineProperty(exports, "immutableCustomMerge", { enumerable: true, get: function () { return merge_conf_3.immutableCustomMerge; } });
|
|
54
64
|
var merge_conf_4 = require("./merge-conf");
|
|
55
65
|
Object.defineProperty(exports, "bypassMerge", { enumerable: true, get: function () { return merge_conf_4.bypassMerge; } });
|
|
56
|
-
var
|
|
57
|
-
Object.defineProperty(exports, "
|
|
58
|
-
Object.defineProperty(exports, "
|
|
59
|
-
var
|
|
60
|
-
Object.defineProperty(exports, "
|
|
61
|
-
Object.defineProperty(exports, "
|
|
66
|
+
var merge_patch_1 = require("./merge-patch");
|
|
67
|
+
Object.defineProperty(exports, "customMergePatch", { enumerable: true, get: function () { return merge_patch_1.customMergePatch; } });
|
|
68
|
+
Object.defineProperty(exports, "bypassMergePatch", { enumerable: true, get: function () { return merge_patch_1.bypassMergePatch; } });
|
|
69
|
+
var merge_patch_2 = require("./merge-patch");
|
|
70
|
+
Object.defineProperty(exports, "deepMergeLog", { enumerable: true, get: function () { return merge_patch_2.deepMergeLog; } });
|
|
71
|
+
Object.defineProperty(exports, "selectPathCode", { enumerable: true, get: function () { return merge_patch_2.selectPathCode; } });
|
|
62
72
|
var merge_high_5 = require("./merge-high");
|
|
63
73
|
Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return merge_high_5.deepMerge; } });
|
|
64
74
|
var merge_conf_5 = require("./merge-conf");
|
package/dist/cjs/merge-high.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.diffFromMerge = exports.immutableDeepMerge = exports.deepMerge = exports.immutableMerge = exports.shallowMerge = exports.updateCodeInfo = void 0;
|
|
3
|
+
exports.patchFromMerge = exports.diffFromMerge = exports.immutableDeepMerge = exports.deepMerge = exports.immutableMerge = exports.shallowMerge = exports.updateCodeInfo = void 0;
|
|
4
4
|
const type_utils_1 = require("./type-utils");
|
|
5
5
|
const datum_utils_1 = require("./datum-utils");
|
|
6
|
-
const diff_high_1 = require("./diff-high");
|
|
7
6
|
const merge_low_1 = require("./merge-low");
|
|
7
|
+
const diff_high_1 = require("./diff-high");
|
|
8
|
+
const patch_low_1 = require("./patch-low");
|
|
8
9
|
function updateCodeInfo(mergeCode) {
|
|
9
10
|
if (!(0, type_utils_1.isString)(mergeCode)) {
|
|
10
11
|
return { enable: false };
|
|
@@ -43,8 +44,9 @@ function shallowMerge(target, source, scalarCode, vectorCode, excludeKeys, inclu
|
|
|
43
44
|
}
|
|
44
45
|
continue;
|
|
45
46
|
}
|
|
46
|
-
if ((0, merge_low_1.mergeScalarField)(target, source, label, scalarCode))
|
|
47
|
+
if ((0, merge_low_1.mergeScalarField)(target, source, label, scalarCode)) {
|
|
47
48
|
changed = true;
|
|
49
|
+
}
|
|
48
50
|
}
|
|
49
51
|
return changed;
|
|
50
52
|
}
|
|
@@ -64,27 +66,20 @@ function deepMerge(target, source, scalarCode, vectorCode, nestedCode) {
|
|
|
64
66
|
let changed = false;
|
|
65
67
|
for (const label of sourceKeys) {
|
|
66
68
|
if ((0, type_utils_1.isArrayOfAny)(target[label]) || (0, type_utils_1.isArrayOfAny)(source[label])) {
|
|
67
|
-
|
|
68
|
-
changed = true;
|
|
69
|
-
}
|
|
69
|
+
changed = (0, merge_low_1.mergeVectorField)(target, source, label, vectorCode) || changed;
|
|
70
70
|
continue;
|
|
71
71
|
}
|
|
72
72
|
if ((0, type_utils_1.isObject)(target[label]) && (0, type_utils_1.isObject)(source[label])) {
|
|
73
73
|
if (nestedCode === merge_low_1.UpdateCode.N)
|
|
74
74
|
continue;
|
|
75
75
|
if (nestedCode === merge_low_1.UpdateCode.Y) {
|
|
76
|
-
|
|
77
|
-
changed = true;
|
|
76
|
+
changed = (0, merge_low_1.mergeScalarField)(target, source, label, scalarCode) || changed;
|
|
78
77
|
continue;
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
changed = true;
|
|
82
|
-
}
|
|
79
|
+
changed = deepMerge(target[label], source[label], nestedCode.startsWith("X") ? scalarCode : nestedCode, nestedCode.startsWith("X") ? nestedCode : vectorCode, nestedCode) || changed;
|
|
83
80
|
continue;
|
|
84
81
|
}
|
|
85
|
-
|
|
86
|
-
changed = true;
|
|
87
|
-
}
|
|
82
|
+
changed = (0, merge_low_1.mergeScalarField)(target, source, label, scalarCode) || changed;
|
|
88
83
|
}
|
|
89
84
|
return changed;
|
|
90
85
|
}
|
|
@@ -102,3 +97,9 @@ function diffFromMerge(target, source, scalarCode, vectorCode, nestedCode, order
|
|
|
102
97
|
return (0, type_utils_1.emptyObject)(delta) ? false : delta;
|
|
103
98
|
}
|
|
104
99
|
exports.diffFromMerge = diffFromMerge;
|
|
100
|
+
function patchFromMerge(target, source, scalarCode, vectorCode, nestedCode, orderInd = false) {
|
|
101
|
+
const targetCopy = immutableDeepMerge(target, source, scalarCode, vectorCode, nestedCode);
|
|
102
|
+
const patch = (0, patch_low_1.deepPatchLog)(target, targetCopy, orderInd, true);
|
|
103
|
+
return !(patch === null || patch === void 0 ? void 0 : patch.length) ? false : patch;
|
|
104
|
+
}
|
|
105
|
+
exports.patchFromMerge = patchFromMerge;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selectPathCode = exports.deepMergeLog = exports.bypassMergePatch = exports.customMergePatch = void 0;
|
|
4
|
+
const type_utils_1 = require("./type-utils");
|
|
5
|
+
const datum_utils_1 = require("./datum-utils");
|
|
6
|
+
const patch_low_1 = require("./patch-low");
|
|
7
|
+
const merge_low_1 = require("./merge-low");
|
|
8
|
+
const merge_conf_1 = require("./merge-conf");
|
|
9
|
+
function customMergePatch(target, source, mergeConf, excludeKeys) {
|
|
10
|
+
switch (mergeConf) {
|
|
11
|
+
case merge_low_1.UpdateCode.C:
|
|
12
|
+
return false;
|
|
13
|
+
case merge_low_1.UpdateCode.T:
|
|
14
|
+
return [];
|
|
15
|
+
case merge_low_1.UpdateCode.N:
|
|
16
|
+
return false;
|
|
17
|
+
case merge_low_1.UpdateCode.Y:
|
|
18
|
+
return bypassMergePatch(target, source);
|
|
19
|
+
}
|
|
20
|
+
const mergeCodes = (0, merge_conf_1.fillUpdateCodes)(source, mergeConf, false, excludeKeys);
|
|
21
|
+
if ((0, type_utils_1.emptyObject)(mergeCodes)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const targetBkp = (0, datum_utils_1.deepClone)(target);
|
|
25
|
+
const changed = (0, merge_conf_1.detailMerge)(target, source, mergeCodes);
|
|
26
|
+
const patch = deepMergeLog(targetBkp, target, mergeCodes);
|
|
27
|
+
if (changed || (patch === null || patch === void 0 ? void 0 : patch.length) > 0) {
|
|
28
|
+
return patch;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
exports.customMergePatch = customMergePatch;
|
|
33
|
+
function bypassMergePatch(target, source) {
|
|
34
|
+
const sourceKeys = (0, datum_utils_1.getObjectKeys)(source !== null && source !== void 0 ? source : {});
|
|
35
|
+
if (!source || !sourceKeys.length) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const mergeCodes = (0, datum_utils_1.createValueKeys)(sourceKeys, merge_low_1.UpdateCode.Y);
|
|
39
|
+
const targetBkp = (0, datum_utils_1.deepClone)(target);
|
|
40
|
+
Object.assign(target, Object.assign({}, source));
|
|
41
|
+
const patch = deepMergeLog(targetBkp, target, mergeCodes);
|
|
42
|
+
return !(patch === null || patch === void 0 ? void 0 : patch.length) ? false : patch;
|
|
43
|
+
}
|
|
44
|
+
exports.bypassMergePatch = bypassMergePatch;
|
|
45
|
+
function deepMergeLog(lhsObj, rhsObj, mergeCodes) {
|
|
46
|
+
const mergeLog = (0, patch_low_1.deepPatchLog)(lhsObj, rhsObj, false, true);
|
|
47
|
+
if (!(mergeLog === null || mergeLog === void 0 ? void 0 : mergeLog.length)) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const opCodeMap = {
|
|
51
|
+
"add": merge_low_1.UpdateCode.I,
|
|
52
|
+
"replace": merge_low_1.UpdateCode.H,
|
|
53
|
+
"remove": merge_low_1.UpdateCode.D,
|
|
54
|
+
"test": merge_low_1.UpdateCode.N,
|
|
55
|
+
};
|
|
56
|
+
for (const patchItem of mergeLog) {
|
|
57
|
+
const pathParts = (0, patch_low_1.asLodashPath)(patchItem.path);
|
|
58
|
+
patchItem.code = !mergeCodes
|
|
59
|
+
? opCodeMap[patchItem.op]
|
|
60
|
+
: selectPathCode(mergeCodes, pathParts);
|
|
61
|
+
}
|
|
62
|
+
return mergeLog;
|
|
63
|
+
}
|
|
64
|
+
exports.deepMergeLog = deepMergeLog;
|
|
65
|
+
;
|
|
66
|
+
function selectPathCode(mergeCodes, pathParts) {
|
|
67
|
+
if (!mergeCodes || (0, type_utils_1.emptyObject)(mergeCodes)) {
|
|
68
|
+
return merge_low_1.UpdateCode.N;
|
|
69
|
+
}
|
|
70
|
+
let currConf = mergeCodes;
|
|
71
|
+
for (let itr = 0; itr < pathParts.length; itr++) {
|
|
72
|
+
const part = pathParts[itr];
|
|
73
|
+
const partConf = currConf[part];
|
|
74
|
+
if (!partConf) {
|
|
75
|
+
return merge_low_1.UpdateCode.N;
|
|
76
|
+
}
|
|
77
|
+
if ((0, type_utils_1.isString)(partConf)) {
|
|
78
|
+
return partConf;
|
|
79
|
+
}
|
|
80
|
+
if (itr === pathParts.length - 1) {
|
|
81
|
+
return merge_low_1.UpdateCode.I;
|
|
82
|
+
}
|
|
83
|
+
currConf = partConf;
|
|
84
|
+
}
|
|
85
|
+
return merge_low_1.UpdateCode.N;
|
|
86
|
+
}
|
|
87
|
+
exports.selectPathCode = selectPathCode;
|
package/dist/cjs/patch-low.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getPointerValue = exports.asLodashPath = exports.immutablePatch = exports.revertPatchLog = exports.applyPatchLog = exports.deepPatchLog = exports.diffToPatchLog = void 0;
|
|
4
4
|
const lodash_es_1 = require("lodash-es");
|
|
5
|
+
const datum_utils_1 = require("./datum-utils");
|
|
5
6
|
const diff_high_1 = require("./diff-high");
|
|
6
7
|
function diffToPatchLog(differences, storePrev = false) {
|
|
7
8
|
var _a, _b, _c;
|
|
@@ -35,26 +36,63 @@ function diffToPatchLog(differences, storePrev = false) {
|
|
|
35
36
|
return jsonPatch;
|
|
36
37
|
}
|
|
37
38
|
exports.diffToPatchLog = diffToPatchLog;
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
function deepPatchLog(lhsObj, rhsObj, orderInd = false, storePrev = false) {
|
|
40
|
+
const differences = (0, diff_high_1.deepDiffLow)(lhsObj, rhsObj, orderInd);
|
|
41
|
+
return !differences ? [] : diffToPatchLog(differences, storePrev);
|
|
42
|
+
}
|
|
43
|
+
exports.deepPatchLog = deepPatchLog;
|
|
44
|
+
;
|
|
45
|
+
function applyPatchLog(patchLog, target) {
|
|
46
|
+
if (!target || !(patchLog === null || patchLog === void 0 ? void 0 : patchLog.length))
|
|
47
|
+
return false;
|
|
48
|
+
let changed = false;
|
|
41
49
|
for (const patchItem of patchLog) {
|
|
42
50
|
const difPath = asLodashPath(patchItem.path);
|
|
51
|
+
if (patchItem.op === "test")
|
|
52
|
+
continue;
|
|
43
53
|
if (patchItem.op === "remove") {
|
|
44
|
-
(0, lodash_es_1.unset)(target, difPath);
|
|
54
|
+
changed = (0, lodash_es_1.unset)(target, difPath) || changed;
|
|
55
|
+
continue;
|
|
45
56
|
}
|
|
46
|
-
|
|
57
|
+
const targetVal = (0, lodash_es_1.get)(target, difPath);
|
|
58
|
+
if (!targetVal && !patchItem.value)
|
|
59
|
+
continue;
|
|
60
|
+
if (!targetVal || !(0, datum_utils_1.deepEquals)(targetVal, patchItem.value)) {
|
|
47
61
|
(0, lodash_es_1.set)(target, difPath, patchItem.value);
|
|
62
|
+
changed = true;
|
|
48
63
|
}
|
|
49
64
|
}
|
|
50
|
-
return
|
|
65
|
+
return changed;
|
|
51
66
|
}
|
|
52
67
|
exports.applyPatchLog = applyPatchLog;
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
68
|
+
function revertPatchLog(patchLog, target) {
|
|
69
|
+
if (!target || !(patchLog === null || patchLog === void 0 ? void 0 : patchLog.length))
|
|
70
|
+
return false;
|
|
71
|
+
let changed = false;
|
|
72
|
+
for (const patchItem of patchLog) {
|
|
73
|
+
const difPath = asLodashPath(patchItem.path);
|
|
74
|
+
if (patchItem.op === "add") {
|
|
75
|
+
changed = (0, lodash_es_1.unset)(target, difPath) || changed;
|
|
76
|
+
}
|
|
77
|
+
else if (patchItem.op !== "test") {
|
|
78
|
+
(0, lodash_es_1.set)(target, difPath, patchItem.prev);
|
|
79
|
+
changed = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return changed;
|
|
56
83
|
}
|
|
57
|
-
exports.
|
|
84
|
+
exports.revertPatchLog = revertPatchLog;
|
|
85
|
+
function immutablePatch(target, patchSrc, patchDir) {
|
|
86
|
+
const targetCopy = (0, datum_utils_1.deepClone)(target !== null && target !== void 0 ? target : {});
|
|
87
|
+
if (patchDir === "revert") {
|
|
88
|
+
revertPatchLog(patchSrc, targetCopy);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
applyPatchLog(patchSrc, targetCopy);
|
|
92
|
+
}
|
|
93
|
+
return targetCopy;
|
|
94
|
+
}
|
|
95
|
+
exports.immutablePatch = immutablePatch;
|
|
58
96
|
;
|
|
59
97
|
function escapePathPart(path) {
|
|
60
98
|
if (typeof path === 'number')
|
|
@@ -80,8 +118,8 @@ function asLodashPath(pointer) {
|
|
|
80
118
|
return !(parts === null || parts === void 0 ? void 0 : parts.length) ? [] : (0, lodash_es_1.toPath)(parts.join("."));
|
|
81
119
|
}
|
|
82
120
|
exports.asLodashPath = asLodashPath;
|
|
83
|
-
function
|
|
121
|
+
function getPointerValue(document, pointer) {
|
|
84
122
|
return pointer === "" ? document
|
|
85
123
|
: (0, lodash_es_1.get)(document, asLodashPath(pointer));
|
|
86
124
|
}
|
|
87
|
-
exports.
|
|
125
|
+
exports.getPointerValue = getPointerValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datum-utils.d.ts","sourceRoot":"","sources":["../../src/datum-utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,CACzB,GAAG,EAAE,GAAG,EACR,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,MAAM,EAAE,CAaV;AAED,w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EAAU,EAC7B,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,MAAM,EAAE,CAmBV;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAC1C,GAAG,EAAE,CAAC,EACN,WAAW,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,CAAC,CAAC,CAMZ"}
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -4,22 +4,26 @@ export { deepDiffLow } from "./diff-high";
|
|
|
4
4
|
export { deepDiffTyped, antiDiffTyped } from "./diff-high";
|
|
5
5
|
export { deepDiffFlat } from "./diff-high";
|
|
6
6
|
export { flattenObject, unflattenObject } from "./diff-high";
|
|
7
|
+
export { type PatchResult } from "./patch-low";
|
|
8
|
+
export { diffToPatchLog, deepPatchLog } from "./patch-low";
|
|
9
|
+
export { applyPatchLog, revertPatchLog } from "./patch-low";
|
|
10
|
+
export { immutablePatch, getPointerValue } from "./patch-low";
|
|
7
11
|
export { UpdateCode } from "./merge-low";
|
|
8
12
|
export { UpdateCode as MC } from "./merge-low";
|
|
9
13
|
export { type MergeCode } from "./merge-low";
|
|
10
14
|
export { updateCodeInfo } from "./merge-high";
|
|
11
15
|
export { shallowMerge, immutableMerge } from "./merge-high";
|
|
12
16
|
export { deepMerge, immutableDeepMerge } from "./merge-high";
|
|
13
|
-
export { diffFromMerge } from "./merge-high";
|
|
17
|
+
export { diffFromMerge, patchFromMerge } from "./merge-high";
|
|
14
18
|
export { type DetailConfig } from "./merge-conf";
|
|
15
19
|
export { detailMerge, immutableDetailMerge } from "./merge-conf";
|
|
16
20
|
export { type MergeConfig } from "./merge-conf";
|
|
17
21
|
export { fillUpdateCodes } from "./merge-conf";
|
|
18
22
|
export { customMerge, immutableCustomMerge } from "./merge-conf";
|
|
19
23
|
export { bypassMerge } from "./merge-conf";
|
|
20
|
-
export { type
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
24
|
+
export { type MergeResult } from "./merge-patch";
|
|
25
|
+
export { customMergePatch, bypassMergePatch } from "./merge-patch";
|
|
26
|
+
export { deepMergeLog, selectPathCode } from "./merge-patch";
|
|
23
27
|
export { deepMerge as merge } from "./merge-high";
|
|
24
28
|
export { customMerge as mergeDiff } from "./merge-conf";
|
|
25
29
|
export * from "./diff-lib/deep-diff";
|
package/dist/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,IAAI,EAAE,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE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M,eAAe,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG7D,OAAO,EAAE,SAAS,IAAI,KAAK,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,WAAW,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AACxD,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,WAAW,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/dts/merge-high.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MergeCode } from "./merge-low";
|
|
2
|
+
import { PatchResult } from "./patch-low";
|
|
2
3
|
export type MergePerms = {
|
|
3
4
|
enable: boolean;
|
|
4
5
|
insert?: boolean;
|
|
@@ -23,4 +24,9 @@ export declare function diffFromMerge(target: {
|
|
|
23
24
|
}, source: {
|
|
24
25
|
[key: string]: any;
|
|
25
26
|
}, scalarCode: MergeCode, vectorCode?: MergeCode, nestedCode?: MergeCode, orderInd?: boolean): any | false;
|
|
27
|
+
export declare function patchFromMerge(target: {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}, source: {
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}, scalarCode: MergeCode, vectorCode?: MergeCode, nestedCode?: MergeCode, orderInd?: boolean): PatchResult[] | false;
|
|
26
32
|
//# sourceMappingURL=merge-high.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-high.d.ts","sourceRoot":"","sources":["../../src/merge-high.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"merge-high.d.ts","sourceRoot":"","sources":["../../src/merge-high.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAkD,MAAM,aAAa,CAAC;AAExF,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAC;AAExD,MAAM,MAAM,UAAU,GAAG;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OA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,EACrB,UAAU,CAAC,EAAE,SAAS,EACtB,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,GAAE,OAAe,GAC1B,GAAG,GAAG,KAAK,CAIb;AAOD,wBAAgB,cAAc,CAC1B,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC9B,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC9B,UAAU,EAAE,SAAS,EACrB,UAAU,CAAC,EAAE,SAAS,EACtB,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,GAAE,OAAe,GAC1B,WAAW,EAAE,GAAG,KAAK,CAIvB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MergeCode } from "./merge-low";
|
|
2
|
+
import { DetailConfig, MergeConfig } from "./merge-conf";
|
|
3
|
+
export type MergeResult<T = any> = {
|
|
4
|
+
path: string;
|
|
5
|
+
op: "add" | "remove" | "replace";
|
|
6
|
+
value?: Readonly<T>;
|
|
7
|
+
prev?: Readonly<T>;
|
|
8
|
+
code: MergeCode;
|
|
9
|
+
};
|
|
10
|
+
export declare function customMergePatch<T extends object>(target: T, source: Partial<T>, mergeConf: MergeConfig | MergeCode, excludeKeys?: string[]): MergeResult[] | false;
|
|
11
|
+
export declare function bypassMergePatch<T extends object>(target: T, source: Partial<T>): MergeResult[] | false;
|
|
12
|
+
export declare function deepMergeLog(lhsObj: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}, rhsObj: {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}, mergeCodes?: DetailConfig): MergeResult[];
|
|
17
|
+
export declare function selectPathCode(mergeCodes: DetailConfig, pathParts: string[]): MergeCode;
|
|
18
|
+
//# sourceMappingURL=merge-patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-patch.d.ts","sourceRoot":"","sources":["../../src/merge-patch.ts"],"names":[],"mappings":"AA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: string;
|
|
4
|
-
op: "add" | "remove" | "replace";
|
|
4
|
+
op: "add" | "remove" | "replace" | "test";
|
|
5
5
|
value?: Readonly<T>;
|
|
6
6
|
prev?: any;
|
|
7
7
|
};
|
|
8
8
|
export declare function diffToPatchLog(differences: readonly Diff<any, any>[], storePrev?: boolean): PatchResult[];
|
|
9
|
-
export declare function applyPatchLog(patchLog: PatchResult[], target?: object): object;
|
|
10
9
|
export declare function deepPatchLog(lhsObj: {
|
|
11
10
|
[key: string]: any;
|
|
12
11
|
}, rhsObj: {
|
|
13
12
|
[key: string]: any;
|
|
14
13
|
}, orderInd?: boolean, storePrev?: boolean): PatchResult[];
|
|
14
|
+
export declare function applyPatchLog(patchLog: PatchResult[], target: object): boolean;
|
|
15
|
+
export declare function revertPatchLog(patchLog: PatchResult[], target: object): boolean;
|
|
16
|
+
export declare function immutablePatch(target: object, patchSrc: PatchResult[], patchDir?: "apply" | "revert"): object;
|
|
15
17
|
export declare function asLodashPath(pointer: string): string[];
|
|
16
|
-
export declare function
|
|
18
|
+
export declare function getPointerValue(document: any, pointer: string): any;
|
|
17
19
|
//# sourceMappingURL=patch-low.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-low.d.ts","sourceRoot":"","sources":["../../src/patch-low.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"patch-low.d.ts","sourceRoot":"","sources":["../../src/patch-low.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAG5C,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,GAAG,IAAI;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,KAAK,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;IAC1C,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,EAAE,GAAG,CAAC;CACd,CAAC;AAOF,wBAAgB,cAAc,CAC1B,WAAW,EAAE,SAAS,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EACtC,SAAS,GAAE,OAAe,GAC3B,WAAW,EAAE,CA6Bf;AAED,wBAAgB,YAAY,CACxB,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC9B,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC9B,QAAQ,GAAE,OAAe,EACzB,SAAS,GAAE,OAAe,GAC3B,WAAW,EAAE,CAGf;AAKD,wBAAgB,aAAa,CACzB,QAAQ,EAAE,WAAW,EAAE,EACvB,MAAM,EAAE,MAAM,GACf,OAAO,CAqBT;AAKD,wBAAgB,cAAc,CAC1B,QAAQ,EAAE,WAAW,EAAE,EACvB,MAAM,EAAE,MAAM,GACf,OAAO,CAcT;AAED,wBAAgB,cAAc,CAC1B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,EAAE,EACvB,QAAQ,CAAC,EAAE,OAAO,GAAG,QAAQ,GAC9B,MAAM,CAQR;AAuBD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAMtD;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,GAAG,CAGnE"}
|
package/dist/esm/datum-utils.js
CHANGED
|
@@ -19,6 +19,8 @@ export function createValueKeys(keys, value) {
|
|
|
19
19
|
return Object.fromEntries(keys.map((k) => [k, value]));
|
|
20
20
|
}
|
|
21
21
|
export function deepEquals(lhs, rhs) {
|
|
22
|
+
if (lhs === rhs)
|
|
23
|
+
return true;
|
|
22
24
|
return equal(lhs, rhs);
|
|
23
25
|
}
|
|
24
26
|
export function deepEqualsPath(lhs, rhs, atPath) {
|
package/dist/esm/index.js
CHANGED
|
@@ -4,18 +4,21 @@ export { deepDiffLow } from "./diff-high";
|
|
|
4
4
|
export { deepDiffTyped, antiDiffTyped } from "./diff-high";
|
|
5
5
|
export { deepDiffFlat } from "./diff-high";
|
|
6
6
|
export { flattenObject, unflattenObject } from "./diff-high";
|
|
7
|
+
export { diffToPatchLog, deepPatchLog } from "./patch-low";
|
|
8
|
+
export { applyPatchLog, revertPatchLog } from "./patch-low";
|
|
9
|
+
export { immutablePatch, getPointerValue } from "./patch-low";
|
|
7
10
|
export { UpdateCode } from "./merge-low";
|
|
8
11
|
export { UpdateCode as MC } from "./merge-low";
|
|
9
12
|
export { updateCodeInfo } from "./merge-high";
|
|
10
13
|
export { shallowMerge, immutableMerge } from "./merge-high";
|
|
11
14
|
export { deepMerge, immutableDeepMerge } from "./merge-high";
|
|
12
|
-
export { diffFromMerge } from "./merge-high";
|
|
15
|
+
export { diffFromMerge, patchFromMerge } from "./merge-high";
|
|
13
16
|
export { detailMerge, immutableDetailMerge } from "./merge-conf";
|
|
14
17
|
export { fillUpdateCodes } from "./merge-conf";
|
|
15
18
|
export { customMerge, immutableCustomMerge } from "./merge-conf";
|
|
16
19
|
export { bypassMerge } from "./merge-conf";
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
20
|
+
export { customMergePatch, bypassMergePatch } from "./merge-patch";
|
|
21
|
+
export { deepMergeLog, selectPathCode } from "./merge-patch";
|
|
19
22
|
export { deepMerge as merge } from "./merge-high";
|
|
20
23
|
export { customMerge as mergeDiff } from "./merge-conf";
|
|
21
24
|
export * from "./diff-lib/deep-diff";
|
package/dist/esm/merge-high.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isArrayOfAny, emptyObject, isObject, isString } from "./type-utils";
|
|
2
2
|
import { deepClone, getObjectKeys } from "./datum-utils";
|
|
3
|
-
import { deepDiffTyped } from "./diff-high";
|
|
4
3
|
import { UpdateCode, mergeScalarField, mergeVectorField } from "./merge-low";
|
|
4
|
+
import { deepDiffTyped } from "./diff-high";
|
|
5
|
+
import { deepPatchLog } from "./patch-low";
|
|
5
6
|
export function updateCodeInfo(mergeCode) {
|
|
6
7
|
if (!isString(mergeCode)) {
|
|
7
8
|
return { enable: false };
|
|
@@ -39,8 +40,9 @@ export function shallowMerge(target, source, scalarCode, vectorCode, excludeKeys
|
|
|
39
40
|
}
|
|
40
41
|
continue;
|
|
41
42
|
}
|
|
42
|
-
if (mergeScalarField(target, source, label, scalarCode))
|
|
43
|
+
if (mergeScalarField(target, source, label, scalarCode)) {
|
|
43
44
|
changed = true;
|
|
45
|
+
}
|
|
44
46
|
}
|
|
45
47
|
return changed;
|
|
46
48
|
}
|
|
@@ -58,27 +60,20 @@ export function deepMerge(target, source, scalarCode, vectorCode, nestedCode) {
|
|
|
58
60
|
let changed = false;
|
|
59
61
|
for (const label of sourceKeys) {
|
|
60
62
|
if (isArrayOfAny(target[label]) || isArrayOfAny(source[label])) {
|
|
61
|
-
|
|
62
|
-
changed = true;
|
|
63
|
-
}
|
|
63
|
+
changed = mergeVectorField(target, source, label, vectorCode) || changed;
|
|
64
64
|
continue;
|
|
65
65
|
}
|
|
66
66
|
if (isObject(target[label]) && isObject(source[label])) {
|
|
67
67
|
if (nestedCode === UpdateCode.N)
|
|
68
68
|
continue;
|
|
69
69
|
if (nestedCode === UpdateCode.Y) {
|
|
70
|
-
|
|
71
|
-
changed = true;
|
|
70
|
+
changed = mergeScalarField(target, source, label, scalarCode) || changed;
|
|
72
71
|
continue;
|
|
73
72
|
}
|
|
74
|
-
|
|
75
|
-
changed = true;
|
|
76
|
-
}
|
|
73
|
+
changed = deepMerge(target[label], source[label], nestedCode.startsWith("X") ? scalarCode : nestedCode, nestedCode.startsWith("X") ? nestedCode : vectorCode, nestedCode) || changed;
|
|
77
74
|
continue;
|
|
78
75
|
}
|
|
79
|
-
|
|
80
|
-
changed = true;
|
|
81
|
-
}
|
|
76
|
+
changed = mergeScalarField(target, source, label, scalarCode) || changed;
|
|
82
77
|
}
|
|
83
78
|
return changed;
|
|
84
79
|
}
|
|
@@ -93,3 +88,8 @@ export function diffFromMerge(target, source, scalarCode, vectorCode, nestedCode
|
|
|
93
88
|
const delta = deepDiffTyped(target, targetCopy, orderInd);
|
|
94
89
|
return emptyObject(delta) ? false : delta;
|
|
95
90
|
}
|
|
91
|
+
export function patchFromMerge(target, source, scalarCode, vectorCode, nestedCode, orderInd = false) {
|
|
92
|
+
const targetCopy = immutableDeepMerge(target, source, scalarCode, vectorCode, nestedCode);
|
|
93
|
+
const patch = deepPatchLog(target, targetCopy, orderInd, true);
|
|
94
|
+
return !(patch === null || patch === void 0 ? void 0 : patch.length) ? false : patch;
|
|
95
|
+
}
|