1
- /**
2
- * @flow
3
- */
4
-
5
1
import arrayContainsObject from './arrayContainsObject' ;
6
2
import decode from './decode' ;
7
3
import encode from './encode' ;
8
4
import CoreManager from './CoreManager' ;
9
5
import type ParseObject from './ParseObject' ;
6
+ import type Pointer from './ParseObject' ;
10
7
import ParseRelation from './ParseRelation' ;
11
8
import unique from './unique' ;
12
9
13
- export function opFromJSON ( json : { [ key : string ] : any } ) : ? Op {
10
+ export function opFromJSON ( json : { [ key : string ] : any } ) : Op | null {
14
11
if ( ! json || ! json . __op ) {
15
12
return null ;
16
13
}
@@ -58,12 +55,12 @@ export function opFromJSON(json: { [key: string]: any }): ?Op {
58
55
export class Op {
59
56
// Empty parent class
60
57
applyTo ( value : any ) : any { } /* eslint-disable-line @typescript-eslint/no-unused-vars */
61
- mergeWith ( previous : Op ) : ? Op { } /* eslint-disable-line @typescript-eslint/no-unused-vars */
62
- toJSON ( ) : any { }
58
+ mergeWith ( previous : Op ) : Op | void { } /* eslint-disable-line @typescript-eslint/no-unused-vars */
59
+ toJSON ( offline ?: boolean ) : any { } /* eslint-disable-line @typescript-eslint/no-unused-vars */
63
60
}
64
61
65
62
export class SetOp extends Op {
66
- _value : ? any ;
63
+ _value : any ;
67
64
68
65
constructor ( value : any ) {
69
66
super ( ) ;
@@ -78,7 +75,7 @@ export class SetOp extends Op {
78
75
return new SetOp ( this . _value ) ;
79
76
}
80
77
81
- toJSON ( offline ?: boolean ) {
78
+ toJSON ( offline ?: boolean ) : any {
82
79
return encode ( this . _value , false , true , undefined , offline ) ;
83
80
}
84
81
}
@@ -108,7 +105,7 @@ export class IncrementOp extends Op {
108
105
this . _amount = amount ;
109
106
}
110
107
111
- applyTo ( value : ? any ) : number {
108
+ applyTo ( value : any ) : number {
112
109
if ( typeof value === 'undefined' ) {
113
110
return this . _amount ;
114
111
}
@@ -192,7 +189,7 @@ export class AddUniqueOp extends Op {
192
189
}
193
190
if ( Array . isArray ( value ) ) {
194
191
const ParseObject = CoreManager . getParseObject ( ) ;
195
- const toAdd = [ ] ;
192
+ const toAdd : any [ ] = [ ] ;
196
193
this . _value . forEach ( v => {
197
194
if ( v instanceof ParseObject ) {
198
195
if ( ! arrayContainsObject ( value , v ) ) {
@@ -301,7 +298,7 @@ export class RemoveOp extends Op {
301
298
}
302
299
303
300
export class RelationOp extends Op {
304
- _targetClassName : ? string ;
301
+ _targetClassName : string | null ;
305
302
relationsToAdd : Array < string > ;
306
303
relationsToRemove : Array < string > ;
307
304
@@ -340,7 +337,7 @@ export class RelationOp extends Op {
340
337
return obj . id ;
341
338
}
342
339
343
- applyTo ( value : any , parent : ParseObject , key ?: string ) : ? ParseRelation {
340
+ applyTo ( value : any , parent ? : ParseObject , key ?: string ) : ParseRelation {
344
341
if ( ! value ) {
345
342
if ( ! parent || ! key ) {
346
343
throw new Error (
@@ -426,17 +423,17 @@ export class RelationOp extends Op {
426
423
}
427
424
428
425
toJSON ( ) : { __op ?: string ; objects ?: any ; ops ?: any } {
429
- const idToPointer = id => {
426
+ const idToPointer = ( id : string ) => {
430
427
return {
431
428
__type : 'Pointer' ,
432
429
className : this . _targetClassName ,
433
430
objectId : id ,
434
431
} ;
435
432
} ;
436
433
437
- let adds = null ;
438
- let removes = null ;
439
- let pointers = null ;
434
+ let pointers : any = null ;
435
+ let adds : null | { __op : string ; objects : null | Pointer [ ] } = null ;
436
+ let removes : null | { __op : string ; objects : null | Pointer [ ] } = null ;
440
437
441
438
if ( this . relationsToAdd . length > 0 ) {
442
439
pointers = this . relationsToAdd . map ( idToPointer ) ;
0 commit comments