datum-merge 0.3.1-alpha → 0.5.1

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
@@ -6,13 +6,13 @@
6
6
 
7
7
  **NPM library** : https://www.npmjs.com/package/datum-merge
8
8
 
9
- ![](https://github.com/therohk/datum-merge/actions/workflows/build.yml/badge.svg)
9
+ ![](https://github.com/therohk/datum-merge/actions/workflows/build.yml/badge.svg) ![](https://img.shields.io/github/v/release/therohk/datum-merge)
10
10
 
11
11
  ---
12
12
 
13
13
  ## Upcoming Features
14
14
 
15
- 1. inline entire [deep-diff](https://github.com/flitbit/diff) library which is unmaintained and contains serious bugs.
15
+ 1. inline the unmaintained [deep-diff](https://github.com/flitbit/diff) library which contains serious bugs. (available)
16
16
 
17
17
  2. support merging for top level arrays or primitives.
18
18
 
@@ -24,21 +24,21 @@ Code contributions are welcome via issues and pull requests.
24
24
 
25
25
  ---
26
26
 
27
- ## Examples
27
+ ## Sample Usage
28
28
 
29
29
  ```
30
- import { merge, MergeConfig, UpdateCode } from "datum-merge";
31
- const conf: MergeConfig = {
32
- "id": UpdateCode.I,
33
- "field1": UpdateCode.B,
34
- "arr*": UpdateCode.XM,
35
- nested: UpdatedCode.N,
36
- "obj1": {
37
- scalar: UpdateCode.B,
38
- vector: UpdateCode.XM,
39
- },
40
- };
41
- const diff = merge(target, source, conf);
30
+ import { merge, detailMerge, UpdateCode } from "datum-merge";
31
+
32
+ //merges all fields
33
+ let diff = merge(target, source, UpdateCode.I, UpdateCode.XM, UpdateCode.B);
34
+
35
+ //merges only given fields
36
+ diff = detailMerge(target, source, {
37
+ mykey: UpdateCode.I,
38
+ myarr: UpdateCode.XM,
39
+ anobj: UpdateCode.B,
40
+ myobj: { myid: UpdateCode.I },
41
+ });
42
42
  ```
43
43
 
44
44
  ## Merge Strategy
@@ -51,12 +51,12 @@ It decides whether a change to the value of the field is allowed during a merge
51
51
  The same field within a source and target object is represented by `s` and `t` respectively.
52
52
  Whether the strategy requires data to be present for the field, is shown by { 0=no, 1=yes, X=irrelavant }.
53
53
  The value of the source field is migrated to the target field only if the predicate passes.
54
- See the implementation of this logic in [merge-low.ts](src/merge-low.ts).
55
54
 
56
55
  | Code Value | Predicate | Meaning |
57
56
  |----|----|----|
58
57
  | C | n/a | always create new instance |
59
- | N | `0` | reject any change, skip merge |
58
+ | T | n/a | touch datum ; empty merge |
59
+ | N | `0` | reject any change ; skip merge |
60
60
  | Y | `sX & tX` | accept any change ; bypass merge |
61
61
  | B | `s1 & tX` | insert or update, no delete |
62
62
  | H | `s1 & t1` | update only if exists |
@@ -74,9 +74,11 @@ Applying the merge results in one of these transitions per primitive value in th
74
74
 
75
75
  | Code Value | Meaning | Transitions |
76
76
  |----|----|----|
77
- | Z | noop / ignore | `null <- null` or `non-null == non-null` |
78
- | N | new / insert | `null <- non-null` |
79
- | E | edit / update | `non-null <- non-null` |
80
- | D | unset / delete | `non-null <- null` |
77
+ | Z | noop / ignore | `null <-- null` or `non-null == non-null` |
78
+ | N | new / insert | `null <-- non-null` |
79
+ | E | edit / update | `non-null <-- non-null` |
80
+ | D | unset / delete | `non-null <-- null` |
81
+ | AN | array size increase | `non-null > non-null` |
82
+ | AD | array size decrease | `non-null < non-null` |
81
83
 
82
84
  ---
@@ -1,9 +1,17 @@
1
1
  export declare function getObjectKeys(obj: any, excludeKeys?: string[], includeKeys?: string[]): string[];
2
- export declare function createGlobRegex(search: string): RegExp;
3
2
  export declare function deepEquals(lhs: any, rhs: any): boolean;
4
- export declare function objToString(value: any): string;
5
3
  export declare function deepClone(val: any): any;
6
4
  export declare function toUniqueArray<T>(arr: T[]): T[];
7
5
  export declare function areArraysEqual<T>(arr1: T[] | undefined, arr2: T[] | undefined): boolean;
8
- export declare function flattenObject(obj: any): any;
9
- export declare function unflattenObject(flatObj: any): any;
6
+ export declare function createGlobRegex(search: string): RegExp;
7
+ 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
+ };
@@ -15,16 +15,9 @@ export function getObjectKeys(obj, excludeKeys, includeKeys) {
15
15
  return sourceKeys;
16
16
  }
17
17
  ;
18
- export function createGlobRegex(search) {
19
- let pattern = search.replace(/\*/g, ".+");
20
- return new RegExp(`^${pattern}$`);
21
- }
22
18
  export function deepEquals(lhs, rhs) {
23
19
  return equal(lhs, rhs);
24
20
  }
25
- export function objToString(value) {
26
- return JSON.stringify(value, null, 1);
27
- }
28
21
  export function deepClone(val) {
29
22
  return cloneDeep(val);
30
23
  }
@@ -45,8 +38,25 @@ export function areArraysEqual(arr1, arr2) {
45
38
  }
46
39
  return true;
47
40
  }
41
+ export function createGlobRegex(search) {
42
+ let pattern = search.replace(/\*/g, ".+");
43
+ return new RegExp(`^${pattern}$`);
44
+ }
45
+ export function selectGlobKeys(obj, includePats = ["*"], excludeKeys) {
46
+ const includeKeys = [];
47
+ if (!obj || !(includePats === null || includePats === void 0 ? void 0 : includePats.length)) {
48
+ return includeKeys;
49
+ }
50
+ const globPats = includePats.map((g) => createGlobRegex(g));
51
+ for (const label of getObjectKeys(obj, excludeKeys)) {
52
+ if (globPats.findIndex((r) => r.test(label)) >= 0) {
53
+ includeKeys.push(label);
54
+ }
55
+ }
56
+ return includeKeys;
57
+ }
48
58
  export function flattenObject(obj) {
49
- const flatten = {};
59
+ const flatObj = {};
50
60
  const path = [];
51
61
  const isObject = (value) => Object(value) === value;
52
62
  function dig(obj) {
@@ -56,29 +66,29 @@ export function flattenObject(obj) {
56
66
  dig(value);
57
67
  }
58
68
  else {
59
- flatten[path.join('.')] = value;
69
+ flatObj[path.join('.')] = value;
60
70
  }
61
71
  path.pop();
62
72
  }
63
73
  }
64
74
  dig(obj);
65
- return flatten;
75
+ return flatObj;
66
76
  }
67
77
  export function unflattenObject(flatObj) {
68
- const unFlatten = {};
78
+ const unflatObj = {};
69
79
  for (const [path, value] of Object.entries(flatObj)) {
70
80
  const chain = path.split('.');
71
- let object = unFlatten;
81
+ let obj = unflatObj;
72
82
  for (const [i, key] of chain.slice(0, -1).entries()) {
73
- if (!object[key]) {
83
+ if (!obj[key]) {
74
84
  const needArray = Number.isInteger(Number(chain[+i + 1]));
75
- object[key] = needArray ? [] : {};
85
+ obj[key] = needArray ? [] : {};
76
86
  }
77
- object = object[key];
87
+ obj = obj[key];
78
88
  }
79
89
  const lastkey = chain.pop();
80
- object[lastkey] = value;
90
+ obj[lastkey] = value;
81
91
  }
82
- return unFlatten;
92
+ return unflatObj;
83
93
  }
84
- //# sourceMappingURL=data-utils.js.map
94
+ //# sourceMappingURL=datum-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datum-utils.js","sourceRoot":"","sources":["../../src/datum-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,MAAM,UAAU,aAAa,CACzB,GAAQ,EACR,WAAsB,EACtB,WAAsB;IAEtB,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;IACd,CAAC;IACD,IAAI,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,WAAW,IAAI,CAAC,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QACtC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;aAC7C,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,WAAW,IAAI,CAAC,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QACt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?: boolean): [any, any];
3
3
  export declare function deepDiffTyped<T>(lhsObj: T, rhsObj: T): Partial<T>;
4
- export declare function deepDiffLow<T, S>(lhsObj: T, rhsObj: S, orderInd?: boolean): Diff<T, S>[] | false;
4
+ export declare function deepDiffLow<T, S>(lhsObj: T, rhsObj: S, orderInd?: boolean): readonly Diff<T, S>[] | false;
@@ -1,5 +1,5 @@
1
- import { applyChange, diff, orderIndependentDiff } from "deep-diff";
2
- import { flattenObject, getObjectKeys } from "./data-utils";
1
+ import { applyChange, diff, orderIndependentDiff } from "./diff-lib/deep-diff";
2
+ import { flattenObject, getObjectKeys } from "./datum-utils";
3
3
  export function deepDiffFlat(oldFlat, newFlat, flatten = false) {
4
4
  if (flatten) {
5
5
  oldFlat = flattenObject(oldFlat);
@@ -1 +1 @@
1
- {"version":3,"file":"diff-high.js","sourceRoot":"","sources":["../../src/diff-high.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,WAAW,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE5D,MAAM,UAAU,YAAY,CACxB,OAAY,EACZ,OAAY,EACZ,OAAO,GAAG,KAAK;IAEf,IAAI,OAAO,EAAE,CAAC;QACV,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QACjC,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAE3C,KAAK,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACnC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAChC,O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AC;QACnC,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAC5C,CAAC;IACD,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC3B,OAAO,QAAQ,CAAC;AACpB,CAAC;AAAA,CAAC;AAEF,SAAS,gBAAgB,CAAC,GAAQ;;IAE9B,KAAK,MAAM,MAAM,IAAI,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,IAAI,MAAA,GAAG,CAAC,MAAM,CAAC,0CAAE,MAAM,EAAE,CAAC;YACtB,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtD,CAAC;IACL,CAAC;AACL,CAAC;AAED,MAAM,UAAU,WAAW,CACvB,MAAS,EACT,MAAS,EACT,WAAoB,KAAK;IAEzB,MAAM,WAAW,GAAG,CAAC,QAAQ;QACzB,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;QACtB,CAAC,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,OAAO,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,CAAA;QACvB,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,WAAW,CAAC;AACtB,CAAC;AAAA,CAAC"}
@@ -0,0 +1,59 @@
1
+ export { type Diff };
2
+ export { type PreFilterFunction };
3
+ export { type PreFilterObject };
4
+ export { type Accumulator };
5
+ export { type Observer };
6
+ export { diff };
7
+ export { orderIndependentDiff };
8
+ export { accumulateDiff };
9
+ export { observableDiff };
10
+ export { orderIndependentObservableDiff };
11
+ export { applyChange, revertChange };
12
+ export { applyDiff };
13
+ export { realTypeOf };
14
+ export { getOrderIndependentHash };
15
+ type DiffNew<RHS> = {
16
+ readonly kind: "N";
17
+ readonly path?: any[];
18
+ readonly rhs: RHS;
19
+ };
20
+ type DiffDeleted<LHS> = {
21
+ readonly kind: "D";
22
+ readonly path?: any[];
23
+ readonly lhs: LHS;
24
+ };
25
+ type DiffEdit<LHS, RHS = LHS> = {
26
+ readonly kind: "E";
27
+ readonly path?: any[];
28
+ readonly lhs: LHS;
29
+ readonly rhs: RHS;
30
+ };
31
+ type DiffArray<LHS, RHS = LHS> = {
32
+ readonly kind: "A";
33
+ readonly path?: any[];
34
+ readonly index: number;
35
+ readonly item: Diff<LHS, RHS>;
36
+ };
37
+ type Diff<LHS, RHS = LHS> = DiffNew<RHS> | DiffDeleted<LHS> | DiffEdit<LHS, RHS> | DiffArray<LHS, RHS>;
38
+ type PreFilterFunction = (path: any[], key: any) => boolean;
39
+ type PreFilterObject<LHS, RHS = LHS> = {
40
+ prefilter?(path: any[], key: any): boolean;
41
+ normalize?(currentPath: any, key: any, lhs: LHS, rhs: RHS): [LHS, RHS] | false | undefined;
42
+ };
43
+ type PreFilter<LHS, RHS = LHS> = PreFilterFunction | PreFilterObject<LHS, RHS>;
44
+ type Filter<LHS, RHS = LHS> = (target: LHS, source: RHS, change: Diff<LHS, RHS>) => boolean;
45
+ type Accumulator<LHS, RHS = LHS> = {
46
+ push(diff: Diff<LHS, RHS>): void;
47
+ length: number;
48
+ };
49
+ type Observer<LHS, RHS = LHS> = (diff: Diff<LHS, RHS>) => void;
50
+ declare function diff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, prefilter?: PreFilter<LHS, RHS>): readonly Diff<LHS, RHS>[];
51
+ declare function orderIndependentDiff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, prefilter?: PreFilter<LHS, RHS>): readonly Diff<LHS, RHS>[];
52
+ declare function observableDiff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, observer?: Observer<LHS, RHS>, prefilter?: PreFilter<LHS, RHS>, orderIndependent?: boolean): Array<Diff<LHS, RHS>>;
53
+ declare function accumulateDiff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, prefilter?: PreFilter<LHS, RHS>, accum?: Accumulator<LHS, RHS>, orderIndependent?: boolean): Accumulator<LHS, RHS> | Diff<LHS, RHS>[];
54
+ declare function orderIndependentObservableDiff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, changes: Array<Diff<LHS, RHS>>, prefilter?: PreFilter<LHS, RHS>, path?: any[], key?: any, stack?: any[]): void;
55
+ declare function applyDiff<LHS, RHS = LHS>(target: LHS, source: RHS, filter?: Filter<LHS, RHS>): LHS;
56
+ declare function applyChange<LHS>(target: LHS, source: any, change: Diff<LHS, any>): void;
57
+ declare function revertChange<LHS>(target: LHS, source: any, change: Diff<LHS, any>): void;
58
+ declare function realTypeOf(val: any): string;
59
+ declare function getOrderIndependentHash(val: any): number;