This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfh-sync-js.d.ts
409 lines (354 loc) · 12.2 KB
/
fh-sync-js.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
// Type definitions for fh-sync-js 2.18.0
// Project: https://github.com/feedhenry/fh-sync-js
// Definitions by: [email protected]
/**
* interface for the data provided in the NotifyCallback in the notify function.
* @interface NotificationData
*/
interface NotificationData {
dataset_id: string;
uid: string;
message?: string;
code: string;
}
/**
* Interface for the options object provided to the init function.
*
* @interface SyncOptions
*/
interface SyncOptions {
/**
* Sync cloud url (used by default handler to call server)
*/
cloudUrl: string,
/**
* How often to synchronize data with the cloud, in seconds.
* Optional. Default: 10
*/
sync_frequency?: number,
/**
* Should local changes be synchronized to the cloud immediately, or should they wait for the next synchronization interval.
* Optional. Default: true
*/
auto_sync_local_updates?: boolean,
/**
* Should a notification event be triggered when loading or saving to client storage fails.
* Optional. Default: true
*/
notify_client_storage_failed?: boolean,
/** Should a notification event be triggered when connection to client storage fails. ...*/
notify_connection_to_storage_failed?: boolean,
/**
* Should a notification event be triggered when a synchronization cycle with the server has been started.
* Optional. Default: true
*/
notify_sync_started?: boolean,
/**
* Should a notification event be triggered when a synchronization cycle with the server has been completed.
* Optional. Default: true
*/
notify_sync_complete?: boolean,
/**
* Should a notification event be triggered when an attempt was made to update a record while offline.
* Optional. Default: true
*/
notify_offline_update?: boolean,
/**
* Should a notification event be triggered when an update failed due to data collision.
* Optional. Default: true
*/
notify_collision_detected?: boolean,
/**
* Should a notification event be triggered when an update was applied to the local data store.
* Optional. Default: true
*/
notify_local_update_applied?: boolean,
/**
* Should a notification event be triggered when an update failed for a reason other than data collision.
* Optional. Default: true
*/
notify_remote_update_failed?: boolean,
/**
* Should a notification event be triggered when an update was applied to the remote data store.
* Optional. Default: true
*/
notify_remote_update_applied?: boolean,
/**
* Should a notification event be triggered when a delta was received from the remote data store.
* Optional. Default: true
*/
notify_delta_received?: boolean,
/**
* Should a notification event be triggered when a delta was received from the remote data store for a record.
* Optional. Default: true
*/
notify_record_delta_received?: boolean,
/**
* Should a notification event be triggered when the synchronization loop failed to complete.
* Optional. Default: true
*/
notify_sync_failed?: boolean,
/**
* How many synchronization cycles to check for updates on crashed in-flight updates.
* Optional. Default: 10
*/
crashed_count_wait?: number,
/**
* If crashed_count_wait limit is reached, should the client retry sending the crashed in flight pending records.
* Optional. Default: true
*/
resend_crashed_updates?: boolean,
/**
* Is the background synchronization with the cloud currently active. If this is set to false, the synchronization loop will not start automatically.
* You need to call startSync to start the synchronization loop. Optional. Default: true
*/
sync_active?: boolean,
/**
* Storage strategy to use for the underlying client storage framework Lawnchair. Valid values include 'dom', 'html5-filesystem', 'webkit-sqlite', 'indexed-db'.
* Multiple values can be specified as an array and the first valid storage option will be used.
* Optional. Default: 'html5-filesystem'
*/
storage_strategy?: "html5-filesystem" | "dom" | "webkit-sqlite" | "indexed-db"
/**
* Amount of space to request from the HTML5 filesystem API when running in browser
* Optional. Default: 50 * 1024 * 1024
*/
file_system_quota?: number,
/**
* iOS only. If set to true, the file will be backed by iCloud. Default to false;
*/
icloud_backup?: boolean,
/*
* If set, the client will resend the pending changes that are inflight, but haven't crashed, and have lived longer than this value.
* This is to prevent the situation where updates are lost for certain pending changes, those pending changes will be stuck on the client forever.
* Default value is 24 hours.
* Optional. Default: 60*24
*/
resend_inflight_pendings_minutes?: number
}
/**
* Interface for the callback used in the notify function.
*
* @interface NotifyCallback
*/
interface NotifyCallback {
(data: NotificationData): any
}
/**
* Interface for everything a sync client can do
*/
interface SyncApi {
/**
* Initialize the client data sync service.
*
* @param {Object} options
*/
init(options: SyncOptions): void;
/**
* Register a callback function to be invoked when the sync service has notifications to communicate to the client.
*
* @param dataset_id - dataset identifier
* @param {Function} callback
*/
notify(dataset_id: string, callback: NotifyCallback): void;
/**
* Put a dataset under the management of the sync service.
*
* @param {String} datasetId
* @param {Object} options
* @param {Object} query_params
* @param {Object} meta_data
* @param {Function} callback
*/
manage(datasetId: string, options: SyncOptions, query_params: any, meta_data: any, callback: () => void): void;
/**
* Get a list of the records for the dataset.
*
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
doList(datasetId: string, success: (dataset: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* Update the data associated with the unique id.
*
* @param {String} datasetId
* @param {Object} data
* @param {Function} success
* @param {Function} [failure]
*/
doCreate(datasetId: string, data: any, success: (obj: any) => void, failure?: (err: string, datasetId: string) => void): void;
/**
* Read a single data record.
*
* @param {String} datasetId
* @param {String} uid
* @param {Function} success
* @param {Function} failure
*/
doRead(datasetId: string, uid: string, success: (record: any) => void, failure?: (err: string, datasetId: string) => void): void;
/**
* Update the data associated with the unique id.
*
* @param {String} datasetId
* @param {String} uid
* @param {Object} data
* @param {Function} success
* @param {Function} failure
*/
doUpdate(datasetId: string, uid: string, data: any, success: (obj: any) => void, failure?: (err: string, datasetId: string) => void): void;
/**
* Delete the data associated with the unique id.
*
* @param {String} datasetId
* @param {String} uid
* @param {Function} success
* @param {Function} failure
*/
doDelete(datasetId: string, uid: string, success: (obj: any) => void, failure?: (err: string, datasetId: string) => void): void;
/**
* Start the sync loop if `sync_active` option is set to false.
*
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
startSync(datasetId: string, success: () => void, failure?: (obj: any) => void): void;
/**
* Stop the sync loop for a dataset.
*
* @param {String} datasetId
* @param {Function} [success]
* @param {Function} [failure]
*/
stopSync(datasetId: string, success?: () => void, failure?: (obj: any) => void): void;
/**
* Run the sync loop almost immediately (within next 500 ms) if `sync_active` is true.
*
* @param {String} datasetId
* @param {Function} [success]
* @param {Function} [failure]
*/
doSync(datasetId: string, success?: () => void, failure?: (err: string, datasetId: string) => void): void;
/**
* Run the sync loop almost immediately (within next 500 ms) even if `sync_active` is false.
*
* @param {String} datasetId
* @param {Function} [success]
* @param {Function} [failure]
*/
forceSync(datasetId: string, success?: () => void, failure?: (err: string, datasetId: string) => void): void;
/**
* List collisions in sync
*
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
listCollisions(datasetId: string, success: (res: any) => void, failure?: (msg: string, err: any) => void): void;
/**
* Remove a collision in sync
*
* @param {String} datasetId
* @param {String} collisionHash
* @param {Function} success
* @param {Function} failure
*/
removeCollision(datasetId: string, collisionHash: string, success: (res: any) => void, failure: (msg: string, err: any) => void): void;
/**
* @param {String} datasetId
* @param {Function} callback
*/
getPending(datasetId: string, callback: () => void): void;
/**
* @param {String} datasetId
* @param {Function} callback
*/
clearPending(datasetId: string, callback: () => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
getDataSet(datasetId: string, success: (dataset: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
getQueryParams(datasetId: string, success: (queryParams: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
setQueryParams(datasetId: string, success: (queryParams: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
getMetaData(datasetId: string, success: (queryParams: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
setMetaData(datasetId: string, metaData: any, success: (metaData: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
getConfig(datasetId: string, success: (config: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
setConfig(datasetId: string, config: any, success: (config: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* Produces a SHA1 hash of the provided object (sorted before hash) or string.
*
* @param {Object|String} toHash - Object to hash
* @returns {String} - SHA1 hash of the provided string or object.
*/
generateHash(toHash: {} | string): string;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
loadDataSet(datasetId: string, success: (dataset: any) => void, failure: () => void): void;
/**
* @param {String} datasetId
* @param {Function} callback
*/
clearCache(datasetId: string, callback?: () => void): void;
/**
* Sets cloud call handler for sync. Required to make any sync requests to the server side (sync cloud)
*
* @param {Function} handler - method responsible for handling network requests
*/
setCloudHandler(handler: (params: any, success: (result: any) => void, failure: (error: any) => void) => void): void;
/**
* Allows to override default storage adapter
*
* @param handler - function that wraps underlying storage solution
*/
setStorageAdapter(handler: (dataset_id: string, isSave: boolean, cb: any) => void): void;
/**
* Allows to override default hashing method
*
* @param method - function that wraps underlying hashing method
*/
setHashMethod(method: () => any): void;
}
/**
* Used to create an isolated instance of the SyncApi
*/
interface SyncApiFactory {
factory(id: string): SyncApi;
}
declare const sync: SyncApi & SyncApiFactory;
export = sync;