parse 6.2.0-alpha.3 → 7.0.0
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/browser/decode.js
CHANGED
|
@@ -13,6 +13,7 @@ var _ParseFile = _interopRequireDefault(require("./ParseFile"));
|
|
|
13
13
|
var _ParseGeoPoint = _interopRequireDefault(require("./ParseGeoPoint"));
|
|
14
14
|
var _ParsePolygon = _interopRequireDefault(require("./ParsePolygon"));
|
|
15
15
|
var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
|
|
16
|
+
var _isDangerousKey = require("./isDangerousKey");
|
|
16
17
|
function decode(value) {
|
|
17
18
|
if (value === null || typeof value !== 'object' || value instanceof Date) {
|
|
18
19
|
return value;
|
|
@@ -60,7 +61,13 @@ function decode(value) {
|
|
|
60
61
|
}
|
|
61
62
|
const copy = {};
|
|
62
63
|
for (const k in value) {
|
|
63
|
-
|
|
64
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
65
|
+
// Skip dangerous keys that could pollute prototypes
|
|
66
|
+
if ((0, _isDangerousKey.isDangerousKey)(k)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
copy[k] = decode(value[k]);
|
|
70
|
+
}
|
|
64
71
|
}
|
|
65
72
|
return copy;
|
|
66
73
|
}
|
package/lib/browser/encode.js
CHANGED
|
@@ -18,6 +18,7 @@ var _ParseFile = _interopRequireDefault(require("./ParseFile"));
|
|
|
18
18
|
var _ParseGeoPoint = _interopRequireDefault(require("./ParseGeoPoint"));
|
|
19
19
|
var _ParsePolygon = _interopRequireDefault(require("./ParsePolygon"));
|
|
20
20
|
var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
|
|
21
|
+
var _isDangerousKey = require("./isDangerousKey");
|
|
21
22
|
function encode(value, disallowObjects, forcePointers, seen, offline) {
|
|
22
23
|
const ParseObject = _CoreManager.default.getParseObject();
|
|
23
24
|
if (value instanceof ParseObject) {
|
|
@@ -67,7 +68,14 @@ function encode(value, disallowObjects, forcePointers, seen, offline) {
|
|
|
67
68
|
if (value && typeof value === 'object') {
|
|
68
69
|
const output = {};
|
|
69
70
|
for (const k in value) {
|
|
70
|
-
|
|
71
|
+
// Only iterate over own properties
|
|
72
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
73
|
+
// Skip dangerous keys that could pollute prototypes
|
|
74
|
+
if ((0, _isDangerousKey.isDangerousKey)(k)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
output[k] = encode(value[k], disallowObjects, forcePointers, seen, offline);
|
|
78
|
+
}
|
|
71
79
|
}
|
|
72
80
|
return output;
|
|
73
81
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.isDangerousKey = isDangerousKey;
|
|
9
|
+
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
10
|
+
var _some = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/some"));
|
|
11
|
+
/**
|
|
12
|
+
* Check if a property name or path is potentially dangerous for prototype pollution
|
|
13
|
+
* Dangerous keys include: __proto__, constructor, prototype
|
|
14
|
+
* @param key - The property name or dotted path to check
|
|
15
|
+
* @returns true if the key is dangerous, false otherwise
|
|
16
|
+
*/
|
|
17
|
+
function isDangerousKey(key) {
|
|
18
|
+
const dangerousKeys = ["__proto__", "constructor", "prototype"];
|
|
19
|
+
// Check if the key itself is dangerous
|
|
20
|
+
if ((0, _includes.default)(dangerousKeys).call(dangerousKeys, key)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
// Check if any part of a dotted path is dangerous
|
|
24
|
+
if ((0, _includes.default)(key).call(key, ".")) {
|
|
25
|
+
const parts = key.split(".");
|
|
26
|
+
return (0, _some.default)(parts).call(parts, part => (0, _includes.default)(dangerousKeys).call(dangerousKeys, part));
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
package/lib/node/CoreManager.js
CHANGED
|
@@ -12,11 +12,9 @@ const config = {
|
|
|
12
12
|
REQUEST_BATCH_SIZE: 20,
|
|
13
13
|
REQUEST_HEADERS: {},
|
|
14
14
|
SERVER_URL: 'https://api.parse.com/1',
|
|
15
|
-
SERVER_AUTH_TYPE: null,
|
|
16
|
-
SERVER_AUTH_TOKEN: null,
|
|
17
15
|
LIVEQUERY_SERVER_URL: null,
|
|
18
16
|
ENCRYPTED_KEY: null,
|
|
19
|
-
VERSION: 'js' + "
|
|
17
|
+
VERSION: 'js' + "7.0.0",
|
|
20
18
|
APPLICATION_ID: null,
|
|
21
19
|
JAVASCRIPT_KEY: null,
|
|
22
20
|
MAINTENANCE_KEY: null,
|
|
@@ -27,7 +25,8 @@ const config = {
|
|
|
27
25
|
ENCRYPTED_USER: false,
|
|
28
26
|
IDEMPOTENCY: false,
|
|
29
27
|
ALLOW_CUSTOM_OBJECT_ID: false,
|
|
30
|
-
PARSE_ERRORS: []
|
|
28
|
+
PARSE_ERRORS: [],
|
|
29
|
+
NODE_LOGGING: false
|
|
31
30
|
};
|
|
32
31
|
function requireMethods(name, methods, controller) {
|
|
33
32
|
methods.forEach(func => {
|
|
@@ -18,6 +18,7 @@ var _ParseFile = _interopRequireDefault(require("./ParseFile"));
|
|
|
18
18
|
var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
|
|
19
19
|
var _TaskQueue = _interopRequireDefault(require("./TaskQueue"));
|
|
20
20
|
var _ParseOp = require("./ParseOp");
|
|
21
|
+
var _isDangerousKey = require("./isDangerousKey");
|
|
21
22
|
function _interopRequireDefault(e) {
|
|
22
23
|
return e && e.__esModule ? e : {
|
|
23
24
|
default: e
|
|
@@ -25,16 +26,24 @@ function _interopRequireDefault(e) {
|
|
|
25
26
|
}
|
|
26
27
|
function defaultState() {
|
|
27
28
|
return {
|
|
28
|
-
serverData:
|
|
29
|
-
pendingOps: [
|
|
30
|
-
objectCache:
|
|
29
|
+
serverData: Object.create(null),
|
|
30
|
+
pendingOps: [Object.create(null)],
|
|
31
|
+
objectCache: Object.create(null),
|
|
31
32
|
tasks: new _TaskQueue.default(),
|
|
32
33
|
existed: false
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
function setServerData(serverData, attributes) {
|
|
36
37
|
for (const attr in attributes) {
|
|
37
|
-
|
|
38
|
+
// Skip properties from prototype chain
|
|
39
|
+
if (!Object.prototype.hasOwnProperty.call(attributes, attr)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// Skip dangerous keys that could pollute prototypes
|
|
43
|
+
if ((0, _isDangerousKey.isDangerousKey)(attr)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (typeof attributes[attr] !== "undefined") {
|
|
38
47
|
serverData[attr] = attributes[attr];
|
|
39
48
|
} else {
|
|
40
49
|
delete serverData[attr];
|
|
@@ -42,6 +51,10 @@ function setServerData(serverData, attributes) {
|
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
53
|
function setPendingOp(pendingOps, attr, op) {
|
|
54
|
+
// Skip dangerous keys that could pollute prototypes
|
|
55
|
+
if ((0, _isDangerousKey.isDangerousKey)(attr)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
45
58
|
const last = pendingOps.length - 1;
|
|
46
59
|
if (op) {
|
|
47
60
|
pendingOps[last][attr] = op;
|
|
@@ -50,12 +63,12 @@ function setPendingOp(pendingOps, attr, op) {
|
|
|
50
63
|
}
|
|
51
64
|
}
|
|
52
65
|
function pushPendingState(pendingOps) {
|
|
53
|
-
pendingOps.push(
|
|
66
|
+
pendingOps.push(Object.create(null));
|
|
54
67
|
}
|
|
55
68
|
function popPendingState(pendingOps) {
|
|
56
69
|
const first = pendingOps.shift();
|
|
57
70
|
if (!pendingOps.length) {
|
|
58
|
-
pendingOps[0] =
|
|
71
|
+
pendingOps[0] = Object.create(null);
|
|
59
72
|
}
|
|
60
73
|
return first;
|
|
61
74
|
}
|
|
@@ -63,6 +76,14 @@ function mergeFirstPendingState(pendingOps) {
|
|
|
63
76
|
const first = popPendingState(pendingOps);
|
|
64
77
|
const next = pendingOps[0];
|
|
65
78
|
for (const attr in first) {
|
|
79
|
+
// Skip properties from prototype chain
|
|
80
|
+
if (!Object.prototype.hasOwnProperty.call(first, attr)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
// Skip dangerous keys that could pollute prototypes
|
|
84
|
+
if ((0, _isDangerousKey.isDangerousKey)(attr)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
66
87
|
if (next[attr] && first[attr]) {
|
|
67
88
|
const merged = next[attr].mergeWith(first[attr]);
|
|
68
89
|
if (merged) {
|
|
@@ -74,6 +95,10 @@ function mergeFirstPendingState(pendingOps) {
|
|
|
74
95
|
}
|
|
75
96
|
}
|
|
76
97
|
function estimateAttribute(serverData, pendingOps, object, attr) {
|
|
98
|
+
// Skip dangerous keys that could pollute prototypes
|
|
99
|
+
if ((0, _isDangerousKey.isDangerousKey)(attr)) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
77
102
|
let value = serverData[attr];
|
|
78
103
|
for (let i = 0; i < pendingOps.length; i++) {
|
|
79
104
|
if (pendingOps[i][attr]) {
|
|
@@ -89,12 +114,20 @@ function estimateAttribute(serverData, pendingOps, object, attr) {
|
|
|
89
114
|
return value;
|
|
90
115
|
}
|
|
91
116
|
function estimateAttributes(serverData, pendingOps, object) {
|
|
92
|
-
const data =
|
|
117
|
+
const data = Object.create(null);
|
|
93
118
|
for (var attr in serverData) {
|
|
94
119
|
data[attr] = serverData[attr];
|
|
95
120
|
}
|
|
96
121
|
for (let i = 0; i < pendingOps.length; i++) {
|
|
97
122
|
for (attr in pendingOps[i]) {
|
|
123
|
+
// Skip properties from prototype chain
|
|
124
|
+
if (!Object.prototype.hasOwnProperty.call(pendingOps[i], attr)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
// Skip dangerous keys that could pollute prototypes
|
|
128
|
+
if ((0, _isDangerousKey.isDangerousKey)(attr)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
98
131
|
if (pendingOps[i][attr] instanceof _ParseOp.RelationOp) {
|
|
99
132
|
if (object.id) {
|
|
100
133
|
data[attr] = pendingOps[i][attr].applyTo(data[attr], object, attr);
|
|
@@ -112,7 +145,7 @@ function estimateAttributes(serverData, pendingOps, object) {
|
|
|
112
145
|
if (!isNaN(nextKey)) {
|
|
113
146
|
object[key] = [];
|
|
114
147
|
} else {
|
|
115
|
-
object[key] =
|
|
148
|
+
object[key] = Object.create(null);
|
|
116
149
|
}
|
|
117
150
|
} else {
|
|
118
151
|
if (Array.isArray(object[key])) {
|
|
@@ -154,7 +187,7 @@ function nestedSet(obj, key, value) {
|
|
|
154
187
|
if (!isNaN(nextPath)) {
|
|
155
188
|
obj[path] = [];
|
|
156
189
|
} else {
|
|
157
|
-
obj[path] =
|
|
190
|
+
obj[path] = Object.create(null);
|
|
158
191
|
}
|
|
159
192
|
}
|
|
160
193
|
obj = obj[path];
|
|
@@ -168,6 +201,14 @@ function nestedSet(obj, key, value) {
|
|
|
168
201
|
function commitServerChanges(serverData, objectCache, changes) {
|
|
169
202
|
const ParseObject = _CoreManager.default.getParseObject();
|
|
170
203
|
for (const attr in changes) {
|
|
204
|
+
// Skip properties from prototype chain
|
|
205
|
+
if (!Object.prototype.hasOwnProperty.call(changes, attr)) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
// Skip dangerous keys that could pollute prototypes
|
|
209
|
+
if ((0, _isDangerousKey.isDangerousKey)(attr)) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
171
212
|
const val = changes[attr];
|
|
172
213
|
nestedSet(serverData, attr, val);
|
|
173
214
|
if (val && typeof val === 'object' && !(val instanceof ParseObject) && !(val instanceof _ParseFile.default) && !(val instanceof _ParseRelation.default)) {
|
package/lib/node/Parse.js
CHANGED
|
@@ -42,30 +42,25 @@ var _LiveQueryClient = _interopRequireDefault(require("./LiveQueryClient"));
|
|
|
42
42
|
var _LocalDatastoreController = _interopRequireDefault(require("./LocalDatastoreController"));
|
|
43
43
|
var _StorageController = _interopRequireDefault(require("./StorageController"));
|
|
44
44
|
var _WebSocketController = _interopRequireDefault(require("./WebSocketController"));
|
|
45
|
-
function
|
|
46
|
-
if ("function"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
65
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
66
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
67
|
-
}
|
|
68
|
-
return n.default = e, t && t.set(e, n), n;
|
|
45
|
+
function _interopRequireWildcard(e, t) {
|
|
46
|
+
if ("function" == typeof WeakMap) var r = new WeakMap(),
|
|
47
|
+
n = new WeakMap();
|
|
48
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
49
|
+
if (!t && e && e.__esModule) return e;
|
|
50
|
+
var o,
|
|
51
|
+
i,
|
|
52
|
+
f = {
|
|
53
|
+
__proto__: null,
|
|
54
|
+
default: e
|
|
55
|
+
};
|
|
56
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return f;
|
|
57
|
+
if (o = t ? n : r) {
|
|
58
|
+
if (o.has(e)) return o.get(e);
|
|
59
|
+
o.set(e, f);
|
|
60
|
+
}
|
|
61
|
+
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]);
|
|
62
|
+
return f;
|
|
63
|
+
})(e, t);
|
|
69
64
|
}
|
|
70
65
|
function _interopRequireDefault(e) {
|
|
71
66
|
return e && e.__esModule ? e : {
|
|
@@ -225,26 +220,6 @@ const Parse = {
|
|
|
225
220
|
get serverURL() {
|
|
226
221
|
return _CoreManager.default.get('SERVER_URL');
|
|
227
222
|
},
|
|
228
|
-
/**
|
|
229
|
-
* @property {string} Parse.serverAuthToken
|
|
230
|
-
* @static
|
|
231
|
-
*/
|
|
232
|
-
set serverAuthToken(value) {
|
|
233
|
-
_CoreManager.default.set('SERVER_AUTH_TOKEN', value);
|
|
234
|
-
},
|
|
235
|
-
get serverAuthToken() {
|
|
236
|
-
return _CoreManager.default.get('SERVER_AUTH_TOKEN');
|
|
237
|
-
},
|
|
238
|
-
/**
|
|
239
|
-
* @property {string} Parse.serverAuthType
|
|
240
|
-
* @static
|
|
241
|
-
*/
|
|
242
|
-
set serverAuthType(value) {
|
|
243
|
-
_CoreManager.default.set('SERVER_AUTH_TYPE', value);
|
|
244
|
-
},
|
|
245
|
-
get serverAuthType() {
|
|
246
|
-
return _CoreManager.default.get('SERVER_AUTH_TYPE');
|
|
247
|
-
},
|
|
248
223
|
/**
|
|
249
224
|
* @property {ParseLiveQuery} Parse.LiveQuery
|
|
250
225
|
* @static
|
|
@@ -305,6 +280,27 @@ const Parse = {
|
|
|
305
280
|
get allowCustomObjectId() {
|
|
306
281
|
return _CoreManager.default.get('ALLOW_CUSTOM_OBJECT_ID');
|
|
307
282
|
},
|
|
283
|
+
/**
|
|
284
|
+
* Setting this property to `true` enables enhanced logging for `Parse.Object`
|
|
285
|
+
* in Node.js environments. Specifically, it will log:
|
|
286
|
+
*
|
|
287
|
+
* ```
|
|
288
|
+
* ParseObject: className: <CLASS_NAME>, id: <OBJECT_ID>
|
|
289
|
+
* Attributes: <OBJECT_ATTRIBUTES>
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* @warning This should not be enabled in production environments as this may
|
|
293
|
+
* expose sensitive information in server logs.
|
|
294
|
+
*
|
|
295
|
+
* @property {boolean} Parse.nodeLogging
|
|
296
|
+
* @static
|
|
297
|
+
*/
|
|
298
|
+
set nodeLogging(value) {
|
|
299
|
+
_CoreManager.default.set('NODE_LOGGING', value);
|
|
300
|
+
},
|
|
301
|
+
get nodeLogging() {
|
|
302
|
+
return _CoreManager.default.get('NODE_LOGGING');
|
|
303
|
+
},
|
|
308
304
|
_request(...args) {
|
|
309
305
|
return _CoreManager.default.getRESTController().request.apply(null, args);
|
|
310
306
|
},
|
package/lib/node/ParseFile.js
CHANGED
|
@@ -7,18 +7,13 @@ exports.b64Digit = b64Digit;
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
9
9
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
10
|
-
var _Xhr = _interopRequireDefault(require("./Xhr.weapp"));
|
|
11
10
|
function _interopRequireDefault(e) {
|
|
12
11
|
return e && e.__esModule ? e : {
|
|
13
12
|
default: e
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
|
-
/* global
|
|
15
|
+
/* global Blob */
|
|
17
16
|
|
|
18
|
-
let XHR = null;
|
|
19
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
|
20
|
-
XHR = XMLHttpRequest;
|
|
21
|
-
}
|
|
22
17
|
function b64Digit(number) {
|
|
23
18
|
if (number < 26) {
|
|
24
19
|
return String.fromCharCode(65 + number);
|
|
@@ -120,19 +115,31 @@ class ParseFile {
|
|
|
120
115
|
* Data is present if initialized with Byte Array, Base64 or Saved with Uri.
|
|
121
116
|
* Data is cleared if saved with File object selected with a file upload control
|
|
122
117
|
*
|
|
118
|
+
* @param {object} options
|
|
119
|
+
* @param {function} [options.progress] callback for download progress
|
|
120
|
+
* <pre>
|
|
121
|
+
* const parseFile = new Parse.File(name, file);
|
|
122
|
+
* parseFile.getData({
|
|
123
|
+
* progress: (progressValue, loaded, total) => {
|
|
124
|
+
* if (progressValue !== null) {
|
|
125
|
+
* // Update the UI using progressValue
|
|
126
|
+
* }
|
|
127
|
+
* }
|
|
128
|
+
* });
|
|
129
|
+
* </pre>
|
|
123
130
|
* @returns {Promise} Promise that is resolve with base64 data
|
|
124
131
|
*/
|
|
125
|
-
async getData() {
|
|
132
|
+
async getData(options) {
|
|
133
|
+
options = options || {};
|
|
126
134
|
if (this._data) {
|
|
127
135
|
return this._data;
|
|
128
136
|
}
|
|
129
137
|
if (!this._url) {
|
|
130
138
|
throw new Error('Cannot retrieve data for unsaved ParseFile.');
|
|
131
139
|
}
|
|
140
|
+
options.requestTask = task => this._requestTask = task;
|
|
132
141
|
const controller = _CoreManager.default.getFileController();
|
|
133
|
-
const result = await controller.download(this._url,
|
|
134
|
-
requestTask: task => this._requestTask = task
|
|
135
|
-
});
|
|
142
|
+
const result = await controller.download(this._url, options);
|
|
136
143
|
this._data = result.base64;
|
|
137
144
|
return this._data;
|
|
138
145
|
}
|
|
@@ -195,12 +202,12 @@ class ParseFile {
|
|
|
195
202
|
* be used for this request.
|
|
196
203
|
* <li>sessionToken: A valid session token, used for making a request on
|
|
197
204
|
* behalf of a specific user.
|
|
198
|
-
* <li>progress:
|
|
205
|
+
* <li>progress: callback for upload progress. For example:
|
|
199
206
|
* <pre>
|
|
200
207
|
* let parseFile = new Parse.File(name, file);
|
|
201
208
|
* parseFile.save({
|
|
202
|
-
* progress: (progressValue, loaded, total
|
|
203
|
-
* if (
|
|
209
|
+
* progress: (progressValue, loaded, total) => {
|
|
210
|
+
* if (progressValue !== null) {
|
|
204
211
|
* // Update the UI using progressValue
|
|
205
212
|
* }
|
|
206
213
|
* }
|
|
@@ -428,55 +435,59 @@ const DefaultController = {
|
|
|
428
435
|
}
|
|
429
436
|
return _CoreManager.default.getRESTController().request('POST', 'files/' + name, data, options);
|
|
430
437
|
},
|
|
431
|
-
download: function (uri, options) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
resp.on('data', data => base64 += data);
|
|
441
|
-
resp.on('end', () => {
|
|
442
|
-
resolve({
|
|
443
|
-
base64,
|
|
444
|
-
contentType: resp.headers['content-type']
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
req.on('abort', () => {
|
|
449
|
-
resolve({});
|
|
450
|
-
});
|
|
451
|
-
req.on('error', reject);
|
|
452
|
-
options.requestTask(req);
|
|
438
|
+
download: async function (uri, options) {
|
|
439
|
+
const controller = new AbortController();
|
|
440
|
+
options.requestTask(controller);
|
|
441
|
+
const {
|
|
442
|
+
signal
|
|
443
|
+
} = controller;
|
|
444
|
+
try {
|
|
445
|
+
const response = await fetch(uri, {
|
|
446
|
+
signal
|
|
453
447
|
});
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
448
|
+
const reader = response.body.getReader();
|
|
449
|
+
const length = +response.headers.get('Content-Length') || 0;
|
|
450
|
+
const contentType = response.headers.get('Content-Type');
|
|
451
|
+
if (length === 0) {
|
|
452
|
+
var _options$progress;
|
|
453
|
+
(_options$progress = options.progress) === null || _options$progress === void 0 || _options$progress.call(options, null, null, null);
|
|
454
|
+
return {
|
|
455
|
+
base64: '',
|
|
456
|
+
contentType
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
let recieved = 0;
|
|
460
|
+
const chunks = [];
|
|
461
|
+
while (true) {
|
|
462
|
+
var _options$progress2;
|
|
463
|
+
const {
|
|
464
|
+
done,
|
|
465
|
+
value
|
|
466
|
+
} = await reader.read();
|
|
467
|
+
if (done) {
|
|
468
|
+
break;
|
|
470
469
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
470
|
+
chunks.push(value);
|
|
471
|
+
recieved += (value === null || value === void 0 ? void 0 : value.length) || 0;
|
|
472
|
+
(_options$progress2 = options.progress) === null || _options$progress2 === void 0 || _options$progress2.call(options, recieved / length, recieved, length);
|
|
473
|
+
}
|
|
474
|
+
const body = new Uint8Array(recieved);
|
|
475
|
+
let offset = 0;
|
|
476
|
+
for (const chunk of chunks) {
|
|
477
|
+
body.set(chunk, offset);
|
|
478
|
+
offset += chunk.length;
|
|
479
|
+
}
|
|
480
|
+
return {
|
|
481
|
+
base64: ParseFile.encodeBase64(body),
|
|
482
|
+
contentType
|
|
476
483
|
};
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
484
|
+
} catch (error) {
|
|
485
|
+
if (error.name === 'AbortError') {
|
|
486
|
+
return {};
|
|
487
|
+
} else {
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
480
491
|
},
|
|
481
492
|
deleteFile: function (name, options) {
|
|
482
493
|
const headers = {
|
|
@@ -492,18 +503,12 @@ const DefaultController = {
|
|
|
492
503
|
url += 'files/' + name;
|
|
493
504
|
return _CoreManager.default.getRESTController().ajax('DELETE', url, '', headers).catch(response => {
|
|
494
505
|
// TODO: return JSON object in server
|
|
495
|
-
if (!response || response === 'SyntaxError: Unexpected end of JSON input') {
|
|
506
|
+
if (!response || response.toString() === 'SyntaxError: Unexpected end of JSON input') {
|
|
496
507
|
return Promise.resolve();
|
|
497
508
|
} else {
|
|
498
509
|
return _CoreManager.default.getRESTController().handleError(response);
|
|
499
510
|
}
|
|
500
511
|
});
|
|
501
|
-
},
|
|
502
|
-
_setXHR(xhr) {
|
|
503
|
-
XHR = xhr;
|
|
504
|
-
},
|
|
505
|
-
_getXHR() {
|
|
506
|
-
return XHR;
|
|
507
512
|
}
|
|
508
513
|
};
|
|
509
514
|
_CoreManager.default.setFileController(DefaultController);
|
package/lib/node/ParseObject.js
CHANGED
|
@@ -22,30 +22,25 @@ var SingleInstanceStateController = _interopRequireWildcard(require("./SingleIns
|
|
|
22
22
|
var _unique = _interopRequireDefault(require("./unique"));
|
|
23
23
|
var UniqueInstanceStateController = _interopRequireWildcard(require("./UniqueInstanceStateController"));
|
|
24
24
|
var _unsavedChildren = _interopRequireDefault(require("./unsavedChildren"));
|
|
25
|
-
function
|
|
26
|
-
if ("function"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
45
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
46
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
47
|
-
}
|
|
48
|
-
return n.default = e, t && t.set(e, n), n;
|
|
25
|
+
function _interopRequireWildcard(e, t) {
|
|
26
|
+
if ("function" == typeof WeakMap) var r = new WeakMap(),
|
|
27
|
+
n = new WeakMap();
|
|
28
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
29
|
+
if (!t && e && e.__esModule) return e;
|
|
30
|
+
var o,
|
|
31
|
+
i,
|
|
32
|
+
f = {
|
|
33
|
+
__proto__: null,
|
|
34
|
+
default: e
|
|
35
|
+
};
|
|
36
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return f;
|
|
37
|
+
if (o = t ? n : r) {
|
|
38
|
+
if (o.has(e)) return o.get(e);
|
|
39
|
+
o.set(e, f);
|
|
40
|
+
}
|
|
41
|
+
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]);
|
|
42
|
+
return f;
|
|
43
|
+
})(e, t);
|
|
49
44
|
}
|
|
50
45
|
function _interopRequireDefault(e) {
|
|
51
46
|
return e && e.__esModule ? e : {
|
|
@@ -54,7 +49,7 @@ function _interopRequireDefault(e) {
|
|
|
54
49
|
}
|
|
55
50
|
// Mapping of class names to constructors, so we can populate objects from the
|
|
56
51
|
// server with appropriate subclasses of ParseObject
|
|
57
|
-
const classMap =
|
|
52
|
+
const classMap = Object.create(null);
|
|
58
53
|
|
|
59
54
|
// Global counter for generating unique Ids for non-single-instance objects
|
|
60
55
|
let objectCount = 0;
|
|
@@ -132,6 +127,11 @@ class ParseObject {
|
|
|
132
127
|
throw new Error("Can't create an invalid Parse Object");
|
|
133
128
|
}
|
|
134
129
|
}
|
|
130
|
+
if (_CoreManager.default.get('NODE_LOGGING')) {
|
|
131
|
+
this[Symbol.for('nodejs.util.inspect.custom')] = function () {
|
|
132
|
+
return `ParseObject: className: ${this.className}, id: ${this.id}\nAttributes: ${JSON.stringify(this.attributes, null, 2)}`;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/**
|
|
@@ -417,6 +417,9 @@ class ParseObject {
|
|
|
417
417
|
}
|
|
418
418
|
static _getRequestOptions(options = {}) {
|
|
419
419
|
const requestOptions = {};
|
|
420
|
+
if (Object.prototype.toString.call(options) !== '[object Object]') {
|
|
421
|
+
throw new Error('request options must be of type Object');
|
|
422
|
+
}
|
|
420
423
|
const {
|
|
421
424
|
hasOwn
|
|
422
425
|
} = Object;
|
|
@@ -2337,7 +2340,6 @@ const DefaultController = {
|
|
|
2337
2340
|
const status = responses[index]._status;
|
|
2338
2341
|
delete responses[index]._status;
|
|
2339
2342
|
delete responses[index]._headers;
|
|
2340
|
-
delete responses[index]._xhr;
|
|
2341
2343
|
mapIdForPin[objectId] = obj._localId;
|
|
2342
2344
|
obj._handleSaveResponse(responses[index].success, status);
|
|
2343
2345
|
} else {
|
|
@@ -2399,7 +2401,6 @@ const DefaultController = {
|
|
|
2399
2401
|
const status = response._status;
|
|
2400
2402
|
delete response._status;
|
|
2401
2403
|
delete response._headers;
|
|
2402
|
-
delete response._xhr;
|
|
2403
2404
|
targetCopy._handleSaveResponse(response, status);
|
|
2404
2405
|
}, error => {
|
|
2405
2406
|
targetCopy._handleSaveError();
|