datum-merge 1.0.3 → 1.1.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/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.asLodashPath = exports.applyPatchLog = exports.deepPatchLog = exports.diffToPatchLog = exports.bypassMerge = exports.immutableCustomMerge = exports.customMerge = exports.fillUpdateCodes = exports.immutableDetailMerge = exports.detailMerge = exports.diffFromMerge = exports.immutableDeepMerge = exports.deepMerge = exports.immutableMerge = exports.shallowMerge = exports.updateCodeInfo = exports.MC = exports.UpdateCode = exports.unflattenObject = exports.flattenObject = exports.deepDiffFlat = exports.antiDiffTyped = exports.deepDiffTyped = exports.deepDiffLow = exports.deepClone = exports.deepEquals = void 0;
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.asLodashPath = 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,13 @@ 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
+ Object.defineProperty(exports, "asLodashPath", { enumerable: true, get: function () { return patch_low_2.asLodashPath; } });
32
39
  var merge_low_1 = require("./merge-low");
33
40
  Object.defineProperty(exports, "UpdateCode", { enumerable: true, get: function () { return merge_low_1.UpdateCode; } });
34
41
  var merge_low_2 = require("./merge-low");
@@ -43,6 +50,7 @@ Object.defineProperty(exports, "deepMerge", { enumerable: true, get: function ()
43
50
  Object.defineProperty(exports, "immutableDeepMerge", { enumerable: true, get: function () { return merge_high_3.immutableDeepMerge; } });
44
51
  var merge_high_4 = require("./merge-high");
45
52
  Object.defineProperty(exports, "diffFromMerge", { enumerable: true, get: function () { return merge_high_4.diffFromMerge; } });
53
+ Object.defineProperty(exports, "patchFromMerge", { enumerable: true, get: function () { return merge_high_4.patchFromMerge; } });
46
54
  var merge_conf_1 = require("./merge-conf");
47
55
  Object.defineProperty(exports, "detailMerge", { enumerable: true, get: function () { return merge_conf_1.detailMerge; } });
48
56
  Object.defineProperty(exports, "immutableDetailMerge", { enumerable: true, get: function () { return merge_conf_1.immutableDetailMerge; } });
@@ -53,12 +61,12 @@ Object.defineProperty(exports, "customMerge", { enumerable: true, get: function
53
61
  Object.defineProperty(exports, "immutableCustomMerge", { enumerable: true, get: function () { return merge_conf_3.immutableCustomMerge; } });
54
62
  var merge_conf_4 = require("./merge-conf");
55
63
  Object.defineProperty(exports, "bypassMerge", { enumerable: true, get: function () { return merge_conf_4.bypassMerge; } });
56
- var patch_low_1 = require("./patch-low");
57
- Object.defineProperty(exports, "diffToPatchLog", { enumerable: true, get: function () { return patch_low_1.diffToPatchLog; } });
58
- Object.defineProperty(exports, "deepPatchLog", { enumerable: true, get: function () { return patch_low_1.deepPatchLog; } });
59
- var patch_low_2 = require("./patch-low");
60
- Object.defineProperty(exports, "applyPatchLog", { enumerable: true, get: function () { return patch_low_2.applyPatchLog; } });
61
- Object.defineProperty(exports, "asLodashPath", { enumerable: true, get: function () { return patch_low_2.asLodashPath; } });
64
+ var merge_patch_1 = require("./merge-patch");
65
+ Object.defineProperty(exports, "customMergePatch", { enumerable: true, get: function () { return merge_patch_1.customMergePatch; } });
66
+ Object.defineProperty(exports, "bypassMergePatch", { enumerable: true, get: function () { return merge_patch_1.bypassMergePatch; } });
67
+ var merge_patch_2 = require("./merge-patch");
68
+ Object.defineProperty(exports, "deepMergeLog", { enumerable: true, get: function () { return merge_patch_2.deepMergeLog; } });
69
+ Object.defineProperty(exports, "selectPathCode", { enumerable: true, get: function () { return merge_patch_2.selectPathCode; } });
62
70
  var merge_high_5 = require("./merge-high");
63
71
  Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return merge_high_5.deepMerge; } });
64
72
  var merge_conf_5 = require("./merge-conf");
@@ -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
- if ((0, merge_low_1.mergeVectorField)(target, source, label, vectorCode)) {
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
- if ((0, merge_low_1.mergeScalarField)(target, source, label, scalarCode))
77
- changed = true;
76
+ changed = (0, merge_low_1.mergeScalarField)(target, source, label, scalarCode) || changed;
78
77
  continue;
79
78
  }
80
- if (deepMerge(target[label], source[label], nestedCode.startsWith("X") ? scalarCode : nestedCode, nestedCode.startsWith("X") ? nestedCode : vectorCode, nestedCode)) {
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
- if ((0, merge_low_1.mergeScalarField)(target, source, label, scalarCode)) {
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;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValueByPointer = exports.asLodashPath = exports.deepPatchLog = exports.applyPatchLog = exports.diffToPatchLog = void 0;
3
+ exports.getValueByPointer = exports.asLodashPath = exports.revertPatchLog = exports.applyPatchLog = exports.deepPatchLog = exports.diffToPatchLog = void 0;
4
4
  const lodash_es_1 = require("lodash-es");
5
5
  const diff_high_1 = require("./diff-high");
6
6
  function diffToPatchLog(differences, storePrev = false) {
@@ -35,6 +35,12 @@ function diffToPatchLog(differences, storePrev = false) {
35
35
  return jsonPatch;
36
36
  }
37
37
  exports.diffToPatchLog = diffToPatchLog;
38
+ function deepPatchLog(lhsObj, rhsObj, orderInd = false, storePrev = false) {
39
+ const differences = (0, diff_high_1.deepDiffLow)(lhsObj, rhsObj, orderInd);
40
+ return !differences ? [] : diffToPatchLog(differences, storePrev);
41
+ }
42
+ exports.deepPatchLog = deepPatchLog;
43
+ ;
38
44
  function applyPatchLog(patchLog, target = {}) {
39
45
  if (!patchLog)
40
46
  return target;
@@ -50,12 +56,21 @@ function applyPatchLog(patchLog, target = {}) {
50
56
  return target;
51
57
  }
52
58
  exports.applyPatchLog = applyPatchLog;
53
- function deepPatchLog(lhsObj, rhsObj, orderInd = false, storePrev = false) {
54
- const differences = (0, diff_high_1.deepDiffLow)(lhsObj, rhsObj, orderInd);
55
- return !differences ? [] : diffToPatchLog(differences, storePrev);
59
+ function revertPatchLog(patchLog, target) {
60
+ if (!patchLog)
61
+ return target;
62
+ for (const patchItem of patchLog) {
63
+ const difPath = asLodashPath(patchItem.path);
64
+ if (patchItem.op === "add") {
65
+ (0, lodash_es_1.unset)(target, difPath);
66
+ }
67
+ else {
68
+ (0, lodash_es_1.set)(target, difPath, patchItem.prev);
69
+ }
70
+ }
71
+ return target;
56
72
  }
57
- exports.deepPatchLog = deepPatchLog;
58
- ;
73
+ exports.revertPatchLog = revertPatchLog;
59
74
  function escapePathPart(path) {
60
75
  if (typeof path === 'number')
61
76
  return path.toString();
@@ -4,22 +4,25 @@ 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, asLodashPath } from "./patch-low";
7
10
  export { UpdateCode } from "./merge-low";
8
11
  export { UpdateCode as MC } from "./merge-low";
9
12
  export { type MergeCode } from "./merge-low";
10
13
  export { updateCodeInfo } from "./merge-high";
11
14
  export { shallowMerge, immutableMerge } from "./merge-high";
12
15
  export { deepMerge, immutableDeepMerge } from "./merge-high";
13
- export { diffFromMerge } from "./merge-high";
16
+ export { diffFromMerge, patchFromMerge } from "./merge-high";
14
17
  export { type DetailConfig } from "./merge-conf";
15
18
  export { detailMerge, immutableDetailMerge } from "./merge-conf";
16
19
  export { type MergeConfig } from "./merge-conf";
17
20
  export { fillUpdateCodes } from "./merge-conf";
18
21
  export { customMerge, immutableCustomMerge } from "./merge-conf";
19
22
  export { bypassMerge } from "./merge-conf";
20
- export { type PatchResult } from "./patch-low";
21
- export { diffToPatchLog, deepPatchLog } from "./patch-low";
22
- export { applyPatchLog, asLodashPath } from "./patch-low";
23
+ export { type MergeResult } from "./merge-patch";
24
+ export { customMergePatch, bypassMergePatch } from "./merge-patch";
25
+ export { deepMergeLog, selectPathCode } from "./merge-patch";
23
26
  export { deepMerge as merge } from "./merge-high";
24
27
  export { customMerge as mergeDiff } from "./merge-conf";
25
28
  export * from "./diff-lib/deep-diff";
@@ -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;AAE7C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MA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AAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,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"}
@@ -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":"AAGA,OAAO,EAAE,SAAS,EAAkD,MAAM,aAAa,CAAC;AAExF,MAAM,MAAM,UAAU,GAAG;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,wBAAgB,cAAc,CAC1B,SAAS,EAAE,SAAS,GACrB,UAAU,CAuBZ;AASD,wBAAgB,YAAY,CACxB,MAAM,EAAE,GAAG,EACX,MAAM,EAAE,GAAG,EACX,UAAU,EAAE,SAAS,EACrB,UAAU,CAAC,EAAE,SAAS,EACtB,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,OAAO,CAkBT;AAMD,wBAAgB,cAAc,CAC1B,MAAM,EAAE,GAAG,EACX,MAAM,EAAE,GAAG,EACX,UAAU,EAAE,SAAS,EACrB,UAAU,CAAC,EAAE,SAAS,GACvB,GAAG,CAIL;AAUD,wBAAgB,SAAS,CACrB,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,EAAE,SAAS,EACrB,UAAU,EAAE,SAAS,GACtB,OAAO,CAqCT;AAMD,wBAAgB,kBAAkB,CAC9B,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC9B,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,C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;
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":"AAGA,OAAO,EAAc,SAAS,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAgC,MAAM,cAAc,CAAC;AAEvF,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,GAAG,IAAI;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;IACjC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnB,IAAI,EAAE,SAAS,CAAC;CACnB,CAAC;AAMF,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC7C,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAClB,SAAS,EAAE,WAAW,GAAG,SAAS,EAClC,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,WAAW,EAAE,GAAG,KAAK,CAwBvB;AAMD,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC7C,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GACnB,WAAW,EAAE,GAAG,KAAK,CAavB;AAQD,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,UAAU,CAAC,EAAE,YAAY,GAC1B,WAAW,EAAE,CAmBf;AAMD,wBAAgB,cAAc,CAC1B,UAAU,EAAE,YAAY,EACxB,SAAS,EAAE,MAAM,EAAE,GACpB,SAAS,CAwBX"}
@@ -6,12 +6,13 @@ export type PatchResult<T = any> = {
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): object;
15
+ export declare function revertPatchLog(patchLog: PatchResult[], target: object): object;
15
16
  export declare function asLodashPath(pointer: string): string[];
16
17
  export declare function getValueByPointer(document: any, pointer: string): any;
17
18
  //# sourceMappingURL=patch-low.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"patch-low.d.ts","sourceRoot":"","sources":["../../src/patch-low.ts"],"names":[],"mappings":"AACA,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,CAAC;IACjC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,EAAE,GAAG,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,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,GAAE,MAAW,GACpB,MAAM,CAYR;AAKD,wBAAgB,cAAc,CAC1B,QAAQ,EAAE,WAAW,EAAE,EACvB,MAAM,EAAE,MAAM,GACf,MAAM,CAYR;AAuBD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAMtD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,GAAG,CAGrE"}
package/dist/esm/index.js CHANGED
@@ -4,18 +4,20 @@ 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, asLodashPath } from "./patch-low";
7
9
  export { UpdateCode } from "./merge-low";
8
10
  export { UpdateCode as MC } from "./merge-low";
9
11
  export { updateCodeInfo } from "./merge-high";
10
12
  export { shallowMerge, immutableMerge } from "./merge-high";
11
13
  export { deepMerge, immutableDeepMerge } from "./merge-high";
12
- export { diffFromMerge } from "./merge-high";
14
+ export { diffFromMerge, patchFromMerge } from "./merge-high";
13
15
  export { detailMerge, immutableDetailMerge } from "./merge-conf";
14
16
  export { fillUpdateCodes } from "./merge-conf";
15
17
  export { customMerge, immutableCustomMerge } from "./merge-conf";
16
18
  export { bypassMerge } from "./merge-conf";
17
- export { diffToPatchLog, deepPatchLog } from "./patch-low";
18
- export { applyPatchLog, asLodashPath } from "./patch-low";
19
+ export { customMergePatch, bypassMergePatch } from "./merge-patch";
20
+ export { deepMergeLog, selectPathCode } from "./merge-patch";
19
21
  export { deepMerge as merge } from "./merge-high";
20
22
  export { customMerge as mergeDiff } from "./merge-conf";
21
23
  export * from "./diff-lib/deep-diff";
@@ -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
- if (mergeVectorField(target, source, label, vectorCode)) {
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
- if (mergeScalarField(target, source, label, scalarCode))
71
- changed = true;
70
+ changed = mergeScalarField(target, source, label, scalarCode) || changed;
72
71
  continue;
73
72
  }
74
- if (deepMerge(target[label], source[label], nestedCode.startsWith("X") ? scalarCode : nestedCode, nestedCode.startsWith("X") ? nestedCode : vectorCode, nestedCode)) {
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
- if (mergeScalarField(target, source, label, scalarCode)) {
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
+ }
@@ -0,0 +1,80 @@
1
+ import { emptyObject, isString } from "./type-utils";
2
+ import { createValueKeys, deepClone, getObjectKeys } from "./datum-utils";
3
+ import { asLodashPath, deepPatchLog } from "./patch-low";
4
+ import { UpdateCode } from "./merge-low";
5
+ import { detailMerge, fillUpdateCodes } from "./merge-conf";
6
+ export function customMergePatch(target, source, mergeConf, excludeKeys) {
7
+ switch (mergeConf) {
8
+ case UpdateCode.C:
9
+ return false;
10
+ case UpdateCode.T:
11
+ return [];
12
+ case UpdateCode.N:
13
+ return false;
14
+ case UpdateCode.Y:
15
+ return bypassMergePatch(target, source);
16
+ }
17
+ const mergeCodes = fillUpdateCodes(source, mergeConf, false, excludeKeys);
18
+ if (emptyObject(mergeCodes)) {
19
+ return false;
20
+ }
21
+ const targetBkp = deepClone(target);
22
+ const changed = detailMerge(target, source, mergeCodes);
23
+ const patch = deepMergeLog(targetBkp, target, mergeCodes);
24
+ if (changed || (patch === null || patch === void 0 ? void 0 : patch.length) > 0) {
25
+ return patch;
26
+ }
27
+ return false;
28
+ }
29
+ export function bypassMergePatch(target, source) {
30
+ const sourceKeys = getObjectKeys(source !== null && source !== void 0 ? source : {});
31
+ if (!source || !sourceKeys.length) {
32
+ return false;
33
+ }
34
+ const mergeCodes = createValueKeys(sourceKeys, UpdateCode.Y);
35
+ const targetBkp = deepClone(target);
36
+ Object.assign(target, Object.assign({}, source));
37
+ const patch = deepMergeLog(targetBkp, target, mergeCodes);
38
+ return !(patch === null || patch === void 0 ? void 0 : patch.length) ? false : patch;
39
+ }
40
+ export function deepMergeLog(lhsObj, rhsObj, mergeCodes) {
41
+ const mergeLog = deepPatchLog(lhsObj, rhsObj, false, true);
42
+ if (!(mergeLog === null || mergeLog === void 0 ? void 0 : mergeLog.length)) {
43
+ return [];
44
+ }
45
+ const opCodeMap = {
46
+ "add": UpdateCode.I,
47
+ "replace": UpdateCode.H,
48
+ "remove": UpdateCode.D,
49
+ "test": UpdateCode.N,
50
+ };
51
+ for (const patchItem of mergeLog) {
52
+ const pathParts = asLodashPath(patchItem.path);
53
+ patchItem.code = !mergeCodes
54
+ ? opCodeMap[patchItem.op]
55
+ : selectPathCode(mergeCodes, pathParts);
56
+ }
57
+ return mergeLog;
58
+ }
59
+ ;
60
+ export function selectPathCode(mergeCodes, pathParts) {
61
+ if (!mergeCodes || emptyObject(mergeCodes)) {
62
+ return UpdateCode.N;
63
+ }
64
+ let currConf = mergeCodes;
65
+ for (let itr = 0; itr < pathParts.length; itr++) {
66
+ const part = pathParts[itr];
67
+ const partConf = currConf[part];
68
+ if (!partConf) {
69
+ return UpdateCode.N;
70
+ }
71
+ if (isString(partConf)) {
72
+ return partConf;
73
+ }
74
+ if (itr === pathParts.length - 1) {
75
+ return UpdateCode.I;
76
+ }
77
+ currConf = partConf;
78
+ }
79
+ return UpdateCode.N;
80
+ }
@@ -31,6 +31,11 @@ export function diffToPatchLog(differences, storePrev = false) {
31
31
  }
32
32
  return jsonPatch;
33
33
  }
34
+ export function deepPatchLog(lhsObj, rhsObj, orderInd = false, storePrev = false) {
35
+ const differences = deepDiffLow(lhsObj, rhsObj, orderInd);
36
+ return !differences ? [] : diffToPatchLog(differences, storePrev);
37
+ }
38
+ ;
34
39
  export function applyPatchLog(patchLog, target = {}) {
35
40
  if (!patchLog)
36
41
  return target;
@@ -45,11 +50,20 @@ export function applyPatchLog(patchLog, target = {}) {
45
50
  }
46
51
  return target;
47
52
  }
48
- export function deepPatchLog(lhsObj, rhsObj, orderInd = false, storePrev = false) {
49
- const differences = deepDiffLow(lhsObj, rhsObj, orderInd);
50
- return !differences ? [] : diffToPatchLog(differences, storePrev);
53
+ export function revertPatchLog(patchLog, target) {
54
+ if (!patchLog)
55
+ return target;
56
+ for (const patchItem of patchLog) {
57
+ const difPath = asLodashPath(patchItem.path);
58
+ if (patchItem.op === "add") {
59
+ unset(target, difPath);
60
+ }
61
+ else {
62
+ set(target, difPath, patchItem.prev);
63
+ }
64
+ }
65
+ return target;
51
66
  }
52
- ;
53
67
  function escapePathPart(path) {
54
68
  if (typeof path === 'number')
55
69
  return path.toString();