1 |
|
2 |
|
3 | declare namespace SelfReloadJSON {
|
4 | export default class SelfReloadJSON<T> extends NodeJS.EventEmitter, T {
|
5 | |
6 |
|
7 |
|
8 |
|
9 | constructor(fileName: string);
|
10 |
|
11 | /**
|
12 | * Construct the instance.
|
13 | * @param options
|
14 | */
|
15 | constructor(options: SelfReloadJSONOptions);
|
16 |
|
17 | [key: string | number]: any;
|
18 |
|
19 | /**
|
20 | * Stop watching the changes of the JSON file.
|
21 | * You can use `resume` to continue watching the changes.
|
22 | */
|
23 | stop();
|
24 |
|
25 | /**
|
26 | * Start to watch the changes of the JSON file.
|
27 | * In default, this is automatically called after instance construction.
|
28 | */
|
29 | resume();
|
30 |
|
31 | /**
|
32 | * Write the changes back to the JSON file.
|
33 | * @param options
|
34 | */
|
35 | save(options?: SelfReloadJSONSaveOptions);
|
36 |
|
37 | /**
|
38 | * Force update the JSON file.
|
39 | */
|
40 | forceUpdate();
|
41 |
|
42 | /**
|
43 | * This event will be emitted after the JSON content refreshed.
|
44 | * The `json` parameter is the raw parsed JSON object (not the SelfReloadJSON instance itself).
|
45 | */
|
46 | on(event: 'updated', callback: (json: any) => void): this;
|
47 |
|
48 | /**
|
49 | * This event will be emitted while error occured when loading the updated JSON file.
|
50 | * The `err` parameter will be the error thrown by the updater.
|
51 | */
|
52 | on(event: 'save', callback: (err: any) => void): this;
|
53 |
|
54 | /**
|
55 | * This event will be emitted if any errors thrown during reload.
|
56 | */
|
57 | on(event: 'error', callback: (err: any) => void): this;
|
58 |
|
59 | /**
|
60 | * Deep patch an object in order to keep it's reference.
|
61 | * @param source Object to be patched.
|
62 | * @param patch Object for patching.
|
63 | * @param options
|
64 | */
|
65 | static deepPatch(source: any, patch: any, options?: DeepPatchOptions);
|
66 | }
|
67 |
|
68 | export interface SelfReloadJSONOptions extends SelfReloadJSONSaveOptions {
|
69 | /**
|
70 | * Defines the path to the JSON file.
|
71 | */
|
72 | fileName?: string;
|
73 |
|
74 | /**
|
75 | * defines the behavior when the JSON file changed externally,
|
76 | * set to `true` if you want to keep the removed properties in the instance.
|
77 | * Default is `false`.
|
78 | */
|
79 | additive?: boolean;
|
80 |
|
81 | /**
|
82 | * Defines what method to determine the changes of JSON file.
|
83 | * `'native'` mode will use system API to detect,
|
84 | * and `'polling'` mode will poll the modified time of the JSON file.
|
85 | * In the most case 'native' is more efficient,
|
86 | * but some of the operating system does not support this,
|
87 | * in this case `'polling'` should be used as fallback.
|
88 | */
|
89 | method?: 'native' | 'polling';
|
90 |
|
91 | /**
|
92 | * The checking interval if 'polling' mode is used.
|
93 | * Default is `5000` milliseconds.
|
94 | */
|
95 | interval?: number;
|
96 |
|
97 | /**
|
98 | * The [reviver](https:
|
99 | * function when parsing JSON. Default is `null`.
|
100 | */
|
101 | reviver?: (key: string, value: any) => any;
|
102 |
|
103 | |
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | delay?: number;
|
111 |
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 | depth?: number;
|
118 | }
|
119 |
|
120 | export interface SelfReloadJSONSaveOptions {
|
121 | |
122 |
|
123 |
|
124 | encoding?: string;
|
125 |
|
126 | |
127 |
|
128 |
|
129 |
|
130 |
|
131 | replacer?: ((this: any, key: string, value: any) => any) | string[];
|
132 |
|
133 | |
134 |
|
135 |
|
136 |
|
137 | space?: number | string;
|
138 | }
|
139 |
|
140 | export interface DeepPatchOptions {
|
141 | |
142 |
|
143 |
|
144 | ignoreProperties?: string[];
|
145 |
|
146 | |
147 |
|
148 |
|
149 |
|
150 | keepNonExists?: boolean;
|
151 |
|
152 | |
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | depth?: number;
|
159 | }
|
160 |
|
161 |
|
162 |
|
163 | |
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | export function walkThroughTree<U>(fn: (this: WalkThroughTreeScope0) => U, options?: WalkThroughTreeOptions): U | undefined;
|
170 | export function walkThroughTree<T, U>(fn: (this: WalkThroughTreeScope1<T>, arg: T) => U, options: WalkThroughTreeOptions, arg: T): U | undefined;
|
171 | export function walkThroughTree<T1, T2, U>(fn: (this: WalkThroughTreeScope2<T1, T2>, arg1: T1, arg2: T2) => U, options: WalkThroughTreeOptions, arg1: T1, arg2: T2): U | undefined;
|
172 | export function walkThroughTree<T1, T2, T3, U>(fn: (this: WalkThroughTreeScope3<T1, T2, T3>, arg1: T1, arg2: T2, arg3: T3) => U, options: WalkThroughTreeOptions, arg1: T1, arg2: T2, arg3: T3): U | undefined;
|
173 | export function walkThroughTree<T1, T2, T3, T4, U>(fn: (this: WalkThroughTreeScope4<T1, T2, T3, T4>, arg1: T1, arg2: T2, arg3: T3, arg4: T4) => U, options: WalkThroughTreeOptions, arg1: T1, arg2: T2, arg3: T3, arg4: T4): U | undefined;
|
174 | export function walkThroughTree<T1, T2, T3, T4, T5, U>(fn: (this: WalkThroughTreeScope5<T1, T2, T3, T4, T5>, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => U, options: WalkThroughTreeOptions, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5): U | undefined;
|
175 | export function walkThroughTree<U>(fn: (this: WalkThroughTreeScope, ...args: any[]) => U, options: WalkThroughTreeOptions, ...args: any[]): U | undefined;
|
176 |
|
177 | |
178 |
|
179 |
|
180 | export function walkThroughTreeGen<U>(fn: (this: WalkThroughTreeScope0) => U, options?: WalkThroughTreeOptions): IterableIterator<U>;
|
181 | export function walkThroughTreeGen<T, U>(fn: (this: WalkThroughTreeScope1<T>, arg: T) => U, options: WalkThroughTreeOptions, arg: T): IterableIterator<U>;
|
182 | export function walkThroughTreeGen<T1, T2, U>(fn: (this: WalkThroughTreeScope2<T1, T2>, arg1: T1, arg2: T2) => U, options: WalkThroughTreeOptions, arg1: T1, arg2: T2): IterableIterator<U>;
|
183 | export function walkThroughTreeGen<T1, T2, T3, U>(fn: (this: WalkThroughTreeScope3<T1, T2, T3>, arg1: T1, arg2: T2, arg3: T3) => U, options: WalkThroughTreeOptions, arg1: T1, arg2: T2, arg3: T3): IterableIterator<U>;
|
184 | export function walkThroughTreeGen<T1, T2, T3, T4, U>(fn: (this: WalkThroughTreeScope4<T1, T2, T3, T4>, arg1: T1, arg2: T2, arg3: T3, arg4: T4) => U, options: WalkThroughTreeOptions, arg1: T1, arg2: T2, arg3: T3, arg4: T4): IterableIterator<U>;
|
185 | export function walkThroughTreeGen<T1, T2, T3, T4, T5, U>(fn: (this: WalkThroughTreeScope5<T1, T2, T3, T4, T5>, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => U, options: WalkThroughTreeOptions, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5): IterableIterator<U>;
|
186 | export function walkThroughTreeGen<U>(fn: (this: WalkThroughTreeScope, ...args: any[]) => U, options: WalkThroughTreeOptions, ...args: any[]): IterableIterator<U>;
|
187 |
|
188 | export interface WalkThroughTreeOptions {
|
189 | |
190 |
|
191 |
|
192 | horizontal?: boolean;
|
193 |
|
194 | |
195 |
|
196 |
|
197 | firstResult?: boolean;
|
198 | }
|
199 |
|
200 | export interface WalkThroughTreeScope {
|
201 | next(...args: any[]): void;
|
202 | }
|
203 |
|
204 | export interface WalkThroughTreeScope0 {
|
205 | next(): void;
|
206 | }
|
207 |
|
208 | export interface WalkThroughTreeScope1<T> {
|
209 | next(arg: T): void;
|
210 | }
|
211 |
|
212 | export interface WalkThroughTreeScope2<T1, T2> {
|
213 | next(arg1: T1, arg2: T2): void;
|
214 | }
|
215 |
|
216 | export interface WalkThroughTreeScope3<T1, T2, T3> {
|
217 | next(arg1: T1, arg2: T2, arg3: T3): void;
|
218 | }
|
219 |
|
220 | export interface WalkThroughTreeScope4<T1, T2, T3, T4> {
|
221 | next(arg1: T1, arg2: T2, arg3: T3, arg4: T4): void;
|
222 | }
|
223 |
|
224 | export interface WalkThroughTreeScope5<T1, T2, T3, T4, T5> {
|
225 | next(arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5): void;
|
226 | }
|
227 | }
|
228 |
|
229 | export as namespace SelfReloadJSON;
|
230 |
|
\ | No newline at end of file |