|
1 | 1 | (function(root) { |
2 | 2 | root.AV = root.AV || {}; |
3 | | - root.AV.VERSION = "js0.5.4"; |
| 3 | + root.AV.VERSION = "js0.5.5"; |
4 | 4 | }(this)); |
5 | 5 |
|
6 | 6 | // Underscore.js 1.4.4 |
|
1623 | 1623 | route !== "cloudQuery" && |
1624 | 1624 | route !== "qiniu" && |
1625 | 1625 | route !== "statuses" && |
| 1626 | + route !== "bigquery" && |
1626 | 1627 | route !== 'search/select' && |
1627 | 1628 | route !== 'subscribe/statuses/count' && |
1628 | 1629 | route !== 'subscribe/statuses' && |
|
3410 | 3411 | * </p> |
3411 | 3412 | */ |
3412 | 3413 | AV.Relation = function(parent, key) { |
| 3414 | + if (! _.isString(key)) { |
| 3415 | + throw TypeError('key must be a string'); |
| 3416 | + } |
3413 | 3417 | this.parent = parent; |
3414 | 3418 | this.key = key; |
3415 | 3419 | this.targetClassName = null; |
|
3548 | 3552 |
|
3549 | 3553 | _.extend(AV.Promise, /** @lends AV.Promise */ { |
3550 | 3554 |
|
3551 | | - _isPromisesAPlusCompliant: false, |
| 3555 | + _isPromisesAPlusCompliant: true, |
3552 | 3556 |
|
3553 | 3557 | /** |
3554 | 3558 | * Returns true iff the given object fulfils the Promise interface. |
|
4449 | 4453 |
|
4450 | 4454 | AV.File.prototype = { |
4451 | 4455 |
|
| 4456 | + toJSON: function() { |
| 4457 | + return AV._encode(this); |
| 4458 | + }, |
| 4459 | + |
4452 | 4460 | /** |
4453 | 4461 | * Returns the ACL for this file. |
4454 | 4462 | * @returns {AV.ACL} An instance of AV.ACL. |
|
7501 | 7509 | * @param {Object} options A Backbone-style options object. |
7502 | 7510 | */ |
7503 | 7511 | get: function(objectId, options) { |
| 7512 | + if(!objectId) { |
| 7513 | + var errorObject = new AV.Error(AV.Error.OBJECT_NOT_FOUND, |
| 7514 | + "Object not found."); |
| 7515 | + return AV.Promise.error(errorObject); |
| 7516 | + } |
| 7517 | + |
7504 | 7518 | var self = this; |
7505 | 7519 | self.equalTo('objectId', objectId); |
7506 | 7520 |
|
7507 | 7521 | return self.first().then(function(response) { |
7508 | | - if (response) { |
| 7522 | + if (!AV._.isEmpty(response)) { |
7509 | 7523 | return response; |
7510 | 7524 | } |
7511 | 7525 |
|
|
9023 | 9037 | } |
9024 | 9038 | }); |
9025 | 9039 | })(this); |
| 9040 | + |
| 9041 | +(function(root) { |
| 9042 | + root.AV = root.AV || {}; |
| 9043 | + var AV = root.AV; |
| 9044 | + var _ = AV._; |
| 9045 | + |
| 9046 | + /** |
| 9047 | + * @namespace 包含了使用了 LeanCloud |
| 9048 | + * <a href='/docs/bigquery_guide.html'>离线数据分析功能</a>的函数。 |
| 9049 | + * <p><strong><em> |
| 9050 | + * 部分函数仅在云引擎运行环境下有效。 |
| 9051 | + * </em></strong></p> |
| 9052 | + */ |
| 9053 | + AV.BigQuery = AV.BigQuery || {}; |
| 9054 | + |
| 9055 | + _.extend(AV.BigQuery, /** @lends AV.BigQuery */ { |
| 9056 | + |
| 9057 | + /** |
| 9058 | + * 开始一个 BigQuery 任务。结果里将返回 Job id,你可以拿得到的 id 使用 |
| 9059 | + * AV.BigQuery.JobQuery 查询任务状态和结果。 |
| 9060 | + * @param {Object} jobConfig 任务配置的 JSON 对象,例如:<code><pre> |
| 9061 | + * { "sql" : "select count(*) as c,gender from _User group by gender", |
| 9062 | + * "saveAs": { |
| 9063 | + * "className" : "UserGender", |
| 9064 | + * "limit": 1 |
| 9065 | + * } |
| 9066 | + * } |
| 9067 | + * </pre></code> |
| 9068 | + * sql 指定任务执行的 SQL 语句, saveAs(可选) 指定将结果保存在哪张表里,limit 最大 1000。 |
| 9069 | + * @param {Object} options A Backbone-style options object |
| 9070 | + * options.success, if set, should be a function to handle a successful |
| 9071 | + * call to a cloud function. options.error should be a function that |
| 9072 | + * handles an error running the cloud function. Both functions are |
| 9073 | + * optional. Both functions take a single argument. |
| 9074 | + * @return {AV.Promise} A promise that will be resolved with the result |
| 9075 | + * of the function. |
| 9076 | + */ |
| 9077 | + startJob: function(jobConfig, options) { |
| 9078 | + if(!jobConfig || !jobConfig.sql) { |
| 9079 | + throw new Error('Please provide the sql to run the job.'); |
| 9080 | + } |
| 9081 | + var data = { |
| 9082 | + jobConfig: jobConfig, |
| 9083 | + appId: AV.applicationId |
| 9084 | + } |
| 9085 | + var request = AV._request("bigquery", 'jobs', null, 'POST', |
| 9086 | + AV._encode(data, null, true)); |
| 9087 | + |
| 9088 | + return request.then(function(resp) { |
| 9089 | + return AV._decode(null, resp).id; |
| 9090 | + })._thenRunCallbacks(options); |
| 9091 | + }, |
| 9092 | + |
| 9093 | + /** |
| 9094 | + * 监听 BigQuery 任务事件,目前仅支持 end 事件,表示任务完成。 |
| 9095 | + * <p><strong><em> |
| 9096 | + * 仅在云引擎运行环境下有效。 |
| 9097 | + * </em></strong></p> |
| 9098 | + * @param {String} event 监听的事件,目前仅支持 'end' ,表示任务完成 |
| 9099 | + * @param {Function} 监听回调函数,接收 (err, id) 两个参数,err 表示错误信息, |
| 9100 | + * id 表示任务 id。接下来你可以拿这个 id 使用AV.BigQuery.JobQuery 查询任务状态和结果。 |
| 9101 | + * |
| 9102 | + */ |
| 9103 | + on: function(event, cb) { |
| 9104 | + } |
| 9105 | + }); |
| 9106 | + |
| 9107 | + /** |
| 9108 | + * 创建一个对象,用于查询 BigQuery 任务状态和结果。 |
| 9109 | + * @class |
| 9110 | + * @param {String} id 任务 id |
| 9111 | + * @since 0.5.5 |
| 9112 | + */ |
| 9113 | + AV.BigQuery.JobQuery = function(id, className) { |
| 9114 | + if(!id) { |
| 9115 | + throw new Error('Please provide the job id.'); |
| 9116 | + } |
| 9117 | + this.id = id; |
| 9118 | + this.className = className; |
| 9119 | + this._skip = 0; |
| 9120 | + this._limit = 100; |
| 9121 | + }; |
| 9122 | + |
| 9123 | + AV.BigQuery.JobQuery.prototype = { |
| 9124 | + |
| 9125 | + /** |
| 9126 | + * Sets the number of results to skip before returning any results. |
| 9127 | + * This is useful for pagination. |
| 9128 | + * Default is to skip zero results. |
| 9129 | + * @param {Number} n the number of results to skip. |
| 9130 | + * @return {AV.Query} Returns the query, so you can chain this call. |
| 9131 | + */ |
| 9132 | + skip: function(n) { |
| 9133 | + this._skip = n; |
| 9134 | + return this; |
| 9135 | + }, |
| 9136 | + |
| 9137 | + /** |
| 9138 | + * Sets the limit of the number of results to return. The default limit is |
| 9139 | + * 100, with a maximum of 1000 results being returned at a time. |
| 9140 | + * @param {Number} n the number of results to limit to. |
| 9141 | + * @return {AV.Query} Returns the query, so you can chain this call. |
| 9142 | + */ |
| 9143 | + limit: function(n) { |
| 9144 | + this._limit = n; |
| 9145 | + return this; |
| 9146 | + }, |
| 9147 | + |
| 9148 | + /** |
| 9149 | + * 查询任务状态和结果,任务结果为一个 JSON 对象,包括 status 表示任务状态, totalCount 表示总数, |
| 9150 | + * results 数组表示任务结果数组,previewCount 表示可以返回的结果总数,任务的开始和截止时间 |
| 9151 | + * startTime、endTime 等信息。 |
| 9152 | + * |
| 9153 | + * @param {Object} options A Backbone-style options object |
| 9154 | + * options.success, if set, should be a function to handle a successful |
| 9155 | + * call to a cloud function. options.error should be a function that |
| 9156 | + * handles an error running the cloud function. Both functions are |
| 9157 | + * optional. Both functions take a single argument. |
| 9158 | + * @return {AV.Promise} A promise that will be resolved with the result |
| 9159 | + * of the function. |
| 9160 | + * |
| 9161 | + */ |
| 9162 | + find: function(options) { |
| 9163 | + var params = { |
| 9164 | + skip: this._skip, |
| 9165 | + limit: this._limit |
| 9166 | + }; |
| 9167 | + |
| 9168 | + var request = AV._request("bigquery", 'jobs', this.id, "GET", |
| 9169 | + params); |
| 9170 | + var self = this; |
| 9171 | + return request.then(function(response) { |
| 9172 | + if(response.error) { |
| 9173 | + return AV.Promise.error(new AV.Error(response.code, response.error)); |
| 9174 | + } |
| 9175 | + return AV.Promise.as(response); |
| 9176 | + })._thenRunCallbacks(options); |
| 9177 | + } |
| 9178 | + |
| 9179 | + }; |
| 9180 | + |
| 9181 | +}(this)); |
0 commit comments