Skip to content

Commit dafc245

Browse files
committed
chore(release): v1.3.0
1 parent ecedf63 commit dafc245

File tree

12 files changed

+169
-41
lines changed

12 files changed

+169
-41
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "leancloud-storage",
3-
"version": "1.2.1",
3+
"version": "1.3.0",
44
"homepage": "https://github.com/leancloud/javascript-sdk",
55
"authors": [
66
"LeanCloud <[email protected]>"

changelog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# 1.2.1 日期:2016 年 6 月 30 日
1+
# 1.3.0 日期:2016 年 7 月 20 日
2+
* 增加 `AV.Object.fetchAll()` 方法
3+
* 修复抛出的异常没有堆栈信息的问题
4+
* 修复在某些异常情况下,发出的请求不带域名的问题。
5+
6+
## 1.2.1 日期:2016 年 6 月 30 日
27
* 修复美国节点文件上传成功后 File 实例没有 id 的问题
38

49
# 1.2.0 日期:2016 年 6 月 29 日

dist/av-es6.js

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4652,8 +4652,9 @@ const _ = require('underscore');
46524652

46534653
// Class used for all objects passed to error callbacks
46544654
function AVError(code, message) {
4655-
this.code = code;
4656-
this.message = message;
4655+
const error = new Error(message);
4656+
error.code = code;
4657+
return error;
46574658
}
46584659

46594660
_.extend(AVError, {
@@ -6132,7 +6133,7 @@ const AVError = require('./error');
61326133
*/
61336134
AV.Error = (...args) => {
61346135
console.warn('AV.Error() is deprecated, and will be removed in next release.');
6135-
new AVError(...args);
6136+
return new AVError(...args);
61366137
};
61376138

61386139
},{"./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){
@@ -6441,6 +6442,42 @@ module.exports = function(AV) {
64416442
return AV.Object._deepSaveAsync(list, null, options)._thenRunCallbacks(options);
64426443
};
64436444

6445+
/**
6446+
* Fetch the given list of AV.Object.
6447+
*
6448+
* @param {AV.Object[]} objects A list of <code>AV.Object</code>
6449+
* @param {Object} options
6450+
* @param {String} options.sessionToken specify user's session, used in LeanEngine.
6451+
* @return {Promise.<AV.Object[]>} The given list of <code>AV.Object</code>, updated
6452+
*/
6453+
6454+
AV.Object.fetchAll = (objects, options) =>
6455+
AV.Promise.as().then(() =>
6456+
AVRequest('batch', null, null, 'POST', {
6457+
requests: _.map(objects, object => {
6458+
if (!object.className) throw new Error('object must have className to fetch');
6459+
if (!object.id) throw new Error('object must have id to fetch');
6460+
if (object.dirty()) throw new Error('object is modified but not saved');
6461+
return {
6462+
method: 'GET',
6463+
path: `/1.1/classes/${object.className}/${object.id}`,
6464+
};
6465+
}),
6466+
}, options && options.sessionToken)
6467+
).then(function(response) {
6468+
_.forEach(objects, function(object, i) {
6469+
if (response[i].success) {
6470+
object._finishFetch(
6471+
object.parse(response[i].success));
6472+
} else {
6473+
const error = new Error(response[i].error.error);
6474+
error.code = response[i].error.code;
6475+
throw error;
6476+
}
6477+
});
6478+
return objects;
6479+
});
6480+
64446481
// Attach all inheritable methods to the AV.Object prototype.
64456482
_.extend(AV.Object.prototype, AV.Events,
64466483
/** @lends AV.Object.prototype */ {
@@ -6900,7 +6937,7 @@ module.exports = function(AV) {
69006937
* @param {Object} options A set of Backbone-like options for the set.
69016938
* The only supported options are <code>silent</code>,
69026939
* <code>error</code>, and <code>promise</code>.
6903-
* @return {Boolean} true if the set succeeded.
6940+
* @return {AV.Object} self if succeeded, false if the value is not valid.
69046941
* @see AV.Object#validate
69056942
* @see AVError
69066943
*/
@@ -7584,7 +7621,7 @@ module.exports = function(AV) {
75847621
};
75857622
/**
75867623
* Delete objects in batch.The objects className must be the same.
7587-
* @param {Array} The ParseObject array to be deleted.
7624+
* @param {Array} The <code>AV.Object</code> array to be deleted.
75887625
* @param {Object} options Standard options object with success and error
75897626
* callbacks.
75907627
* @return {AV.Promise} A promise that is fulfilled when the save
@@ -10316,7 +10353,7 @@ const createApiUrl = (route, className, objectId, method, dataObject) => {
1031610353
console.warn('Please use AV._config.APIServerURL to replace AV.serverURL, and it is an internal interface.');
1031710354
}
1031810355

10319-
let apiURL = AV._config.APIServerURL;
10356+
let apiURL = AV._config.APIServerURL || API_HOST.cn;
1032010357

1032110358
if (apiURL.charAt(apiURL.length - 1) !== '/') {
1032210359
apiURL += '/';
@@ -10413,6 +10450,11 @@ const refreshServerUrlByRouter = () => {
1041310450
setServerUrl(servers.api_server);
1041410451
return cacheServerURL(servers.api_server, servers.ttl);
1041510452
}
10453+
}, error => {
10454+
// bypass all non-4XX errors
10455+
if (error.statusCode >= 400 && error.statusCode < 500) {
10456+
throw error;
10457+
}
1041610458
});
1041710459
};
1041810460

@@ -10427,14 +10469,13 @@ const setServerUrlByRegion = (region = 'cn') => {
1042710469
Cache.getAsync('APIServerURL').then((serverURL) => {
1042810470
if (serverURL) {
1042910471
setServerUrl(serverURL);
10430-
getServerURLPromise.resolve();
1043110472
} else {
1043210473
return refreshServerUrlByRouter();
1043310474
}
1043410475
}).then(() => {
1043510476
getServerURLPromise.resolve();
10436-
}).catch(() => {
10437-
getServerURLPromise.reject();
10477+
}).catch((error) => {
10478+
getServerURLPromise.reject(error);
1043810479
});
1043910480
} else {
1044010481
AV._config.region = region;
@@ -10461,7 +10502,7 @@ const AVRequest = (route, className, objectId, method, dataObject = {}, sessionT
1046110502

1046210503
checkRouter(route);
1046310504

10464-
return getServerURLPromise.always(() => {
10505+
return getServerURLPromise.then(() => {
1046510506
const apiURL = createApiUrl(route, className, objectId, method, dataObject);
1046610507
return setHeaders(sessionToken).then(
1046710508
headers => ajax(method, apiURL, dataObject, headers)
@@ -13119,7 +13160,7 @@ module.exports = {
1311913160
* Each engineer has a duty to keep the code elegant
1312013161
**/
1312113162

13122-
module.exports = 'js1.2.1';
13163+
module.exports = 'js1.3.0';
1312313164

1312413165
},{}]},{},[28])(28)
1312513166
});

