Skip to content

Commit 2bbcb24

Browse files
committed
Merge pull request #41 from leancloud/feature/v0.4.6
Feature/v0.4.6
2 parents 3b0b8eb + 1ea389a commit 2bbcb24

File tree

5 files changed

+139
-10
lines changed

5 files changed

+139
-10
lines changed

lib/av.js

Lines changed: 110 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* AVOSCloud JavaScript SDK
3-
* Version: 0.4.5
3+
* Version: 0.4.6
44
* Built: Mon Jun 03 2013 13:45:00
55
* http://avoscloud.com
66
*
@@ -13,7 +13,7 @@
1313
*/
1414
(function(root) {
1515
root.AV = root.AV || {};
16-
root.AV.VERSION = "js0.4.5";
16+
root.AV.VERSION = "js0.4.6";
1717
}(this));
1818
// Underscore.js 1.4.4
1919
// http://underscorejs.org
@@ -1364,7 +1364,6 @@
13641364
* This method is for AV's own private use.
13651365
* @param {String} applicationId Your AV Application ID.
13661366
* @param {String} applicationKey Your AV Application Key
1367-
13681367
*/
13691368
AV._initialize = function(applicationId, applicationKey, masterKey) {
13701369
AV.applicationId = applicationId;
@@ -1373,6 +1372,21 @@
13731372
AV._useMasterKey = false;
13741373
};
13751374

