@@ -4623,8 +4623,9 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
46234623
46244624 // Class used for all objects passed to error callbacks
46254625 function AVError ( code , message ) {
4626- this . code = code ;
4627- this . message = message ;
4626+ var error = new Error ( message ) ;
4627+ error . code = code ;
4628+ return error ;
46284629 }
46294630
46304631 _ . extend ( AVError , {
@@ -6096,7 +6097,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
60966097 }
60976098
60986099 console . warn ( 'AV.Error() is deprecated, and will be removed in next release.' ) ;
6099- new ( Function . prototype . bind . apply ( AVError , [ null ] . concat ( args ) ) ) ( ) ;
6100+ return new ( Function . prototype . bind . apply ( AVError , [ null ] . concat ( args ) ) ) ( ) ;
61006101 } ;
61016102 } , { "./acl" : 18 , "./av" : 19 , "./cache" : 22 , "./cloudfunction" : 23 , "./error" : 24 , "./event" : 25 , "./file" : 26 , "./geopoint" : 27 , "./insight" : 29 , "./localstorage" : 30 , "./object" : 31 , "./op" : 32 , "./promise" : 33 , "./push" : 34 , "./query" : 35 , "./relation" : 36 , "./role" : 38 , "./search" : 39 , "./status" : 40 , "./user" : 44 , "./utils" : 45 , "./version" : 46 , "underscore" : 17 } ] , 29 : [ function ( require , module , exports ) {
61026103 /**
@@ -6393,6 +6394,42 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
63936394 return AV . Object . _deepSaveAsync ( list , null , options ) . _thenRunCallbacks ( options ) ;
63946395 } ;
63956396
6397+ /**
6398+ * Fetch the given list of AV.Object.
6399+ *
6400+ * @param {AV.Object[] } objects A list of <code>AV.Object</code>
6401+ * @param {Object } options
6402+ * @param {String } options.sessionToken specify user's session, used in LeanEngine.
6403+ * @return {Promise.<AV.Object[]> } The given list of <code>AV.Object</code>, updated
6404+ */
6405+
6406+ AV . Object . fetchAll = function ( objects , options ) {
6407+ return AV . Promise . as ( ) . then ( function ( ) {
6408+ return AVRequest ( 'batch' , null , null , 'POST' , {
6409+ requests : _ . map ( objects , function ( object ) {
6410+ if ( ! object . className ) throw new Error ( 'object must have className to fetch' ) ;
6411+ if ( ! object . id ) throw new Error ( 'object must have id to fetch' ) ;
6412+ if ( object . dirty ( ) ) throw new Error ( 'object is modified but not saved' ) ;
6413+ return {
6414+ method : 'GET' ,
6415+ path : "/1.1/classes/" + object . className + "/" + object . id
6416+ } ;
6417+ } )
6418+ } , options && options . sessionToken ) ;
6419+ } ) . then ( function ( response ) {
6420+ _ . forEach ( objects , function ( object , i ) {
6421+ if ( response [ i ] . success ) {
6422+ object . _finishFetch ( object . parse ( response [ i ] . success ) ) ;
6423+ } else {
6424+ var error = new Error ( response [ i ] . error . error ) ;
6425+ error . code = response [ i ] . error . code ;
6426+ throw error ;
6427+ }
6428+ } ) ;
6429+ return objects ;
6430+ } ) ;
6431+ } ;
6432+
63966433 // Attach all inheritable methods to the AV.Object prototype.
63976434 _ . extend ( AV . Object . prototype , AV . Events ,
63986435 /** @lends AV.Object.prototype */ {
@@ -6850,7 +6887,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
68506887 * @param {Object } options A set of Backbone-like options for the set.
68516888 * The only supported options are <code>silent</code>,
68526889 * <code>error</code>, and <code>promise</code>.
6853- * @return {Boolean } true if the set succeeded .
6890+ * @return {AV.Object } self if succeeded, false if the value is not valid .
68546891 * @see AV.Object#validate
68556892 * @see AVError
68566893 */
@@ -7525,7 +7562,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
75257562 } ;
75267563 /**
75277564 * Delete objects in batch.The objects className must be the same.
7528- * @param {Array } The ParseObject array to be deleted.
7565+ * @param {Array } The <code>AV.Object</code> array to be deleted.
75297566 * @param {Object } options Standard options object with success and error
75307567 * callbacks.
75317568 * @return {AV.Promise } A promise that is fulfilled when the save
@@ -10185,7 +10222,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1018510222 console . warn ( 'Please use AV._config.APIServerURL to replace AV.serverURL, and it is an internal interface.' ) ;
1018610223 }
1018710224
10188- var apiURL = AV . _config . APIServerURL ;
10225+ var apiURL = AV . _config . APIServerURL || API_HOST . cn ;
1018910226
1019010227 if ( apiURL . charAt ( apiURL . length - 1 ) !== '/' ) {
1019110228 apiURL += '/' ;
@@ -10284,6 +10321,11 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1028410321 setServerUrl ( servers . api_server ) ;
1028510322 return cacheServerURL ( servers . api_server , servers . ttl ) ;
1028610323 }
10324+ } , function ( error ) {
10325+ // bypass all non-4XX errors
10326+ if ( error . statusCode >= 400 && error . statusCode < 500 ) {
10327+ throw error ;
10328+ }
1028710329 } ) ;
1028810330 } ;
1028910331
@@ -10300,14 +10342,13 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1030010342 Cache . getAsync ( 'APIServerURL' ) . then ( function ( serverURL ) {
1030110343 if ( serverURL ) {
1030210344 setServerUrl ( serverURL ) ;
10303- getServerURLPromise . resolve ( ) ;
1030410345 } else {
1030510346 return refreshServerUrlByRouter ( ) ;
1030610347 }
1030710348 } ) . then ( function ( ) {
1030810349 getServerURLPromise . resolve ( ) ;
10309- } ) . catch ( function ( ) {
10310- getServerURLPromise . reject ( ) ;
10350+ } ) . catch ( function ( error ) {
10351+ getServerURLPromise . reject ( error ) ;
1031110352 } ) ;
1031210353 } else {
1031310354 AV . _config . region = region ;
@@ -10337,7 +10378,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1033710378
1033810379 checkRouter ( route ) ;
1033910380
10340- return getServerURLPromise . always ( function ( ) {
10381+ return getServerURLPromise . then ( function ( ) {
1034110382 var apiURL = createApiUrl ( route , className , objectId , method , dataObject ) ;
1034210383 return setHeaders ( sessionToken ) . then ( function ( headers ) {
1034310384 return ajax ( method , apiURL , dataObject , headers ) . then ( null , function ( res ) {
@@ -12916,6 +12957,6 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1291612957 * Each engineer has a duty to keep the code elegant
1291712958 **/
1291812959
12919- module . exports = 'js1.2.1 ' ;
12960+ module . exports = 'js1.3.0 ' ;
1292012961 } , { } ] } , { } , [ 28 ] ) ( 28 ) ;
1292112962} ) ;
0 commit comments