datum-merge 0.9.3 → 0.9.5

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 CHANGED
@@ -93,7 +93,7 @@ The value is migrated from the source field to the target field only if the pred
93
93
  | D | `s0 & tX` | delete only, no update or insert |
94
94
  | XR | `sX & tX` | full vector replacement |
95
95
  | XM | `s ∪ t` | set union, vector merge |
96
- | XD | `s - t` | set difference, delete given values |
96
+ | XD | `t - s` | set difference, delete given values |
97
97
  | XI | `s ∩ t` | set intersection, delete missing values |
98
98
  | XS | `t + s` | preserve order insert (allows dupes) |
99
99
  | XF | `s + t` | insert from start (allows dupes) |
@@ -1,18 +1,12 @@
1
1
  export declare function getObjectKeys(obj: any, excludeKeys?: string[], includeKeys?: string[]): string[];
2
+ export declare function createValueKeys<T>(keys: string[], value: T): {
3
+ [key: string]: T;
4
+ };
2
5
  export declare function deepEquals(lhs: any, rhs: any): boolean;
6
+ export declare function deepEqualsPath(lhs: any, rhs: any, atPath: string): boolean;
3
7
  export declare function deepClone(val: any): any;
4
8
  export declare function toUniqueArray<T>(arr: T[]): T[];
5
9
  export declare function areArraysEqual<T>(arr1: T[] | undefined, arr2: T[] | undefined): boolean;
6
10
  export declare function createGlobRegex(search: string): RegExp;
7
11
  export declare function selectGlobKeys(obj: any, includePats?: string[], excludeKeys?: string[]): string[];
8
- export declare function flattenObject(obj: {
9
- [key: string]: any;
10
- }): {
11
- [key: string]: any;
12
- };
13
- export declare function unflattenObject(flatObj: {
14
- [key: string]: any;
15
- }): {
16
- [key: string]: any;
17
- };
18
12
  //# sourceMappingURL=datum-utils.d.ts.map
@@ -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,GACv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AG,EAAE,MAAM,GAAG,CAAC,CAAA;CAAE,CAEtB;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAEtD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAE1E;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAEvC;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAE9C;AAED,wBAAgB,cAAc,CAAC,CAAC,EAC5B,IAAI,EAAE,CAAC,EAAE,GAAG,SAAS,EACrB,IAAI,EAAE,CAAC,EAAE,GAAG,SAAS,GACtB,OAAO,CAaT;AAID,wBAAgB,eAAe,CAC3B,MAAM,EAAE,MAAM,GACf,MAAM,CAIR;AAED,wBAAgB,cAAc,CAC1B,GAAG,EAAE,GAAG,EACR,WAAW,GAAE,MAAM,EAAU,EAC7B,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,MAAM,EAAE,CAYV"}
@@ -3,7 +3,7 @@ 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.unflattenObject = exports.flattenObject = exports.selectGlobKeys = exports.createGlobRegex = exports.areArraysEqual = exports.toUniqueArray = exports.deepClone = exports.deepEquals = exports.getObjectKeys = void 0;
6
+ exports.selectGlobKeys = exports.createGlobRegex = exports.areArraysEqual = exports.toUniqueArray = exports.deepClone = exports.deepEqualsPath = exports.deepEquals = exports.createValueKeys = exports.getObjectKeys = void 0;
7
7
  const lodash_es_1 = require("lodash-es");
8
8
  const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
