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
|
@@ -8,7 +8,7 @@ var _uuid = _interopRequireDefault(require("./uuid"));
|
|
|
8
8
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
9
9
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
10
10
|
var _promiseUtils = require("./promiseUtils");
|
|
11
|
-
var _Xhr =
|
|
11
|
+
var _Xhr = require("./Xhr.weapp");
|
|
12
12
|
function _interopRequireDefault(e) {
|
|
13
13
|
return e && e.__esModule ? e : {
|
|
14
14
|
default: e
|
|
@@ -16,16 +16,20 @@ function _interopRequireDefault(e) {
|
|
|
16
16
|
}
|
|
17
17
|
/* global XMLHttpRequest, XDomainRequest */
|
|
18
18
|
|
|
19
|
-
let XHR = null;
|
|
20
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
|
21
|
-
XHR = XMLHttpRequest;
|
|
22
|
-
}
|
|
23
|
-
XHR = require('xmlhttprequest').XMLHttpRequest;
|
|
24
19
|
let useXDomainRequest = false;
|
|
25
20
|
// @ts-ignore
|
|
26
21
|
if (typeof XDomainRequest !== 'undefined' && !('withCredentials' in new XMLHttpRequest())) {
|
|
27
22
|
useXDomainRequest = true;
|
|
28
23
|
}
|
|
24
|
+
function getPath(base, pathname) {
|
|
25
|
+
if (base.endsWith('/')) {
|
|
26
|
+
base = base.slice(0, -1);
|
|
27
|
+
}
|
|
28
|
+
if (!pathname.startsWith('/')) {
|
|
29
|
+
pathname = '/' + pathname;
|
|
30
|
+
}
|
|
31
|
+
return base + pathname;
|
|
32
|
+
}
|
|
29
33
|
function ajaxIE9(method, url, data, _headers, options) {
|
|
30
34
|
return new Promise((resolve, reject) => {
|
|
31
35
|
// @ts-ignore
|
|
@@ -68,66 +72,22 @@ function ajaxIE9(method, url, data, _headers, options) {
|
|
|
68
72
|
});
|
|
69
73
|
}
|
|
70
74
|
const RESTController = {
|
|
71
|
-
ajax(method, url, data, headers, options) {
|
|
75
|
+
async ajax(method, url, data, headers, options) {
|
|
72
76
|
if (useXDomainRequest) {
|
|
73
77
|
return ajaxIE9(method, url, data, headers, options);
|
|
74
78
|
}
|
|
79
|
+
if (typeof fetch !== 'function') {
|
|
80
|
+
throw new Error('Cannot make a request: Fetch API not found.');
|
|
81
|
+
}
|
|
75
82
|
const promise = (0, _promiseUtils.resolvingPromise)();
|
|
76
83
|
const isIdempotent = _CoreManager.default.get('IDEMPOTENCY') && ['POST', 'PUT'].includes(method);
|
|
77
84
|
const requestId = isIdempotent ? (0, _uuid.default)() : '';
|
|
78
85
|
let attempts = 0;
|
|
79
|
-
const dispatch = function () {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const xhr = new XHR();
|
|
85
|
-
xhr.onreadystatechange = function () {
|
|
86
|
-
if (xhr.readyState !== 4 || handled || xhr._aborted) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
handled = true;
|
|
90
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
91
|
-
let response;
|
|
92
|
-
try {
|
|
93
|
-
response = JSON.parse(xhr.responseText);
|
|
94
|
-
const availableHeaders = typeof xhr.getAllResponseHeaders === 'function' ? xhr.getAllResponseHeaders() : '';
|
|
95
|
-
headers = {};
|
|
96
|
-
if (typeof xhr.getResponseHeader === 'function' && (availableHeaders === null || availableHeaders === void 0 ? void 0 : availableHeaders.indexOf('access-control-expose-headers')) >= 0) {
|
|
97
|
-
const responseHeaders = xhr.getResponseHeader('access-control-expose-headers').split(', ');
|
|
98
|
-
responseHeaders.forEach(header => {
|
|
99
|
-
if (availableHeaders.indexOf(header.toLowerCase()) >= 0) {
|
|
100
|
-
headers[header] = xhr.getResponseHeader(header.toLowerCase());
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
} catch (e) {
|
|
105
|
-
promise.reject(e.toString());
|
|
106
|
-
}
|
|
107
|
-
if (response) {
|
|
108
|
-
promise.resolve({
|
|
109
|
-
response,
|
|
110
|
-
headers,
|
|
111
|
-
status: xhr.status,
|
|
112
|
-
xhr
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
} else if (xhr.status >= 500 || xhr.status === 0) {
|
|
116
|
-
// retry on 5XX or node-xmlhttprequest error
|
|
117
|
-
if (++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
118
|
-
// Exponentially-growing random delay
|
|
119
|
-
const delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
120
|
-
setTimeout(dispatch, delay);
|
|
121
|
-
} else if (xhr.status === 0) {
|
|
122
|
-
promise.reject('Unable to connect to the Parse API');
|
|
123
|
-
} else {
|
|
124
|
-
// After the retry limit is reached, fail
|
|
125
|
-
promise.reject(xhr);
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
promise.reject(xhr);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
86
|
+
const dispatch = async function () {
|
|
87
|
+
const controller = new AbortController();
|
|
88
|
+
const {
|
|
89
|
+
signal
|
|
90
|
+
} = controller;
|
|
131
91
|
headers = headers || {};
|
|
132
92
|
if (typeof headers['Content-Type'] !== 'string') {
|
|
133
93
|
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight
|
|
@@ -138,52 +98,116 @@ const RESTController = {
|
|
|
138
98
|
if (isIdempotent) {
|
|
139
99
|
headers['X-Parse-Request-Id'] = requestId;
|
|
140
100
|
}
|
|
141
|
-
if (_CoreManager.default.get('SERVER_AUTH_TYPE') && _CoreManager.default.get('SERVER_AUTH_TOKEN')) {
|
|
142
|
-
headers['Authorization'] = _CoreManager.default.get('SERVER_AUTH_TYPE') + ' ' + _CoreManager.default.get('SERVER_AUTH_TOKEN');
|
|
143
|
-
}
|
|
144
101
|
const customHeaders = _CoreManager.default.get('REQUEST_HEADERS');
|
|
145
102
|
for (const key in customHeaders) {
|
|
146
103
|
headers[key] = customHeaders[key];
|
|
147
104
|
}
|
|
148
|
-
if (options && typeof options.progress === 'function') {
|
|
149
|
-
const handleProgress = function (type, event) {
|
|
150
|
-
if (event.lengthComputable) {
|
|
151
|
-
options.progress(event.loaded / event.total, event.loaded, event.total, {
|
|
152
|
-
type
|
|
153
|
-
});
|
|
154
|
-
} else {
|
|
155
|
-
options.progress(null, null, null, {
|
|
156
|
-
type
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
xhr.onprogress = event => {
|
|
161
|
-
handleProgress('download', event);
|
|
162
|
-
};
|
|
163
|
-
if (xhr.upload) {
|
|
164
|
-
xhr.upload.onprogress = event => {
|
|
165
|
-
handleProgress('upload', event);
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
xhr.open(method, url, true);
|
|
170
|
-
for (const h in headers) {
|
|
171
|
-
xhr.setRequestHeader(h, headers[h]);
|
|
172
|
-
}
|
|
173
|
-
xhr.onabort = function () {
|
|
174
|
-
promise.resolve({
|
|
175
|
-
response: {
|
|
176
|
-
results: []
|
|
177
|
-
},
|
|
178
|
-
status: 0,
|
|
179
|
-
xhr
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
xhr.send(data);
|
|
183
105
|
// @ts-ignore
|
|
184
106
|
if (options && typeof options.requestTask === 'function') {
|
|
185
107
|
// @ts-ignore
|
|
186
|
-
options.requestTask(
|
|
108
|
+
options.requestTask(controller);
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const fetchOptions = {
|
|
112
|
+
method,
|
|
113
|
+
headers,
|
|
114
|
+
signal,
|
|
115
|
+
redirect: 'manual'
|
|
116
|
+
};
|
|
117
|
+
if (data) {
|
|
118
|
+
fetchOptions.body = data;
|
|
119
|
+
}
|
|
120
|
+
const response = await fetch(url, fetchOptions);
|
|
121
|
+
const {
|
|
122
|
+
status
|
|
123
|
+
} = response;
|
|
124
|
+
if (status >= 200 && status < 300) {
|
|
125
|
+
let result;
|
|
126
|
+
const responseHeaders = {};
|
|
127
|
+
const availableHeaders = response.headers.get('access-control-expose-headers') || '';
|
|
128
|
+
availableHeaders.split(', ').forEach(header => {
|
|
129
|
+
if (response.headers.has(header)) {
|
|
130
|
+
responseHeaders[header] = response.headers.get(header);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
if (options && typeof options.progress === 'function' && response.body) {
|
|
134
|
+
const reader = response.body.getReader();
|
|
135
|
+
const length = +response.headers.get('Content-Length') || 0;
|
|
136
|
+
if (length === 0) {
|
|
137
|
+
options.progress(null, null, null);
|
|
138
|
+
result = await response.json();
|
|
139
|
+
} else {
|
|
140
|
+
let recieved = 0;
|
|
141
|
+
const chunks = [];
|
|
142
|
+
while (true) {
|
|
143
|
+
const {
|
|
144
|
+
done,
|
|
145
|
+
value
|
|
146
|
+
} = await reader.read();
|
|
147
|
+
if (done) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
chunks.push(value);
|
|
151
|
+
recieved += (value === null || value === void 0 ? void 0 : value.length) || 0;
|
|
152
|
+
options.progress(recieved / length, recieved, length);
|
|
153
|
+
}
|
|
154
|
+
const body = new Uint8Array(recieved);
|
|
155
|
+
let offset = 0;
|
|
156
|
+
for (const chunk of chunks) {
|
|
157
|
+
body.set(chunk, offset);
|
|
158
|
+
offset += chunk.length;
|
|
159
|
+
}
|
|
160
|
+
const jsonString = new TextDecoder().decode(body);
|
|
161
|
+
result = JSON.parse(jsonString);
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
result = await response.json();
|
|
165
|
+
}
|
|
166
|
+
promise.resolve({
|
|
167
|
+
status,
|
|
168
|
+
response: result,
|
|
169
|
+
headers: responseHeaders
|
|
170
|
+
});
|
|
171
|
+
} else if (status >= 400 && status < 500) {
|
|
172
|
+
const error = await response.json();
|
|
173
|
+
promise.reject(error);
|
|
174
|
+
} else if ([301, 302, 303, 307, 308].includes(status)) {
|
|
175
|
+
const location = response.headers.get('location');
|
|
176
|
+
promise.resolve({
|
|
177
|
+
status,
|
|
178
|
+
location,
|
|
179
|
+
method: status === 303 ? 'GET' : method,
|
|
180
|
+
dropBody: status === 303
|
|
181
|
+
});
|
|
182
|
+
} else if (status >= 500 || status === 0) {
|
|
183
|
+
// retry on 5XX or library error
|
|
184
|
+
if (++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
185
|
+
// Exponentially-growing random delay
|
|
186
|
+
const delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
187
|
+
setTimeout(dispatch, delay);
|
|
188
|
+
} else if (status === 0) {
|
|
189
|
+
promise.reject('Unable to connect to the Parse API');
|
|
190
|
+
} else {
|
|
191
|
+
// After the retry limit is reached, fail
|
|
192
|
+
promise.reject(response);
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
promise.reject(response);
|
|
196
|
+
}
|
|
197
|
+
} catch (error) {
|
|
198
|
+
var _error$cause;
|
|
199
|
+
if (error.name === 'AbortError') {
|
|
200
|
+
promise.resolve({
|
|
201
|
+
response: {
|
|
202
|
+
results: []
|
|
203
|
+
},
|
|
204
|
+
status: 0
|
|
205
|
+
});
|
|
206
|
+
} else if (((_error$cause = error.cause) === null || _error$cause === void 0 ? void 0 : _error$cause.code) === 'ECONNREFUSED') {
|
|
207
|
+
promise.reject('Unable to connect to the Parse API');
|
|
208
|
+
} else {
|
|
209
|
+
promise.reject(error);
|
|
210
|
+
}
|
|
187
211
|
}
|
|
188
212
|
};
|
|
189
213
|
dispatch();
|
|
@@ -191,11 +215,7 @@ const RESTController = {
|
|
|
191
215
|
},
|
|
192
216
|
request(method, path, data, options) {
|
|
193
217
|
options = options || {};
|
|
194
|
-
|
|
195
|
-
if (url[url.length - 1] !== '/') {
|
|
196
|
-
url += '/';
|
|
197
|
-
}
|
|
198
|
-
url += path;
|
|
218
|
+
const url = getPath(_CoreManager.default.get('SERVER_URL'), path);
|
|
199
219
|
const payload = {};
|
|
200
220
|
if (data && typeof data === 'object') {
|
|
201
221
|
for (const k in data) {
|
|
@@ -263,18 +283,34 @@ const RESTController = {
|
|
|
263
283
|
payload._SessionToken = token;
|
|
264
284
|
}
|
|
265
285
|
const payloadString = JSON.stringify(payload);
|
|
266
|
-
return RESTController.ajax(method, url, payloadString, {}, options).then(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
286
|
+
return RESTController.ajax(method, url, payloadString, {}, options).then(async result => {
|
|
287
|
+
if (result.location) {
|
|
288
|
+
let newURL = getPath(result.location, path);
|
|
289
|
+
let newMethod = result.method;
|
|
290
|
+
let newBody = result.dropBody ? undefined : payloadString;
|
|
291
|
+
|
|
292
|
+
// Follow up to 5 redirects to avoid loops
|
|
293
|
+
for (let i = 0; i < 5; i += 1) {
|
|
294
|
+
const r = await RESTController.ajax(newMethod, newURL, newBody, {}, options);
|
|
295
|
+
if (!r.location) {
|
|
296
|
+
result = r;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
newURL = getPath(r.location, path);
|
|
300
|
+
newMethod = r.method;
|
|
301
|
+
newBody = r.dropBody ? undefined : payloadString;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const {
|
|
305
|
+
response,
|
|
306
|
+
status,
|
|
307
|
+
headers
|
|
308
|
+
} = result;
|
|
272
309
|
if (options.returnStatus) {
|
|
273
310
|
return {
|
|
274
311
|
...response,
|
|
275
312
|
_status: status,
|
|
276
|
-
_headers: headers
|
|
277
|
-
_xhr: xhr
|
|
313
|
+
_headers: headers
|
|
278
314
|
};
|
|
279
315
|
} else {
|
|
280
316
|
return response;
|
|
@@ -282,29 +318,16 @@ const RESTController = {
|
|
|
282
318
|
});
|
|
283
319
|
}).catch(RESTController.handleError);
|
|
284
320
|
},
|
|
285
|
-
handleError(
|
|
321
|
+
handleError(errorJSON) {
|
|
286
322
|
// Transform the error into an instance of ParseError by trying to parse
|
|
287
323
|
// the error string as JSON
|
|
288
324
|
let error;
|
|
289
|
-
if (
|
|
290
|
-
|
|
291
|
-
const errorJSON = JSON.parse(response.responseText);
|
|
292
|
-
error = new _ParseError.default(errorJSON.code, errorJSON.error || errorJSON.message);
|
|
293
|
-
} catch (_) {
|
|
294
|
-
// If we fail to parse the error text, that's okay.
|
|
295
|
-
error = new _ParseError.default(_ParseError.default.INVALID_JSON, 'Received an error with invalid JSON from Parse: ' + response.responseText);
|
|
296
|
-
}
|
|
325
|
+
if (errorJSON.code || errorJSON.error || errorJSON.message) {
|
|
326
|
+
error = new _ParseError.default(errorJSON.code, errorJSON.error || errorJSON.message);
|
|
297
327
|
} else {
|
|
298
|
-
|
|
299
|
-
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + JSON.stringify(message));
|
|
328
|
+
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + JSON.stringify(errorJSON));
|
|
300
329
|
}
|
|
301
330
|
return Promise.reject(error);
|
|
302
|
-
},
|
|
303
|
-
_setXHR(xhr) {
|
|
304
|
-
XHR = xhr;
|
|
305
|
-
},
|
|
306
|
-
_getXHR() {
|
|
307
|
-
return XHR;
|
|
308
331
|
}
|
|
309
332
|
};
|
|
310
333
|
var _default = exports.default = RESTController;
|
|
@@ -21,32 +21,29 @@ exports.removeState = removeState;
|
|
|
21
21
|
exports.setPendingOp = setPendingOp;
|
|
22
22
|
exports.setServerData = setServerData;
|
|
23
23
|
var ObjectStateMutations = _interopRequireWildcard(require("./ObjectStateMutations"));
|
|
24
|
-
function
|
|
25
|
-
if ("function"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return n.default = e, t && t.set(e, n), n;
|
|
48
|
-
}
|
|
49
|
-
let objectState = {};
|
|
24
|
+
function _interopRequireWildcard(e, t) {
|
|
25
|
+
if ("function" == typeof WeakMap) var r = new WeakMap(),
|
|
26
|
+
n = new WeakMap();
|
|
27
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
28
|
+
if (!t && e && e.__esModule) return e;
|
|
29
|
+
var o,
|
|
30
|
+
i,
|
|
31
|
+
f = {
|
|
32
|
+
__proto__: null,
|
|
33
|
+
default: e
|
|
34
|
+
};
|
|
35
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return f;
|
|
36
|
+
if (o = t ? n : r) {
|
|
37
|
+
if (o.has(e)) return o.get(e);
|
|
38
|
+
o.set(e, f);
|
|
39
|
+
}
|
|
40
|
+
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]);
|
|
41
|
+
return f;
|
|
42
|
+
})(e, t);
|
|
43
|
+
}
|
|
44
|
+
// Use Object.create(null) to create an object without prototype chain
|
|
45
|
+
// This prevents prototype pollution attacks
|
|
46
|
+
let objectState = Object.create(null);
|
|
50
47
|
function getState(obj) {
|
|
51
48
|
const classData = objectState[obj.className];
|
|
52
49
|
if (classData) {
|
|
@@ -60,7 +57,8 @@ function initializeState(obj, initial) {
|
|
|
60
57
|
return state;
|
|
61
58
|
}
|
|
62
59
|
if (!objectState[obj.className]) {
|
|
63
|
-
|
|
60
|
+
// Use Object.create(null) for nested objects too
|
|
61
|
+
objectState[obj.className] = Object.create(null);
|
|
64
62
|
}
|
|
65
63
|
if (!initial) {
|
|
66
64
|
initial = ObjectStateMutations.defaultState();
|
|
@@ -136,7 +134,7 @@ function enqueueTask(obj, task) {
|
|
|
136
134
|
return state.tasks.enqueue(task);
|
|
137
135
|
}
|
|
138
136
|
function clearAllState() {
|
|
139
|
-
objectState =
|
|
137
|
+
objectState = Object.create(null);
|
|
140
138
|
}
|
|
141
139
|
function duplicateState(source, dest) {
|
|
142
140
|
dest.id = source.id;
|
|
@@ -27,30 +27,25 @@ function _interopRequireDefault(e) {
|
|
|
27
27
|
default: e
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
if ("function"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
50
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
51
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
52
|
-
}
|
|
53
|
-
return n.default = e, t && t.set(e, n), n;
|
|
30
|
+
function _interopRequireWildcard(e, t) {
|
|
31
|
+
if ("function" == typeof WeakMap) var r = new WeakMap(),
|
|
32
|
+
n = new WeakMap();
|
|
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);
|
|
54
49
|
}
|
|
55
50
|
let objectState = new WeakMap();
|
|
56
51
|
function getState(obj) {
|
package/lib/node/Xhr.weapp.js
CHANGED
|
@@ -3,87 +3,64 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.method = method;
|
|
44
|
-
this.url = url;
|
|
45
|
-
}
|
|
46
|
-
abort() {
|
|
47
|
-
if (!this.requestTask) {
|
|
48
|
-
return;
|
|
6
|
+
exports.polyfillFetch = polyfillFetch;
|
|
7
|
+
/* istanbul ignore file */
|
|
8
|
+
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
function parseResponse(res) {
|
|
11
|
+
let headers = res.header || {};
|
|
12
|
+
headers = Object.keys(headers).reduce((map, key) => {
|
|
13
|
+
map[key.toLowerCase()] = headers[key];
|
|
14
|
+
return map;
|
|
15
|
+
}, {});
|
|
16
|
+
return {
|
|
17
|
+
status: res.statusCode,
|
|
18
|
+
json: () => {
|
|
19
|
+
if (typeof res.data === 'object') {
|
|
20
|
+
return Promise.resolve(res.data);
|
|
21
|
+
}
|
|
22
|
+
let json = {};
|
|
23
|
+
try {
|
|
24
|
+
json = JSON.parse(res.data);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.error(err);
|
|
27
|
+
}
|
|
28
|
+
return Promise.resolve(json);
|
|
29
|
+
},
|
|
30
|
+
headers: {
|
|
31
|
+
keys: () => Object.keys(headers),
|
|
32
|
+
get: n => headers[n.toLowerCase()],
|
|
33
|
+
has: n => n.toLowerCase() in headers,
|
|
34
|
+
entries: () => {
|
|
35
|
+
const all = [];
|
|
36
|
+
for (const key in headers) {
|
|
37
|
+
if (headers[key]) {
|
|
38
|
+
all.push([key, headers[key]]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return all;
|
|
42
|
+
}
|
|
49
43
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.requestTask = wx.request({
|
|
59
|
-
url: this.url,
|
|
60
|
-
method: this.method,
|
|
61
|
-
data: data,
|
|
62
|
-
header: this.header,
|
|
63
|
-
responseType: this.responseType,
|
|
64
|
-
success: res => {
|
|
65
|
-
this.status = res.statusCode;
|
|
66
|
-
this.response = res.data;
|
|
67
|
-
this.responseHeader = res.header;
|
|
68
|
-
this.responseText = JSON.stringify(res.data);
|
|
69
|
-
this.requestTask = null;
|
|
70
|
-
this.onreadystatechange();
|
|
71
|
-
},
|
|
72
|
-
fail: err => {
|
|
73
|
-
this.requestTask = null;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function polyfillFetch() {
|
|
47
|
+
const typedGlobal = global;
|
|
48
|
+
if (typeof typedGlobal.fetch !== 'function') {
|
|
49
|
+
typedGlobal.fetch = (url, options) => {
|
|
50
|
+
const dataType = url.match(/\.(txt|json|html|txt|csv)/) ? 'text' : 'arraybuffer';
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
74
52
|
// @ts-ignore
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
53
|
+
wx.request({
|
|
54
|
+
url,
|
|
55
|
+
method: options.method || 'GET',
|
|
56
|
+
data: options.body,
|
|
57
|
+
header: options.headers,
|
|
58
|
+
dataType,
|
|
59
|
+
responseType: dataType,
|
|
60
|
+
success: response => resolve(parseResponse(response)),
|
|
61
|
+
fail: error => reject(error)
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
87
65
|
}
|
|
88
|
-
}
|
|
89
|
-
var _default = exports.default = XhrWeapp;
|
|
66
|
+
}
|
package/lib/node/decode.js
CHANGED
|
@@ -9,6 +9,7 @@ var _ParseFile = _interopRequireDefault(require("./ParseFile"));
|
|
|
9
9
|
var _ParseGeoPoint = _interopRequireDefault(require("./ParseGeoPoint"));
|
|
10
10
|
var _ParsePolygon = _interopRequireDefault(require("./ParsePolygon"));
|
|
11
11
|
var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
|
|
12
|
+
var _isDangerousKey = require("./isDangerousKey");
|
|
12
13
|
function _interopRequireDefault(e) {
|
|
13
14
|
return e && e.__esModule ? e : {
|
|
14
15
|
default: e
|
|
@@ -61,7 +62,13 @@ function decode(value) {
|
|
|
61
62
|
}
|
|
62
63
|
const copy = {};
|
|
63
64
|
for (const k in value) {
|
|
64
|
-
|
|
65
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
66
|
+
// Skip dangerous keys that could pollute prototypes
|
|
67
|
+
if ((0, _isDangerousKey.isDangerousKey)(k)) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
copy[k] = decode(value[k]);
|
|
71
|
+
}
|
|
65
72
|
}
|
|
66
73
|
return copy;
|
|
67
74
|
}
|
package/lib/node/encode.js
CHANGED
|
@@ -10,6 +10,7 @@ var _ParseFile = _interopRequireDefault(require("./ParseFile"));
|
|
|
10
10
|
var _ParseGeoPoint = _interopRequireDefault(require("./ParseGeoPoint"));
|
|
11
11
|
var _ParsePolygon = _interopRequireDefault(require("./ParsePolygon"));
|
|
12
12
|
var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
|
|
13
|
+
var _isDangerousKey = require("./isDangerousKey");
|
|
13
14
|
function _interopRequireDefault(e) {
|
|
14
15
|
return e && e.__esModule ? e : {
|
|
15
16
|
default: e
|
|
@@ -63,7 +64,14 @@ function encode(value, disallowObjects, forcePointers, seen, offline) {
|
|
|
63
64
|
if (value && typeof value === 'object') {
|
|
64
65
|
const output = {};
|
|
65
66
|
for (const k in value) {
|
|
66
|
-
|
|
67
|
+
// Only iterate over own properties
|
|
68
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
69
|
+
// Skip dangerous keys that could pollute prototypes
|
|
70
|
+
if ((0, _isDangerousKey.isDangerousKey)(k)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
output[k] = encode(value[k], disallowObjects, forcePointers, seen, offline);
|
|
74
|
+
}
|
|
67
75
|
}
|
|
68
76
|
return output;
|
|
69
77
|
}
|