parse 6.2.0-alpha.3 → 7.0.0-alpha.1
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/dist/parse.js +7151 -8412
- package/dist/parse.min.js +1 -1
- package/dist/parse.weapp.js +7189 -8478
- package/dist/parse.weapp.min.js +1 -1
- package/lib/browser/CoreManager.js +3 -4
- package/lib/browser/ObjectStateMutations.js +51 -9
- package/lib/browser/Parse.js +40 -43
- package/lib/browser/ParseFile.js +70 -50
- package/lib/browser/ParseObject.js +31 -28
- package/lib/browser/ParseOp.js +2 -2
- package/lib/browser/ParseQuery.js +14 -14
- package/lib/browser/RESTController.js +153 -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/isDangerousKey.js +29 -0
- package/lib/node/CoreManager.js +3 -4
- package/lib/node/ObjectStateMutations.js +50 -9
- package/lib/node/Parse.js +40 -44
- package/lib/node/ParseFile.js +71 -66
- package/lib/node/ParseObject.js +28 -27
- package/lib/node/RESTController.js +151 -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/isDangerousKey.js +25 -0
- package/lib/react-native/CoreManager.js +3 -4
- package/lib/react-native/ObjectStateMutations.js +40 -9
- package/lib/react-native/Parse.js +25 -36
- package/lib/react-native/ParseFile.js +59 -47
- package/lib/react-native/ParseObject.js +28 -27
- package/lib/react-native/ParseQuery.js +25 -25
- package/lib/react-native/RESTController.js +185 -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/isDangerousKey.js +17 -0
- package/lib/weapp/CoreManager.js +3 -4
- package/lib/weapp/ObjectStateMutations.js +51 -9
- package/lib/weapp/Parse.js +40 -43
- package/lib/weapp/ParseFile.js +70 -51
- package/lib/weapp/ParseObject.js +31 -28
- package/lib/weapp/ParseOp.js +2 -2
- package/lib/weapp/ParseQuery.js +14 -14
- package/lib/weapp/RESTController.js +154 -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/isDangerousKey.js +29 -0
- package/package.json +28 -29
- package/types/Parse.d.ts +16 -10
- package/types/ParseFile.d.ts +18 -4
- 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/lib/weapp/ParseQuery.js
CHANGED
|
@@ -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,30 +6,36 @@ _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
|
-
|
|
24
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
|
25
|
-
XHR = XMLHttpRequest;
|
|
26
|
-
}
|
|
27
|
-
XHR = _Xhr.default;
|
|
24
|
+
(0, _Xhr.polyfillFetch)();
|
|
28
25
|
let useXDomainRequest = false;
|
|
29
26
|
// @ts-ignore
|
|
30
27
|
if (typeof XDomainRequest !== 'undefined' && !('withCredentials' in new XMLHttpRequest())) {
|
|
31
28
|
useXDomainRequest = true;
|
|
32
29
|
}
|
|
30
|
+
function getPath(base, pathname) {
|
|
31
|
+
if ((0, _endsWith.default)(base).call(base, '/')) {
|
|
32
|
+
base = (0, _slice.default)(base).call(base, 0, -1);
|
|
33
|
+
}
|
|
34
|
+
if (!(0, _startsWith.default)(pathname).call(pathname, '/')) {
|
|
35
|
+
pathname = '/' + pathname;
|
|
36
|
+
}
|
|
37
|
+
return base + pathname;
|
|
38
|
+
}
|
|
33
39
|
function ajaxIE9(method, url, data, _headers, options) {
|
|
34
40
|
return new _promise.default((resolve, reject) => {
|
|
35
41
|
// @ts-ignore
|
|
@@ -72,68 +78,23 @@ function ajaxIE9(method, url, data, _headers, options) {
|
|
|
72
78
|
});
|
|
73
79
|
}
|
|
74
80
|
const RESTController = {
|
|
75
|
-
ajax(method, url, data, headers, options) {
|
|
81
|
+
async ajax(method, url, data, headers, options) {
|
|
76
82
|
var _context;
|
|
77
83
|
if (useXDomainRequest) {
|
|
78
84
|
return ajaxIE9(method, url, data, headers, options);
|
|
79
85
|
}
|
|
86
|
+
if (typeof fetch !== 'function') {
|
|
87
|
+
throw new Error('Cannot make a request: Fetch API not found.');
|
|
88
|
+
}
|
|
80
89
|
const promise = (0, _promiseUtils.resolvingPromise)();
|
|
81
90
|
const isIdempotent = _CoreManager.default.get('IDEMPOTENCY') && (0, _includes.default)(_context = ['POST', 'PUT']).call(_context, method);
|
|
82
91
|
const requestId = isIdempotent ? (0, _uuid.default)() : '';
|
|
83
92
|
let attempts = 0;
|
|
84
|
-
const dispatch = function () {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const xhr = new XHR();
|
|
90
|
-
xhr.onreadystatechange = function () {
|
|
91
|
-
if (xhr.readyState !== 4 || handled || xhr._aborted) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
handled = true;
|
|
95
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
96
|
-
let response;
|
|
97
|
-
try {
|
|
98
|
-
var _context2, _context3;
|
|
99
|
-
response = JSON.parse(xhr.responseText);
|
|
100
|
-
const availableHeaders = typeof xhr.getAllResponseHeaders === 'function' ? xhr.getAllResponseHeaders() : '';
|
|
101
|
-
headers = {};
|
|
102
|
-
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) {
|
|
103
|
-
const responseHeaders = xhr.getResponseHeader('access-control-expose-headers').split(', ');
|
|
104
|
-
(0, _forEach.default)(responseHeaders).call(responseHeaders, header => {
|
|
105
|
-
if ((0, _indexOf.default)(availableHeaders).call(availableHeaders, header.toLowerCase()) >= 0) {
|
|
106
|
-
headers[header] = xhr.getResponseHeader(header.toLowerCase());
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
} catch (e) {
|
|
111
|
-
promise.reject(e.toString());
|
|
112
|
-
}
|
|
113
|
-
if (response) {
|
|
114
|
-
promise.resolve({
|
|
115
|
-
response,
|
|
116
|
-
headers,
|
|
117
|
-
status: xhr.status,
|
|
118
|
-
xhr
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
} else if (xhr.status >= 500 || xhr.status === 0) {
|
|
122
|
-
// retry on 5XX or node-xmlhttprequest error
|
|
123
|
-
if (++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
124
|
-
// Exponentially-growing random delay
|
|
125
|
-
const delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
126
|
-
(0, _setTimeout2.default)(dispatch, delay);
|
|
127
|
-
} else if (xhr.status === 0) {
|
|
128
|
-
promise.reject('Unable to connect to the Parse API');
|
|
129
|
-
} else {
|
|
130
|
-
// After the retry limit is reached, fail
|
|
131
|
-
promise.reject(xhr);
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
promise.reject(xhr);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
93
|
+
const dispatch = async function () {
|
|
94
|
+
const controller = new AbortController();
|
|
95
|
+
const {
|
|
96
|
+
signal
|
|
97
|
+
} = controller;
|
|
137
98
|
headers = headers || {};
|
|
138
99
|
if (typeof headers['Content-Type'] !== 'string') {
|
|
139
100
|
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight
|
|
@@ -144,52 +105,117 @@ const RESTController = {
|
|
|
144
105
|
if (isIdempotent) {
|
|
145
106
|
headers['X-Parse-Request-Id'] = requestId;
|
|
146
107
|
}
|
|
147
|
-
if (_CoreManager.default.get('SERVER_AUTH_TYPE') && _CoreManager.default.get('SERVER_AUTH_TOKEN')) {
|
|
148
|
-
headers['Authorization'] = _CoreManager.default.get('SERVER_AUTH_TYPE') + ' ' + _CoreManager.default.get('SERVER_AUTH_TOKEN');
|
|
149
|
-
}
|
|
150
108
|
const customHeaders = _CoreManager.default.get('REQUEST_HEADERS');
|
|
151
109
|
for (const key in customHeaders) {
|
|
152
110
|
headers[key] = customHeaders[key];
|
|
153
111
|
}
|
|
154
|
-
if (options && typeof options.progress === 'function') {
|
|
155
|
-
const handleProgress = function (type, event) {
|
|
156
|
-
if (event.lengthComputable) {
|
|
157
|
-
options.progress(event.loaded / event.total, event.loaded, event.total, {
|
|
158
|
-
type
|
|
159
|
-
});
|
|
160
|
-
} else {
|
|
161
|
-
options.progress(null, null, null, {
|
|
162
|
-
type
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
xhr.onprogress = event => {
|
|
167
|
-
handleProgress('download', event);
|
|
168
|
-
};
|
|
169
|
-
if (xhr.upload) {
|
|
170
|
-
xhr.upload.onprogress = event => {
|
|
171
|
-
handleProgress('upload', event);
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
xhr.open(method, url, true);
|
|
176
|
-
for (const h in headers) {
|
|
177
|
-
xhr.setRequestHeader(h, headers[h]);
|
|
178
|
-
}
|
|
179
|
-
xhr.onabort = function () {
|
|
180
|
-
promise.resolve({
|
|
181
|
-
response: {
|
|
182
|
-
results: []
|
|
183
|
-
},
|
|
184
|
-
status: 0,
|
|
185
|
-
xhr
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
xhr.send(data);
|
|
189
112
|
// @ts-ignore
|
|
190
113
|
if (options && typeof options.requestTask === 'function') {
|
|
191
114
|
// @ts-ignore
|
|
192
|
-
options.requestTask(
|
|
115
|
+
options.requestTask(controller);
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
var _context3;
|
|
119
|
+
const fetchOptions = {
|
|
120
|
+
method,
|
|
121
|
+
headers,
|
|
122
|
+
signal,
|
|
123
|
+
redirect: 'manual'
|
|
124
|
+
};
|
|
125
|
+
if (data) {
|
|
126
|
+
fetchOptions.body = data;
|
|
127
|
+
}
|
|
128
|
+
const response = await fetch(url, fetchOptions);
|
|
129
|
+
const {
|
|
130
|
+
status
|
|
131
|
+
} = response;
|
|
132
|
+
if (status >= 200 && status < 300) {
|
|
133
|
+
var _context2;
|
|
134
|
+
let result;
|
|
135
|
+
const responseHeaders = {};
|
|
136
|
+
const availableHeaders = response.headers.get('access-control-expose-headers') || '';
|
|
137
|
+
(0, _forEach.default)(_context2 = availableHeaders.split(', ')).call(_context2, header => {
|
|
138
|
+
if (response.headers.has(header)) {
|
|
139
|
+
responseHeaders[header] = response.headers.get(header);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
if (options && typeof options.progress === 'function' && response.body) {
|
|
143
|
+
const reader = response.body.getReader();
|
|
144
|
+
const length = +response.headers.get('Content-Length') || 0;
|
|
145
|
+
if (length === 0) {
|
|
146
|
+
options.progress(null, null, null);
|
|
147
|
+
result = await response.json();
|
|
148
|
+
} else {
|
|
149
|
+
let recieved = 0;
|
|
150
|
+
const chunks = [];
|
|
151
|
+
while (true) {
|
|
152
|
+
const {
|
|
153
|
+
done,
|
|
154
|
+
value
|
|
155
|
+
} = await reader.read();
|
|
156
|
+
if (done) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
chunks.push(value);
|
|
160
|
+
recieved += value?.length || 0;
|
|
161
|
+
options.progress(recieved / length, recieved, length);
|
|
162
|
+
}
|
|
163
|
+
const body = new Uint8Array(recieved);
|
|
164
|
+
let offset = 0;
|
|
165
|
+
for (const chunk of chunks) {
|
|
166
|
+
body.set(chunk, offset);
|
|
167
|
+
offset += chunk.length;
|
|
168
|
+
}
|
|
169
|
+
const jsonString = new TextDecoder().decode(body);
|
|
170
|
+
result = JSON.parse(jsonString);
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
result = await response.json();
|
|
174
|
+
}
|
|
175
|
+
promise.resolve({
|
|
176
|
+
status,
|
|
177
|
+
response: result,
|
|
178
|
+
headers: responseHeaders
|
|
179
|
+
});
|
|
180
|
+
} else if (status >= 400 && status < 500) {
|
|
181
|
+
const error = await response.json();
|
|
182
|
+
promise.reject(error);
|
|
183
|
+
} else if ((0, _includes.default)(_context3 = [301, 302, 303, 307, 308]).call(_context3, status)) {
|
|
184
|
+
const location = response.headers.get('location');
|
|
185
|
+
promise.resolve({
|
|
186
|
+
status,
|
|
187
|
+
location,
|
|
188
|
+
method: status === 303 ? 'GET' : method,
|
|
189
|
+
dropBody: status === 303
|
|
190
|
+
});
|
|
191
|
+
} else if (status >= 500 || status === 0) {
|
|
192
|
+
// retry on 5XX or library error
|
|
193
|
+
if (++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
194
|
+
// Exponentially-growing random delay
|
|
195
|
+
const delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
196
|
+
(0, _setTimeout2.default)(dispatch, delay);
|
|
197
|
+
} else if (status === 0) {
|
|
198
|
+
promise.reject('Unable to connect to the Parse API');
|
|
199
|
+
} else {
|
|
200
|
+
// After the retry limit is reached, fail
|
|
201
|
+
promise.reject(response);
|
|
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
|
+
}
|
|
193
219
|
}
|
|
194
220
|
};
|
|
195
221
|
dispatch();
|
|
@@ -197,11 +223,7 @@ const RESTController = {
|
|
|
197
223
|
},
|
|
198
224
|
request(method, path, data, options) {
|
|
199
225
|
options = options || {};
|
|
200
|
-
|
|
201
|
-
if (url[url.length - 1] !== '/') {
|
|
202
|
-
url += '/';
|
|
203
|
-
}
|
|
204
|
-
url += path;
|
|
226
|
+
const url = getPath(_CoreManager.default.get('SERVER_URL'), path);
|
|
205
227
|
const payload = {};
|
|
206
228
|
if (data && typeof data === 'object') {
|
|
207
229
|
for (const k in data) {
|
|
@@ -269,19 +291,34 @@ const RESTController = {
|
|
|
269
291
|
payload._SessionToken = token;
|
|
270
292
|
}
|
|
271
293
|
const payloadString = (0, _stringify.default)(payload);
|
|
272
|
-
return RESTController.ajax(method, url, payloadString, {}, options).then(
|
|
273
|
-
|
|
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 {
|
|
274
313
|
response,
|
|
275
314
|
status,
|
|
276
|
-
headers
|
|
277
|
-
|
|
278
|
-
} = _ref;
|
|
315
|
+
headers
|
|
316
|
+
} = result;
|
|
279
317
|
if (options.returnStatus) {
|
|
280
318
|
return {
|
|
281
319
|
...response,
|
|
282
320
|
_status: status,
|
|
283
|
-
_headers: headers
|
|
284
|
-
_xhr: xhr
|
|
321
|
+
_headers: headers
|
|
285
322
|
};
|
|
286
323
|
} else {
|
|
287
324
|
return response;
|
|
@@ -289,29 +326,16 @@ const RESTController = {
|
|
|
289
326
|
});
|
|
290
327
|
}).catch(RESTController.handleError);
|
|
291
328
|
},
|
|
292
|
-
handleError(
|
|
329
|
+
handleError(errorJSON) {
|
|
293
330
|
// Transform the error into an instance of ParseError by trying to parse
|
|
294
331
|
// the error string as JSON
|
|
295
332
|
let error;
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
const errorJSON = JSON.parse(response.responseText);
|
|
299
|
-
error = new _ParseError.default(errorJSON.code, errorJSON.error || errorJSON.message);
|
|
300
|
-
} catch (_) {
|
|
301
|
-
// If we fail to parse the error text, that's okay.
|
|
302
|
-
error = new _ParseError.default(_ParseError.default.INVALID_JSON, 'Received an error with invalid JSON from Parse: ' + response.responseText);
|
|
303
|
-
}
|
|
333
|
+
if (errorJSON.code || errorJSON.error || errorJSON.message) {
|
|
334
|
+
error = new _ParseError.default(errorJSON.code, errorJSON.error || errorJSON.message);
|
|
304
335
|
} else {
|
|
305
|
-
|
|
306
|
-
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));
|
|
307
337
|
}
|
|
308
338
|
return _promise.default.reject(error);
|
|
309
|
-
},
|
|
310
|
-
_setXHR(xhr) {
|
|
311
|
-
XHR = xhr;
|
|
312
|
-
},
|
|
313
|
-
_getXHR() {
|
|
314
|
-
return XHR;
|
|
315
339
|
}
|
|
316
340
|
};
|
|
317
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) {
|