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
package/lib/weapp/ParseObject.js
CHANGED
|
@@ -9,18 +9,19 @@ _Object$defineProperty2(exports, "__esModule", {
|
|
|
9
9
|
});
|
|
10
10
|
exports.default = void 0;
|
|
11
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
12
|
+
var _create = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/create"));
|
|
12
13
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
14
|
+
var _for = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol/for"));
|
|
15
|
+
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
13
16
|
var _freeze = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/freeze"));
|
|
14
17
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
15
18
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
16
|
-
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
17
19
|
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
18
20
|
var _getPrototypeOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-prototype-of"));
|
|
19
21
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
20
22
|
var _some = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/some"));
|
|
21
23
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
22
24
|
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
|
|
23
|
-
var _create = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/create"));
|
|
24
25
|
var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));
|
|
25
26
|
var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
|
|
26
27
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
@@ -42,33 +43,29 @@ var SingleInstanceStateController = _interopRequireWildcard(require("./SingleIns
|
|
|
42
43
|
var _unique = _interopRequireDefault(require("./unique"));
|
|
43
44
|
var UniqueInstanceStateController = _interopRequireWildcard(require("./UniqueInstanceStateController"));
|
|
44
45
|
var _unsavedChildren = _interopRequireDefault(require("./unsavedChildren"));
|
|
45
|
-
function
|
|
46
|
-
if ("function"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var i = _Object$defineProperty2 && _Object$getOwnPropertyDescriptor ? _Object$getOwnPropertyDescriptor(e, u) : null;
|
|
65
|
-
i && (i.get || i.set) ? _Object$defineProperty2(n, u, i) : n[u] = e[u];
|
|
66
|
-
}
|
|
67
|
-
return n.default = e, t && t.set(e, n), n;
|
|
46
|
+
function _interopRequireWildcard(e, t) {
|
|
47
|
+
if ("function" == typeof _WeakMap) var r = new _WeakMap(),
|
|
48
|
+
n = new _WeakMap();
|
|
49
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
50
|
+
if (!t && e && e.__esModule) return e;
|
|
51
|
+
var o,
|
|
52
|
+
i,
|
|
53
|
+
f = {
|
|
54
|
+
__proto__: null,
|
|
55
|
+
default: e
|
|
56
|
+
};
|
|
57
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return f;
|
|
58
|
+
if (o = t ? n : r) {
|
|
59
|
+
if (o.has(e)) return o.get(e);
|
|
60
|
+
o.set(e, f);
|
|
61
|
+
}
|
|
62
|
+
for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = _Object$defineProperty2) && _Object$getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);
|
|
63
|
+
return f;
|
|
64
|
+
})(e, t);
|
|
68
65
|
}
|
|
69
66
|
// Mapping of class names to constructors, so we can populate objects from the
|
|
70
67
|
// server with appropriate subclasses of ParseObject
|
|
71
|
-
const classMap =
|
|
68
|
+
const classMap = (0, _create.default)(null);
|
|
72
69
|
|
|
73
70
|
// Global counter for generating unique Ids for non-single-instance objects
|
|
74
71
|
let objectCount = 0;
|
|
@@ -155,6 +152,11 @@ class ParseObject {
|
|
|
155
152
|
throw new Error("Can't create an invalid Parse Object");
|
|
156
153
|
}
|
|
157
154
|
}
|
|
155
|
+
if (_CoreManager.default.get('NODE_LOGGING')) {
|
|
156
|
+
this[(0, _for.default)('nodejs.util.inspect.custom')] = function () {
|
|
157
|
+
return `ParseObject: className: ${this.className}, id: ${this.id}\nAttributes: ${(0, _stringify.default)(this.attributes, null, 2)}`;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
158
160
|
}
|
|
159
161
|
/* Prototype getters / setters */
|
|
160
162
|
|
|
@@ -434,6 +436,9 @@ class ParseObject {
|
|
|
434
436
|
static _getRequestOptions() {
|
|
435
437
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
436
438
|
const requestOptions = {};
|
|
439
|
+
if (Object.prototype.toString.call(options) !== '[object Object]') {
|
|
440
|
+
throw new Error('request options must be of type Object');
|
|
441
|
+
}
|
|
437
442
|
const {
|
|
438
443
|
hasOwn
|
|
439
444
|
} = Object;
|
|
@@ -920,7 +925,7 @@ class ParseObject {
|
|
|
920
925
|
*/
|
|
921
926
|
op(attr) {
|
|
922
927
|
const pending = this._getPendingOps();
|
|
923
|
-
for (let i = pending.length; i
|
|
928
|
+
for (let i = 0; i < pending.length; i += 1) {
|
|
924
929
|
if (pending[i][attr]) {
|
|
925
930
|
return pending[i][attr];
|
|
926
931
|
}
|
|
@@ -2358,7 +2363,6 @@ const DefaultController = {
|
|
|
2358
2363
|
const status = responses[index]._status;
|
|
2359
2364
|
delete responses[index]._status;
|
|
2360
2365
|
delete responses[index]._headers;
|
|
2361
|
-
delete responses[index]._xhr;
|
|
2362
2366
|
mapIdForPin[objectId] = obj._localId;
|
|
2363
2367
|
obj._handleSaveResponse(responses[index].success, status);
|
|
2364
2368
|
} else {
|
|
@@ -2420,7 +2424,6 @@ const DefaultController = {
|
|
|
2420
2424
|
const status = response._status;
|
|
2421
2425
|
delete response._status;
|
|
2422
2426
|
delete response._headers;
|
|
2423
|
-
delete response._xhr;
|
|
2424
2427
|
targetCopy._handleSaveResponse(response, status);
|
|
2425
2428
|
}, error => {
|
|
2426
2429
|
targetCopy._handleSaveError();
|
package/lib/weapp/ParseOp.js
CHANGED
|
@@ -423,8 +423,8 @@ class RelationOp extends Op {
|
|
|
423
423
|
};
|
|
424
424
|
}
|
|
425
425
|
if (this.relationsToRemove.length > 0) {
|
|
426
|
-
var
|
|
427
|
-
pointers = (0, _map.default)(
|
|
426
|
+
var _context0;
|
|
427
|
+
pointers = (0, _map.default)(_context0 = this.relationsToRemove).call(_context0, idToPointer);
|
|
428
428
|
removes = {
|
|
429
429
|
__op: 'RemoveRelation',
|
|
430
430
|
objects: pointers
|
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,118 @@ 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 (header && 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
|
+
const error = await response.json();
|
|
202
|
+
promise.reject(error);
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
promise.reject(response);
|
|
206
|
+
}
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (error.name === 'AbortError') {
|
|
209
|
+
promise.resolve({
|
|
210
|
+
response: {
|
|
211
|
+
results: []
|
|
212
|
+
},
|
|
213
|
+
status: 0
|
|
214
|
+
});
|
|
215
|
+
} else if (error.cause?.code === 'ECONNREFUSED') {
|
|
216
|
+
promise.reject('Unable to connect to the Parse API');
|
|
217
|
+
} else {
|
|
218
|
+
promise.reject(error);
|
|
219
|
+
}
|
|
193
220
|
}
|
|
194
221
|
};
|
|
195
222
|
dispatch();
|
|
@@ -197,11 +224,7 @@ const RESTController = {
|
|
|
197
224
|
},
|
|
198
225
|
request(method, path, data, options) {
|
|
199
226
|
options = options || {};
|
|
200
|
-
|
|
201
|
-
if (url[url.length - 1] !== '/') {
|
|
202
|
-
url += '/';
|
|
203
|
-
}
|
|
204
|
-
url += path;
|
|
227
|
+
const url = getPath(_CoreManager.default.get('SERVER_URL'), path);
|
|
205
228
|
const payload = {};
|
|
206
229
|
if (data && typeof data === 'object') {
|
|
207
230
|
for (const k in data) {
|
|
@@ -269,19 +292,34 @@ const RESTController = {
|
|
|
269
292
|
payload._SessionToken = token;
|
|
270
293
|
}
|
|
271
294
|
const payloadString = (0, _stringify.default)(payload);
|
|
272
|
-
return RESTController.ajax(method, url, payloadString, {}, options).then(
|
|
273
|
-
|
|
295
|
+
return RESTController.ajax(method, url, payloadString, {}, options).then(async result => {
|
|
296
|
+
if (result.location) {
|
|
297
|
+
let newURL = getPath(result.location, path);
|
|
298
|
+
let newMethod = result.method;
|
|
299
|
+
let newBody = result.dropBody ? undefined : payloadString;
|
|
300
|
+
|
|
301
|
+
// Follow up to 5 redirects to avoid loops
|
|
302
|
+
for (let i = 0; i < 5; i += 1) {
|
|
303
|
+
const r = await RESTController.ajax(newMethod, newURL, newBody, {}, options);
|
|
304
|
+
if (!r.location) {
|
|
305
|
+
result = r;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
newURL = getPath(r.location, path);
|
|
309
|
+
newMethod = r.method;
|
|
310
|
+
newBody = r.dropBody ? undefined : payloadString;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const {
|
|
274
314
|
response,
|
|
275
315
|
status,
|
|
276
|
-
headers
|
|
277
|
-
|
|
278
|
-
} = _ref;
|
|
316
|
+
headers
|
|
317
|
+
} = result;
|
|
279
318
|
if (options.returnStatus) {
|
|
280
319
|
return {
|
|
281
320
|
...response,
|
|
282
321
|
_status: status,
|
|
283
|
-
_headers: headers
|
|
284
|
-
_xhr: xhr
|
|
322
|
+
_headers: headers
|
|
285
323
|
};
|
|
286
324
|
} else {
|
|
287
325
|
return response;
|
|
@@ -289,29 +327,16 @@ const RESTController = {
|
|
|
289
327
|
});
|
|
290
328
|
}).catch(RESTController.handleError);
|
|
291
329
|
},
|
|
292
|
-
handleError(
|
|
330
|
+
handleError(errorJSON) {
|
|
293
331
|
// Transform the error into an instance of ParseError by trying to parse
|
|
294
332
|
// the error string as JSON
|
|
295
333
|
let error;
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
const errorJSON = JSON.parse(response.responseText);
|
|
299
|
-
error = new _ParseError.default(errorJSON.code, errorJSON.error);
|
|
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
|
-
}
|
|
334
|
+
if (errorJSON.code || errorJSON.error || errorJSON.message) {
|
|
335
|
+
error = new _ParseError.default(errorJSON.code, errorJSON.error || errorJSON.message);
|
|
304
336
|
} else {
|
|
305
|
-
|
|
306
|
-
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + (0, _stringify.default)(message));
|
|
337
|
+
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + (0, _stringify.default)(errorJSON));
|
|
307
338
|
}
|
|
308
339
|
return _promise.default.reject(error);
|
|
309
|
-
},
|
|
310
|
-
_setXHR(xhr) {
|
|
311
|
-
XHR = xhr;
|
|
312
|
-
},
|
|
313
|
-
_getXHR() {
|
|
314
|
-
return XHR;
|
|
315
340
|
}
|
|
316
341
|
};
|
|
317
342
|
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;
|