1- /**
2- * @flow
3- */
4-
51import arrayContainsObject from './arrayContainsObject' ;
62import decode from './decode' ;
73import encode from './encode' ;
84import CoreManager from './CoreManager' ;
95import type ParseObject from './ParseObject' ;
6+ import type Pointer from './ParseObject' ;
107import ParseRelation from './ParseRelation' ;
118import unique from './unique' ;
129
13- export function opFromJSON ( json : { [ key : string ] : any } ) : ? Op {
10+ export function opFromJSON ( json : { [ key : string ] : any } ) : Op | null {
1411 if ( ! json || ! json . __op ) {
1512 return null ;
1613 }
@@ -58,12 +55,12 @@ export function opFromJSON(json: { [key: string]: any }): ?Op {
5855export class Op {
5956 // Empty parent class
6057 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 */
6360}
6461
6562export class SetOp extends Op {
66- _value : ? any ;
63+ _value : any ;
6764
6865 constructor ( value : any ) {
6966 super ( ) ;
@@ -78,7 +75,7 @@ export class SetOp extends Op {
7875 return new SetOp ( this . _value ) ;
7976 }
8077
81- toJSON ( offline ?: boolean ) {
78+ toJSON ( offline ?: boolean ) : any {
8279 return encode ( this . _value , false , true , undefined , offline ) ;
8380 }
8481}
@@ -108,7 +105,7 @@ export class IncrementOp extends Op {
108105 this . _amount = amount ;
109106 }
110107
111- applyTo ( value : ? any ) : number {
108+ applyTo ( value : any ) : number {
112109 if ( typeof value === 'undefined' ) {
113110 return this . _amount ;
114111 }
@@ -192,7 +189,7 @@ export class AddUniqueOp extends Op {
192189 }
193190 if ( Array . isArray ( value ) ) {
194191 const ParseObject = CoreManager . getParseObject ( ) ;
195- const toAdd = [ ] ;
192+ const toAdd : any [ ] = [ ] ;
196193 this . _value . forEach ( v => {
197194 if ( v instanceof ParseObject ) {
198195 if ( ! arrayContainsObject ( value , v ) ) {
@@ -301,7 +298,7 @@ export class RemoveOp extends Op {
301298}
302299
303300export class RelationOp extends Op {
304- _targetClassName : ? string ;
301+ _targetClassName : string | null ;
305302 relationsToAdd : Array < string > ;
306303 relationsToRemove : Array < string > ;
307304
@@ -340,7 +337,7 @@ export class RelationOp extends Op {
340337 return obj . id ;
341338 }
342339
343- applyTo ( value : any , parent : ParseObject , key ?: string ) : ? ParseRelation {
340+ applyTo ( value : any , parent ? : ParseObject , key ?: string ) : ParseRelation {
344341 if ( ! value ) {
345342 if ( ! parent || ! key ) {
346343 throw new Error (
@@ -426,17 +423,17 @@ export class RelationOp extends Op {
426423 }
427424
428425 toJSON ( ) : { __op ?: string ; objects ?: any ; ops ?: any } {
429- const idToPointer = id => {
426+ const idToPointer = ( id : string ) => {
430427 return {
431428 __type : 'Pointer' ,
432429 className : this . _targetClassName ,
433430 objectId : id ,
434431 } ;
435432 } ;
436433
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 ;
440437
441438 if ( this . relationsToAdd . length > 0 ) {
442439 pointers = this . relationsToAdd . map ( idToPointer ) ;
0 commit comments