@@ -136,8 +136,12 @@ class ParseObject {
136136 options = attributes as any ;
137137 }
138138 }
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+ }
141145 }
142146 }
143147
@@ -733,9 +737,9 @@ class ParseObject {
733737 * @param {(string|object) } value The value to give it.
734738 * @param {object } options A set of options for the set.
735739 * 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 .
737741 */
738- set ( key : any , value ?: any , options ?: any ) : ParseObject | boolean {
742+ set ( key : any , value ?: any , options ?: any ) : this {
739743 let changes = { } ;
740744 const newOps = { } ;
741745 if ( key && typeof key === 'object' ) {
@@ -804,12 +808,9 @@ class ParseObject {
804808
805809 // Validate changes
806810 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 ;
813814 }
814815 }
815816
@@ -831,9 +832,9 @@ class ParseObject {
831832 *
832833 * @param {string } attr The string name of an attribute.
833834 * @param options
834- * @returns {(ParseObject | boolean) }
835+ * @returns {Parse.Object } Returns the object, so you can chain this call.
835836 */
836- unset ( attr : string , options ?: { [ opt : string ] : any } ) : ParseObject | boolean {
837+ unset ( attr : string , options ?: { [ opt : string ] : any } ) : this {
837838 options = options || { } ;
838839 options . unset = true ;
839840 return this . set ( attr , null , options ) ;
@@ -845,9 +846,9 @@ class ParseObject {
845846 *
846847 * @param attr {String} The key.
847848 * @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.
849850 */
850- increment ( attr : string , amount ?: number ) : ParseObject | boolean {
851+ increment ( attr : string , amount ?: number ) : this {
851852 if ( typeof amount === 'undefined' ) {
852853 amount = 1 ;
853854 }
@@ -863,9 +864,9 @@ class ParseObject {
863864 *
864865 * @param attr {String} The key.
865866 * @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.
867868 */
868- decrement ( attr : string , amount ?: number ) : ParseObject | boolean {
869+ decrement ( attr : string , amount ?: number ) : this {
869870 if ( typeof amount === 'undefined' ) {
870871 amount = 1 ;
871872 }
@@ -881,9 +882,9 @@ class ParseObject {
881882 *
882883 * @param attr {String} The key.
883884 * @param item { } The item to add.
884- * @returns {(ParseObject | boolean) }
885+ * @returns {Parse.Object } Returns the object, so you can chain this call.
885886 */
886- add ( attr : string , item : any ) : ParseObject | boolean {
887+ add ( attr : string , item : any ) : this {
887888 return this . set ( attr , new AddOp ( [ item ] ) ) ;
888889 }
889890
@@ -893,9 +894,9 @@ class ParseObject {
893894 *
894895 * @param attr {String} The key.
895896 * @param items {Object[]} The items to add.
896- * @returns {(ParseObject | boolean) }
897+ * @returns {Parse.Object } Returns the object, so you can chain this call.
897898 */
898- addAll ( attr : string , items : Array < any > ) : ParseObject | boolean {
899+ addAll ( attr : string , items : Array < any > ) : this {
899900 return this . set ( attr , new AddOp ( items ) ) ;
900901 }
901902
@@ -906,9 +907,9 @@ class ParseObject {
906907 *
907908 * @param attr {String} The key.
908909 * @param item { } The object to add.
909- * @returns {(ParseObject | boolean) }
910+ * @returns {Parse.Object } Returns the object, so you can chain this call.
910911 */
911- addUnique ( attr : string , item : any ) : ParseObject | boolean {
912+ addUnique ( attr : string , item : any ) : this {
912913 return this . set ( attr , new AddUniqueOp ( [ item ] ) ) ;
913914 }
914915
@@ -919,9 +920,9 @@ class ParseObject {
919920 *
920921 * @param attr {String} The key.
921922 * @param items {Object[]} The objects to add.
922- * @returns {(ParseObject | boolean) }
923+ * @returns {Parse.Object } Returns the object, so you can chain this call.
923924 */
924- addAllUnique ( attr : string , items : Array < any > ) : ParseObject | boolean {
925+ addAllUnique ( attr : string , items : Array < any > ) : this {
925926 return this . set ( attr , new AddUniqueOp ( items ) ) ;
926927 }
927928
@@ -931,9 +932,9 @@ class ParseObject {
931932 *
932933 * @param attr {String} The key.
933934 * @param item { } The object to remove.
934- * @returns {(ParseObject | boolean) }
935+ * @returns {Parse.Object } Returns the object, so you can chain this call.
935936 */
936- remove ( attr : string , item : any ) : ParseObject | boolean {
937+ remove ( attr : string , item : any ) : this {
937938 return this . set ( attr , new RemoveOp ( [ item ] ) ) ;
938939 }
939940
@@ -943,9 +944,9 @@ class ParseObject {
943944 *
944945 * @param attr {String} The key.
945946 * @param items {Object[]} The object to remove.
946- * @returns {(ParseObject | boolean) }
947+ * @returns {Parse.Object } Returns the object, so you can chain this call.
947948 */
948- removeAll ( attr : string , items : Array < any > ) : ParseObject | boolean {
949+ removeAll ( attr : string , items : Array < any > ) : this {
949950 return this . set ( attr , new RemoveOp ( items ) ) ;
950951 }
951952
@@ -1099,7 +1100,7 @@ class ParseObject {
10991100 }
11001101 for ( const key in attrs ) {
11011102 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 } "` ) ;
11031104 }
11041105 }
11051106 return false ;
@@ -1124,10 +1125,10 @@ class ParseObject {
11241125 *
11251126 * @param {Parse.ACL } acl An instance of Parse.ACL.
11261127 * @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 .
11281129 * @see Parse.Object#set
11291130 */
1130- setACL ( acl : ParseACL , options ?: any ) : ParseObject | boolean {
1131+ setACL ( acl : ParseACL , options ?: any ) : this {
11311132 return this . set ( 'ACL' , acl , options ) ;
11321133 }
11331134
@@ -1154,9 +1155,9 @@ class ParseObject {
11541155 /**
11551156 * Clears all attributes on a model
11561157 *
1157- * @returns {(ParseObject | boolean) }
1158+ * @returns {Parse.Object } Returns the object, so you can chain this call.
11581159 */
1159- clear ( ) : ParseObject | boolean {
1160+ clear ( ) : this {
11601161 const attributes = this . attributes ;
11611162 const erasable = { } ;
11621163 let readonly = [ 'createdAt' , 'updatedAt' ] ;
@@ -1320,7 +1321,7 @@ class ParseObject {
13201321 * @returns {Promise } A promise that is fulfilled when the save
13211322 * completes.
13221323 */
1323- save (
1324+ async save (
13241325 arg1 : undefined | string | { [ attr : string ] : any } | null ,
13251326 arg2 : SaveOptions | any ,
13261327 arg3 ?: SaveOptions
@@ -1337,17 +1338,9 @@ class ParseObject {
13371338 attrs [ arg1 ] = arg2 ;
13381339 options = arg3 ;
13391340 }
1340-
13411341 options = options || { } ;
13421342 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 ) ;
13511344 }
13521345 const saveOptions = ParseObject . _getRequestOptions ( options ) ;
13531346 const controller = CoreManager . getObjectController ( ) ;
@@ -1985,7 +1978,9 @@ class ParseObject {
19851978 }
19861979
19871980 if ( attributes && typeof attributes === 'object' ) {
1988- if ( ! this . set ( attributes || { } , options ) ) {
1981+ try {
1982+ this . set ( attributes || { } , options ) ;
1983+ } catch ( _ ) {
19891984 throw new Error ( "Can't create an invalid Parse Object" ) ;
19901985 }
19911986 }
0 commit comments