datum-merge 0.9.1 → 0.9.4
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 +47 -35
- package/dist/cjs/datum-utils.d.ts +4 -10
- package/dist/cjs/datum-utils.d.ts.map +1 -1
- package/dist/cjs/datum-utils.js +9 -39
- package/dist/cjs/diff-high.d.ts +11 -1
- package/dist/cjs/diff-high.d.ts.map +1 -1
- package/dist/cjs/diff-high.js +61 -26
- package/dist/cjs/index.d.ts +6 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +16 -11
- package/dist/cjs/merge-conf.d.ts +1 -1
- package/dist/cjs/merge-conf.d.ts.map +1 -1
- package/dist/cjs/merge-conf.js +36 -25
- package/dist/cjs/merge-high.d.ts +5 -1
- package/dist/cjs/merge-high.d.ts.map +1 -1
- package/dist/cjs/merge-high.js +7 -7
- package/dist/cjs/merge-low.d.ts.map +1 -1
- package/dist/cjs/merge-low.js +11 -12
- package/dist/cjs/patch-low.d.ts +16 -0
- package/dist/cjs/patch-low.d.ts.map +1 -0
- package/dist/cjs/patch-low.js +70 -0
- package/dist/cjs/type-utils.d.ts +2 -1
- package/dist/cjs/type-utils.d.ts.map +1 -1
- package/dist/cjs/type-utils.js +20 -6
- package/dist/esm/datum-utils.d.ts +4 -10
- package/dist/esm/datum-utils.d.ts.map +1 -1
- package/dist/esm/datum-utils.js +7 -37
- package/dist/esm/diff-high.d.ts +11 -1
- package/dist/esm/diff-high.d.ts.map +1 -1
- package/dist/esm/diff-high.js +58 -25
- package/dist/esm/index.d.ts +6 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -3
- package/dist/esm/merge-conf.d.ts +1 -1
- package/dist/esm/merge-conf.d.ts.map +1 -1
- package/dist/esm/merge-conf.js +34 -23
- package/dist/esm/merge-high.d.ts +5 -1
- package/dist/esm/merge-high.d.ts.map +1 -1
- package/dist/esm/merge-high.js +5 -5
- package/dist/esm/merge-low.d.ts.map +1 -1
- package/dist/esm/merge-low.js +12 -13
- package/dist/esm/patch-low.d.ts +16 -0
- package/dist/esm/patch-low.d.ts.map +1 -0
- package/dist/esm/patch-low.js +63 -0
- package/dist/esm/type-utils.d.ts +2 -1
- package/dist/esm/type-utils.d.ts.map +1 -1
- package/dist/esm/type-utils.js +17 -4
- package/package.json +1 -1
- package/src/datum-utils.ts +12 -44
- package/src/diff-high.ts +71 -32
- package/src/diff-lib/README.md +16 -7
- package/src/index.ts +7 -3
- package/src/merge-conf.ts +48 -36
- package/src/merge-high.ts +17 -16
- package/src/merge-low.ts +15 -16
- package/src/patch-low.ts +91 -0
- package/src/type-utils.ts +16 -5
package/README.md
CHANGED
|
@@ -10,31 +10,26 @@
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
## Upcoming Features
|
|
14
|
-
|
|
15
|
-
1. inline the unmaintained [deep-diff](https://github.com/flitbit/diff) library which contains serious bugs. (available)
|
|
16
|
-
|
|
17
|
-
2. support merging for top level arrays or primitives.
|
|
18
|
-
|
|
19
|
-
3. option to throw error if field datatype changes during merge.
|
|
20
|
-
|
|
21
|
-
4. project should compile in strict mode.
|
|
22
|
-
|
|
23
|
-
5. formalize config schema for deeply nested objects (for v1).
|
|
24
|
-
|
|
25
|
-
Code contributions are welcome via issues and pull requests.
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
13
|
## Sample Usage
|
|
30
14
|
|
|
31
|
-
Merge with default
|
|
15
|
+
Merge with default config:
|
|
16
|
+
```
|
|
17
|
+
import { merge, customMerge, UpdateCode } from "datum-merge";
|
|
18
|
+
const changed = merge(target, source, UpdateCode.I, UpdateCode.XM, UpdateCode.B);
|
|
19
|
+
//same as
|
|
20
|
+
const diff = customMerge(target, source, {
|
|
21
|
+
scalar: UpdateCode.I,
|
|
22
|
+
vector: UpdateCode.XM,
|
|
23
|
+
nested: UpdateCode.B,
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Exact nestable config that ignores all other fields:
|
|
32
28
|
```
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
myarr: UpdateCode.XM,
|
|
29
|
+
import { detailMerge, UpdateCode } from "datum-merge";
|
|
30
|
+
const changed = detailMerge(target, source, {
|
|
31
|
+
mykey: UpdateCode.I,
|
|
32
|
+
myarr: UpdateCode.XM,
|
|
38
33
|
anobj: UpdateCode.B,
|
|
39
34
|
myobj: { myid: UpdateCode.I },
|
|
40
35
|
});
|
|
@@ -54,21 +49,38 @@ const conf: MergeConfig = {
|
|
|
54
49
|
vector: UpdateCode.XM,
|
|
55
50
|
},
|
|
56
51
|
};
|
|
57
|
-
|
|
52
|
+
const diff = customMerge(target, source, conf);
|
|
58
53
|
```
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Upcoming Features
|
|
57
|
+
|
|
58
|
+
1. inline the unmaintained [deep-diff](https://github.com/flitbit/diff) library which contains serious bugs. (available)
|
|
59
|
+
|
|
60
|
+
2. formalize config schema for deeply nested objects (for v1).
|
|
61
|
+
|
|
62
|
+
3. option to ignore errors for datatype mismatch during merge.
|
|
63
|
+
|
|
64
|
+
4. support merging for top level arrays or primitives.
|
|
65
|
+
|
|
66
|
+
5. accept a subset of [json-patch](https://jsonpatch.com/) operations for merge.
|
|
67
|
+
|
|
68
|
+
Code contributions are welcome via issues and pull requests.
|
|
69
|
+
|
|
70
|
+
---
|
|
59
71
|
|
|
60
72
|
## Merge Strategy
|
|
61
73
|
|
|
62
74
|
This string code describes how modifications to an attribute for a PUT/UPDATE operation should be handled.
|
|
63
|
-
It decides whether a change to the value of the field is allowed during a merge
|
|
75
|
+
It decides whether a change to the value of the field is allowed during a merge between two entities.
|
|
64
76
|
|
|
65
77
|
### Strategy Codes
|
|
66
78
|
|
|
67
79
|
The same field within a source and target object is represented by `s` and `t` respectively.
|
|
68
80
|
Whether the strategy requires data to be present for the field, is shown by { 0=no, 1=yes, X=irrelavant }.
|
|
69
|
-
The value
|
|
81
|
+
The value is migrated from the source field to the target field only if the predicate passes.
|
|
70
82
|
|
|
71
|
-
| Code
|
|
83
|
+
| Code | Predicate | Meaning |
|
|
72
84
|
|----|----|----|
|
|
73
85
|
| C | n/a | always create new instance |
|
|
74
86
|
| T | n/a | touch datum ; empty merge |
|
|
@@ -81,20 +93,20 @@ The value of the source field is migrated to the target field only if the predic
|
|
|
81
93
|
| D | `s0 & tX` | delete only, no update or insert |
|
|
82
94
|
| XR | `sX & tX` | full vector replacement |
|
|
83
95
|
| XM | `s ∪ t` | set union, vector merge |
|
|
84
|
-
| XD | `
|
|
96
|
+
| XD | `t - s` | set difference, delete given values |
|
|
85
97
|
| XI | `s ∩ t` | set intersection, delete missing values |
|
|
86
98
|
| XS | `t + s` | preserve order insert (allows dupes) |
|
|
87
99
|
| XF | `s + t` | insert from start (allows dupes) |
|
|
88
100
|
|
|
101
|
+
### Diff Codes
|
|
102
|
+
|
|
89
103
|
Applying the merge results in one of these transitions per primitive value in the target object.
|
|
90
104
|
|
|
91
|
-
|
|
|
92
|
-
|
|
93
|
-
|
|
|
94
|
-
|
|
|
95
|
-
|
|
|
96
|
-
|
|
|
97
|
-
| AN | array size increase | `non-null > non-null` |
|
|
98
|
-
| AD | array size decrease | `non-null < non-null` |
|
|
105
|
+
| Patch Op | Meaning | Rev Code | Transitions |
|
|
106
|
+
|----|----|----|----|
|
|
107
|
+
| `add` | new / insert | I | `null <-- non-null` |
|
|
108
|
+
| `replace` | edit / update | H | `non-null <-- non-null` |
|
|
109
|
+
| `remove` | unset / delete | D | `non-null <-- null` |
|
|
110
|
+
| `test` | noop / skip / ignore (tbd) | N | `null <-- null` or `non-null == non-null` |
|
|
99
111
|
|
|
100
112
|
---
|
|
@@ -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,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AM,EAAE,GACvB,MAAM,EAAE,CAYV"}
|
package/dist/cjs/datum-utils.js
CHANGED
|
@@ -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.
|
|
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;
|
package/dist/cjs/diff-high.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { Diff } from "./diff-lib/deep-diff";
|
|
2
|
-
export declare function deepDiffFlat(oldFlat: any, newFlat: any, flatten?: boolean): [any, any];
|
|
3
2
|
export declare function deepDiffTyped<T>(lhsObj: T, rhsObj: T, orderInd?: boolean): Partial<T>;
|
|
4
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
|
+
[key: string]: any;
|
|
7
|
+
}): {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
export declare function unflattenObject(flatObj: {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}): {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
5
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;AAIrF,wBAAgB,
|
|
1
|
+
{"version":3,"file":"diff-high.d.ts","sourceRoot":"","sources":["../../src/diff-high.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA2C,MAAM,sBAAsB,CAAC;AAIrF,wBAAgB,aAAa,CAAC,CAAC,EAC3B,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,EACT,QAAQ,GAAE,OAAe,GAC1B,OAAO,CAAC,CAAC,CAAC,CAgBZ;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC5B,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,EACT,QAAQ,GAAE,OAAe,GAC1B,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,CAO/B;AAID,wBAAgB,YAAY,CACxB,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,GAAG,EACZ,OAAO,GAAE,OAAc,GACxB,CAAC,GAAG,EAAE,GAAG,CAAC,CAeZ;AAED,wBAAgB,aAAa,CACzB,GAAG,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,GAC5B;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAiBxB;AAED,wBAAgB,eAAe,CAC3B,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,GAChC;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAgBxB"}
|
package/dist/cjs/diff-high.js
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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
5
|
const datum_utils_1 = require("./datum-utils");
|
|
6
|
-
function deepDiffFlat(oldFlat, newFlat, flatten = false) {
|
|
7
|
-
if (flatten) {
|
|
8
|
-
oldFlat = (0, datum_utils_1.flattenObject)(oldFlat);
|
|
9
|
-
newFlat = (0, datum_utils_1.flattenObject)(newFlat);
|
|
10
|
-
}
|
|
11
|
-
const updated = Object.assign({}, oldFlat);
|
|
12
|
-
const removed = Object.assign({}, newFlat);
|
|
13
|
-
for (const key of Object.keys(newFlat)) {
|
|
14
|
-
if (newFlat[key] === oldFlat[key]) {
|
|
15
|
-
delete updated[key];
|
|
16
|
-
delete removed[key];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return [updated, removed];
|
|
20
|
-
}
|
|
21
|
-
exports.deepDiffFlat = deepDiffFlat;
|
|
22
6
|
function deepDiffTyped(lhsObj, rhsObj, orderInd = false) {
|
|
7
|
+
var _a;
|
|
23
8
|
const differences = deepDiffLow(lhsObj, rhsObj, orderInd);
|
|
24
9
|
const deltaObj = {};
|
|
25
10
|
if (!differences) {
|
|
@@ -28,19 +13,15 @@ function deepDiffTyped(lhsObj, rhsObj, orderInd = false) {
|
|
|
28
13
|
for (const difference of differences) {
|
|
29
14
|
(0, deep_diff_1.applyChange)(deltaObj, null, difference);
|
|
30
15
|
}
|
|
31
|
-
|
|
16
|
+
for (const objKey of (0, datum_utils_1.getObjectKeys)(deltaObj)) {
|
|
17
|
+
if ((_a = deltaObj[objKey]) === null || _a === void 0 ? void 0 : _a.filter) {
|
|
18
|
+
deltaObj[objKey] = deltaObj[objKey].filter((e) => !!e);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
32
21
|
return deltaObj;
|
|
33
22
|
}
|
|
34
23
|
exports.deepDiffTyped = deepDiffTyped;
|
|
35
24
|
;
|
|
36
|
-
function cleanupObjArrays(obj) {
|
|
37
|
-
var _a;
|
|
38
|
-
for (const objKey of (0, datum_utils_1.getObjectKeys)(obj)) {
|
|
39
|
-
if ((_a = obj[objKey]) === null || _a === void 0 ? void 0 : _a.filter) {
|
|
40
|
-
obj[objKey] = obj[objKey].filter((e) => !!e);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
25
|
function deepDiffLow(lhsObj, rhsObj, orderInd = false) {
|
|
45
26
|
const differences = !orderInd
|
|
46
27
|
? (0, deep_diff_1.diff)(lhsObj, rhsObj)
|
|
@@ -51,3 +32,57 @@ function deepDiffLow(lhsObj, rhsObj, orderInd = false) {
|
|
|
51
32
|
}
|
|
52
33
|
exports.deepDiffLow = deepDiffLow;
|
|
53
34
|
;
|
|
35
|
+
function deepDiffFlat(oldFlat, newFlat, flatten = true) {
|
|
36
|
+
if (flatten) {
|
|
37
|
+
oldFlat = flattenObject(oldFlat);
|
|
38
|
+
newFlat = flattenObject(newFlat);
|
|
39
|
+
}
|
|
40
|
+
const updated = Object.assign({}, oldFlat);
|
|
41
|
+
const removed = Object.assign({}, newFlat);
|
|
42
|
+
for (const key of Object.keys(newFlat)) {
|
|
43
|
+
if (newFlat[key] === oldFlat[key]) {
|
|
44
|
+
delete updated[key];
|
|
45
|
+
delete removed[key];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [updated, removed];
|
|
49
|
+
}
|
|
50
|
+
exports.deepDiffFlat = deepDiffFlat;
|
|
51
|
+
function flattenObject(obj) {
|
|
52
|
+
const flatObj = {};
|
|
53
|
+
const path = [];
|
|
54
|
+
const isObject = (value) => Object(value) === value;
|
|
55
|
+
function dig(obj) {
|
|
56
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
57
|
+
path.push(key);
|
|
58
|
+
if (isObject(value)) {
|
|
59
|
+
dig(value);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
flatObj[path.join('.')] = value;
|
|
63
|
+
}
|
|
64
|
+
path.pop();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
dig(obj);
|
|
68
|
+
return flatObj;
|
|
69
|
+
}
|
|
70
|
+
exports.flattenObject = flattenObject;
|
|
71
|
+
function unflattenObject(flatObj) {
|
|
72
|
+
const unflatObj = {};
|
|
73
|
+
for (const [path, value] of Object.entries(flatObj)) {
|
|
74
|
+
const parts = path.split('.');
|
|
75
|
+
let obj = unflatObj;
|
|
76
|
+
for (const [i, key] of parts.slice(0, -1).entries()) {
|
|
77
|
+
if (!obj[key]) {
|
|
78
|
+
const needArray = Number.isInteger(Number(parts[+i + 1]));
|
|
79
|
+
obj[key] = needArray ? [] : {};
|
|
80
|
+
}
|
|
81
|
+
obj = obj[key];
|
|
82
|
+
}
|
|
83
|
+
const lastkey = parts.pop();
|
|
84
|
+
obj[lastkey] = value;
|
|
85
|
+
}
|
|
86
|
+
return unflatObj;
|
|
87
|
+
}
|
|
88
|
+
exports.unflattenObject = unflattenObject;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
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";
|
|
17
17
|
export { fillUpdateCodes } from "./merge-conf";
|
|
18
18
|
export { customMerge, immutableCustomMerge } from "./merge-conf";
|
|
19
|
+
export { type PatchResult } from "./patch-low";
|
|
20
|
+
export { diffToPatchLog, asLodashPath } from "./patch-low";
|
|
21
|
+
export { deepPatchLog } from "./patch-low";
|
|
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/cjs/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;
|
|
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,EAA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
package/dist/cjs/index.js
CHANGED
|
@@ -14,20 +14,20 @@ 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.immutableCustomMerge = exports.customMerge = exports.fillUpdateCodes = exports.immutableDetailMerge = exports.detailMerge = exports.
|
|
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, "
|
|
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, "
|
|
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, "
|
|
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, "
|
|
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; } });
|
|
@@ -50,10 +50,15 @@ Object.defineProperty(exports, "fillUpdateCodes", { enumerable: true, get: funct
|
|
|
50
50
|
var merge_conf_3 = require("./merge-conf");
|
|
51
51
|
Object.defineProperty(exports, "customMerge", { enumerable: true, get: function () { return merge_conf_3.customMerge; } });
|
|
52
52
|
Object.defineProperty(exports, "immutableCustomMerge", { enumerable: true, get: function () { return merge_conf_3.immutableCustomMerge; } });
|
|
53
|
+
var patch_low_1 = require("./patch-low");
|
|
54
|
+
Object.defineProperty(exports, "diffToPatchLog", { enumerable: true, get: function () { return patch_low_1.diffToPatchLog; } });
|
|
55
|
+
Object.defineProperty(exports, "asLodashPath", { enumerable: true, get: function () { return patch_low_1.asLodashPath; } });
|
|
56
|
+
var patch_low_2 = require("./patch-low");
|
|
57
|
+
Object.defineProperty(exports, "deepPatchLog", { enumerable: true, get: function () { return patch_low_2.deepPatchLog; } });
|
|
53
58
|
var merge_high_5 = require("./merge-high");
|
|
54
59
|
Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return merge_high_5.deepMerge; } });
|
|
55
60
|
var merge_conf_4 = require("./merge-conf");
|
|
56
61
|
Object.defineProperty(exports, "mergeDiff", { enumerable: true, get: function () { return merge_conf_4.customMerge; } });
|
|
57
62
|
__exportStar(require("./diff-lib/deep-diff"), exports);
|
|
58
|
-
var
|
|
59
|
-
Object.defineProperty(exports, "deepDiff", { enumerable: true, get: function () { return
|
|
63
|
+
var diff_high_5 = require("./diff-high");
|
|
64
|
+
Object.defineProperty(exports, "deepDiff", { enumerable: true, get: function () { return diff_high_5.deepDiffLow; } });
|
package/dist/cjs/merge-conf.d.ts
CHANGED
|
@@ -17,6 +17,6 @@ export declare function detailMerge(target: {
|
|
|
17
17
|
export declare function immutableDetailMerge(target: any, source: any, mergeCodes: DetailConfig): any;
|
|
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
|
-
export declare const fillUpdateCodes: (source: any, mergeConf: MergeConfig | MergeCode, excludeKeys?: string[], blockUnset?: boolean) => DetailConfig;
|
|
21
20
|
export declare function immutableCustomMerge(target: any, source: any, mergeConf: MergeConfig, skipFill?: boolean): any;
|
|
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.ts","sourceRoot":"","sources":["../../src/merge-conf.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4D,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGlG,OAAO,EAAc,SAAS,EAAsC,MAAM,aAAa,CAAC;AAGxF,MAAM,MAAM,YAAY,GAAG;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACtB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;CACvD,CAAC;AAUF,wBAAgB,WAAW,CACvB,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,YAAY,GACzB,OAAO,
|
|
1
|
+
{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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,YAkEF,CAAA"}
|
package/dist/cjs/merge-conf.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.fillUpdateCodes = exports.immutableCustomMerge = exports.customMerge = exports.selectDetailKeys = exports.immutableDetailMerge = exports.detailMerge = void 0;
|
|
4
4
|
const type_utils_1 = require("./type-utils");
|
|
5
5
|
const datum_utils_1 = require("./datum-utils");
|
|
6
6
|
const diff_high_1 = require("./diff-high");
|
|
@@ -15,11 +15,17 @@ function detailMerge(target, source, mergeCodes) {
|
|
|
15
15
|
for (const label of mergeKeys) {
|
|
16
16
|
const mergeCode = mergeCodes[label];
|
|
17
17
|
if (!(0, type_utils_1.isString)(mergeCode)) {
|
|
18
|
-
if ((
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if ((0, type_utils_1.isObject)(target[label]) && (0, type_utils_1.isObject)(source[label])) {
|
|
19
|
+
changed = detailMerge(target[label], source[label], mergeCode) || changed;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (!(0, type_utils_1.isObject)(target[label]) && (0, type_utils_1.isObject)(source[label])) {
|
|
23
|
+
const targetVal = {};
|
|
24
|
+
detailMerge(targetVal, source[label], mergeCode);
|
|
25
|
+
changed = (0, merge_low_1.mergeScalarField)(target, { [label]: targetVal }, label, merge_low_1.UpdateCode.I) || changed;
|
|
26
|
+
continue;
|
|
22
27
|
}
|
|
28
|
+
changed = (0, merge_low_1.mergeScalarField)(target, source, label, merge_low_1.UpdateCode.I) || changed;
|
|
23
29
|
continue;
|
|
24
30
|
}
|
|
25
31
|
if (mergeCode.toString().startsWith("X")
|
|
@@ -65,7 +71,7 @@ function customMerge(target, source, mergeConf, excludeKeys) {
|
|
|
65
71
|
Object.assign(target, Object.assign({}, source));
|
|
66
72
|
return delta;
|
|
67
73
|
}
|
|
68
|
-
const mergeCodes = (0, exports.fillUpdateCodes)(source, mergeConf,
|
|
74
|
+
const mergeCodes = (0, exports.fillUpdateCodes)(source, mergeConf, false, excludeKeys);
|
|
69
75
|
if ((0, type_utils_1.emptyObject)(mergeCodes)) {
|
|
70
76
|
return false;
|
|
71
77
|
}
|
|
@@ -78,11 +84,25 @@ function customMerge(target, source, mergeConf, excludeKeys) {
|
|
|
78
84
|
return false;
|
|
79
85
|
}
|
|
80
86
|
exports.customMerge = customMerge;
|
|
81
|
-
|
|
87
|
+
function immutableCustomMerge(target, source, mergeConf, skipFill = false) {
|
|
88
|
+
const mergeCodes = !skipFill
|
|
89
|
+
? (0, exports.fillUpdateCodes)(source, mergeConf)
|
|
90
|
+
: mergeConf;
|
|
91
|
+
const targetCopy = (0, datum_utils_1.deepClone)(target);
|
|
92
|
+
detailMerge(targetCopy, source, mergeCodes);
|
|
93
|
+
return targetCopy;
|
|
94
|
+
}
|
|
95
|
+
exports.immutableCustomMerge = immutableCustomMerge;
|
|
96
|
+
const fillUpdateCodes = (source, mergeConf, blockUnset = false, excludeKeys) => {
|
|
82
97
|
var _a, _b, _c;
|
|
83
98
|
if ((0, type_utils_1.isString)(mergeConf)) {
|
|
84
99
|
mergeConf = { scalar: mergeConf };
|
|
85
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
|
+
};
|
|
86
106
|
const globKeys = (0, datum_utils_1.getObjectKeys)(mergeConf)
|
|
87
107
|
.filter((s) => s.includes("*"));
|
|
88
108
|
const globPats = globKeys.map((g) => (0, datum_utils_1.createGlobRegex)(g));
|
|
@@ -95,16 +115,16 @@ const fillUpdateCodes = (source, mergeConf, excludeKeys, blockUnset = false) =>
|
|
|
95
115
|
mergeCodes[srcLabel] = merge_low_1.UpdateCode.N;
|
|
96
116
|
continue;
|
|
97
117
|
}
|
|
98
|
-
if ((0, type_utils_1.
|
|
99
|
-
mergeCodes[srcLabel] =
|
|
118
|
+
if ((0, type_utils_1.isNullish)(srcValue) && blockUnset) {
|
|
119
|
+
mergeCodes[srcLabel] = merge_low_1.UpdateCode.N;
|
|
100
120
|
continue;
|
|
101
121
|
}
|
|
102
|
-
if ((0, type_utils_1.
|
|
103
|
-
mergeCodes[srcLabel] =
|
|
122
|
+
if ((0, type_utils_1.isString)(labelConf)) {
|
|
123
|
+
mergeCodes[srcLabel] = labelConf;
|
|
104
124
|
continue;
|
|
105
125
|
}
|
|
106
126
|
if ((0, type_utils_1.isObject)(labelConf) && (0, type_utils_1.isObject)(srcValue)) {
|
|
107
|
-
mergeCodes[srcLabel] = (0, exports.fillUpdateCodes)(srcValue, labelConf,
|
|
127
|
+
mergeCodes[srcLabel] = (0, exports.fillUpdateCodes)(srcValue, labelConf, blockUnset);
|
|
108
128
|
continue;
|
|
109
129
|
}
|
|
110
130
|
const globIndex = globPats.findIndex((r) => r.test(srcLabel));
|
|
@@ -115,18 +135,18 @@ const fillUpdateCodes = (source, mergeConf, excludeKeys, blockUnset = false) =>
|
|
|
115
135
|
continue;
|
|
116
136
|
}
|
|
117
137
|
else if ((0, type_utils_1.isObject)(srcValue)) {
|
|
118
|
-
mergeCodes[srcLabel] = (0, exports.fillUpdateCodes)(srcValue, globConf,
|
|
138
|
+
mergeCodes[srcLabel] = (0, exports.fillUpdateCodes)(srcValue, globConf, blockUnset);
|
|
119
139
|
continue;
|
|
120
140
|
}
|
|
121
141
|
}
|
|
122
142
|
if ((0, type_utils_1.isObject)(srcValue)) {
|
|
123
|
-
mergeCodes[srcLabel] =
|
|
143
|
+
mergeCodes[srcLabel] = deepConf.nested;
|
|
124
144
|
}
|
|
125
145
|
else if ((0, type_utils_1.isArrayOfAny)(srcValue)) {
|
|
126
|
-
mergeCodes[srcLabel] =
|
|
146
|
+
mergeCodes[srcLabel] = deepConf.vector;
|
|
127
147
|
}
|
|
128
148
|
else {
|
|
129
|
-
mergeCodes[srcLabel] =
|
|
149
|
+
mergeCodes[srcLabel] = deepConf.scalar;
|
|
130
150
|
}
|
|
131
151
|
}
|
|
132
152
|
if ((0, datum_utils_1.getObjectKeys)(mergeCodes).length !== sourceKeys.length) {
|
|
@@ -135,12 +155,3 @@ const fillUpdateCodes = (source, mergeConf, excludeKeys, blockUnset = false) =>
|
|
|
135
155
|
return mergeCodes;
|
|
136
156
|
};
|
|
137
157
|
exports.fillUpdateCodes = fillUpdateCodes;
|
|
138
|
-
function immutableCustomMerge(target, source, mergeConf, skipFill) {
|
|
139
|
-
const mergeCodes = !skipFill
|
|
140
|
-
? (0, exports.fillUpdateCodes)(source, mergeConf)
|
|
141
|
-
: mergeConf;
|
|
142
|
-
const targetCopy = (0, datum_utils_1.deepClone)(target);
|
|
143
|
-
detailMerge(targetCopy, source, mergeCodes);
|
|
144
|
-
return targetCopy;
|
|
145
|
-
}
|
|
146
|
-
exports.immutableCustomMerge = immutableCustomMerge;
|
package/dist/cjs/merge-high.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export type MergePerms = {
|
|
|
8
8
|
export declare function updateCodeInfo(mergeCode: MergeCode): MergePerms;
|
|
9
9
|
export declare function shallowMerge(target: any, source: any, scalarCode: MergeCode, vectorCode?: MergeCode, excludeKeys?: string[], includeKeys?: string[]): boolean;
|
|
10
10
|
export declare function immutableMerge(target: any, source: any, scalarCode: MergeCode, vectorCode?: MergeCode): any;
|
|
11
|
-
export declare function diffFromMerge(target: any, source: any, scalarCode: MergeCode, vectorCode?: MergeCode): any | false;
|
|
12
11
|
export declare function deepMerge(target: {
|
|
13
12
|
[key: string]: any;
|
|
14
13
|
}, source: {
|
|
@@ -19,4 +18,9 @@ export declare function immutableDeepMerge(target: {
|
|
|
19
18
|
}, source: {
|
|
20
19
|
[key: string]: any;
|
|
21
20
|
}, scalarCode: MergeCode, vectorCode?: MergeCode, nestedCode?: MergeCode): any;
|
|
21
|
+
export declare function diffFromMerge(target: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}, source: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}, scalarCode: MergeCode, vectorCode?: MergeCode, nestedCode?: MergeCode): any | false;
|
|
22
26
|
//# 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,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