@@ -136,8 +136,12 @@ class ParseObject {
136
136
options = attributes as any ;
137
137
}
138
138
}
139
- if ( toSet && ! this . set ( toSet , options ) ) {
140
- throw new Error ( "Can't create an invalid Parse Object" ) ;
139
+ if ( toSet ) {
140
+ try {
141
+ this . set ( toSet , options ) ;
142
+ } catch ( _ ) {
143
+ throw new Error ( "Can't create an invalid Parse Object" ) ;
144
+ }
141
145
}
142
146
}
143
147
@@ -733,9 +737,9 @@ class ParseObject {
733
737
* @param {(string|object) } value The value to give it.
734
738
* @param {object } options A set of options for the set.
735
739
* The only supported option is <code>error</code>.
736
- * @returns {(ParseObject|boolean) } true if the set succeeded .
740
+ * @returns {Parse.Object } Returns the object, so you can chain this call .
737
741
*/
738
- set ( key : any , value ?: any , options ?: any ) : ParseObject | boolean {
742
+ set ( key : any , value ?: any , options ?: any ) : this {
739
743
let changes = { } ;
740
744
const newOps = { } ;
741
745
if ( key && typeof key === 'object' ) {
@@ -804,12 +808,9 @@ class ParseObject {
804
808
805
809
// Validate changes
806
810
if ( ! options . ignoreValidation ) {
807
- const validation = this . validate ( newValues ) ;
808
- if ( validation ) {
809
- if ( typeof options . error === 'function' ) {
810
- options . error ( this , validation ) ;
811
- }
812
- return false ;
811
+ const validationError = this . validate ( newValues ) ;
812
+ if ( validationError ) {
813
+ throw validationError ;
813
814
}
814
815
}
815
816
@@ -831,9 +832,9 @@ class ParseObject {
831
832
*
832
833
* @param {string } attr The string name of an attribute.
833
834
* @param options
834
- * @returns {(ParseObject | boolean) }
835
+ * @returns {Parse.Object } Returns the object, so you can chain this call.
835
836
*/
836
- unset ( attr : string , options ?: { [ opt : string ] : any } ) : ParseObject | boolean {
837
+ unset ( attr : string , options ?: { [ opt : string ] : any } ) : this {
837
838
options = options || { } ;
838
839
options . unset = true ;
839
840
return this . set ( attr , null , options ) ;
@@ -845,9 +846,9 @@ class ParseObject {
845
846
*
846
847
* @param attr {String} The key.
847
848
* @param amount {Number} The amount to increment by (optional).
848
- * @returns {(ParseObject|boolean) }
849
+ * @returns {Parse.Object } Returns the object, so you can chain this call.
849
850
*/
850
- increment ( attr : string , amount ?: number ) : ParseObject | boolean {
851
+ increment ( attr : string , amount ?: number ) : this {
851
852
if ( typeof amount === 'undefined' ) {
852
853
amount = 1 ;
853
854
}
@@ -863,9 +864,9 @@ class ParseObject {
863
864
*
864
865
* @param attr {String} The key.
865
866
* @param amount {Number} The amount to decrement by (optional).
866
- * @returns {(ParseObject | boolean) }
867
+ * @returns {Parse.Object } Returns the object, so you can chain this call.
867
868
*/
868
- decrement ( attr : string , amount ?: number ) : ParseObject | boolean {
869
+ decrement ( attr : string , amount ?: number ) : this {
869
870
if ( typeof amount === 'undefined' ) {
870
871
amount = 1 ;
871
872
}
@@ -881,9 +882,9 @@ class ParseObject {
881
882
*
882
883
* @param attr {String} The key.
883
884
* @param item { } The item to add.
884
- * @returns {(ParseObject | boolean) }
885
+ * @returns {Parse.Object } Returns the object, so you can chain this call.
885
886
*/
886
- add ( attr : string , item : any ) : ParseObject | boolean {
887
+ add ( attr : string , item : any ) : this {
887
888
return this . set ( attr , new AddOp ( [ item ] ) ) ;
888
889
}
889
890
@@ -893,9 +894,9 @@ class ParseObject {
893
894
*
894
895
* @param attr {String} The key.
895
896
* @param items {Object[]} The items to add.
896
- * @returns {(ParseObject | boolean) }
897
+ * @returns {Parse.Object } Returns the object, so you can chain this call.
897
898
*/
898
- addAll ( attr : string , items : Array < any > ) : ParseObject | boolean {
899
+ addAll ( attr : string , items : Array < any > ) : this {
899
900
return this . set ( attr , new AddOp ( items ) ) ;
900
901
}
901
902
@@ -906,9 +907,9 @@ class ParseObject {
906
907
*
907
908
* @param attr {String} The key.
908
909
* @param item { } The object to add.
909
- * @returns {(ParseObject | boolean) }
910
+ * @returns {Parse.Object } Returns the object, so you can chain this call.
910
911
*/
911
- addUnique ( attr : string , item : any ) : ParseObject | boolean {
912
+ addUnique ( attr : string , item : any ) : this {
912
913
return this . set ( attr , new AddUniqueOp ( [ item ] ) ) ;
913
914
}
914
915
@@ -919,9 +920,9 @@ class ParseObject {
919
920
*
920
921
* @param attr {String} The key.
921
922
* @param items {Object[]} The objects to add.
922
- * @returns {(ParseObject | boolean) }
923
+ * @returns {Parse.Object } Returns the object, so you can chain this call.
923
924
*/
924
- addAllUnique ( attr : string , items : Array < any > ) : ParseObject | boolean {
925
+ addAllUnique ( attr : string , items : Array < any > ) : this {
925
926
return this . set ( attr , new AddUniqueOp ( items ) ) ;
926
927
}
927
928
@@ -931,9 +932,9 @@ class ParseObject {
931
932
*
932
933
* @param attr {String} The key.
933
934
* @param item { } The object to remove.
934
- * @returns {(ParseObject | boolean) }
935
+ * @returns {Parse.Object } Returns the object, so you can chain this call.
935
936
*/
936
- remove ( attr : string , item : any ) : ParseObject | boolean {
937
+ remove ( attr : string , item : any ) : this {
937
938
return this . set ( attr , new RemoveOp ( [ item ] ) ) ;
938
939
}
939
940
@@ -943,9 +944,9 @@ class ParseObject {
943
944
*
944
945
* @param attr {String} The key.
945
946
* @param items {Object[]} The object to remove.
946
- * @returns {(ParseObject | boolean) }
947
+ * @returns {Parse.Object } Returns the object, so you can chain this call.
947
948
*/
948
- removeAll ( attr : string , items : Array < any > ) : ParseObject | boolean {
949
+ removeAll ( attr : string , items : Array < any > ) : this {
949
950
return this . set ( attr , new RemoveOp ( items ) ) ;
950
951
}
951
952
@@ -1099,7 +1100,7 @@ class ParseObject {
1099
1100
}
1100
1101
for ( const key in attrs ) {
1101
1102
if ( ! / ^ [ A - Z a - z ] [ 0 - 9 A - Z a - z _ . ] * $ / . test ( key ) ) {
1102
- return new ParseError ( ParseError . INVALID_KEY_NAME ) ;
1103
+ return new ParseError ( ParseError . INVALID_KEY_NAME , `Invalid key name: " ${ key } "` ) ;
1103
1104
}
1104
1105
}
1105
1106
return false ;
@@ -1124,10 +1125,10 @@ class ParseObject {
1124
1125
*
1125
1126
* @param {Parse.ACL } acl An instance of Parse.ACL.
1126
1127
* @param {object } options
1127
- * @returns {(ParseObject | boolean) } Whether the set passed validation .
1128
+ * @returns {Parse.Object } Returns the object, so you can chain this call .
1128
1129
* @see Parse.Object#set
1129
1130
*/
1130
- setACL ( acl : ParseACL , options ?: any ) : ParseObject | boolean {
1131
+ setACL ( acl : ParseACL , options ?: any ) : this {
1131
1132
return this . set ( 'ACL' , acl , options ) ;
1132
1133
}
1133
1134
@@ -1154,9 +1155,9 @@ class ParseObject {
1154
1155
/**
1155
1156
* Clears all attributes on a model
1156
1157
*
1157
- * @returns {(ParseObject | boolean) }
1158
+ * @returns {Parse.Object } Returns the object, so you can chain this call.
1158
1159
*/
1159
- clear ( ) : ParseObject | boolean {
1160
+ clear ( ) : this {
1160
1161
const attributes = this . attributes ;
1161
1162
const erasable = { } ;
1162
1163
let readonly = [ 'createdAt' , 'updatedAt' ] ;
@@ -1320,7 +1321,7 @@ class ParseObject {
1320
1321
* @returns {Promise } A promise that is fulfilled when the save
1321
1322
* completes.
1322
1323
*/
1323
- save (
1324
+ async save (
1324
1325
arg1 : undefined | string | { [ attr : string ] : any } | null ,
1325
1326
arg2 : SaveOptions | any ,
1326
1327
arg3 ?: SaveOptions
@@ -1337,17 +1338,9 @@ class ParseObject {
1337
1338
attrs [ arg1 ] = arg2 ;
1338
1339
options = arg3 ;
1339
1340
}
1340
-
1341
1341
options = options || { } ;
1342
1342
if ( attrs ) {
1343
- let validationError ;
1344
- options . error = ( _ , validation ) => {
1345
- validationError = validation ;
1346
- } ;
1347
- const success = this . set ( attrs , options ) ;
1348
- if ( ! success ) {
1349
- return Promise . reject ( validationError ) ;
1350
- }
1343
+ this . set ( attrs , options ) ;
1351
1344
}
1352
1345
const saveOptions = ParseObject . _getRequestOptions ( options ) ;
1353
1346
const controller = CoreManager . getObjectController ( ) ;
@@ -1985,7 +1978,9 @@ class ParseObject {
1985
1978
}
1986
1979
1987
1980
if ( attributes && typeof attributes === 'object' ) {
1988
- if ( ! this . set ( attributes || { } , options ) ) {
1981
+ try {
1982
+ this . set ( attributes || { } , options ) ;
1983
+ } catch ( _ ) {
1989
1984
throw new Error ( "Can't create an invalid Parse Object" ) ;
1990
1985
}
1991
1986
}
0 commit comments