@@ -15,28 +15,25 @@ import type ParseConfig from './ParseConfig';
15
15
import type LiveQueryClient from './LiveQueryClient' ;
16
16
import type ParseInstallation from './ParseInstallation' ;
17
17
18
- type AnalyticsController = {
19
- track : ( name : string , dimensions : { [ key : string ] : string } ) => Promise < any > ;
20
- } ;
21
- type CloudController = {
18
+ export interface AnalyticsController {
19
+ track : ( name : string , dimensions : Record < string , string > ) => Promise < any > ;
20
+ }
21
+ export interface CloudController {
22
22
run : ( name : string , data : any , options ?: RequestOptions ) => Promise < any > ;
23
23
getJobsData : ( options ?: RequestOptions ) => Promise < any > ;
24
24
/** Returns promise which resolves with JobStatusId of the job */
25
25
startJob : ( name : string , data : any , options ?: RequestOptions ) => Promise < string > ;
26
- } ;
27
- type ConfigController = {
26
+ }
27
+ export interface ConfigController {
28
28
current : ( ) => Promise < ParseConfig > | ParseConfig ;
29
29
get : ( opts ?: RequestOptions ) => Promise < ParseConfig > ;
30
- save : (
31
- attrs : { [ key : string ] : any } ,
32
- masterKeyOnlyFlags ?: { [ key : string ] : any }
33
- ) => Promise < void > ;
34
- } ;
35
- type CryptoController = {
30
+ save : ( attrs : Record < string , any > , masterKeyOnlyFlags ?: Record < string , any > ) => Promise < void > ;
31
+ }
32
+ export interface CryptoController {
36
33
encrypt : ( obj : any , secretKey : string ) => string ;
37
34
decrypt : ( encryptedText : string , secretKey : any ) => string ;
38
- } ;
39
- type FileController = {
35
+ }
36
+ export interface FileController {
40
37
saveFile : ( name : string , source : FileSource , options ?: FullOptions ) => Promise < any > ;
41
38
saveBase64 : (
42
39
name : string ,
@@ -45,34 +42,34 @@ type FileController = {
45
42
) => Promise < { name : string ; url : string } > ;
46
43
download : ( uri : string , options ?: any ) => Promise < { base64 ?: string ; contentType ?: string } > ;
47
44
deleteFile : ( name : string , options ?: { useMasterKey ?: boolean } ) => Promise < void > ;
48
- } ;
49
- type InstallationController = {
45
+ }
46
+ export interface InstallationController {
50
47
currentInstallationId : ( ) => Promise < string > ;
51
48
currentInstallation : ( ) => Promise < ParseInstallation | null > ;
52
49
updateInstallationOnDisk : ( installation : ParseInstallation ) => Promise < void > ;
53
- } ;
54
- type ObjectController = {
50
+ }
51
+ export interface ObjectController {
55
52
fetch : (
56
- object : ParseObject | Array < ParseObject > ,
53
+ object : ParseObject | ParseObject [ ] ,
57
54
forceFetch : boolean ,
58
55
options ?: RequestOptions
59
- ) => Promise < Array < ParseObject | undefined > | ParseObject | undefined > ;
56
+ ) => Promise < ( ParseObject | undefined ) [ ] | ParseObject | undefined > ;
60
57
save : (
61
- object : ParseObject | Array < ParseObject | ParseFile > | null ,
58
+ object : ParseObject | ( ParseObject | ParseFile ) [ ] | null ,
62
59
options ?: RequestOptions
63
- ) => Promise < ParseObject | Array < ParseObject > | ParseFile | undefined > ;
60
+ ) => Promise < ParseObject | ParseObject [ ] | ParseFile | undefined > ;
64
61
destroy : (
65
- object : ParseObject | Array < ParseObject > ,
62
+ object : ParseObject | ParseObject [ ] ,
66
63
options ?: RequestOptions
67
- ) => Promise < ParseObject | Array < ParseObject > > ;
68
- } ;
69
- type ObjectStateController = {
64
+ ) => Promise < ParseObject | ParseObject [ ] > ;
65
+ }
66
+ export interface ObjectStateController {
70
67
getState : ( obj : any ) => State | null ;
71
68
initializeState : ( obj : any , initial ?: State ) => State ;
72
69
removeState : ( obj : any ) => State | null ;
73
70
getServerData : ( obj : any ) => AttributeMap ;
74
71
setServerData : ( obj : any , attributes : AttributeMap ) => void ;
75
- getPendingOps : ( obj : any ) => Array < OpsMap > ;
72
+ getPendingOps : ( obj : any ) => OpsMap [ ] ;
76
73
setPendingOp : ( obj : any , attr : string , op ?: Op ) => void ;
77
74
pushPendingState : ( obj : any ) => void ;
78
75
popPendingState : ( obj : any ) => OpsMap | undefined ;
@@ -84,23 +81,19 @@ type ObjectStateController = {
84
81
enqueueTask : ( obj : any , task : ( ) => Promise < void > ) => Promise < void > ;
85
82
clearAllState : ( ) => void ;
86
83
duplicateState : ( source : any , dest : any ) => void ;
87
- } ;
88
- type PushController = {
84
+ }
85
+ export interface PushController {
89
86
send : ( data : PushData , options ?: FullOptions ) => Promise < any > ;
90
- } ;
91
- type QueryController = {
87
+ }
88
+ export interface QueryController {
92
89
find (
93
90
className : string ,
94
91
params : QueryJSON ,
95
92
options ?: RequestOptions
96
- ) : Promise < { results ?: Array < ParseObject > ; className ?: string ; count ?: number } > ;
97
- aggregate (
98
- className : string ,
99
- params : any ,
100
- options ?: RequestOptions
101
- ) : Promise < { results ?: Array < any > } > ;
102
- } ;
103
- export type QueueObject = {
93
+ ) : Promise < { results ?: ParseObject [ ] ; className ?: string ; count ?: number } > ;
94
+ aggregate ( className : string , params : any , options ?: RequestOptions ) : Promise < { results ?: any [ ] } > ;
95
+ }
96
+ export interface QueueObject {
104
97
queueId : string ;
105
98
action : string ;
106
99
object : ParseObject ;
@@ -109,9 +102,9 @@ export type QueueObject = {
109
102
className : string ;
110
103
hash : string ;
111
104
createdAt : Date ;
112
- } ;
113
- export type Queue = Array < QueueObject > ;
114
- export type EventuallyQueue = {
105
+ }
106
+ export type Queue = QueueObject [ ] ;
107
+ export interface EventuallyQueue {
115
108
save : ( object : ParseObject , serverOptions ?: SaveOptions ) => Promise < void > ;
116
109
destroy : ( object : ParseObject , serverOptions ?: RequestOptions ) => Promise < void > ;
117
110
generateQueueId : ( action : string , object : ParseObject ) => string ;
@@ -138,8 +131,8 @@ export type EventuallyQueue = {
138
131
byId ( ObjectType : any , queueObject : any ) : Promise < void > ;
139
132
byHash ( ObjectType : any , queueObject : any ) : Promise < void > ;
140
133
} ;
141
- } ;
142
- type RESTController = {
134
+ }
135
+ export interface RESTController {
143
136
request : ( method : string , path : string , data ?: any , options ?: RequestOptions ) => Promise < any > ;
144
137
ajax : (
145
138
method : string ,
@@ -149,18 +142,18 @@ type RESTController = {
149
142
options ?: FullOptions
150
143
) => Promise < any > ;
151
144
handleError : ( err ?: any ) => void ;
152
- } ;
153
- type SchemaController = {
145
+ }
146
+ export interface SchemaController {
154
147
purge : ( className : string ) => Promise < any > ;
155
148
get : ( className : string , options ?: RequestOptions ) => Promise < any > ;
156
149
delete : ( className : string , options ?: RequestOptions ) => Promise < void > ;
157
150
create : ( className : string , params : any , options ?: RequestOptions ) => Promise < any > ;
158
151
update : ( className : string , params : any , options ?: RequestOptions ) => Promise < any > ;
159
152
send ( className : string , method : string , params : any , options ?: RequestOptions ) : Promise < any > ;
160
- } ;
161
- type SessionController = {
153
+ }
154
+ export interface SessionController {
162
155
getSession : ( options ?: RequestOptions ) => Promise < ParseSession > ;
163
- } ;
156
+ }
164
157
type StorageController =
165
158
| {
166
159
async : 0 ;
@@ -171,8 +164,8 @@ type StorageController =
171
164
setItemAsync ?: ( path : string , value : string ) => Promise < void > ;
172
165
removeItemAsync ?: ( path : string ) => Promise < void > ;
173
166
clear : ( ) => void ;
174
- getAllKeys ?: ( ) => Array < string > ;
175
- getAllKeysAsync ?: ( ) => Promise < Array < string > > ;
167
+ getAllKeys ?: ( ) => string [ ] ;
168
+ getAllKeysAsync ?: ( ) => Promise < string [ ] > ;
176
169
}
177
170
| {
178
171
async : 1 ;
@@ -183,19 +176,19 @@ type StorageController =
183
176
setItemAsync : ( path : string , value : string ) => Promise < void > ;
184
177
removeItemAsync : ( path : string ) => Promise < void > ;
185
178
clear : ( ) => void ;
186
- getAllKeys ?: ( ) => Array < string > ;
187
- getAllKeysAsync ?: ( ) => Promise < Array < string > > ;
179
+ getAllKeys ?: ( ) => string [ ] ;
180
+ getAllKeysAsync ?: ( ) => Promise < string [ ] > ;
188
181
} ;
189
- type LocalDatastoreController = {
182
+ export interface LocalDatastoreController {
190
183
fromPinWithName : ( name : string ) => any | undefined ;
191
184
pinWithName : ( name : string , objects : any ) => void ;
192
185
unPinWithName : ( name : string ) => void ;
193
186
getAllContents : ( ) => any | undefined ;
194
187
clear : ( ) => void ;
195
188
// Use for testing
196
189
// getRawStorage(): Promise<Object>,
197
- } ;
198
- type UserController = {
190
+ }
191
+ export interface UserController {
199
192
setCurrentUser : ( user : ParseUser ) => Promise < void > ;
200
193
currentUser : ( ) => ParseUser | null ;
201
194
currentUserAsync : ( ) => Promise < ParseUser | null > ;
@@ -210,29 +203,29 @@ type UserController = {
210
203
updateUserOnDisk : ( user : ParseUser ) => Promise < ParseUser > ;
211
204
upgradeToRevocableSession : ( user : ParseUser , options ?: RequestOptions ) => Promise < void > ;
212
205
linkWith : ( user : ParseUser , authData : AuthData , options ?: FullOptions ) => Promise < ParseUser > ;
213
- removeUserFromDisk : ( ) => Promise < ParseUser | void > ;
206
+ removeUserFromDisk : ( ) => Promise < void > ;
214
207
verifyPassword : (
215
208
username : string ,
216
209
password : string ,
217
210
options ?: RequestOptions
218
211
) => Promise < ParseUser > ;
219
212
requestEmailVerification : ( email : string , options ?: RequestOptions ) => Promise < void > ;
220
- } ;
221
- type HooksController = {
213
+ }
214
+ export interface HooksController {
222
215
get : ( type : string , functionName ?: string , triggerName ?: string ) => Promise < any > ;
223
216
create : ( hook : HookDeclaration ) => Promise < any > ;
224
217
remove : ( hook : HookDeleteArg ) => Promise < any > ;
225
218
update : ( hook : HookDeclaration ) => Promise < any > ;
226
219
// Renamed to sendRequest since ParseHooks file & tests file uses this. (originally declared as just "send")
227
220
sendRequest ?: ( method : string , path : string , body ?: any ) => Promise < any > ;
228
- } ;
229
- type LiveQueryControllerType = {
221
+ }
222
+ export interface LiveQueryControllerType {
230
223
setDefaultLiveQueryClient ( liveQueryClient : LiveQueryClient ) : void ;
231
224
getDefaultLiveQueryClient ( ) : Promise < LiveQueryClient > ;
232
225
_clearCachedDefaultClient ( ) : void ;
233
- } ;
226
+ }
234
227
/** Based on https://github.com/react-native-async-storage/async-storage/blob/main/packages/default-storage-backend/src/types.ts */
235
- type AsyncStorageType = {
228
+ export interface AsyncStorageType {
236
229
/** Fetches an item for a `key` and invokes a callback upon completion. */
237
230
getItem : (
238
231
key : string ,
@@ -302,16 +295,16 @@ type AsyncStorageType = {
302
295
keyValuePairs : [ string , string ] [ ] ,
303
296
callback ?: ( errors ?: readonly ( Error | null ) [ ] | null ) => void
304
297
) => Promise < void > ;
305
- } ;
306
- export type WebSocketController = {
298
+ }
299
+ export interface WebSocketController {
307
300
onopen : ( ) => void ;
308
301
onmessage : ( message : any ) => void ;
309
302
onclose : ( arg ?: any ) => void ;
310
303
onerror : ( error : any ) => void ;
311
304
send : ( data : any ) => void ;
312
305
close : ( ) => void ;
313
- } ;
314
- type Config = {
306
+ }
307
+ interface Config {
315
308
AnalyticsController ?: AnalyticsController ;
316
309
CloudController ?: CloudController ;
317
310
ConfigController ?: ConfigController ;
@@ -334,9 +327,9 @@ type Config = {
334
327
) => WebSocketController ;
335
328
LiveQueryController ?: LiveQueryControllerType ;
336
329
AsyncStorage ?: AsyncStorageType ;
337
- } ;
330
+ }
338
331
339
- const config : Config & { [ key : string ] : any } = {
332
+ const config : Config & Record < string , any > = {
340
333
IS_NODE :
341
334
typeof process !== 'undefined' &&
342
335
! ! process . versions &&
@@ -364,7 +357,7 @@ const config: Config & { [key: string]: any } = {
364
357
PARSE_ERRORS : [ ] ,
365
358
} ;
366
359
367
- function requireMethods ( name : string , methods : Array < string > , controller : any ) {
360
+ function requireMethods ( name : string , methods : string [ ] , controller : any ) {
368
361
methods . forEach ( func => {
369
362
if ( typeof controller [ func ] !== 'function' ) {
370
363
throw new Error ( `${ name } must implement ${ func } ()` ) ;
0 commit comments