dist/av-min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av.js

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});

dist/node/error.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ var _ = require('underscore');
99

1010
// Class used for all objects passed to error callbacks
1111
function AVError(code, message) {
12-
this.code = code;
13-
this.message = message;
12+
var error = new Error(message);
13+
error.code = code;
14+
return error;
1415
}
1516

1617
_.extend(AVError, {

dist/node/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ AV.Error = function () {
5353
}
5454

5555
console.warn('AV.Error() is deprecated, and will be removed in next release.');
56-
new (Function.prototype.bind.apply(AVError, [null].concat(args)))();
56+
return new (Function.prototype.bind.apply(AVError, [null].concat(args)))();
5757
};

dist/node/object.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,42 @@ module.exports = function (AV) {
117117
return AV.Object._deepSaveAsync(list, null, options)._thenRunCallbacks(options);
118118
};
119119

120+
/**
121+
* Fetch the given list of AV.Object.
122+
*
123+
* @param {AV.Object[]} objects A list of <code>AV.Object</code>
124+
* @param {Object} options
125+
* @param {String} options.sessionToken specify user's session, used in LeanEngine.
126+
* @return {Promise.<AV.Object[]>} The given list of <code>AV.Object</code>, updated
127+
*/
128+
129+
AV.Object.fetchAll = function (objects, options) {
130+
return AV.Promise.as().then(function () {
131+
return AVRequest('batch', null, null, 'POST', {
132+
requests: _.map(objects, function (object) {
133+
if (!object.className) throw new Error('object must have className to fetch');
134+
if (!object.id) throw new Error('object must have id to fetch');
135+
if (object.dirty()) throw new Error('object is modified but not saved');
136+
return {
137+
method: 'GET',
138+
path: '/1.1/classes/' + object.className + '/' + object.id
139+
};
140+
})
141+
}, options && options.sessionToken);
142+
}).then(function (response) {
143+
_.forEach(objects, function (object, i) {
144+
if (response[i].success) {
145+
object._finishFetch(object.parse(response[i].success));
146+
} else {
147+
var error = new Error(response[i].error.error);
148+
error.code = response[i].error.code;
149+
throw error;
150+
}
151+
});
152+
return objects;
153+
});
154+
};
155+
120156
// Attach all inheritable methods to the AV.Object prototype.
121157
_.extend(AV.Object.prototype, AV.Events,
122158
/** @lends AV.Object.prototype */{
@@ -574,7 +610,7 @@ module.exports = function (AV) {
574610
* @param {Object} options A set of Backbone-like options for the set.
575611
* The only supported options are <code>silent</code>,
576612
* <code>error</code>, and <code>promise</code>.
577-
* @return {Boolean} true if the set succeeded.
613+
* @return {AV.Object} self if succeeded, false if the value is not valid.
578614
* @see AV.Object#validate
579615
* @see AVError
580616
*/
@@ -1249,7 +1285,7 @@ module.exports = function (AV) {
12491285
};
12501286
/**
12511287
* Delete objects in batch.The objects className must be the same.
1252-
* @param {Array} The ParseObject array to be deleted.
1288+
* @param {Array} The <code>AV.Object</code> array to be deleted.
12531289
* @param {Object} options Standard options object with success and error
12541290
* callbacks.
12551291
* @return {AV.Promise} A promise that is fulfilled when the save

0 commit comments

Comments
 (0)