9
9
  function getObjectKeys(obj, excludeKeys, includeKeys) {
@@ -22,10 +22,18 @@ function getObjectKeys(obj, excludeKeys, includeKeys) {
22
22
  }
23
23
  exports.getObjectKeys = getObjectKeys;
24
24
  ;
25
+ function createValueKeys(keys, value) {
26
+ return Object.fromEntries(keys.map((k) => [k, value]));
27
+ }
28
+ exports.createValueKeys = createValueKeys;
25
29
  function deepEquals(lhs, rhs) {
26
30
  return (0, fast_deep_equal_1.default)(lhs, rhs);
27
31
  }
28
32
  exports.deepEquals = deepEquals;
33
+ function deepEqualsPath(lhs, rhs, atPath) {
34
+ return (0, fast_deep_equal_1.default)((0, lodash_es_1.get)(lhs, atPath), (0, lodash_es_1.get)(rhs, atPath));
35
+ }
36
+ exports.deepEqualsPath = deepEqualsPath;
29
37
  function deepClone(val) {
30
38
  return (0, lodash_es_1.cloneDeep)(val);
31
39
  }
@@ -68,41 +76,3 @@ function selectGlobKeys(obj, includePats = ["*"], excludeKeys) {
68
76
  return includeKeys;
69
77
  }
70
78
  exports.selectGlobKeys = selectGlobKeys;
71
- function flattenObject(obj) {
72
- const flatObj = {};
73
- const path = [];
74
- const isObject = (value) => Object(value) === value;
75
- function dig(obj) {
76
- for (const [key, value] of Object.entries(obj)) {
77
- path.push(key);
78
- if (isObject(value)) {
79
- dig(value);
80
- }
81
- else {
82
- flatObj[path.join('.')] = value;
83
- }
84
- path.pop();
85
- }
86
- }
87
- dig(obj);
88
- return flatObj;
89
- }
90
- exports.flattenObject = flattenObject;
91
- function unflattenObject(flatObj) {
92
- const unflatObj = {};
93
- for (const [path, value] of Object.entries(flatObj)) {
94
- const chain = path.split('.');
95
- let obj = unflatObj;
96
- for (const [i, key] of chain.slice(0, -1).entries()) {
97
- if (!obj[key]) {
98
- const needArray = Number.isInteger(Number(chain[+i + 1]));
99
- obj[key] = needArray ? [] : {};
100
- }
101
- obj = obj[key];
102
- }
103
- const lastkey = chain.pop();
104
- obj[lastkey] = value;
105
- }
106
- return unflatObj;
107
- }
108
- exports.unflattenObject = unflattenObject;
@@ -1,11 +1,15 @@
1
1
  import { Diff } from "./diff-lib/deep-diff";
2
- import { PatchResult } from "./patch-low";
3
- export declare function deepDiffFlat(oldFlat: any, newFlat: any, flatten?: boolean): [any, any];
4
2
  export declare function deepDiffTyped<T>(lhsObj: T, rhsObj: T, orderInd?: boolean): Partial<T>;
5
- export declare function deepDiffPatch(lhsObj: {
3
+ export declare function deepDiffLow<T, S>(lhsObj: T, rhsObj: S, orderInd?: boolean): readonly Diff<T, S>[] | false;
4
+ export declare function deepDiffFlat(oldFlat: any, newFlat: any, flatten?: boolean): [any, any];
5
+ export declare function flattenObject(obj: {
6
6
  [key: string]: any;
7
- }, rhsObj: {
7
+ }): {
8
8
  [key: string]: any;
9
- }, orderInd?: boolean): PatchResult[];
10
- export declare function deepDiffLow<T, S>(lhsObj: T, rhsObj: S, orderInd?: boolean): readonly Diff<T, S>[] | false;
9
+ };
10
+ export declare function unflattenObject(flatObj: {
11
+ [key: string]: any;
12
+ }): {
13
+ [key: string]: any;
14
+ };
11
15
  //# sourceMappingURL=diff-high.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"diff-high.d.ts","sourceRoot":"","sources":["../../src/diff-high.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA2C,MAAM,sBAAsB,CAAC;AAGrF,OAAO,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE1D,wBAAgB,YAAY,CACxB,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,GAAG,EACZ,OAAO,GAAE,OAAe,GACzB,CAAC,GAAG,EAAE,GAAG,CAAC,CAeZ;AAED,wBAAgB,aAAa,CAAC,CAAC,EAC3B,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,EACT,QAAQ,GAAE,OAAe,GAC1B,OAAO,CAAC,CAAC,CAAC,CAWZ;AAWD,wBAAgB,aAAa,CACzB,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC9B,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAA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.defineProperty(exports, "__esModule", { value: true });
3
- exports.deepDiffLow = exports.deepDiffPatch = exports.deepDiffTyped = exports.deepDiffFlat = void 0;
3
+ exports.unflattenObject = exports.flattenObject = exports.deepDiffFlat = exports.deepDiffLow = exports.deepDiffTyped = void 0;
4
4
  const deep_diff_1 = require("./diff-lib/deep-diff");
5
- const datum_utils_1 = require("./datum-utils");
6
- const patch_low_1 = require("./patch-low");
7
- function deepDiffFlat(oldFlat, newFlat, flatten = false) {
8
- if (flatten) {
9
- oldFlat = (0, datum_utils_1.flattenObject)(oldFlat);
10
- newFlat = (0, datum_utils_1.flattenObject)(newFlat);
11
- }
12
- const updated = Object.assign({}, oldFlat);
13
- const removed = Object.assign({}, newFlat);
14
- for (const key of Object.keys(newFlat)) {
15
- if (newFlat[key] === oldFlat[key]) {
16
- delete updated[key];
17
- delete removed[key];
18
- }
19
- }
20
- return [updated, removed];
21
- }
22
- exports.deepDiffFlat = deepDiffFlat;
23
5
  function deepDiffTyped(lhsObj, rhsObj, orderInd = false) {
24
6
  const differences = deepDiffLow(lhsObj, rhsObj, orderInd);
25
7
  const deltaObj = {};
@@ -36,18 +18,12 @@ exports.deepDiffTyped = deepDiffTyped;
36
18
  ;
37
19
  function cleanupObjArrays(obj) {
38
20
  var _a;
39
- for (const objKey of (0, datum_utils_1.getObjectKeys)(obj)) {
21
+ for (const objKey of Object.keys(obj)) {
40
22
  if ((_a = obj[objKey]) === null || _a === void 0 ? void 0 : _a.filter) {
41
23
  obj[objKey] = obj[objKey].filter((e) => !!e);
42
24
  }
43
25
  }
44
26
  }
45
- function deepDiffPatch(lhsObj, rhsObj, orderInd = false) {
46
- const differences = deepDiffLow(lhsObj, rhsObj, orderInd);
47
- return !differences ? [] : (0, patch_low_1.diffToPatchLog)(differences);
48
- }
49
- exports.deepDiffPatch = deepDiffPatch;
50
- ;
51
27
  function deepDiffLow(lhsObj, rhsObj, orderInd = false) {
52
28
  const differences = !orderInd
53
29
  ? (0, deep_diff_1.diff)(lhsObj, rhsObj)
@@ -58,3 +34,57 @@ function deepDiffLow(lhsObj, rhsObj, orderInd = false) {
58
34
  }
59
35
  exports.deepDiffLow = deepDiffLow;
60
36
  ;
37
+ function deepDiffFlat(oldFlat, newFlat, flatten = true) {
38
+ if (flatten) {
39
+ oldFlat = flattenObject(oldFlat);
40
+ newFlat = flattenObject(newFlat);
41
+ }
42
+ const updated = Object.assign({}, oldFlat);
43
+ const removed = Object.assign({}, newFlat);
44
+ for (const key of Object.keys(newFlat)) {
45
+ if (newFlat[key] === oldFlat[key]) {
46
+ delete updated[key];
47
+ delete removed[key];
48
+ }
49
+ }
50
+ return [updated, removed];
51
+ }
52
+ exports.deepDiffFlat = deepDiffFlat;
53
+ function flattenObject(obj) {
54
+ const flatObj = {};
55
+ const path = [];
56
+ const isObject = (value) => Object(value) === value;
57
+ function dig(obj) {
58
+ for (const [key, value] of Object.entries(obj)) {
59
+ path.push(key);
60
+ if (isObject(value)) {
61
+ dig(value);
62
+ }
63
+ else {
64
+ flatObj[path.join('.')] = value;
65
+ }
66
+ path.pop();
67
+ }
68
+ }
69
+ dig(obj);
70
+ return flatObj;
71
+ }
72
+ exports.flattenObject = flattenObject;
73
+ function unflattenObject(flatObj) {
74
+ const unflatObj = {};
75
+ for (const [path, value] of Object.entries(flatObj)) {
76
+ const parts = path.split('.');
77
+ let obj = unflatObj;
78
+ for (const [i, key] of parts.slice(0, -1).entries()) {
79
+ if (!obj[key]) {
80
+ const needArray = Number.isInteger(Number(parts[+i + 1]));
81
+ obj[key] = needArray ? [] : {};
82
+ }
83
+ obj = obj[key];
84
+ }
85
+ const lastkey = parts.pop();
86
+ obj[lastkey] = value;
87
+ }
88
+ return unflatObj;
89
+ }
90
+ exports.unflattenObject = unflattenObject;
@@ -1,16 +1,16 @@
1
1
  export { deepEquals } from "./datum-utils";
2
2
  export { deepClone } from "./datum-utils";
3
- export { flattenObject, unflattenObject } from "./datum-utils";
4
3
  export { deepDiffLow } from "./diff-high";
5
- export { deepDiffFlat } from "./diff-high";
6
4
  export { deepDiffTyped } from "./diff-high";
5
+ export { deepDiffFlat } from "./diff-high";
6
+ export { flattenObject, unflattenObject } from "./diff-high";
7
7
  export { UpdateCode } from "./merge-low";
8
8
  export { UpdateCode as MC } from "./merge-low";
9
9
  export { type MergeCode } from "./merge-low";
10
10
  export { updateCodeInfo } from "./merge-high";
11
11
  export { shallowMerge, immutableMerge } from "./merge-high";
12
- export { diffFromMerge } from "./merge-high";
13
12
  export { deepMerge, immutableDeepMerge } from "./merge-high";
13
+ export { diffFromMerge } from "./merge-high";
14
14
  export { type DetailConfig } from "./merge-conf";
15
15
  export { detailMerge, immutableDetailMerge } from "./merge-conf";
16
16
  export { type MergeConfig } from "./merge-conf";
@@ -18,7 +18,7 @@ export { fillUpdateCodes } from "./merge-conf";
18
18
  export { customMerge, immutableCustomMerge } from "./merge-conf";
19
19
  export { type PatchResult } from "./patch-low";
20
20
  export { diffToPatchLog, asLodashPath } from "./patch-low";
21
- export { deepDiffPatch } from "./diff-high";
21
+ export { deepPatchLog } from "./patch-low";
22
22
  export { deepMerge as merge } from "./merge-high";
23
23
  export { customMerge as mergeDiff } from "./merge-conf";
24
24
  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;AAC1C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,IAAI,EAAE,EAAE,MAAM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) 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.deepDiffPatch = exports.asLodashPath = exports.diffToPatchLog = exports.immutableCustomMerge = exports.customMerge = exports.fillUpdateCodes = exports.immutableDetailMerge = exports.detailMerge = exports.immutableDeepMerge = exports.deepMerge = exports.diffFromMerge = exports.immutableMerge = exports.shallowMerge = exports.updateCodeInfo = exports.MC = exports.UpdateCode = exports.deepDiffTyped = exports.deepDiffFlat = exports.deepDiffLow = exports.unflattenObject = exports.flattenObject = exports.deepClone = exports.deepEquals = void 0;
17
+ exports.deepDiff = exports.mergeDiff = exports.merge = exports.deepPatchLog = exports.asLodashPath = exports.diffToPatchLog = 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.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");
21
21
  Object.defineProperty(exports, "deepClone", { enumerable: true, get: function () { return datum_utils_2.deepClone; } });
22
- var datum_utils_3 = require("./datum-utils");
23
- Object.defineProperty(exports, "flattenObject", { enumerable: true, get: function () { return datum_utils_3.flattenObject; } });
24
- Object.defineProperty(exports, "unflattenObject", { enumerable: true, get: function () { return datum_utils_3.unflattenObject; } });
25
22
  var diff_high_1 = require("./diff-high");
26
23
  Object.defineProperty(exports, "deepDiffLow", { enumerable: true, get: function () { return diff_high_1.deepDiffLow; } });
27
24
  var diff_high_2 = require("./diff-high");
28
- Object.defineProperty(exports, "deepDiffFlat", { enumerable: true, get: function () { return diff_high_2.deepDiffFlat; } });
25
+ Object.defineProperty(exports, "deepDiffTyped", { enumerable: true, get: function () { return diff_high_2.deepDiffTyped; } });
29
26
  var diff_high_3 = require("./diff-high");
30
- Object.defineProperty(exports, "deepDiffTyped", { enumerable: true, get: function () { return diff_high_3.deepDiffTyped; } });
27
+ Object.defineProperty(exports, "deepDiffFlat", { enumerable: true, get: function () { return diff_high_3.deepDiffFlat; } });
28
+ var diff_high_4 = require("./diff-high");
29
+ Object.defineProperty(exports, "flattenObject", { enumerable: true, get: function () { return diff_high_4.flattenObject; } });
30
+ Object.defineProperty(exports, "unflattenObject", { enumerable: true, get: function () { return diff_high_4.unflattenObject; } });
31
31
  var merge_low_1 = require("./merge-low");
32
32
  Object.defineProperty(exports, "UpdateCode", { enumerable: true, get: function () { return merge_low_1.UpdateCode; } });
33
33
  var merge_low_2 = require("./merge-low");
@@ -38,10 +38,10 @@ var merge_high_2 = require("./merge-high");
38
38
  Object.defineProperty(exports, "shallowMerge", { enumerable: true, get: function () { return merge_high_2.shallowMerge; } });
39
39
  Object.defineProperty(exports, "immutableMerge", { enumerable: true, get: function () { return merge_high_2.immutableMerge; } });
40
40
  var merge_high_3 = require("./merge-high");
41
- Object.defineProperty(exports, "diffFromMerge", { enumerable: true, get: function () { return merge_high_3.diffFromMerge; } });
41
+ Object.defineProperty(exports, "deepMerge", { enumerable: true, get: function () { return merge_high_3.deepMerge; } });
42
+ Object.defineProperty(exports, "immutableDeepMerge", { enumerable: true, get: function () { return merge_high_3.immutableDeepMerge; } });
42
43
  var merge_high_4 = require("./merge-high");
43
- Object.defineProperty(exports, "deepMerge", { enumerable: true, get: function () { return merge_high_4.deepMerge; } });
44
- Object.defineProperty(exports, "immutableDeepMerge", { enumerable: true, get: function () { return merge_high_4.immutableDeepMerge; } });
44
+ Object.defineProperty(exports, "diffFromMerge", { enumerable: true, get: function () { return merge_high_4.diffFromMerge; } });
45
45
  var merge_conf_1 = require("./merge-conf");
46
46
  Object.defineProperty(exports, "detailMerge", { enumerable: true, get: function () { return merge_conf_1.detailMerge; } });
47
47
  Object.defineProperty(exports, "immutableDetailMerge", { enumerable: true, get: function () { return merge_conf_1.immutableDetailMerge; } });
@@ -53,8 +53,8 @@ Object.defineProperty(exports, "immutableCustomMerge", { enumerable: true, get:
53
53
  var patch_low_1 = require("./patch-low");
54
54
  Object.defineProperty(exports, "diffToPatchLog", { enumerable: true, get: function () { return patch_low_1.diffToPatchLog; } });
55
55
  Object.defineProperty(exports, "asLodashPath", { enumerable: true, get: function () { return patch_low_1.asLodashPath; } });
56
- var diff_high_4 = require("./diff-high");
57
- Object.defineProperty(exports, "deepDiffPatch", { enumerable: true, get: function () { return diff_high_4.deepDiffPatch; } });
56
+ var patch_low_2 = require("./patch-low");
57
+ Object.defineProperty(exports, "deepPatchLog", { enumerable: true, get: function () { return patch_low_2.deepPatchLog; } });
58
58
  var merge_high_5 = require("./merge-high");
59
59
  Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return merge_high_5.deepMerge; } });
60
60
  var merge_conf_4 = require("./merge-conf");
@@ -18,5 +18,5 @@ export declare function immutableDetailMerge(target: any, source: any, mergeCode
18
18
  export declare function selectDetailKeys(obj: any, mergeCodes: DetailConfig, excludeKeys?: string[]): string[];
19
19
  export declare function customMerge<T extends TupleObj>(target: T, source: Partial<T>, mergeConf: MergeConfig | MergeCode, excludeKeys?: string[]): Partial<T> | false;
20
20
  export declare function immutableCustomMerge(target: any, source: any, mergeConf: MergeConfig, skipFill?: boolean): any;
21
- export declare const fillUpdateCodes: (source: any, mergeConf: MergeConfig | MergeCode, excludeKeys?: string[], blockUnset?: boolean) => DetailConfig;
21
+ export declare const fillUpdateCodes: (source: any, mergeConf: MergeConfig | MergeCode, blockUnset?: boolean, excludeKeys?: string[]) => DetailConfig;
22
22
  //# sourceMappingURL=merge-conf.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"merge-conf.d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CAAC,CAAC,CAAC,EAClB,SAAS,EAAE,WAAW,GAAG,SAAS,EAClC,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAyBpB;AAMD,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,GAAG,EACX,MAAM,EAAE,GAAG,EACX,SAAS,EAAE,WAAW,EACtB,QAAQ,GAAE,OAAe,GAC1B,GAAG,CAOL;AAWD,eAAO,MAAM,eAAe,WAChB,GAAG,aACA,WAAW,GAAG,SAAS,eACtB,OAAO,gBACL,MAAM,EAAE,KACvB,YAmEF,CAAA"}
@@ -71,7 +71,7 @@ function customMerge(target, source, mergeConf, excludeKeys) {
71
71
  Object.assign(target, Object.assign({}, source));
72
72
  return delta;
73
73
  }
74
- const mergeCodes = (0, exports.fillUpdateCodes)(source, mergeConf, excludeKeys, false);
74
+ const mergeCodes = (0, exports.fillUpdateCodes)(source, mergeConf, false, excludeKeys);
75
75
  if ((0, type_utils_1.emptyObject)(mergeCodes)) {
76
76
  return false;
77
77
  }
@@ -93,11 +93,16 @@ function immutableCustomMerge(target, source, mergeConf, skipFill = false) {
93
93
  return targetCopy;
94
94
  }
95
95
  exports.immutableCustomMerge = immutableCustomMerge;
96
- const fillUpdateCodes = (source, mergeConf, excludeKeys, blockUnset = false) => {
96
+ const fillUpdateCodes = (source, mergeConf, blockUnset = false, excludeKeys) => {
97
97
  var _a, _b, _c;
98
98
  if ((0, type_utils_1.isString)(mergeConf)) {
99
99
  mergeConf = { scalar: mergeConf };
100
100
  }
101
+ const deepConf = {
102
+ scalar: (_a = mergeConf === null || mergeConf === void 0 ? void 0 : mergeConf.scalar) !== null && _a !== void 0 ? _a : merge_low_1.UpdateCode.B,
103
+ vector: (_b = mergeConf === null || mergeConf === void 0 ? void 0 : mergeConf.vector) !== null && _b !== void 0 ? _b : merge_low_1.UpdateCode.XS,
104
+ nested: (_c = mergeConf === null || mergeConf === void 0 ? void 0 : mergeConf.nested) !== null && _c !== void 0 ? _c : merge_low_1.UpdateCode.N,
105
+ };
101
106
  const globKeys = (0, datum_utils_1.getObjectKeys)(mergeConf)
102
107
  .filter((s) => s.includes("*"));
103
108
  const globPats = globKeys.map((g) => (0, datum_utils_1.createGlobRegex)(g));
@@ -119,7 +124,7 @@ const fillUpdateCodes = (source, mergeConf, excludeKeys, blockUnset = false) =>
119
124
  continue;
120
125
  }
121
126
  if ((0, type_utils_1.isObject)(labelConf) && (0, type_utils_1.isObject)(srcValue)) {
122
- mergeCodes[srcLabel] = (0, exports.fillUpdateCodes)(srcValue, labelConf, [], blockUnset);
127
+ mergeCodes[srcLabel] = (0, exports.fillUpdateCodes)(srcValue, labelConf, blockUnset);
123
128
  continue;
124
129
  }
125
130
  const globIndex = globPats.findIndex((r) => r.test(srcLabel));
@@ -129,19 +134,19 @@ const fillUpdateCodes = (source, mergeConf, excludeKeys, blockUnset = false) =>
129
134
  mergeCodes[srcLabel] = globConf;
130
135
  continue;
131
136
  }
132
- else if ((0, type_utils_1.isObject)(srcValue)) {
133
- mergeCodes[srcLabel] = (0, exports.fillUpdateCodes)(srcValue, globConf, [], blockUnset);
137
+ if ((0, type_utils_1.isObject)(globConf) && (0, type_utils_1.isObject)(srcValue)) {
138
+ mergeCodes[srcLabel] = (0, exports.fillUpdateCodes)(srcValue, globConf, blockUnset);
134
139
  continue;
135
140
  }
136
141
  }
137
142
  if ((0, type_utils_1.isObject)(srcValue)) {
138
- mergeCodes[srcLabel] = (_a = mergeConf === null || mergeConf === void 0 ? void 0 : mergeConf.nested) !== null && _a !== void 0 ? _a : merge_low_1.UpdateCode.N;
143
+ mergeCodes[srcLabel] = deepConf.nested;
139
144
  }
140
145
  else if ((0, type_utils_1.isArrayOfAny)(srcValue)) {
141
- mergeCodes[srcLabel] = (_b = mergeConf === null || mergeConf === void 0 ? void 0 : mergeConf.vector) !== null && _b !== void 0 ? _b : merge_low_1.UpdateCode.XS;
146
+ mergeCodes[srcLabel] = deepConf.vector;
142
147
  }
143
148
  else {
144
- mergeCodes[srcLabel] = (_c = mergeConf === null || mergeConf === void 0 ? void 0 : mergeConf.scalar) !== null && _c !== void 0 ? _c : merge_low_1.UpdateCode.B;
149
+ mergeCodes[srcLabel] = deepConf.scalar;
145
150
  }
146
151
  }
147
152
  if ((0, datum_utils_1.getObjectKeys)(mergeCodes).length !== sourceKeys.length) {
@@ -1,9 +1,16 @@
1
1
  import { Diff } from "./diff-lib/deep-diff";
2
2
  export type PatchResult<T = any> = {
3
3
  path: string;
4
- op: 'add' | "remove" | "replace";
5
- value?: T;
4
+ op: "add" | "remove" | "replace";
5
+ value?: Readonly<T>;
6
+ prev?: any;
6
7
  };
8
+ export declare function diffToPatchLog(differences: readonly Diff<any, any>[], storePrev?: boolean): PatchResult[];
9
+ export declare function deepPatchLog(lhsObj: {
10
+ [key: string]: any;
11
+ }, rhsObj: {
12
+ [key: string]: any;
13
+ }, orderInd?: boolean, storePrev?: boolean): PatchResult[];
7
14
  export declare function asLodashPath(pointer: string): string[];
8
- export declare function diffToPatchLog(differences: readonly Diff<any, any>[]): PatchResult[];
15
+ export declare function getValueByPointer(document: any, pointer: string): any;
9
16
  //# 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;AAE5C,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,CAAC,CAAC;CACb,CAAC;AAoBF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAMtD;AAOD,wBAAgB,cAAc,CAC1B,WAAW,EAAE,SAAS,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GACvC,WAAW,EAAE,CA0Bf"}
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,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;AAqBD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAMtD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,GAAG,CAGrE"}
@@ -1,7 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.diffToPatchLog = exports.asLodashPath = void 0;
3
+ exports.getValueByPointer = exports.asLodashPath = exports.deepPatchLog = exports.diffToPatchLog = void 0;
4
4
  const lodash_es_1 = require("lodash-es");
5
+ const diff_high_1 = require("./diff-high");
6
+ function diffToPatchLog(differences, storePrev = false) {
7
+ var _a, _b, _c;
8
+ const jsonPatch = [];
9
+ for (const dif of differences) {
10
+ let pointer = asJsonPointer((_a = dif.path) !== null && _a !== void 0 ? _a : []);
11
+ switch (dif.kind) {
12
+ case "N":
13
+ jsonPatch.push({ op: "add", path: pointer, value: dif.rhs });
14
+ break;
15
+ case "E":
16
+ jsonPatch.push({ op: "replace", path: pointer, value: dif.rhs, prev: dif.lhs });
17
+ break;
18
+ case "D":
19
+ jsonPatch.push({ op: "remove", path: pointer, prev: dif.lhs });
20
+ break;
21
+ case "A":
22
+ pointer = `${pointer}/${dif.index}`;
23
+ if (((_b = dif.item) === null || _b === void 0 ? void 0 : _b.kind) === 'N') {
24
+ jsonPatch.push({ op: "add", path: pointer, value: dif.item.rhs });
25
+ }
26
+ if (((_c = dif.item) === null || _c === void 0 ? void 0 : _c.kind) === 'D') {
27
+ jsonPatch.push({ op: "remove", path: pointer, prev: dif.item.lhs });
28
+ }
29
+ break;
30
+ }
31
+ }
32
+ if (!storePrev) {
33
+ jsonPatch.forEach((p) => delete p.prev);
34
+ }
35
+ return jsonPatch;
36
+ }
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
+ ;
5
44
  function escapePathPart(path) {
6
45
  if (typeof path === 'number')
7
46
  return path.toString();
@@ -12,44 +51,20 @@ function escapePathPart(path) {
12
51
  function unescapePathPart(path) {
13
52
  return path.replace(/~1/g, '/').replace(/~0/g, '~');
14
53
  }
15
- function asPatchPath(path) {
16
- var _a;
17
- return "/" + ((_a = path === null || path === void 0 ? void 0 : path.map((s) => escapePathPart(s)).join("/")) !== null && _a !== void 0 ? _a : "");
54
+ function asJsonPointer(path) {
55
+ return !(path === null || path === void 0 ? void 0 : path.length) ? ""
56
+ : "/" + path.map((s) => escapePathPart(s)).join("/");
18
57
  }
19
58
  function asLodashPath(pointer) {
20
59
  if (!pointer || !pointer.startsWith("/"))
21
- return null;
60
+ return [];
22
61
  const parts = pointer.slice(1).split("/")
23
62
  .map((s) => unescapePathPart(s));
24
63
  return !(parts === null || parts === void 0 ? void 0 : parts.length) ? [] : (0, lodash_es_1.toPath)(parts.join("."));
25
64
  }
26
65
  exports.asLodashPath = asLodashPath;
27
- function diffToPatchLog(differences) {
28
- var _a, _b;
29
- const jsonPatch = [];
30
- for (const difference of differences) {
31
- const difPath = asPatchPath(difference.path);
32
- switch (difference.kind) {
33
- case "N":
34
- jsonPatch.push({ op: "add", path: difPath, value: difference.rhs });
35
- break;
36
- case "E":
37
- jsonPatch.push({ op: "replace", path: difPath, value: difference.rhs });
38
- break;
39
- case "D":
40
- jsonPatch.push({ op: "remove", path: difPath });
41
- break;
42
- case "A":
43
- const vecPath = `${difPath}/${difference.index}`;
44
- if (((_a = difference.item) === null || _a === void 0 ? void 0 : _a.kind) === 'N') {
45
- jsonPatch.push({ op: "add", path: vecPath, value: difference.item.rhs });
46
- }
47
- if (((_b = difference.item) === null || _b === void 0 ? void 0 : _b.kind) === 'D') {
48
- jsonPatch.push({ op: "remove", path: vecPath });
49
- }
50
- break;
51
- }
52
- }
53
- return jsonPatch;
66
+ function getValueByPointer(document, pointer) {
67
+ return pointer === "" ? document
68
+ : (0, lodash_es_1.get)(document, asLodashPath(pointer));
54
69
  }
55
- exports.diffToPatchLog = diffToPatchLog;
70
+ exports.getValueByPointer = getValueByPointer;
@@ -1,18 +1,12 @@
1
1
  export declare function getObjectKeys(obj: any, excludeKeys?: string[], includeKeys?: string[]): string[];
2
+ export declare function createValueKeys<T>(keys: string[], value: T): {
3
+ [key: string]: T;
4
+ };
2
5
  export declare function deepEquals(lhs: any, rhs: any): boolean;
6
+ export declare function deepEqualsPath(lhs: any, rhs: any, atPath: string): boolean;
3
7
  export declare function deepClone(val: any): any;
4
8
  export declare function toUniqueArray<T>(arr: T[]): T[];
5
9
  export declare function areArraysEqual<T>(arr1: T[] | undefined, arr2: T[] | undefined): boolean;
6
10
  export declare function createGlobRegex(search: string): RegExp;
7
11
  export declare function selectGlobKeys(obj: any, includePats?: string[], excludeKeys?: string[]): string[];
8
- export declare function flattenObject(obj: {
9
- [key: string]: any;
10
- }): {
11
- [key: string]: any;
12
- };
13
- export declare function unflattenObject(flatObj: {
14
- [key: string]: any;
15
- }): {
16
- [key: string]: any;
17
- };
18
12
  //# sourceMappingURL=datum-utils.d.ts.map
@@ -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,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAEtD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAEvC;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAE9C;AAED,wBAAgB,cAAc,CAAC,CAAC,EAC5B,IAAI,EAAE,CAAC,EAAE,GAAG,SAAS,EACrB,IAAI,EAAE,CAAC,EAAE,GAAG,SAAS,GACtB,OAAO,CAaT;AAID,wBAAgB,eAAe,CAC3B,MAAM,EAAE,MAAM,GACf,MAAM,CAIR;AAED,wBAAgB,cAAc,CAC1B,GAAG,EAAE,GAAG,EACR,WAAW,GAAE,MAAM,EAAU,EAC7B,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,MAAM,EAAE,CAYV;AAID,wBAAgB,aAAa,CACzB,GAAG,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,GAC5B;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAA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
@@ -1,4 +1,4 @@
1
- import { cloneDeep } from "lodash-es";
1
+ import { cloneDeep, get } from "lodash-es";
2
2
  import equal from 'fast-deep-equal';
3
3
  export function getObjectKeys(obj, excludeKeys, includeKeys) {
4
4
  if (!obj) {
@@ -15,9 +15,15 @@ export function getObjectKeys(obj, excludeKeys, includeKeys) {
15
15
  return sourceKeys;
16
16
  }
17
17
  ;
18
+ export function createValueKeys(keys, value) {
19
+ return Object.fromEntries(keys.map((k) => [k, value]));
20
+ }
18
21
  export function deepEquals(lhs, rhs) {
19
22
  return equal(lhs, rhs);
20
23
  }
24
+ export function deepEqualsPath(lhs, rhs, atPath) {
25
+ return equal(get(lhs, atPath), get(rhs, atPath));
26
+ }
21
27
  export function deepClone(val) {
22
28
  return cloneDeep(val);
23
29
  }
@@ -55,39 +61,3 @@ export function selectGlobKeys(obj, includePats = ["*"], excludeKeys) {
55
61
  }
56
62
  return includeKeys;
57
63
  }
58
- export function flattenObject(obj) {
59
- const flatObj = {};
60
- const path = [];
61
- const isObject = (value) => Object(value) === value;
62
- function dig(obj) {
63
- for (const [key, value] of Object.entries(obj)) {
64
- path.push(key);
65
- if (isObject(value)) {
66
- dig(value);
67
- }
68
- else {
69
- flatObj[path.join('.')] = value;
70
- }
71
- path.pop();
72
- }
73
- }
74
- dig(obj);
75
- return flatObj;
76
- }
77
- export function unflattenObject(flatObj) {
78
- const unflatObj = {};
79
- for (const [path, value] of Object.entries(flatObj)) {
80
- const chain = path.split('.');
81
- let obj = unflatObj;
82
- for (const [i, key] of chain.slice(0, -1).entries()) {
83
- if (!obj[key]) {
84
- const needArray = Number.isInteger(Number(chain[+i + 1]));
85
- obj[key] = needArray ? [] : {};
86
- }
87
- obj = obj[key];
88
- }
89
- const lastkey = chain.pop();
90
- obj[lastkey] = value;
91
- }
92
- return unflatObj;
93
- }