1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | declare function deepDiff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, prefilter?: deepDiff.PreFilter<LHS, RHS>): Array<deepDiff.Diff<LHS, RHS>> | undefined;
|
8 | declare function deepDiff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, prefilter?: deepDiff.PreFilter<LHS, RHS>, acc?: deepDiff.Accumulator<LHS, RHS>): deepDiff.Accumulator<LHS, RHS>;
|
9 | declare namespace deepDiff {
|
10 | interface DiffNew<RHS> {
|
11 | kind: 'N';
|
12 | path?: any[] | undefined;
|
13 | rhs: RHS;
|
14 | }
|
15 |
|
16 | interface DiffDeleted<LHS> {
|
17 | kind: 'D';
|
18 | path?: any[] | undefined;
|
19 | lhs: LHS;
|
20 | }
|
21 |
|
22 | interface DiffEdit<LHS, RHS = LHS> {
|
23 | kind: 'E';
|
24 | path?: any[] | undefined;
|
25 | lhs: LHS;
|
26 | rhs: RHS;
|
27 | }
|
28 |
|
29 | interface DiffArray<LHS, RHS = LHS> {
|
30 | kind: 'A';
|
31 | path?: any[] | undefined;
|
32 | index: number;
|
33 | item: Diff<LHS, RHS>;
|
34 | }
|
35 |
|
36 | type Diff<LHS, RHS = LHS> = DiffNew<RHS> | DiffDeleted<LHS> | DiffEdit<LHS, RHS> | DiffArray<LHS, RHS>;
|
37 |
|
38 | type PreFilterFunction = (path: any[], key: any) => boolean;
|
39 |
|
40 | interface PreFilterObject<LHS, RHS = LHS> {
|
41 | prefilter?(path: any[], key: any): boolean;
|
42 | normalize?(currentPath: any, key: any, lhs: LHS, rhs: RHS): [ LHS, RHS ] | undefined;
|
43 | }
|
44 | type PreFilter<LHS, RHS = LHS> = PreFilterFunction | PreFilterObject<LHS, RHS>;
|
45 |
|
46 | interface Accumulator<LHS, RHS = LHS> {
|
47 | push(diff: Diff<LHS, RHS>): void;
|
48 | length: number;
|
49 | }
|
50 |
|
51 | type Observer<LHS, RHS = LHS> = (diff: Diff<LHS, RHS>) => void;
|
52 |
|
53 | type Filter<LHS, RHS = LHS> = (target: LHS, source: RHS, change: Diff<LHS, RHS>) => boolean;
|
54 |
|
55 | function diff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, prefilter?: PreFilter<LHS, RHS>): Array<Diff<LHS, RHS>> | undefined;
|
56 | function diff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, prefilter?: PreFilter<LHS, RHS>, acc?: Accumulator<LHS, RHS>): Accumulator<LHS, RHS>;
|
57 | function orderIndependentDiff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, prefilter?: PreFilter<LHS, RHS>): Array<Diff<LHS, RHS>> | undefined;
|
58 | function orderIndependentDiff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, prefilter?: PreFilter<LHS, RHS>, acc?: Accumulator<LHS, RHS>): Accumulator<LHS, RHS>;
|
59 | function observableDiff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, observer?: Observer<LHS, RHS>, prefilter?: PreFilter<LHS, RHS>, orderIndependent?: boolean): Array<Diff<LHS, RHS>>;
|
60 | function orderIndependentDeepDiff<LHS, RHS = LHS>(lhs: LHS, rhs: RHS, changes: Array<Diff<LHS, RHS>>, prefilter: PreFilter<LHS, RHS>, path: any[], key: any, stack: any[]): void;
|
61 | function orderIndepHash(object: any): number;
|
62 | function applyDiff<LHS, RHS = LHS>(target: LHS, source: RHS, filter?: Filter<LHS, RHS>): void;
|
63 | function applyChange<LHS>(target: LHS, source: any, change: Diff<LHS, any>): void;
|
64 | function revertChange<LHS>(target: LHS, source: any, change: Diff<LHS, any>): void;
|
65 | }
|
66 |
|
67 | export = deepDiff;
|