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