parse 6.1.1 → 7.1.2
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/README.md +2 -1
- package/dist/parse.js +58626 -26564
- package/dist/parse.min.js +1 -14
- package/dist/parse.weapp.js +58737 -26628
- package/dist/parse.weapp.min.js +1 -14
- package/index.js +1 -1
- package/lib/browser/CoreManager.js +3 -4
- package/lib/browser/ObjectStateMutations.js +51 -9
- package/lib/browser/Parse.js +42 -44
- package/lib/browser/ParseFile.js +74 -54
- package/lib/browser/ParseObject.js +32 -29
- package/lib/browser/ParseOp.js +2 -2
- package/lib/browser/ParseQuery.js +14 -14
- package/lib/browser/RESTController.js +154 -129
- package/lib/browser/SingleInstanceStateController.js +28 -27
- package/lib/browser/UniqueInstanceStateController.js +19 -23
- package/lib/browser/Xhr.weapp.js +62 -102
- package/lib/browser/decode.js +8 -1
- package/lib/browser/encode.js +9 -1
- package/lib/browser/equals.js +1 -1
- package/lib/browser/isDangerousKey.js +29 -0
- package/lib/browser/uuid.js +6 -2
- package/lib/node/CoreManager.js +3 -4
- package/lib/node/ObjectStateMutations.js +50 -9
- package/lib/node/Parse.js +43 -47
- package/lib/node/ParseFile.js +75 -70
- package/lib/node/ParseObject.js +29 -28
- package/lib/node/RESTController.js +152 -128
- package/lib/node/SingleInstanceStateController.js +26 -28
- package/lib/node/UniqueInstanceStateController.js +19 -24
- package/lib/node/Xhr.weapp.js +58 -81
- package/lib/node/decode.js +8 -1
- package/lib/node/encode.js +9 -1
- package/lib/node/equals.js +1 -1
- package/lib/node/isDangerousKey.js +25 -0
- package/lib/node/uuid.js +4 -2
- package/lib/react-native/CoreManager.js +3 -4
- package/lib/react-native/ObjectStateMutations.js +40 -9
- package/lib/react-native/Parse.js +25 -37
- package/lib/react-native/ParseFile.js +62 -50
- package/lib/react-native/ParseObject.js +29 -28
- package/lib/react-native/ParseQuery.js +25 -25
- package/lib/react-native/RESTController.js +186 -150
- package/lib/react-native/SingleInstanceStateController.js +23 -28
- package/lib/react-native/UniqueInstanceStateController.js +19 -24
- package/lib/react-native/Xhr.weapp.js +63 -95
- package/lib/react-native/decode.js +7 -1
- package/lib/react-native/encode.js +7 -1
- package/lib/react-native/equals.js +1 -1
- package/lib/react-native/isDangerousKey.js +17 -0
- package/lib/react-native/uuid.js +1 -2
- package/lib/weapp/CoreManager.js +3 -4
- package/lib/weapp/ObjectStateMutations.js +51 -9
- package/lib/weapp/Parse.js +40 -44
- package/lib/weapp/ParseFile.js +74 -55
- package/lib/weapp/ParseObject.js +32 -29
- package/lib/weapp/ParseOp.js +2 -2
- package/lib/weapp/ParseQuery.js +14 -14
- package/lib/weapp/RESTController.js +155 -130
- package/lib/weapp/SingleInstanceStateController.js +28 -27
- package/lib/weapp/UniqueInstanceStateController.js +19 -23
- package/lib/weapp/Xhr.weapp.js +62 -102
- package/lib/weapp/decode.js +8 -1
- package/lib/weapp/encode.js +9 -1
- package/lib/weapp/equals.js +1 -1
- package/lib/weapp/isDangerousKey.js +29 -0
- package/lib/weapp/uuid.js +2 -1
- package/node.js +1 -1
- package/package.json +38 -55
- package/react-native.js +1 -1
- package/types/Parse.d.ts +16 -10
- package/types/ParseFile.d.ts +20 -5
- package/types/ParseObject.d.ts +1 -1
- package/types/RESTController.d.ts +2 -7
- package/types/SingleInstanceStateController.d.ts +3 -3
- package/types/Xhr.weapp.d.ts +1 -29
- package/types/isDangerousKey.d.ts +7 -0
- package/types/tests.ts +2 -0
- package/weapp.js +1 -1
|
@@ -1632,11 +1632,11 @@ class ParseQuery {
|
|
|
1632
1632
|
keys[_key4] = arguments[_key4];
|
|
1633
1633
|
}
|
|
1634
1634
|
(0, _forEach.default)(keys).call(keys, key => {
|
|
1635
|
-
var _context9,
|
|
1635
|
+
var _context9, _context0;
|
|
1636
1636
|
if ((0, _isArray.default)(key)) {
|
|
1637
1637
|
key = key.join();
|
|
1638
1638
|
}
|
|
1639
|
-
this._order = (0, _concat.default)(_context9 = this._order).call(_context9, (0, _map.default)(
|
|
1639
|
+
this._order = (0, _concat.default)(_context9 = this._order).call(_context9, (0, _map.default)(_context0 = key.replace(/\s/g, '').split(',')).call(_context0, k => {
|
|
1640
1640
|
return '-' + k;
|
|
1641
1641
|
}));
|
|
1642
1642
|
});
|
|
@@ -1709,8 +1709,8 @@ class ParseQuery {
|
|
|
1709
1709
|
}
|
|
1710
1710
|
(0, _forEach.default)(keys).call(keys, key => {
|
|
1711
1711
|
if ((0, _isArray.default)(key)) {
|
|
1712
|
-
var
|
|
1713
|
-
this._include = (0, _concat.default)(
|
|
1712
|
+
var _context1;
|
|
1713
|
+
this._include = (0, _concat.default)(_context1 = this._include).call(_context1, key);
|
|
1714
1714
|
} else {
|
|
1715
1715
|
this._include.push(key);
|
|
1716
1716
|
}
|
|
@@ -1746,8 +1746,8 @@ class ParseQuery {
|
|
|
1746
1746
|
}
|
|
1747
1747
|
(0, _forEach.default)(keys).call(keys, key => {
|
|
1748
1748
|
if ((0, _isArray.default)(key)) {
|
|
1749
|
-
var
|
|
1750
|
-
this._select = (0, _concat.default)(
|
|
1749
|
+
var _context10;
|
|
1750
|
+
this._select = (0, _concat.default)(_context10 = this._select).call(_context10, key);
|
|
1751
1751
|
} else {
|
|
1752
1752
|
this._select.push(key);
|
|
1753
1753
|
}
|
|
@@ -1770,8 +1770,8 @@ class ParseQuery {
|
|
|
1770
1770
|
}
|
|
1771
1771
|
(0, _forEach.default)(keys).call(keys, key => {
|
|
1772
1772
|
if ((0, _isArray.default)(key)) {
|
|
1773
|
-
var
|
|
1774
|
-
this._exclude = (0, _concat.default)(
|
|
1773
|
+
var _context11;
|
|
1774
|
+
this._exclude = (0, _concat.default)(_context11 = this._exclude).call(_context11, key);
|
|
1775
1775
|
} else {
|
|
1776
1776
|
this._exclude.push(key);
|
|
1777
1777
|
}
|
|
@@ -1793,8 +1793,8 @@ class ParseQuery {
|
|
|
1793
1793
|
}
|
|
1794
1794
|
(0, _forEach.default)(keys).call(keys, key => {
|
|
1795
1795
|
if ((0, _isArray.default)(key)) {
|
|
1796
|
-
var
|
|
1797
|
-
this._watch = (0, _concat.default)(
|
|
1796
|
+
var _context12;
|
|
1797
|
+
this._watch = (0, _concat.default)(_context12 = this._watch).call(_context12, key);
|
|
1798
1798
|
} else {
|
|
1799
1799
|
this._watch.push(key);
|
|
1800
1800
|
}
|
|
@@ -1874,8 +1874,8 @@ class ParseQuery {
|
|
|
1874
1874
|
* @returns {Parse.Query} The query that is the AND of the passed in queries.
|
|
1875
1875
|
*/
|
|
1876
1876
|
static and() {
|
|
1877
|
-
for (var
|
|
1878
|
-
queries[
|
|
1877
|
+
for (var _len0 = arguments.length, queries = new Array(_len0), _key0 = 0; _key0 < _len0; _key0++) {
|
|
1878
|
+
queries[_key0] = arguments[_key0];
|
|
1879
1879
|
}
|
|
1880
1880
|
const className = _getClassNameFromQueries(queries);
|
|
1881
1881
|
const query = new ParseQuery(className);
|
|
@@ -1896,8 +1896,8 @@ class ParseQuery {
|
|
|
1896
1896
|
* @returns {Parse.Query} The query that is the NOR of the passed in queries.
|
|
1897
1897
|
*/
|
|
1898
1898
|
static nor() {
|
|
1899
|
-
for (var
|
|
1900
|
-
queries[
|
|
1899
|
+
for (var _len1 = arguments.length, queries = new Array(_len1), _key1 = 0; _key1 < _len1; _key1++) {
|
|
1900
|
+
queries[_key1] = arguments[_key1];
|
|
1901
1901
|
}
|
|
1902
1902
|
const className = _getClassNameFromQueries(queries);
|
|
1903
1903
|
const query = new ParseQuery(className);
|
|
@@ -6,29 +6,35 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
|
+
var _endsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/ends-with"));
|
|
10
|
+
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
|
|
11
|
+
var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/starts-with"));
|
|
9
12
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
10
13
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
11
14
|
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
12
|
-
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
13
|
-
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
|
|
14
15
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
15
16
|
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
|
16
17
|
var _uuid = _interopRequireDefault(require("./uuid"));
|
|
17
18
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
18
19
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
19
20
|
var _promiseUtils = require("./promiseUtils");
|
|
20
|
-
var _Xhr =
|
|
21
|
+
var _Xhr = require("./Xhr.weapp");
|
|
21
22
|
/* global XMLHttpRequest, XDomainRequest */
|
|
22
23
|
|
|
23
|
-
let XHR = null;
|
|
24
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
|
25
|
-
XHR = XMLHttpRequest;
|
|
26
|
-
}
|
|
27
24
|
let useXDomainRequest = false;
|
|
28
25
|
// @ts-ignore
|
|
29
26
|
if (typeof XDomainRequest !== 'undefined' && !('withCredentials' in new XMLHttpRequest())) {
|
|
30
27
|
useXDomainRequest = true;
|
|
31
28
|
}
|
|
29
|
+
function getPath(base, pathname) {
|
|
30
|
+
if ((0, _endsWith.default)(base).call(base, '/')) {
|
|
31
|
+
base = (0, _slice.default)(base).call(base, 0, -1);
|
|
32
|
+
}
|
|
33
|
+
if (!(0, _startsWith.default)(pathname).call(pathname, '/')) {
|
|
34
|
+
pathname = '/' + pathname;
|
|
35
|
+
}
|
|
36
|
+
return base + pathname;
|
|
37
|
+
}
|
|
32
38
|
function ajaxIE9(method, url, data, _headers, options) {
|
|
33
39
|
return new _promise.default((resolve, reject) => {
|
|
34
40
|
// @ts-ignore
|
|
@@ -71,68 +77,23 @@ function ajaxIE9(method, url, data, _headers, options) {
|
|
|
71
77
|
});
|
|
72
78
|
}
|
|
73
79
|
const RESTController = {
|
|
74
|
-
ajax(method, url, data, headers, options) {
|
|
80
|
+
async ajax(method, url, data, headers, options) {
|
|
75
81
|
var _context;
|
|
76
82
|
if (useXDomainRequest) {
|
|
77
83
|
return ajaxIE9(method, url, data, headers, options);
|
|
78
84
|
}
|
|
85
|
+
if (typeof fetch !== 'function') {
|
|
86
|
+
throw new Error('Cannot make a request: Fetch API not found.');
|
|
87
|
+
}
|
|
79
88
|
const promise = (0, _promiseUtils.resolvingPromise)();
|
|
80
89
|
const isIdempotent = _CoreManager.default.get('IDEMPOTENCY') && (0, _includes.default)(_context = ['POST', 'PUT']).call(_context, method);
|
|
81
90
|
const requestId = isIdempotent ? (0, _uuid.default)() : '';
|
|
82
91
|
let attempts = 0;
|
|
83
|
-
const dispatch = function () {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const xhr = new XHR();
|
|
89
|
-
xhr.onreadystatechange = function () {
|
|
90
|
-
if (xhr.readyState !== 4 || handled || xhr._aborted) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
handled = true;
|
|
94
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
95
|
-
let response;
|
|
96
|
-
try {
|
|
97
|
-
var _context2, _context3;
|
|
98
|
-
response = JSON.parse(xhr.responseText);
|
|
99
|
-
const availableHeaders = typeof xhr.getAllResponseHeaders === 'function' ? xhr.getAllResponseHeaders() : '';
|
|
100
|
-
headers = {};
|
|
101
|
-
if (typeof xhr.getResponseHeader === 'function' && ((_context2 = availableHeaders) == null ? void 0 : (0, _bind.default)(_context3 = Function.call).call(_context3, (0, _indexOf.default)(_context2), _context2))?.('access-control-expose-headers') >= 0) {
|
|
102
|
-
const responseHeaders = xhr.getResponseHeader('access-control-expose-headers').split(', ');
|
|
103
|
-
(0, _forEach.default)(responseHeaders).call(responseHeaders, header => {
|
|
104
|
-
if ((0, _indexOf.default)(availableHeaders).call(availableHeaders, header.toLowerCase()) >= 0) {
|
|
105
|
-
headers[header] = xhr.getResponseHeader(header.toLowerCase());
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
} catch (e) {
|
|
110
|
-
promise.reject(e.toString());
|
|
111
|
-
}
|
|
112
|
-
if (response) {
|
|
113
|
-
promise.resolve({
|
|
114
|
-
response,
|
|
115
|
-
headers,
|
|
116
|
-
status: xhr.status,
|
|
117
|
-
xhr
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
} else if (xhr.status >= 500 || xhr.status === 0) {
|
|
121
|
-
// retry on 5XX or node-xmlhttprequest error
|
|
122
|
-
if (++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
123
|
-
// Exponentially-growing random delay
|
|
124
|
-
const delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
125
|
-
(0, _setTimeout2.default)(dispatch, delay);
|
|
126
|
-
} else if (xhr.status === 0) {
|
|
127
|
-
promise.reject('Unable to connect to the Parse API');
|
|
128
|
-
} else {
|
|
129
|
-
// After the retry limit is reached, fail
|
|
130
|
-
promise.reject(xhr);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
promise.reject(xhr);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
92
|
+
const dispatch = async function () {
|
|
93
|
+
const controller = new AbortController();
|
|
94
|
+
const {
|
|
95
|
+
signal
|
|
96
|
+
} = controller;
|
|
136
97
|
headers = headers || {};
|
|
137
98
|
if (typeof headers['Content-Type'] !== 'string') {
|
|
138
99
|
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight
|
|
@@ -143,52 +104,118 @@ const RESTController = {
|
|
|
143
104
|
if (isIdempotent) {
|
|
144
105
|
headers['X-Parse-Request-Id'] = requestId;
|
|
145
106
|
}
|
|
146
|
-
if (_CoreManager.default.get('SERVER_AUTH_TYPE') && _CoreManager.default.get('SERVER_AUTH_TOKEN')) {
|
|
147
|
-
headers['Authorization'] = _CoreManager.default.get('SERVER_AUTH_TYPE') + ' ' + _CoreManager.default.get('SERVER_AUTH_TOKEN');
|
|
148
|
-
}
|
|
149
107
|
const customHeaders = _CoreManager.default.get('REQUEST_HEADERS');
|
|
150
108
|
for (const key in customHeaders) {
|
|
151
109
|
headers[key] = customHeaders[key];
|
|
152
110
|
}
|
|
153
|
-
if (options && typeof options.progress === 'function') {
|
|
154
|
-
const handleProgress = function (type, event) {
|
|
155
|
-
if (event.lengthComputable) {
|
|
156
|
-
options.progress(event.loaded / event.total, event.loaded, event.total, {
|
|
157
|
-
type
|
|
158
|
-
});
|
|
159
|
-
} else {
|
|
160
|
-
options.progress(null, null, null, {
|
|
161
|
-
type
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
xhr.onprogress = event => {
|
|
166
|
-
handleProgress('download', event);
|
|
167
|
-
};
|
|
168
|
-
if (xhr.upload) {
|
|
169
|
-
xhr.upload.onprogress = event => {
|
|
170
|
-
handleProgress('upload', event);
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
xhr.open(method, url, true);
|
|
175
|
-
for (const h in headers) {
|
|
176
|
-
xhr.setRequestHeader(h, headers[h]);
|
|
177
|
-
}
|
|
178
|
-
xhr.onabort = function () {
|
|
179
|
-
promise.resolve({
|
|
180
|
-
response: {
|
|
181
|
-
results: []
|
|
182
|
-
},
|
|
183
|
-
status: 0,
|
|
184
|
-
xhr
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
xhr.send(data);
|
|
188
111
|
// @ts-ignore
|
|
189
112
|
if (options && typeof options.requestTask === 'function') {
|
|
190
113
|
// @ts-ignore
|
|
191
|
-
options.requestTask(
|
|
114
|
+
options.requestTask(controller);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
var _context3;
|
|
118
|
+
const fetchOptions = {
|
|
119
|
+
method,
|
|
120
|
+
headers,
|
|
121
|
+
signal,
|
|
122
|
+
redirect: 'manual'
|
|
123
|
+
};
|
|
124
|
+
if (data) {
|
|
125
|
+
fetchOptions.body = data;
|
|
126
|
+
}
|
|
127
|
+
const response = await fetch(url, fetchOptions);
|
|
128
|
+
const {
|
|
129
|
+
status
|
|
130
|
+
} = response;
|
|
131
|
+
if (status >= 200 && status < 300) {
|
|
132
|
+
var _context2;
|
|
133
|
+
let result;
|
|
134
|
+
const responseHeaders = {};
|
|
135
|
+
const availableHeaders = response.headers.get('access-control-expose-headers') || '';
|
|
136
|
+
(0, _forEach.default)(_context2 = availableHeaders.split(', ')).call(_context2, header => {
|
|
137
|
+
if (header && response.headers.has(header)) {
|
|
138
|
+
responseHeaders[header] = response.headers.get(header);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
if (options && typeof options.progress === 'function' && response.body) {
|
|
142
|
+
const reader = response.body.getReader();
|
|
143
|
+
const length = +response.headers.get('Content-Length') || 0;
|
|
144
|
+
if (length === 0) {
|
|
145
|
+
options.progress(null, null, null);
|
|
146
|
+
result = await response.json();
|
|
147
|
+
} else {
|
|
148
|
+
let recieved = 0;
|
|
149
|
+
const chunks = [];
|
|
150
|
+
while (true) {
|
|
151
|
+
const {
|
|
152
|
+
done,
|
|
153
|
+
value
|
|
154
|
+
} = await reader.read();
|
|
155
|
+
if (done) {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
chunks.push(value);
|
|
159
|
+
recieved += value?.length || 0;
|
|
160
|
+
options.progress(recieved / length, recieved, length);
|
|
161
|
+
}
|
|
162
|
+
const body = new Uint8Array(recieved);
|
|
163
|
+
let offset = 0;
|
|
164
|
+
for (const chunk of chunks) {
|
|
165
|
+
body.set(chunk, offset);
|
|
166
|
+
offset += chunk.length;
|
|
167
|
+
}
|
|
168
|
+
const jsonString = new TextDecoder().decode(body);
|
|
169
|
+
result = JSON.parse(jsonString);
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
result = await response.json();
|
|
173
|
+
}
|
|
174
|
+
promise.resolve({
|
|
175
|
+
status,
|
|
176
|
+
response: result,
|
|
177
|
+
headers: responseHeaders
|
|
178
|
+
});
|
|
179
|
+
} else if (status >= 400 && status < 500) {
|
|
180
|
+
const error = await response.json();
|
|
181
|
+
promise.reject(error);
|
|
182
|
+
} else if ((0, _includes.default)(_context3 = [301, 302, 303, 307, 308]).call(_context3, status)) {
|
|
183
|
+
const location = response.headers.get('location');
|
|
184
|
+
promise.resolve({
|
|
185
|
+
status,
|
|
186
|
+
location,
|
|
187
|
+
method: status === 303 ? 'GET' : method,
|
|
188
|
+
dropBody: status === 303
|
|
189
|
+
});
|
|
190
|
+
} else if (status >= 500 || status === 0) {
|
|
191
|
+
// retry on 5XX or library error
|
|
192
|
+
if (++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
193
|
+
// Exponentially-growing random delay
|
|
194
|
+
const delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
195
|
+
(0, _setTimeout2.default)(dispatch, delay);
|
|
196
|
+
} else if (status === 0) {
|
|
197
|
+
promise.reject('Unable to connect to the Parse API');
|
|
198
|
+
} else {
|
|
199
|
+
// After the retry limit is reached, fail
|
|
200
|
+
const error = await response.json();
|
|
201
|
+
promise.reject(error);
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
promise.reject(response);
|
|
205
|
+
}
|
|
206
|
+
} catch (error) {
|
|
207
|
+
if (error.name === 'AbortError') {
|
|
208
|
+
promise.resolve({
|
|
209
|
+
response: {
|
|
210
|
+
results: []
|
|
211
|
+
},
|
|
212
|
+
status: 0
|
|
213
|
+
});
|
|
214
|
+
} else if (error.cause?.code === 'ECONNREFUSED') {
|
|
215
|
+
promise.reject('Unable to connect to the Parse API');
|
|
216
|
+
} else {
|
|
217
|
+
promise.reject(error);
|
|
218
|
+
}
|
|
192
219
|
}
|
|
193
220
|
};
|
|
194
221
|
dispatch();
|
|
@@ -196,11 +223,7 @@ const RESTController = {
|
|
|
196
223
|
},
|
|
197
224
|
request(method, path, data, options) {
|
|
198
225
|
options = options || {};
|
|
199
|
-
|
|
200
|
-
if (url[url.length - 1] !== '/') {
|
|
201
|
-
url += '/';
|
|
202
|
-
}
|
|
203
|
-
url += path;
|
|
226
|
+
const url = getPath(_CoreManager.default.get('SERVER_URL'), path);
|
|
204
227
|
const payload = {};
|
|
205
228
|
if (data && typeof data === 'object') {
|
|
206
229
|
for (const k in data) {
|
|
@@ -268,19 +291,34 @@ const RESTController = {
|
|
|
268
291
|
payload._SessionToken = token;
|
|
269
292
|
}
|
|
270
293
|
const payloadString = (0, _stringify.default)(payload);
|
|
271
|
-
return RESTController.ajax(method, url, payloadString, {}, options).then(
|
|
272
|
-
|
|
294
|
+
return RESTController.ajax(method, url, payloadString, {}, options).then(async result => {
|
|
295
|
+
if (result.location) {
|
|
296
|
+
let newURL = getPath(result.location, path);
|
|
297
|
+
let newMethod = result.method;
|
|
298
|
+
let newBody = result.dropBody ? undefined : payloadString;
|
|
299
|
+
|
|
300
|
+
// Follow up to 5 redirects to avoid loops
|
|
301
|
+
for (let i = 0; i < 5; i += 1) {
|
|
302
|
+
const r = await RESTController.ajax(newMethod, newURL, newBody, {}, options);
|
|
303
|
+
if (!r.location) {
|
|
304
|
+
result = r;
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
newURL = getPath(r.location, path);
|
|
308
|
+
newMethod = r.method;
|
|
309
|
+
newBody = r.dropBody ? undefined : payloadString;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const {
|
|
273
313
|
response,
|
|
274
314
|
status,
|
|
275
|
-
headers
|
|
276
|
-
|
|
277
|
-
} = _ref;
|
|
315
|
+
headers
|
|
316
|
+
} = result;
|
|
278
317
|
if (options.returnStatus) {
|
|
279
318
|
return {
|
|
280
319
|
...response,
|
|
281
320
|
_status: status,
|
|
282
|
-
_headers: headers
|
|
283
|
-
_xhr: xhr
|
|
321
|
+
_headers: headers
|
|
284
322
|
};
|
|
285
323
|
} else {
|
|
286
324
|
return response;
|
|
@@ -288,29 +326,16 @@ const RESTController = {
|
|
|
288
326
|
});
|
|
289
327
|
}).catch(RESTController.handleError);
|
|
290
328
|
},
|
|
291
|
-
handleError(
|
|
329
|
+
handleError(errorJSON) {
|
|
292
330
|
// Transform the error into an instance of ParseError by trying to parse
|
|
293
331
|
// the error string as JSON
|
|
294
332
|
let error;
|
|
295
|
-
if (
|
|
296
|
-
|
|
297
|
-
const errorJSON = JSON.parse(response.responseText);
|
|
298
|
-
error = new _ParseError.default(errorJSON.code, errorJSON.error);
|
|
299
|
-
} catch (_) {
|
|
300
|
-
// If we fail to parse the error text, that's okay.
|
|
301
|
-
error = new _ParseError.default(_ParseError.default.INVALID_JSON, 'Received an error with invalid JSON from Parse: ' + response.responseText);
|
|
302
|
-
}
|
|
333
|
+
if (errorJSON.code || errorJSON.error || errorJSON.message) {
|
|
334
|
+
error = new _ParseError.default(errorJSON.code, errorJSON.error || errorJSON.message);
|
|
303
335
|
} else {
|
|
304
|
-
|
|
305
|
-
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + (0, _stringify.default)(message));
|
|
336
|
+
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + (0, _stringify.default)(errorJSON));
|
|
306
337
|
}
|
|
307
338
|
return _promise.default.reject(error);
|
|
308
|
-
},
|
|
309
|
-
_setXHR(xhr) {
|
|
310
|
-
XHR = xhr;
|
|
311
|
-
},
|
|
312
|
-
_getXHR() {
|
|
313
|
-
return XHR;
|
|
314
339
|
}
|
|
315
340
|
};
|
|
316
341
|
var _default = exports.default = RESTController;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
|
4
4
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
5
5
|
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
6
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
7
|
_Object$defineProperty(exports, "__esModule", {
|
|
7
8
|
value: true
|
|
8
9
|
});
|
|
@@ -23,32 +24,31 @@ exports.pushPendingState = pushPendingState;
|
|
|
23
24
|
exports.removeState = removeState;
|
|
24
25
|
exports.setPendingOp = setPendingOp;
|
|
25
26
|
exports.setServerData = setServerData;
|
|
27
|
+
var _create = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/create"));
|
|
26
28
|
var ObjectStateMutations = _interopRequireWildcard(require("./ObjectStateMutations"));
|
|
27
|
-
function
|
|
28
|
-
if ("function"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
let objectState = {};
|
|
29
|
+
function _interopRequireWildcard(e, t) {
|
|
30
|
+
if ("function" == typeof _WeakMap) var r = new _WeakMap(),
|
|
31
|
+
n = new _WeakMap();
|
|
32
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
33
|
+
if (!t && e && e.__esModule) return e;
|
|
34
|
+
var o,
|
|
35
|
+
i,
|
|
36
|
+
f = {
|
|
37
|
+
__proto__: null,
|
|
38
|
+
default: e
|
|
39
|
+
};
|
|
40
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return f;
|
|
41
|
+
if (o = t ? n : r) {
|
|
42
|
+
if (o.has(e)) return o.get(e);
|
|
43
|
+
o.set(e, f);
|
|
44
|
+
}
|
|
45
|
+
for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = _Object$defineProperty) && _Object$getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);
|
|
46
|
+
return f;
|
|
47
|
+
})(e, t);
|
|
48
|
+
}
|
|
49
|
+
// Use Object.create(null) to create an object without prototype chain
|
|
50
|
+
// This prevents prototype pollution attacks
|
|
51
|
+
let objectState = (0, _create.default)(null);
|
|
52
52
|
function getState(obj) {
|
|
53
53
|
const classData = objectState[obj.className];
|
|
54
54
|
if (classData) {
|
|
@@ -62,7 +62,8 @@ function initializeState(obj, initial) {
|
|
|
62
62
|
return state;
|
|
63
63
|
}
|
|
64
64
|
if (!objectState[obj.className]) {
|
|
65
|
-
|
|
65
|
+
// Use Object.create(null) for nested objects too
|
|
66
|
+
objectState[obj.className] = (0, _create.default)(null);
|
|
66
67
|
}
|
|
67
68
|
if (!initial) {
|
|
68
69
|
initial = ObjectStateMutations.defaultState();
|
|
@@ -138,7 +139,7 @@ function enqueueTask(obj, task) {
|
|
|
138
139
|
return state.tasks.enqueue(task);
|
|
139
140
|
}
|
|
140
141
|
function clearAllState() {
|
|
141
|
-
objectState =
|
|
142
|
+
objectState = (0, _create.default)(null);
|
|
142
143
|
}
|
|
143
144
|
function duplicateState(source, dest) {
|
|
144
145
|
dest.id = source.id;
|
|
@@ -27,29 +27,25 @@ exports.setServerData = setServerData;
|
|
|
27
27
|
var _weakMap = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/weak-map"));
|
|
28
28
|
var ObjectStateMutations = _interopRequireWildcard(require("./ObjectStateMutations"));
|
|
29
29
|
var _TaskQueue = _interopRequireDefault(require("./TaskQueue"));
|
|
30
|
-
function
|
|
31
|
-
if ("function"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var i = _Object$defineProperty && _Object$getOwnPropertyDescriptor ? _Object$getOwnPropertyDescriptor(e, u) : null;
|
|
50
|
-
i && (i.get || i.set) ? _Object$defineProperty(n, u, i) : n[u] = e[u];
|
|
51
|
-
}
|
|
52
|
-
return n.default = e, t && t.set(e, n), n;
|
|
30
|
+
function _interopRequireWildcard(e, t) {
|
|
31
|
+
if ("function" == typeof _WeakMap2) var r = new _WeakMap2(),
|
|
32
|
+
n = new _WeakMap2();
|
|
33
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
34
|
+
if (!t && e && e.__esModule) return e;
|
|
35
|
+
var o,
|
|
36
|
+
i,
|
|
37
|
+
f = {
|
|
38
|
+
__proto__: null,
|
|
39
|
+
default: e
|
|
40
|
+
};
|
|
41
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return f;
|
|
42
|
+
if (o = t ? n : r) {
|
|
43
|
+
if (o.has(e)) return o.get(e);
|
|
44
|
+
o.set(e, f);
|
|
45
|
+
}
|
|
46
|
+
for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = _Object$defineProperty) && _Object$getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);
|
|
47
|
+
return f;
|
|
48
|
+
})(e, t);
|
|
53
49
|
}
|
|
54
50
|
let objectState = new _weakMap.default();
|
|
55
51
|
function getState(obj) {
|