|
1 | 1 | (function(root) { |
2 | 2 | root.AV = root.AV || {}; |
3 | | - root.AV.VERSION = "js0.5.5"; |
| 3 | + root.AV.VERSION = "js0.5.6"; |
4 | 4 | }(this)); |
5 | 5 |
|
6 | 6 | // Underscore.js 1.4.4 |
|
1329 | 1329 | }; |
1330 | 1330 |
|
1331 | 1331 | // Set the server for AV to talk to. |
1332 | | - AV.serverURL = "https://cn.avoscloud.com"; |
| 1332 | + AV.serverURL = "https://api.leancloud.cn"; |
1333 | 1333 |
|
1334 | 1334 | // Check whether we are running in Node.js. |
1335 | 1335 | if (typeof(process) !== "undefined" && |
|
1360 | 1360 | * @param {String} applicationKey Your AV Application Key |
1361 | 1361 | */ |
1362 | 1362 | AV._initialize = function(applicationId, applicationKey, masterKey) { |
| 1363 | + if (AV.applicationId !== undefined) { |
| 1364 | + console.warn('AVOSCloud SDK is already initialized, please don\'t reinitialize it.'); |
| 1365 | + } |
1363 | 1366 | AV.applicationId = applicationId; |
1364 | 1367 | AV.applicationKey = applicationKey; |
1365 | 1368 | AV.masterKey = masterKey; |
|
1643 | 1646 | if (objectId) { |
1644 | 1647 | url += "/" + objectId; |
1645 | 1648 | } |
1646 | | - if((route ==='users' || route === 'classes') && method === 'PUT' && dataObject._fetchWhenSave){ |
| 1649 | + if((route ==='users' || route === 'classes') && dataObject._fetchWhenSave){ |
1647 | 1650 | delete dataObject._fetchWhenSave; |
1648 | 1651 | url += '?new=true'; |
1649 | 1652 | } |
|
3552 | 3555 |
|
3553 | 3556 | _.extend(AV.Promise, /** @lends AV.Promise */ { |
3554 | 3557 |
|
3555 | | - _isPromisesAPlusCompliant: true, |
| 3558 | + _isPromisesAPlusCompliant: !AV._isNode, |
| 3559 | + _debugError: false, |
| 3560 | + |
| 3561 | + setPromisesAPlusCompliant: function(isCompliant) { |
| 3562 | + AV.Promise._isPromisesAPlusCompliant = isCompliant; |
| 3563 | + }, |
| 3564 | + |
| 3565 | + setDebugError: function(enable) { |
| 3566 | + AV.Promise._debugError = enable; |
| 3567 | + }, |
3556 | 3568 |
|
3557 | 3569 | /** |
3558 | 3570 | * Returns true iff the given object fulfils the Promise interface. |
|
3870 | 3882 | try { |
3871 | 3883 | result = [resolvedCallback.apply(this, result)]; |
3872 | 3884 | } catch (e) { |
| 3885 | + if(AV.Promise._debugError && e) { |
| 3886 | + console.error('Error occurred in promise resolve callback.', e.stack || e); |
| 3887 | + } |
3873 | 3888 | result = [AV.Promise.error(e)]; |
3874 | 3889 | } |
3875 | 3890 | } else { |
|
3894 | 3909 | try { |
3895 | 3910 | result = [rejectedCallback(error)]; |
3896 | 3911 | } catch (e) { |
| 3912 | + if(AV.Promise._debugError && e) { |
| 3913 | + console.error('Error occurred in promise reject callback.', e.stack || e); |
| 3914 | + } |
3897 | 3915 | result = [AV.Promise.error(e)]; |
3898 | 3916 | } |
3899 | 3917 | } else { |
|
3921 | 3939 | func.call(); |
3922 | 3940 | }; |
3923 | 3941 | if (AV.Promise._isPromisesAPlusCompliant) { |
3924 | | - if (typeof(setImmediate) !== 'undefined' && _.isFunction(setImmediate)) { |
3925 | | - runLater = setImmediate; |
| 3942 | + if (typeof(window) !== 'undefined' && _.isFunction(window.setImmediate)) { |
| 3943 | + runLater = function(func) { |
| 3944 | + window.setImmediate(func); |
| 3945 | + }; |
| 3946 | + } else if (typeof(process) !== 'undefined' && process.nextTick) { |
| 3947 | + runLater = function(func) { |
| 3948 | + process.nextTick(func); |
| 3949 | + }; |
3926 | 3950 | } else if (typeof(setTimeout) !== 'undefined' && _.isFunction(setTimeout)) { |
3927 | 3951 | runLater = function(func) { |
3928 | 3952 | setTimeout(func, 0); |
|
3937 | 3961 | }); |
3938 | 3962 | } else if (this._rejected) { |
3939 | 3963 | runLater(function() { |
3940 | | - wrappedRejectedCallback(self._error); |
| 3964 | + wrappedRejectedCallback.apply(self, [self._error]); |
3941 | 3965 | }); |
3942 | 3966 | } else { |
3943 | 3967 | this._resolvedCallbacks.push(wrappedResolvedCallback); |
|
5586 | 5610 |
|
5587 | 5611 | var json = model._getSaveJSON(); |
5588 | 5612 |
|
5589 | | - if(method === 'PUT' && model._fetchWhenSave){ |
| 5613 | + if(model._fetchWhenSave){ |
5590 | 5614 | //Sepcial-case fetchWhenSave when updating object. |
5591 | 5615 | json._fetchWhenSave = true; |
5592 | 5616 | } |
|
9043 | 9067 | var AV = root.AV; |
9044 | 9068 | var _ = AV._; |
9045 | 9069 |
|
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 | | - |
| 9070 | + AV.BigQuery = AV.Insight || {}; |
9181 | 9071 | }(this)); |
0 commit comments