1375+
1376+
/**
1377+
* Call this method to set production environment variable.
1378+
* @param {Boolean} production, true is production environment,and
1379+
* it's true by default.
1380+
*/
1381+
AV.setProduction = function(production){
1382+
if(!AV._isNullOrUndefined(production)) {
1383+
//make sure it's a number
1384+
production = production ? 1 : 0;
1385+
}
1386+
//default is 1
1387+
AV.applicationProduction = AV._isNullOrUndefined(production) ? 1: production;
1388+
}
1389+
13761390
// If we're running in node.js, allow using the master key.
13771391
if (AV._isNode) {
13781392
AV.initialize = AV._initialize;
@@ -1626,6 +1640,9 @@
16261640

16271641
dataObject._ApplicationId = AV.applicationId;
16281642
dataObject._ApplicationKey = AV.applicationKey;
1643+
if(!AV._isNullOrUndefined(AV.applicationProduction)) {
1644+
dataObject._ApplicationProduction = AV.applicationProduction;
1645+
}
16291646
if(AV._useMasterKey)
16301647
dataObject._MasterKey = AV.masterKey;
16311648
dataObject._ClientVersion = AV.VERSION;
@@ -1717,7 +1734,7 @@
17171734
return value.toJSON();
17181735
}
17191736
if (value instanceof AV.File) {
1720-
if (!value.url()) {
1737+
if (!value.url() && !value.id) {
17211738
throw "Tried to save an object containing an unsaved file.";
17221739
}
17231740
return {
@@ -4128,6 +4145,7 @@
41284145
* @param {String} Optional Content-Type header to use for the file. If
41294146
* this is omitted, the content type will be inferred from the name's
41304147
* extension.
4148+
* @return {AV.File} the file object
41314149
*/
41324150
AV.File.withURL = function(name, url, metaData, type){
41334151
if(!name || !url){
@@ -4147,8 +4165,39 @@
41474165
return file;
41484166
};
41494167

4168+
/**
4169+
* Creates a file object with exists objectId.
4170+
* @param {String} The objectId string
4171+
* @return {AV.File} the file object
4172+
*/
4173+
AV.File.createWithoutData = function(objectId){
4174+
var file = new AV.File();
4175+
file.id = objectId;
4176+
return file;
4177+
};
4178+
41504179
AV.File.prototype = {
41514180

4181+
/**
4182+
* Returns the ACL for this file.
4183+
* @returns {AV.ACL} An instance of AV.ACL.
4184+
*/
4185+
getACL: function() {
4186+
return this._acl;
4187+
},
4188+
4189+
/**
4190+
* Sets the ACL to be used for this file.
4191+
* @param {AV.ACL} acl An instance of AV.ACL.
4192+
*/
4193+
setACL: function(acl) {
4194+
if(!(acl instanceof AV.ACL)) {
4195+
return new AV.Error(AV.Error.OTHER_CAUSE,
4196+
"ACL must be a AV.ACL.");
4197+
}
4198+
this._acl = acl;
4199+
},
4200+
41524201
/**
41534202
* Gets the name of the file. Before save is called, this is the filename
41544203
* given by the user. After save is called, that name gets prefixed with a
@@ -4264,6 +4313,7 @@
42644313
var key = hexOctet() + hexOctet() + hexOctet() + hexOctet();
42654314
var data = {
42664315
key: key,
4316+
ACL: self._acl,
42674317
name:self._name,
42684318
mime_type: type,
42694319
metaData: self._metaData,
@@ -4303,6 +4353,7 @@
43034353
var data = {
43044354
base64: base64,
43054355
_ContentType: type,
4356+
ACL: self._acl,
43064357
mime_type: type,
43074358
metaData: self._metaData,
43084359
};
@@ -4317,8 +4368,10 @@
43174368
});
43184369
}
43194370
} else if(self._url && self._metaData['__source'] == 'external') {
4371+
//external link file.
43204372
var data = {
43214373
name: self._name,
4374+
ACL: self._acl,
43224375
metaData: self._metaData,
43234376
mime_type: self._guessedType,
43244377
url: self._url
@@ -5680,7 +5733,7 @@
56805733
}
56815734

56825735
if (object instanceof AV.File) {
5683-
if (!object.url()) {
5736+
if (!object.url() && !object.id) {
56845737
files.push(object);
56855738
}
56865739
return;
@@ -7524,6 +7577,33 @@
75247577
return query;
75257578
};
75267579

7580+
/**
7581+
* Constructs a AV.Query that is the AND of the passed in queries. For
7582+
* example:
7583+
* <pre>var compoundQuery = AV.Query.and(query1, query2, query3);</pre>
7584+
*
7585+
* will create a compoundQuery that is an 'and' of the query1, query2, and
7586+
* query3.
7587+
* @param {...AV.Query} var_args The list of queries to AND.
7588+
* @return {AV.Query} The query that is the AND of the passed in queries.
7589+
*/
7590+
AV.Query.and = function() {
7591+
var queries = _.toArray(arguments);
7592+
var className = null;
7593+
AV._arrayEach(queries, function(q) {
7594+
if (_.isNull(className)) {
7595+
className = q.className;
7596+
}
7597+
7598+
if (className !== q.className) {
7599+
throw "All queries must be for the same class";
7600+
}
7601+
});
7602+
var query = new AV.Query(className);
7603+
query._andQuery(queries);
7604+
return query;
7605+
};
7606+
75277607
/**
75287608
* Retrieves a list of AVObjects that satisfy the CQL.
75297609
* CQL syntax please see <a href='https://cn.avoscloud.com/docs/cql_guide.html'>CQL Guide.</a>
@@ -8001,6 +8081,21 @@
80018081
return this;
80028082
},
80038083

8084+
/**
8085+
* Add constraint that both of the passed in queries matches.
8086+
* @param {Array} queries
8087+
* @return {AV.Query} Returns the query, so you can chain this call.
8088+
*/
8089+
_andQuery: function(queries) {
8090+
var queryJSON = _.map(queries, function(q) {
8091+
return q.toJSON().where;
8092+
});
8093+
8094+
this._where.$and = queryJSON;
8095+
return this;
8096+
},
8097+
8098+
80048099
/**
80058100
* Converts a string into a regex that matches it.
80068101
* Surrounding with \Q .. \E does this, we just need to escape \E's in
@@ -8925,11 +9020,19 @@
89259020
* @return {AV.Promise} A promise that will be resolved with the result
89269021
* of the function.
89279022
*/
8928-
verifySmsCode: function(code, options){
9023+
verifySmsCode: function(code, phone, options){
89299024
if(!code)
89309025
throw "Missing sms code.";
9026+
var params = {};
9027+
if(AV._.isString(phone)) {
9028+
params['mobilePhoneNumber'] = phone;
9029+
} else {
9030+
// To be compatible with old versions.
9031+
options = phone;
9032+
}
9033+
89319034
var request = AV._request("verifySmsCode", code, null, 'POST',
8932-
null);
9035+
params);
89339036
return request._thenRunCallbacks(options);
89349037
}
89359038
});

tests/file.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe("files", function() {
66
var base64 = "d29ya2luZyBhdCBhdm9zY2xvdWQgaXMgZ3JlYXQh";
77
var file = new AV.File("myfile.txt", { base64: base64 });
88
file.metaData('format', 'txt file');
9+
file.setACL(new AV.ACL());
910
file.save().then(function(){
1011
console.log(file.url());
1112
console.log(file.id);

tests/query.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ describe("Counts",function(){
288288
})
289289

290290
describe("Compound Query",function(){
291-
it("satisfy on of the conditions",function(done){
291+
it("satisfy on 'or' conditions",function(done){
292292
var lotsOfWins = new AV.Query("GameScore");
293293
lotsOfWins.greaterThan("score",150);
294294

@@ -298,7 +298,31 @@ describe("Compound Query",function(){
298298
var mainQuery = AV.Query.or(lotsOfWins, fewWins);
299299
mainQuery.find({
300300
success: function(results) {
301-
done();
301+
results.forEach(function(gs){
302+
expect(gs.get('score') > 150 || gs.get('cheatMode')).to.be.ok();
303+
});
304+
done();
305+
// results contains a list of players that either have won a lot of games or won only a few games.
306+
},
307+
error: function(error) {
308+
// There was an error.
309+
}
310+
});
311+
});
312+
it("satisfy on 'and' conditions",function(done){
313+
var lotsOfWins = new AV.Query("GameScore");
314+
lotsOfWins.greaterThan("score",150);
315+
316+
var fewWins = new AV.Query("GameScore");
317+
fewWins.equalTo("cheatMode",true);
318+
319+
var mainQuery = AV.Query.and(lotsOfWins, fewWins);
320+
mainQuery.find({
321+
success: function(results) {
322+
results.forEach(function(gs){
323+
expect(gs.get('score') > 150 && gs.get('cheatMode')).to.be.ok();
324+
});
325+
done();
302326
// results contains a list of players that either have won a lot of games or won only a few games.
303327
},
304328
error: function(error) {

tests/test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<script src="http://www.parsecdn.com/js/parse-1.2.8.min.js"></script>
2121
<script type="text/javascript">
2222
var AV=Parse;
23-
AV.initialize("9WK4a3Ju5r6pm67VcOOKfesKKfLm8XPw7vZbFwJX","fmzd7y5KRsp8LV0fx6s9YGGmsi8RuAJ3gUZcHfYf")
23+
AV.initialize("9WK4a3Ju5r6pm67VcOOKfesKKfLm8XPw7vZbFwJX","fmzd7y5KRsp8LV0fx6s9YGGmsi8RuAJ3gUZcHfYf");
2424
</script>
2525
-->
2626

tests/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ if(typeof require !="undefined"){
55
}
66
AV.serverURL="https://cn-stg1.avoscloud.com";
77
AV._initialize('mxrb5nn3qz7drek0etojy5lh4yrwjnk485lqajnsgjwfxrb5', 'd7sbus0d81mrum4tko4t8gl74b27vl0rh762ff7ngrb6ymmq', 'l0n9wu3kwnrtf2cg1b6w2l87nphzpypgff6240d0lxui2mm4');
8+
AV.setProduction(true);
89
//AV._initialize('blxzylt2g5e8l09zt875hl82nb8clydmvdjotv7ouudltkhj', 'ny0cwned258af60y6epsic72ge368zbnal4rmk7p0knu079o', 'ceotnbt1o1hpvjrr4oh8f8ykrxin973acc0b2hxi62e4f0bi');
910
//AV._initialize("a6jku4sqdxbgidzrxsy8u30evp8nltry2af4atncwg5br0qi","85gi8j21v7l5li9kquh3oy900macawjs4leyx8n788k7z4qy","5cy3lnf97bkznd9su76t05qi6zuzoygxbgtik4egsd9wtl2j");
1011
AV._useMasterKey = true;

0 commit comments

Comments
 (0)