@@ -338,6 +338,8 @@ module.exports = function _ajax(method, url, data, success, error) {
338
338
try {
339
339
response = JSON . parse ( xhr . responseText ) ;
340
340
} catch ( e ) {
341
+ e . statusCode = xhr . status ;
342
+ e . responseText = xhr . responseText ;
341
343
promise . reject ( e ) ;
342
344
}
343
345
if ( response ) {
@@ -584,6 +586,25 @@ module.exports = function(AV) {
584
586
} ) . _thenRunCallbacks ( options ) ;
585
587
} ,
586
588
589
+ /**
590
+ * Makes a call to a cloud function, you can send {AV.Object} as param or a field of param; the response
591
+ * from server will also be parsed as an {AV.Object}, array of {AV.Object}, or object includes {AV.Object}
592
+ * @param {String } name The function name.
593
+ * @param {Object } data The parameters to send to the cloud function.
594
+ * @param {Object } options A Backbone-style options object.
595
+ * @return {AV.Promise } A promise that will be resolved with the result of the function.
596
+ */
597
+ rpc : function ( name , data , options ) {
598
+ if ( _ . isArray ( data ) ) {
599
+ return AV . Promise . error ( new Error ( 'Can\'t pass Array as the param of rpc function in JavaScript SDK.' ) )
600
+ . _thenRunCallbacks ( options ) ;
601
+ }
602
+
603
+ return AV . _request ( 'call' , name , null , 'POST' , AV . _encodeObjectOrArray ( data ) ) . then ( function ( resp ) {
604
+ return AV . _decode ( '' , resp ) . result ;
605
+ } ) . _thenRunCallbacks ( options ) ;
606
+ } ,
607
+
587
608
/**
588
609
* Make a call to request server date time.
589
610
* @param {Object } options A Backbone-style options object
@@ -5109,7 +5130,7 @@ module.exports = function(AV) {
5109
5130
if ( ! objectId ) {
5110
5131
var errorObject = new AV . Error ( AV . Error . OBJECT_NOT_FOUND ,
5111
5132
"Object not found." ) ;
5112
- return AV . Promise . error ( errorObject ) ;
5133
+ throw errorObject ;
5113
5134
}
5114
5135
5115
5136
var self = this ;
@@ -7031,7 +7052,7 @@ module.exports = function(AV) {
7031
7052
if ( options && options . error ) {
7032
7053
options . error ( this , error ) ;
7033
7054
}
7034
- return AV . Promise . error ( error ) ;
7055
+ throw error ;
7035
7056
}
7036
7057
7037
7058
var password = ( attrs && attrs . password ) || this . get ( "password" ) ;
@@ -7042,7 +7063,7 @@ module.exports = function(AV) {
7042
7063
if ( options && options . error ) {
7043
7064
options . error ( this , error ) ;
7044
7065
}
7045
- return AV . Promise . error ( error ) ;
7066
+ throw error ;
7046
7067
}
7047
7068
7048
7069
return this . save ( attrs , filterOutCallbacks ( options ) ) . then ( function ( model ) {
@@ -7084,7 +7105,7 @@ module.exports = function(AV) {
7084
7105
if ( options && options . error ) {
7085
7106
options . error ( this , error ) ;
7086
7107
}
7087
- return AV . Promise . error ( error ) ;
7108
+ throw error ;
7088
7109
}
7089
7110
7090
7111
var smsCode = ( attrs && attrs . smsCode ) || this . get ( "smsCode" ) ;
@@ -7096,7 +7117,7 @@ module.exports = function(AV) {
7096
7117
if ( options && options . error ) {
7097
7118
options . error ( this , error ) ;
7098
7119
}
7099
- return AV . Promise . error ( error ) ;
7120
+ throw error ;
7100
7121
}
7101
7122
7102
7123
var newOptions = filterOutCallbacks ( options ) ;
@@ -7232,7 +7253,15 @@ module.exports = function(AV) {
7232
7253
/**
7233
7254
* @see AV.Object#fetch
7234
7255
*/
7235
- fetch : function ( fetchOptions , options ) {
7256
+ fetch : function ( ) {
7257
+ var options = null ;
7258
+ var fetchOptions = { } ;
7259
+ if ( arguments . length === 1 ) {
7260
+ options = arguments [ 0 ] ;
7261
+ } else if ( arguments . length === 2 ) {
7262
+ fetchOptions = arguments [ 0 ] ;
7263
+ options = arguments [ 1 ] ;
7264
+ }
7236
7265
return AV . Object . prototype . fetch . call ( this , fetchOptions , { } )
7237
7266
. then ( function ( model ) {
7238
7267
return model . _handleSaveResult ( false ) . then ( function ( ) {
@@ -7517,9 +7546,9 @@ module.exports = function(AV) {
7517
7546
* logged in user using <code>current</code>.
7518
7547
*
7519
7548
* <p>Calls options.success or options.error on completion.</p>
7520
- *
7549
+ *
7521
7550
* @param {Object } data The response json data returned from third party token.
7522
- * @param {string } platform Available platform for sign up.
7551
+ * @param {string } platform Available platform for sign up.
7523
7552
* @param {Object } [callback] An object that has an optional success function, that takes no arguments and will be called on a successful puSH. and an error function that takes a AV.Error and will be called if the push failed.
7524
7553
* @return {AV.Promise } A promise that is fulfilled with the user when
7525
7554
* the login completes.
@@ -8141,6 +8170,7 @@ module.exports = function(AV) {
8141
8170
route !== "files" &&
8142
8171
route !== "date" &&
8143
8172
route !== "functions" &&
8173
+ route !== "call" &&
8144
8174
route !== "login" &&
8145
8175
route !== "push" &&
8146
8176
route !== "search/select" &&
@@ -8391,6 +8421,26 @@ module.exports = function(AV) {
8391
8421
return value ;
8392
8422
} ;
8393
8423
8424
+ AV . _encodeObjectOrArray = function ( value ) {
8425
+ var encodeAVObject = function ( object ) {
8426
+ if ( object && object . _toFullJSON ) {
8427
+ object = object . _toFullJSON ( [ ] ) ;
8428
+ }
8429
+
8430
+ return _ . mapObject ( object , function ( value ) {
8431
+ return AV . _encode ( value , [ ] ) ;
8432
+ } ) ;
8433
+ } ;
8434
+
8435
+ if ( _ . isArray ( value ) ) {
8436
+ return value . map ( function ( object ) {
8437
+ return encodeAVObject ( object ) ;
8438
+ } ) ;
8439
+ } else {
8440
+ return encodeAVObject ( value ) ;
8441
+ }
8442
+ } ;
8443
+
8394
8444
AV . _arrayEach = AV . _ . each ;
8395
8445
8396
8446
/**
@@ -8464,7 +8514,7 @@ module.exports = function(AV) {
8464
8514
} , { "./browserify-wrapper/ajax" :4 , "_process" :29 , "underscore" :30 } ] , 26 :[ function ( require , module , exports ) {
8465
8515
'use strict' ;
8466
8516
8467
- module . exports = "js1.0.0-rc6 " ;
8517
+ module . exports = "js1.0.0-rc7 " ;
8468
8518
8469
8519
} , { } ] , 27 :[ function ( require , module , exports ) {
8470
8520
0 commit comments