parse 4.0.0-alpha.1 → 4.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +167 -25
- package/NOTICE +10 -0
- package/README.md +6 -5
- package/dist/parse.js +12838 -21190
- package/dist/parse.min.js +7 -6
- package/dist/parse.weapp.js +7921 -17062
- package/dist/parse.weapp.min.js +7 -6
- package/lib/browser/Analytics.js +2 -27
- package/lib/browser/AnonymousUtils.js +6 -42
- package/lib/browser/Cloud.js +12 -77
- package/lib/browser/CloudCode.js +0 -3
- package/lib/browser/CoreManager.js +46 -191
- package/lib/browser/CryptoController.js +2 -16
- package/lib/browser/EventEmitter.js +1 -8
- package/lib/browser/EventuallyQueue.js +277 -824
- package/lib/browser/FacebookUtils.js +6 -42
- package/lib/browser/IndexedDBStorageController.js +3 -14
- package/lib/browser/InstallationController.js +2 -20
- package/lib/browser/LiveQueryClient.js +105 -213
- package/lib/browser/LiveQuerySubscription.js +10 -39
- package/lib/browser/LocalDatastore.js +451 -1081
- package/lib/browser/LocalDatastoreController.js +145 -602
- package/lib/browser/LocalDatastoreController.react-native.js +137 -573
- package/lib/browser/LocalDatastoreUtils.js +2 -19
- package/lib/browser/ObjectStateMutations.js +18 -121
- package/lib/browser/OfflineQuery.js +61 -222
- package/lib/browser/Parse.js +12 -115
- package/lib/browser/ParseACL.js +33 -148
- package/lib/browser/ParseCLP.js +96 -314
- package/lib/browser/ParseConfig.js +18 -95
- package/lib/browser/ParseError.js +63 -99
- package/lib/browser/ParseFile.js +128 -685
- package/lib/browser/ParseGeoPoint.js +23 -89
- package/lib/browser/ParseHooks.js +1 -34
- package/lib/browser/ParseInstallation.js +4 -32
- package/lib/browser/ParseLiveQuery.js +96 -505
- package/lib/browser/ParseObject.js +665 -1845
- package/lib/browser/ParseOp.js +41 -287
- package/lib/browser/ParsePolygon.js +13 -70
- package/lib/browser/ParseQuery.js +403 -1504
- package/lib/browser/ParseRelation.js +12 -68
- package/lib/browser/ParseRole.js +13 -75
- package/lib/browser/ParseSchema.js +49 -208
- package/lib/browser/ParseSession.js +11 -69
- package/lib/browser/ParseUser.js +274 -1127
- package/lib/browser/Push.js +7 -50
- package/lib/browser/RESTController.js +28 -157
- package/lib/browser/SingleInstanceStateController.js +19 -144
- package/lib/browser/Socket.weapp.js +0 -10
- package/lib/browser/Storage.js +10 -80
- package/lib/browser/StorageController.browser.js +4 -24
- package/lib/browser/StorageController.default.js +4 -24
- package/lib/browser/StorageController.react-native.js +6 -40
- package/lib/browser/StorageController.weapp.js +5 -23
- package/lib/browser/TaskQueue.js +1 -29
- package/lib/browser/UniqueInstanceStateController.js +19 -149
- package/lib/browser/Xhr.weapp.js +0 -17
- package/lib/browser/arrayContainsObject.js +2 -23
- package/lib/browser/canBeSerialized.js +3 -40
- package/lib/browser/decode.js +3 -40
- package/lib/browser/encode.js +9 -77
- package/lib/browser/equals.js +2 -34
- package/lib/browser/escape.js +1 -15
- package/lib/browser/isRevocableSession.js +2 -18
- package/lib/browser/parseDate.js +2 -20
- package/lib/browser/promiseUtils.js +3 -21
- package/lib/browser/unique.js +3 -24
- package/lib/browser/unsavedChildren.js +6 -57
- package/lib/browser/uuid.js +3 -1
- package/lib/node/Analytics.js +1 -25
- package/lib/node/AnonymousUtils.js +5 -44
- package/lib/node/Cloud.js +10 -73
- package/lib/node/CloudCode.js +0 -3
- package/lib/node/CoreManager.js +47 -227
- package/lib/node/CryptoController.js +2 -16
- package/lib/node/EventEmitter.js +1 -8
- package/lib/node/EventuallyQueue.js +16 -123
- package/lib/node/FacebookUtils.js +5 -44
- package/lib/node/IndexedDBStorageController.js +3 -19
- package/lib/node/InstallationController.js +2 -22
- package/lib/node/LiveQueryClient.js +72 -154
- package/lib/node/LiveQuerySubscription.js +7 -26
- package/lib/node/LocalDatastore.js +19 -182
- package/lib/node/LocalDatastoreController.js +6 -45
- package/lib/node/LocalDatastoreController.react-native.js +6 -52
- package/lib/node/LocalDatastoreUtils.js +1 -13
- package/lib/node/ObjectStateMutations.js +13 -100
- package/lib/node/OfflineQuery.js +27 -151
- package/lib/node/Parse.js +11 -108
- package/lib/node/ParseACL.js +32 -157
- package/lib/node/ParseCLP.js +69 -269
- package/lib/node/ParseConfig.js +16 -91
- package/lib/node/ParseError.js +61 -74
- package/lib/node/ParseFile.js +49 -212
- package/lib/node/ParseGeoPoint.js +21 -89
- package/lib/node/ParseHooks.js +0 -35
- package/lib/node/ParseInstallation.js +1 -17
- package/lib/node/ParseLiveQuery.js +10 -43
- package/lib/node/ParseObject.js +229 -964
- package/lib/node/ParseOp.js +31 -262
- package/lib/node/ParsePolygon.js +12 -69
- package/lib/node/ParseQuery.js +169 -888
- package/lib/node/ParseRelation.js +11 -68
- package/lib/node/ParseRole.js +10 -64
- package/lib/node/ParseSchema.js +46 -229
- package/lib/node/ParseSession.js +8 -57
- package/lib/node/ParseUser.js +107 -583
- package/lib/node/Push.js +4 -44
- package/lib/node/RESTController.js +18 -127
- package/lib/node/SingleInstanceStateController.js +17 -137
- package/lib/node/Socket.weapp.js +0 -7
- package/lib/node/Storage.js +10 -90
- package/lib/node/StorageController.browser.js +4 -30
- package/lib/node/StorageController.default.js +5 -28
- package/lib/node/StorageController.react-native.js +6 -47
- package/lib/node/StorageController.weapp.js +6 -28
- package/lib/node/TaskQueue.js +1 -24
- package/lib/node/UniqueInstanceStateController.js +16 -140
- package/lib/node/Xhr.weapp.js +0 -15
- package/lib/node/arrayContainsObject.js +1 -19
- package/lib/node/canBeSerialized.js +2 -35
- package/lib/node/decode.js +1 -33
- package/lib/node/encode.js +3 -61
- package/lib/node/equals.js +0 -27
- package/lib/node/escape.js +1 -13
- package/lib/node/isRevocableSession.js +1 -12
- package/lib/node/parseDate.js +1 -14
- package/lib/node/promiseUtils.js +2 -14
- package/lib/node/unique.js +1 -18
- package/lib/node/unsavedChildren.js +2 -45
- package/lib/node/uuid.js +6 -1
- package/lib/react-native/Analytics.js +0 -9
- package/lib/react-native/AnonymousUtils.js +0 -10
- package/lib/react-native/Cloud.js +0 -26
- package/lib/react-native/CoreManager.js +2 -6
- package/lib/react-native/CryptoController.js +0 -2
- package/lib/react-native/EventEmitter.js +0 -2
- package/lib/react-native/EventuallyQueue.js +156 -711
- package/lib/react-native/FacebookUtils.js +0 -22
- package/lib/react-native/IndexedDBStorageController.js +0 -1
- package/lib/react-native/InstallationController.js +0 -6
- package/lib/react-native/LiveQueryClient.js +46 -157
- package/lib/react-native/LiveQuerySubscription.js +3 -27
- package/lib/react-native/LocalDatastore.js +281 -948
- package/lib/react-native/LocalDatastoreController.js +71 -552
- package/lib/react-native/LocalDatastoreController.react-native.js +91 -526
- package/lib/react-native/LocalDatastoreUtils.js +0 -1
- package/lib/react-native/ObjectStateMutations.js +2 -65
- package/lib/react-native/OfflineQuery.js +25 -196
- package/lib/react-native/Parse.js +0 -65
- package/lib/react-native/ParseACL.js +0 -44
- package/lib/react-native/ParseCLP.js +23 -161
- package/lib/react-native/ParseConfig.js +0 -42
- package/lib/react-native/ParseError.js +1 -21
- package/lib/react-native/ParseFile.js +55 -529
- package/lib/react-native/ParseGeoPoint.js +0 -17
- package/lib/react-native/ParseHooks.js +0 -30
- package/lib/react-native/ParseInstallation.js +1 -23
- package/lib/react-native/ParseLiveQuery.js +55 -472
- package/lib/react-native/ParseObject.js +245 -1246
- package/lib/react-native/ParseOp.js +1 -138
- package/lib/react-native/ParsePolygon.js +0 -24
- package/lib/react-native/ParseQuery.js +182 -874
- package/lib/react-native/ParseRelation.js +0 -25
- package/lib/react-native/ParseRole.js +1 -36
- package/lib/react-native/ParseSchema.js +3 -54
- package/lib/react-native/ParseSession.js +1 -40
- package/lib/react-native/ParseUser.js +95 -773
- package/lib/react-native/Push.js +0 -16
- package/lib/react-native/RESTController.js +12 -109
- package/lib/react-native/SingleInstanceStateController.js +0 -44
- package/lib/react-native/Socket.weapp.js +0 -10
- package/lib/react-native/Storage.js +0 -24
- package/lib/react-native/StorageController.browser.js +0 -2
- package/lib/react-native/StorageController.default.js +0 -1
- package/lib/react-native/StorageController.react-native.js +0 -2
- package/lib/react-native/TaskQueue.js +0 -15
- package/lib/react-native/UniqueInstanceStateController.js +0 -47
- package/lib/react-native/Xhr.weapp.js +0 -16
- package/lib/react-native/arrayContainsObject.js +0 -5
- package/lib/react-native/canBeSerialized.js +0 -18
- package/lib/react-native/decode.js +0 -21
- package/lib/react-native/encode.js +0 -25
- package/lib/react-native/equals.js +0 -18
- package/lib/react-native/escape.js +0 -1
- package/lib/react-native/isRevocableSession.js +0 -1
- package/lib/react-native/parseDate.js +0 -3
- package/lib/react-native/promiseUtils.js +0 -13
- package/lib/react-native/unique.js +0 -4
- package/lib/react-native/unsavedChildren.js +0 -21
- package/lib/react-native/uuid.js +3 -1
- package/lib/weapp/Analytics.js +2 -27
- package/lib/weapp/AnonymousUtils.js +6 -42
- package/lib/weapp/Cloud.js +12 -77
- package/lib/weapp/CloudCode.js +0 -3
- package/lib/weapp/CoreManager.js +46 -191
- package/lib/weapp/CryptoController.js +2 -16
- package/lib/weapp/EventEmitter.js +1 -8
- package/lib/weapp/EventuallyQueue.js +277 -824
- package/lib/weapp/FacebookUtils.js +6 -42
- package/lib/weapp/IndexedDBStorageController.js +3 -14
- package/lib/weapp/InstallationController.js +2 -20
- package/lib/weapp/LiveQueryClient.js +105 -213
- package/lib/weapp/LiveQuerySubscription.js +10 -39
- package/lib/weapp/LocalDatastore.js +451 -1081
- package/lib/weapp/LocalDatastoreController.js +145 -602
- package/lib/weapp/LocalDatastoreController.react-native.js +137 -573
- package/lib/weapp/LocalDatastoreUtils.js +2 -19
- package/lib/weapp/ObjectStateMutations.js +18 -121
- package/lib/weapp/OfflineQuery.js +61 -222
- package/lib/weapp/Parse.js +12 -115
- package/lib/weapp/ParseACL.js +33 -148
- package/lib/weapp/ParseCLP.js +96 -314
- package/lib/weapp/ParseConfig.js +18 -95
- package/lib/weapp/ParseError.js +63 -99
- package/lib/weapp/ParseFile.js +129 -686
- package/lib/weapp/ParseGeoPoint.js +23 -89
- package/lib/weapp/ParseHooks.js +1 -34
- package/lib/weapp/ParseInstallation.js +4 -32
- package/lib/weapp/ParseLiveQuery.js +96 -505
- package/lib/weapp/ParseObject.js +665 -1845
- package/lib/weapp/ParseOp.js +41 -287
- package/lib/weapp/ParsePolygon.js +13 -70
- package/lib/weapp/ParseQuery.js +403 -1504
- package/lib/weapp/ParseRelation.js +12 -68
- package/lib/weapp/ParseRole.js +13 -75
- package/lib/weapp/ParseSchema.js +49 -208
- package/lib/weapp/ParseSession.js +11 -69
- package/lib/weapp/ParseUser.js +274 -1127
- package/lib/weapp/Push.js +7 -50
- package/lib/weapp/RESTController.js +28 -157
- package/lib/weapp/SingleInstanceStateController.js +19 -144
- package/lib/weapp/Socket.weapp.js +0 -10
- package/lib/weapp/Storage.js +10 -80
- package/lib/weapp/StorageController.browser.js +4 -24
- package/lib/weapp/StorageController.default.js +4 -24
- package/lib/weapp/StorageController.react-native.js +6 -40
- package/lib/weapp/StorageController.weapp.js +5 -23
- package/lib/weapp/TaskQueue.js +1 -29
- package/lib/weapp/UniqueInstanceStateController.js +19 -149
- package/lib/weapp/Xhr.weapp.js +0 -17
- package/lib/weapp/arrayContainsObject.js +2 -23
- package/lib/weapp/canBeSerialized.js +3 -40
- package/lib/weapp/decode.js +3 -40
- package/lib/weapp/encode.js +9 -77
- package/lib/weapp/equals.js +2 -34
- package/lib/weapp/escape.js +1 -15
- package/lib/weapp/isRevocableSession.js +2 -18
- package/lib/weapp/parseDate.js +2 -20
- package/lib/weapp/promiseUtils.js +3 -21
- package/lib/weapp/unique.js +3 -24
- package/lib/weapp/unsavedChildren.js +6 -57
- package/lib/weapp/uuid.js +1 -6
- package/package.json +35 -31
- package/PATENTS +0 -37
package/lib/node/Push.js
CHANGED
|
@@ -5,24 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getPushStatus = getPushStatus;
|
|
7
7
|
exports.send = send;
|
|
8
|
-
|
|
9
8
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
10
|
-
|
|
11
9
|
var _ParseQuery = _interopRequireDefault(require("./ParseQuery"));
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) {
|
|
14
11
|
return obj && obj.__esModule ? obj : {
|
|
15
12
|
default: obj
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
|
-
* Copyright (c) 2015-present, Parse, LLC.
|
|
20
|
-
* All rights reserved.
|
|
21
|
-
*
|
|
22
|
-
* This source code is licensed under the BSD-style license found in the
|
|
23
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
24
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
25
|
-
*
|
|
26
16
|
* @flow
|
|
27
17
|
*/
|
|
28
18
|
|
|
@@ -62,41 +52,28 @@ function _interopRequireDefault(obj) {
|
|
|
62
52
|
* @returns {Promise} A promise that is fulfilled when the push request
|
|
63
53
|
* completes.
|
|
64
54
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
function send(data
|
|
68
|
-
/*: PushData*/
|
|
69
|
-
, options
|
|
70
|
-
/*:: ?: FullOptions*/
|
|
71
|
-
= {})
|
|
72
|
-
/*: Promise*/
|
|
73
|
-
{
|
|
55
|
+
function send(data /*: PushData*/, options /*:: ?: FullOptions*/ = {}) /*: Promise*/{
|
|
74
56
|
if (data.where && data.where instanceof _ParseQuery.default) {
|
|
75
57
|
data.where = data.where.toJSON().where;
|
|
76
58
|
}
|
|
77
|
-
|
|
78
59
|
if (data.push_time && typeof data.push_time === 'object') {
|
|
79
60
|
data.push_time = data.push_time.toJSON();
|
|
80
61
|
}
|
|
81
|
-
|
|
82
62
|
if (data.expiration_time && typeof data.expiration_time === 'object') {
|
|
83
63
|
data.expiration_time = data.expiration_time.toJSON();
|
|
84
64
|
}
|
|
85
|
-
|
|
86
65
|
if (data.expiration_time && data.expiration_interval) {
|
|
87
66
|
throw new Error('expiration_time and expiration_interval cannot both be set.');
|
|
88
67
|
}
|
|
89
|
-
|
|
90
68
|
const pushOptions = {
|
|
91
69
|
useMasterKey: true
|
|
92
70
|
};
|
|
93
|
-
|
|
94
71
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
95
72
|
pushOptions.useMasterKey = options.useMasterKey;
|
|
96
73
|
}
|
|
97
|
-
|
|
98
74
|
return _CoreManager.default.getPushController().send(data, pushOptions);
|
|
99
75
|
}
|
|
76
|
+
|
|
100
77
|
/**
|
|
101
78
|
* Gets push status by Id
|
|
102
79
|
*
|
|
@@ -110,36 +87,19 @@ function send(data
|
|
|
110
87
|
* </ul>
|
|
111
88
|
* @returns {Parse.Object} Status of Push.
|
|
112
89
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
function getPushStatus(pushStatusId
|
|
116
|
-
/*: string*/
|
|
117
|
-
, options
|
|
118
|
-
/*:: ?: FullOptions*/
|
|
119
|
-
= {})
|
|
120
|
-
/*: Promise<string>*/
|
|
121
|
-
{
|
|
90
|
+
function getPushStatus(pushStatusId /*: string*/, options /*:: ?: FullOptions*/ = {}) /*: Promise<string>*/{
|
|
122
91
|
const pushOptions = {
|
|
123
92
|
useMasterKey: true
|
|
124
93
|
};
|
|
125
|
-
|
|
126
94
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
127
95
|
pushOptions.useMasterKey = options.useMasterKey;
|
|
128
96
|
}
|
|
129
|
-
|
|
130
97
|
const query = new _ParseQuery.default('_PushStatus');
|
|
131
98
|
return query.get(pushStatusId, pushOptions);
|
|
132
99
|
}
|
|
133
|
-
|
|
134
100
|
const DefaultController = {
|
|
135
|
-
send(data
|
|
136
|
-
/*: PushData*/
|
|
137
|
-
, options
|
|
138
|
-
/*:: ?: FullOptions*/
|
|
139
|
-
) {
|
|
101
|
+
send(data /*: PushData*/, options /*:: ?: FullOptions*/) {
|
|
140
102
|
return _CoreManager.default.getRESTController().request('POST', 'push', data, options);
|
|
141
103
|
}
|
|
142
|
-
|
|
143
104
|
};
|
|
144
|
-
|
|
145
105
|
_CoreManager.default.setPushController(DefaultController);
|
|
@@ -1,75 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
4
|
-
|
|
5
4
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
6
|
-
|
|
7
5
|
var _promiseUtils = require("./promiseUtils");
|
|
8
|
-
|
|
9
6
|
function _interopRequireDefault(obj) {
|
|
10
7
|
return obj && obj.__esModule ? obj : {
|
|
11
8
|
default: obj
|
|
12
9
|
};
|
|
13
10
|
}
|
|
14
11
|
/**
|
|
15
|
-
* Copyright (c) 2015-present, Parse, LLC.
|
|
16
|
-
* All rights reserved.
|
|
17
|
-
*
|
|
18
|
-
* This source code is licensed under the BSD-style license found in the
|
|
19
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
20
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
21
|
-
*
|
|
22
12
|
* @flow
|
|
23
13
|
*/
|
|
24
|
-
|
|
25
14
|
/* global XMLHttpRequest, XDomainRequest */
|
|
26
|
-
|
|
27
|
-
|
|
28
15
|
const uuidv4 = require('./uuid');
|
|
29
|
-
|
|
30
16
|
let XHR = null;
|
|
31
|
-
|
|
32
17
|
if (typeof XMLHttpRequest !== 'undefined') {
|
|
33
18
|
XHR = XMLHttpRequest;
|
|
34
19
|
}
|
|
35
|
-
|
|
36
20
|
XHR = require('xmlhttprequest').XMLHttpRequest;
|
|
37
21
|
let useXDomainRequest = false;
|
|
38
|
-
|
|
39
22
|
if (typeof XDomainRequest !== 'undefined' && !('withCredentials' in new XMLHttpRequest())) {
|
|
40
23
|
useXDomainRequest = true;
|
|
41
24
|
}
|
|
42
|
-
|
|
43
|
-
function ajaxIE9(method
|
|
44
|
-
/*: string*/
|
|
45
|
-
, url
|
|
46
|
-
/*: string*/
|
|
47
|
-
, data
|
|
48
|
-
/*: any*/
|
|
49
|
-
, headers
|
|
50
|
-
/*:: ?: any*/
|
|
51
|
-
, options
|
|
52
|
-
/*:: ?: FullOptions*/
|
|
53
|
-
) {
|
|
25
|
+
function ajaxIE9(method /*: string*/, url /*: string*/, data /*: any*/, headers /*:: ?: any*/, options /*:: ?: FullOptions*/) {
|
|
54
26
|
return new Promise((resolve, reject) => {
|
|
55
27
|
const xdr = new XDomainRequest();
|
|
56
|
-
|
|
57
28
|
xdr.onload = function () {
|
|
58
29
|
let response;
|
|
59
|
-
|
|
60
30
|
try {
|
|
61
31
|
response = JSON.parse(xdr.responseText);
|
|
62
32
|
} catch (e) {
|
|
63
33
|
reject(e);
|
|
64
34
|
}
|
|
65
|
-
|
|
66
35
|
if (response) {
|
|
67
36
|
resolve({
|
|
68
37
|
response
|
|
69
38
|
});
|
|
70
39
|
}
|
|
71
40
|
};
|
|
72
|
-
|
|
73
41
|
xdr.onerror = xdr.ontimeout = function () {
|
|
74
42
|
// Let's fake a real error message.
|
|
75
43
|
const fakeResponse = {
|
|
@@ -80,69 +48,46 @@ function ajaxIE9(method
|
|
|
80
48
|
};
|
|
81
49
|
reject(fakeResponse);
|
|
82
50
|
};
|
|
83
|
-
|
|
84
51
|
xdr.onprogress = function () {
|
|
85
52
|
if (options && typeof options.progress === 'function') {
|
|
86
53
|
options.progress(xdr.responseText);
|
|
87
54
|
}
|
|
88
55
|
};
|
|
89
|
-
|
|
90
56
|
xdr.open(method, url);
|
|
91
57
|
xdr.send(data);
|
|
92
|
-
|
|
93
58
|
if (options && typeof options.requestTask === 'function') {
|
|
94
59
|
options.requestTask(xdr);
|
|
95
60
|
}
|
|
96
61
|
});
|
|
97
62
|
}
|
|
98
|
-
|
|
99
63
|
const RESTController = {
|
|
100
|
-
ajax(method
|
|
101
|
-
/*: string*/
|
|
102
|
-
, url
|
|
103
|
-
/*: string*/
|
|
104
|
-
, data
|
|
105
|
-
/*: any*/
|
|
106
|
-
, headers
|
|
107
|
-
/*:: ?: any*/
|
|
108
|
-
, options
|
|
109
|
-
/*:: ?: FullOptions*/
|
|
110
|
-
) {
|
|
64
|
+
ajax(method /*: string*/, url /*: string*/, data /*: any*/, headers /*:: ?: any*/, options /*:: ?: FullOptions*/) {
|
|
111
65
|
if (useXDomainRequest) {
|
|
112
66
|
return ajaxIE9(method, url, data, headers, options);
|
|
113
67
|
}
|
|
114
|
-
|
|
115
68
|
const promise = (0, _promiseUtils.resolvingPromise)();
|
|
116
69
|
const isIdempotent = _CoreManager.default.get('IDEMPOTENCY') && ['POST', 'PUT'].includes(method);
|
|
117
70
|
const requestId = isIdempotent ? uuidv4() : '';
|
|
118
71
|
let attempts = 0;
|
|
119
|
-
|
|
120
72
|
const dispatch = function () {
|
|
121
73
|
if (XHR == null) {
|
|
122
74
|
throw new Error('Cannot make a request: No definition of XMLHttpRequest was found.');
|
|
123
75
|
}
|
|
124
|
-
|
|
125
76
|
let handled = false;
|
|
126
77
|
const xhr = new XHR();
|
|
127
|
-
|
|
128
78
|
xhr.onreadystatechange = function () {
|
|
129
79
|
if (xhr.readyState !== 4 || handled || xhr._aborted) {
|
|
130
80
|
return;
|
|
131
81
|
}
|
|
132
|
-
|
|
133
82
|
handled = true;
|
|
134
|
-
|
|
135
83
|
if (xhr.status >= 200 && xhr.status < 300) {
|
|
136
84
|
let response;
|
|
137
|
-
|
|
138
85
|
try {
|
|
139
86
|
response = JSON.parse(xhr.responseText);
|
|
140
|
-
|
|
141
87
|
if (typeof xhr.getResponseHeader === 'function') {
|
|
142
88
|
if ((xhr.getAllResponseHeaders() || '').includes('x-parse-job-status-id: ')) {
|
|
143
89
|
response = xhr.getResponseHeader('x-parse-job-status-id');
|
|
144
90
|
}
|
|
145
|
-
|
|
146
91
|
if ((xhr.getAllResponseHeaders() || '').includes('x-parse-push-status-id: ')) {
|
|
147
92
|
response = xhr.getResponseHeader('x-parse-push-status-id');
|
|
148
93
|
}
|
|
@@ -150,7 +95,6 @@ const RESTController = {
|
|
|
150
95
|
} catch (e) {
|
|
151
96
|
promise.reject(e.toString());
|
|
152
97
|
}
|
|
153
|
-
|
|
154
98
|
if (response) {
|
|
155
99
|
promise.resolve({
|
|
156
100
|
response,
|
|
@@ -174,9 +118,7 @@ const RESTController = {
|
|
|
174
118
|
promise.reject(xhr);
|
|
175
119
|
}
|
|
176
120
|
};
|
|
177
|
-
|
|
178
121
|
headers = headers || {};
|
|
179
|
-
|
|
180
122
|
if (typeof headers['Content-Type'] !== 'string') {
|
|
181
123
|
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight
|
|
182
124
|
}
|
|
@@ -184,23 +126,18 @@ const RESTController = {
|
|
|
184
126
|
if (_CoreManager.default.get('IS_NODE')) {
|
|
185
127
|
headers['User-Agent'] = 'Parse/' + _CoreManager.default.get('VERSION') + ' (NodeJS ' + process.versions.node + ')';
|
|
186
128
|
}
|
|
187
|
-
|
|
188
129
|
if (isIdempotent) {
|
|
189
130
|
headers['X-Parse-Request-Id'] = requestId;
|
|
190
131
|
}
|
|
191
|
-
|
|
192
132
|
if (_CoreManager.default.get('SERVER_AUTH_TYPE') && _CoreManager.default.get('SERVER_AUTH_TOKEN')) {
|
|
193
133
|
headers['Authorization'] = _CoreManager.default.get('SERVER_AUTH_TYPE') + ' ' + _CoreManager.default.get('SERVER_AUTH_TOKEN');
|
|
194
134
|
}
|
|
195
|
-
|
|
196
135
|
const customHeaders = _CoreManager.default.get('REQUEST_HEADERS');
|
|
197
|
-
|
|
198
136
|
for (const key in customHeaders) {
|
|
199
137
|
headers[key] = customHeaders[key];
|
|
200
138
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (options && typeof options.progress === 'function') {
|
|
139
|
+
if (options && typeof options.progress === 'function') {
|
|
140
|
+
const handleProgress = function (type, event) {
|
|
204
141
|
if (event.lengthComputable) {
|
|
205
142
|
options.progress(event.loaded / event.total, event.loaded, event.total, {
|
|
206
143
|
type
|
|
@@ -210,25 +147,20 @@ const RESTController = {
|
|
|
210
147
|
type
|
|
211
148
|
});
|
|
212
149
|
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
xhr.onprogress = event => {
|
|
217
|
-
handleProgress('download', event);
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
if (xhr.upload) {
|
|
221
|
-
xhr.upload.onprogress = event => {
|
|
222
|
-
handleProgress('upload', event);
|
|
223
150
|
};
|
|
151
|
+
xhr.onprogress = event => {
|
|
152
|
+
handleProgress('download', event);
|
|
153
|
+
};
|
|
154
|
+
if (xhr.upload) {
|
|
155
|
+
xhr.upload.onprogress = event => {
|
|
156
|
+
handleProgress('upload', event);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
224
159
|
}
|
|
225
|
-
|
|
226
160
|
xhr.open(method, url, true);
|
|
227
|
-
|
|
228
161
|
for (const h in headers) {
|
|
229
162
|
xhr.setRequestHeader(h, headers[h]);
|
|
230
163
|
}
|
|
231
|
-
|
|
232
164
|
xhr.onabort = function () {
|
|
233
165
|
promise.resolve({
|
|
234
166
|
response: {
|
|
@@ -238,71 +170,47 @@ const RESTController = {
|
|
|
238
170
|
xhr
|
|
239
171
|
});
|
|
240
172
|
};
|
|
241
|
-
|
|
242
173
|
xhr.send(data);
|
|
243
|
-
|
|
244
174
|
if (options && typeof options.requestTask === 'function') {
|
|
245
175
|
options.requestTask(xhr);
|
|
246
176
|
}
|
|
247
177
|
};
|
|
248
|
-
|
|
249
178
|
dispatch();
|
|
250
179
|
return promise;
|
|
251
180
|
},
|
|
252
|
-
|
|
253
|
-
request(method
|
|
254
|
-
/*: string*/
|
|
255
|
-
, path
|
|
256
|
-
/*: string*/
|
|
257
|
-
, data
|
|
258
|
-
/*: mixed*/
|
|
259
|
-
, options
|
|
260
|
-
/*:: ?: RequestOptions*/
|
|
261
|
-
) {
|
|
181
|
+
request(method /*: string*/, path /*: string*/, data /*: mixed*/, options /*:: ?: RequestOptions*/) {
|
|
262
182
|
options = options || {};
|
|
263
|
-
|
|
264
183
|
let url = _CoreManager.default.get('SERVER_URL');
|
|
265
|
-
|
|
266
184
|
if (url[url.length - 1] !== '/') {
|
|
267
185
|
url += '/';
|
|
268
186
|
}
|
|
269
|
-
|
|
270
187
|
url += path;
|
|
271
188
|
const payload = {};
|
|
272
|
-
|
|
273
189
|
if (data && typeof data === 'object') {
|
|
274
190
|
for (const k in data) {
|
|
275
191
|
payload[k] = data[k];
|
|
276
192
|
}
|
|
277
|
-
}
|
|
278
|
-
|
|
193
|
+
}
|
|
279
194
|
|
|
195
|
+
// Add context
|
|
280
196
|
const context = options.context;
|
|
281
|
-
|
|
282
197
|
if (context !== undefined) {
|
|
283
198
|
payload._context = context;
|
|
284
199
|
}
|
|
285
|
-
|
|
286
200
|
if (method !== 'POST') {
|
|
287
201
|
payload._method = method;
|
|
288
202
|
method = 'POST';
|
|
289
203
|
}
|
|
290
|
-
|
|
291
204
|
payload._ApplicationId = _CoreManager.default.get('APPLICATION_ID');
|
|
292
|
-
|
|
293
205
|
const jsKey = _CoreManager.default.get('JAVASCRIPT_KEY');
|
|
294
|
-
|
|
295
206
|
if (jsKey) {
|
|
296
207
|
payload._JavaScriptKey = jsKey;
|
|
297
208
|
}
|
|
298
|
-
|
|
299
209
|
payload._ClientVersion = _CoreManager.default.get('VERSION');
|
|
300
210
|
let useMasterKey = options.useMasterKey;
|
|
301
|
-
|
|
302
211
|
if (typeof useMasterKey === 'undefined') {
|
|
303
212
|
useMasterKey = _CoreManager.default.get('USE_MASTER_KEY');
|
|
304
213
|
}
|
|
305
|
-
|
|
306
214
|
if (useMasterKey) {
|
|
307
215
|
if (_CoreManager.default.get('MASTER_KEY')) {
|
|
308
216
|
delete payload._JavaScriptKey;
|
|
@@ -311,27 +219,20 @@ const RESTController = {
|
|
|
311
219
|
throw new Error('Cannot use the Master Key, it has not been provided.');
|
|
312
220
|
}
|
|
313
221
|
}
|
|
314
|
-
|
|
315
222
|
if (_CoreManager.default.get('FORCE_REVOCABLE_SESSION')) {
|
|
316
223
|
payload._RevocableSession = '1';
|
|
317
224
|
}
|
|
318
|
-
|
|
319
225
|
const installationId = options.installationId;
|
|
320
226
|
let installationIdPromise;
|
|
321
|
-
|
|
322
227
|
if (installationId && typeof installationId === 'string') {
|
|
323
228
|
installationIdPromise = Promise.resolve(installationId);
|
|
324
229
|
} else {
|
|
325
230
|
const installationController = _CoreManager.default.getInstallationController();
|
|
326
|
-
|
|
327
231
|
installationIdPromise = installationController.currentInstallationId();
|
|
328
232
|
}
|
|
329
|
-
|
|
330
233
|
return installationIdPromise.then(iid => {
|
|
331
234
|
payload._InstallationId = iid;
|
|
332
|
-
|
|
333
235
|
const userController = _CoreManager.default.getUserController();
|
|
334
|
-
|
|
335
236
|
if (options && typeof options.sessionToken === 'string') {
|
|
336
237
|
return Promise.resolve(options.sessionToken);
|
|
337
238
|
} else if (userController) {
|
|
@@ -339,24 +240,22 @@ const RESTController = {
|
|
|
339
240
|
if (user) {
|
|
340
241
|
return Promise.resolve(user.getSessionToken());
|
|
341
242
|
}
|
|
342
|
-
|
|
343
243
|
return Promise.resolve(null);
|
|
344
244
|
});
|
|
345
245
|
}
|
|
346
|
-
|
|
347
246
|
return Promise.resolve(null);
|
|
348
247
|
}).then(token => {
|
|
349
248
|
if (token) {
|
|
350
249
|
payload._SessionToken = token;
|
|
351
250
|
}
|
|
352
|
-
|
|
353
251
|
const payloadString = JSON.stringify(payload);
|
|
354
252
|
return RESTController.ajax(method, url, payloadString, {}, options).then(({
|
|
355
253
|
response,
|
|
356
254
|
status
|
|
357
255
|
}) => {
|
|
358
256
|
if (options.returnStatus) {
|
|
359
|
-
return {
|
|
257
|
+
return {
|
|
258
|
+
...response,
|
|
360
259
|
_status: status
|
|
361
260
|
};
|
|
362
261
|
} else {
|
|
@@ -365,12 +264,10 @@ const RESTController = {
|
|
|
365
264
|
});
|
|
366
265
|
}).catch(RESTController.handleError);
|
|
367
266
|
},
|
|
368
|
-
|
|
369
267
|
handleError(response) {
|
|
370
268
|
// Transform the error into an instance of ParseError by trying to parse
|
|
371
269
|
// the error string as JSON
|
|
372
270
|
let error;
|
|
373
|
-
|
|
374
271
|
if (response && response.responseText) {
|
|
375
272
|
try {
|
|
376
273
|
const errorJSON = JSON.parse(response.responseText);
|
|
@@ -383,19 +280,13 @@ const RESTController = {
|
|
|
383
280
|
const message = response.message ? response.message : response;
|
|
384
281
|
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + JSON.stringify(message));
|
|
385
282
|
}
|
|
386
|
-
|
|
387
283
|
return Promise.reject(error);
|
|
388
284
|
},
|
|
389
|
-
|
|
390
|
-
_setXHR(xhr
|
|
391
|
-
/*: any*/
|
|
392
|
-
) {
|
|
285
|
+
_setXHR(xhr /*: any*/) {
|
|
393
286
|
XHR = xhr;
|
|
394
287
|
},
|
|
395
|
-
|
|
396
288
|
_getXHR() {
|
|
397
289
|
return XHR;
|
|
398
290
|
}
|
|
399
|
-
|
|
400
291
|
};
|
|
401
292
|
module.exports = RESTController;
|