9
9
* @flow
10
10
*/
11
11
12
- import type { AttributeMap } from './ObjectState ' ;
12
+ import type { AttributeMap , ObjectCache , OpsMap , State } from './ObjectStateMutations ' ;
13
13
import type { FileSource } from './ParseFile' ;
14
+ import type { Op } from './ParseOp' ;
14
15
import type ParseObject from './ParseObject' ;
15
16
import type ParsePromise from './ParsePromise' ;
16
17
import type { QueryJSON } from './ParseQuery' ;
@@ -43,6 +44,24 @@ type ObjectController = {
43
44
save : ( object : ParseObject , options : RequestOptions ) = > ParsePromise ;
44
45
destroy: ( object : ParseObject , options : RequestOptions ) => ParsePromise ;
45
46
} ;
47
+ type ObjectStateController = {
48
+ getState : ( obj : any ) => ?State ;
49
+ initializeState: ( obj : any , initial ? : State ) => State ;
50
+ removeState: ( obj : any ) => ?State ;
51
+ getServerData: ( obj : any ) => AttributeMap ;
52
+ setServerData: ( obj : any , attributes : AttributeMap ) => void ;
53
+ getPendingOps: ( obj : any ) => Array < OpsMap > ;
54
+ setPendingOp: ( obj : any , attr : string , op : ?Op ) => void ;
55
+ pushPendingState: ( obj : any ) => void ;
56
+ popPendingState: ( obj : any ) => OpsMap ;
57
+ mergeFirstPendingState: ( obj : any ) => void ;
58
+ getObjectCache: ( obj : any ) => ObjectCache ;
59
+ estimateAttribute: ( obj : any , attr : string ) => mixed ;
60
+ estimateAttributes: ( obj : any ) => AttributeMap ;
61
+ commitServerChanges: ( obj : any , changes : AttributeMap ) => void ;
62
+ enqueueTask: ( obj : any , task : ( ) => ParsePromise ) => ParsePromise ;
63
+ clearAllState: ( ) => void ;
64
+ } ;
46
65
type PushController = {
47
66
send : ( data : PushData , options : RequestOptions ) => ParsePromise ;
48
67
} ;
@@ -64,6 +83,7 @@ type StorageController = {
64
83
getItemAsync ?: ( path : string ) => ParsePromise ;
65
84
setItemAsync ?: ( path : string , value : string ) => ParsePromise ;
66
85
removeItemAsync ?: ( path : string ) => ParsePromise ;
86
+ clear : ( ) => void ;
67
87
} | {
68
88
async : 1 ;
69
89
getItem ?: ( path : string ) => ?string ;
@@ -72,6 +92,7 @@ type StorageController = {
72
92
getItemAsync : ( path : string ) => ParsePromise ;
73
93
setItemAsync: ( path : string , value : string ) => ParsePromise ;
74
94
removeItemAsync: ( path : string ) => ParsePromise ;
95
+ clear: ( ) => void ;
75
96
} ;
76
97
type UserController = {
77
98
setCurrentUser : ( user : ParseUser ) => ParsePromise ;
@@ -82,6 +103,7 @@ type UserController = {
82
103
become: ( options : RequestOptions ) => ParsePromise ;
83
104
logOut: ( ) => ParsePromise ;
84
105
requestPasswordReset: ( email : string , options : RequestOptions ) => ParsePromise ;
106
+ updateUserOnDisk: ( user : ParseUser ) => ParsePromise ;
85
107
upgradeToRevocableSession: ( user : ParseUser , options : RequestOptions ) => ParsePromise ;
86
108
linkWith: ( user : ParseUser , authData : AuthData ) => ParsePromise ;
87
109
} ;
@@ -179,17 +201,6 @@ module.exports = {
179
201
return config [ 'InstallationController' ] ;
180
202
} ,
181
203
182
- setPushController ( controller : PushController ) {
183
- if ( typeof controller . send !== 'function' ) {
184
- throw new Error ( 'PushController must implement send()' ) ;
185
- }
186
- config [ 'PushController' ] = controller ;
187
- } ,
188
-
189
- getPushController ( ) : PushController {
190
- return config [ 'PushController' ] ;
191
- } ,
192
-
193
204
setObjectController ( controller : ObjectController ) {
194
205
if ( typeof controller . save !== 'function' ) {
195
206
throw new Error ( 'ObjectController must implement save()' ) ;
@@ -207,6 +218,106 @@ module.exports = {
207
218
return config [ 'ObjectController' ] ;
208
219
} ,
209
220
221
+ setObjectStateController ( controller : ObjectStateController ) {
222
+ if ( typeof controller . getState !== 'function' ) {
223
+ throw new Error (
224
+ 'ObjectStateController must implement getState()'
225
+ ) ;
226
+ }
227
+ if ( typeof controller . initializeState !== 'function' ) {
228
+ throw new Error (
229
+ 'ObjectStateController must implement initializeState()'
230
+ ) ;
231
+ }
232
+ if ( typeof controller . removeState !== 'function' ) {
233
+ throw new Error (
234
+ 'ObjectStateController must implement removeState()'
235
+ ) ;
236
+ }
237
+ if ( typeof controller . getServerData !== 'function' ) {
238
+ throw new Error (
239
+ 'ObjectStateController must implement getServerData()'
240
+ ) ;
241
+ }
242
+ if ( typeof controller . setServerData !== 'function' ) {
243
+ throw new Error (
244
+ 'ObjectStateController must implement setServerData()'
245
+ ) ;
246
+ }
247
+ if ( typeof controller . getPendingOps !== 'function' ) {
248
+ throw new Error (
249
+ 'ObjectStateController must implement getPendingOps()'
250
+ ) ;
251
+ }
252
+ if ( typeof controller . setPendingOp !== 'function' ) {
253
+ throw new Error (
254
+ 'ObjectStateController must implement setPendingOp()'
255
+ ) ;
256
+ }
257
+ if ( typeof controller . pushPendingState !== 'function' ) {
258
+ throw new Error (
259
+ 'ObjectStateController must implement pushPendingState()'
260
+ ) ;
261
+ }
262
+ if ( typeof controller . popPendingState !== 'function' ) {
263
+ throw new Error (
264
+ 'ObjectStateController must implement popPendingState()'
265
+ ) ;
266
+ }
267
+ if ( typeof controller . mergeFirstPendingState !== 'function' ) {
268
+ throw new Error (
269
+ 'ObjectStateController must implement mergeFirstPendingState()'
270
+ ) ;
271
+ }
272
+ if ( typeof controller . getObjectCache !== 'function' ) {
273
+ throw new Error (
274
+ 'ObjectStateController must implement getObjectCache()'
275
+ ) ;
276
+ }
277
+ if ( typeof controller . estimateAttribute !== 'function' ) {
278
+ throw new Error (
279
+ 'ObjectStateController must implement estimateAttribute()'
280
+ ) ;
281
+ }
282
+ if ( typeof controller . estimateAttributes !== 'function' ) {
283
+ throw new Error (
284
+ 'ObjectStateController must implement estimateAttributes()'
285
+ ) ;
286
+ }
287
+ if ( typeof controller . commitServerChanges !== 'function' ) {
288
+ throw new Error (
289
+ 'ObjectStateController must implement commitServerChanges()'
290
+ ) ;
291
+ }
292
+ if ( typeof controller . enqueueTask !== 'function' ) {
293
+ throw new Error (
294
+ 'ObjectStateController must implement enqueueTask()'
295
+ ) ;
296
+ }
297
+ if ( typeof controller . clearAllState !== 'function' ) {
298
+ throw new Error (
299
+ 'ObjectStateController must implement clearAllState()'
300
+ ) ;
301
+ }
302
+
303
+ config [ 'ObjectStateController' ] = controller ;
304
+ } ,
305
+
306
+ getObjectStateController ( ) : ObjectStateController {
307
+ return config [ 'ObjectStateController' ] ;
308
+ } ,
309
+
310
+ setPushController ( controller : PushController ) {
311
+ if ( typeof controller . send !== 'function' ) {
312
+ throw new Error ( 'PushController must implement send()' ) ;
313
+ }
314
+ config [ 'PushController' ] = controller ;
315
+ } ,
316
+
317
+ getPushController ( ) : PushController {
318
+ return config [ 'PushController' ] ;
319
+ } ,
320
+
210
321
setQueryController ( controller : QueryController ) {
211
322
if ( typeof controller . find !== 'function' ) {
212
323
throw new Error ( 'QueryController must implement find()' ) ;
0 commit comments