parse 6.2.0-alpha.2 → 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 +58692 -26593
- package/dist/parse.min.js +1 -14
- package/dist/parse.weapp.js +58735 -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 +72 -52
- 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 +43 -47
- package/lib/node/ParseFile.js +73 -68
- 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 -37
- package/lib/react-native/ParseFile.js +61 -49
- 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 -44
- package/lib/weapp/ParseFile.js +72 -53
- 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/node.js +1 -1
- package/package.json +33 -35
- package/react-native.js +1 -1
- package/types/Parse.d.ts +16 -10
- package/types/ParseFile.d.ts +19 -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/weapp.js +1 -1
|
@@ -3,19 +3,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = void 0;
|
|
6
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
6
7
|
var _uuid = _interopRequireDefault(require("./uuid"));
|
|
7
8
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
8
9
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
9
10
|
var _promiseUtils = require("./promiseUtils");
|
|
10
|
-
var _Xhr =
|
|
11
|
-
var XHR = null;
|
|
12
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
|
13
|
-
XHR = XMLHttpRequest;
|
|
14
|
-
}
|
|
11
|
+
var _Xhr = require("./Xhr.weapp");
|
|
15
12
|
var useXDomainRequest = false;
|
|
16
13
|
if (typeof XDomainRequest !== 'undefined' && !('withCredentials' in new XMLHttpRequest())) {
|
|
17
14
|
useXDomainRequest = true;
|
|
18
15
|
}
|
|
16
|
+
function getPath(base, pathname) {
|
|
17
|
+
if (base.endsWith('/')) {
|
|
18
|
+
base = base.slice(0, -1);
|
|
19
|
+
}
|
|
20
|
+
if (!pathname.startsWith('/')) {
|
|
21
|
+
pathname = '/' + pathname;
|
|
22
|
+
}
|
|
23
|
+
return base + pathname;
|
|
24
|
+
}
|
|
19
25
|
function ajaxIE9(method, url, data, _headers, options) {
|
|
20
26
|
return new Promise(function (resolve, reject) {
|
|
21
27
|
var xdr = new XDomainRequest();
|
|
@@ -54,129 +60,151 @@ function ajaxIE9(method, url, data, _headers, options) {
|
|
|
54
60
|
});
|
|
55
61
|
}
|
|
56
62
|
var RESTController = {
|
|
57
|
-
ajax: function (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var attempts = 0;
|
|
65
|
-
var _dispatch = function () {
|
|
66
|
-
if (XHR == null) {
|
|
67
|
-
throw new Error('Cannot make a request: No definition of XMLHttpRequest was found.');
|
|
63
|
+
ajax: function () {
|
|
64
|
+
var _ajax = (0, _asyncToGenerator2.default)(function* (method, url, data, headers, options) {
|
|
65
|
+
if (useXDomainRequest) {
|
|
66
|
+
return ajaxIE9(method, url, data, headers, options);
|
|
67
|
+
}
|
|
68
|
+
if (typeof fetch !== 'function') {
|
|
69
|
+
throw new Error('Cannot make a request: Fetch API not found.');
|
|
68
70
|
}
|
|
69
|
-
var
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
var promise = (0, _promiseUtils.resolvingPromise)();
|
|
72
|
+
var isIdempotent = _CoreManager.default.get('IDEMPOTENCY') && ['POST', 'PUT'].includes(method);
|
|
73
|
+
var requestId = isIdempotent ? (0, _uuid.default)() : '';
|
|
74
|
+
var attempts = 0;
|
|
75
|
+
var _dispatch = function () {
|
|
76
|
+
var _ref = (0, _asyncToGenerator2.default)(function* () {
|
|
77
|
+
var controller = new AbortController();
|
|
78
|
+
var signal = controller.signal;
|
|
79
|
+
headers = headers || {};
|
|
80
|
+
if (typeof headers['Content-Type'] !== 'string') {
|
|
81
|
+
headers['Content-Type'] = 'text/plain';
|
|
82
|
+
}
|
|
83
|
+
if (_CoreManager.default.get('IS_NODE')) {
|
|
84
|
+
headers['User-Agent'] = 'Parse/' + _CoreManager.default.get('VERSION') + ' (NodeJS ' + process.versions.node + ')';
|
|
85
|
+
}
|
|
86
|
+
if (isIdempotent) {
|
|
87
|
+
headers['X-Parse-Request-Id'] = requestId;
|
|
88
|
+
}
|
|
89
|
+
var customHeaders = _CoreManager.default.get('REQUEST_HEADERS');
|
|
90
|
+
for (var key in customHeaders) {
|
|
91
|
+
headers[key] = customHeaders[key];
|
|
92
|
+
}
|
|
93
|
+
if (options && typeof options.requestTask === 'function') {
|
|
94
|
+
options.requestTask(controller);
|
|
95
|
+
}
|
|
78
96
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
var fetchOptions = {
|
|
98
|
+
method: method,
|
|
99
|
+
headers: headers,
|
|
100
|
+
signal: signal,
|
|
101
|
+
redirect: 'manual'
|
|
102
|
+
};
|
|
103
|
+
if (data) {
|
|
104
|
+
fetchOptions.body = data;
|
|
105
|
+
}
|
|
106
|
+
var response = yield fetch(url, fetchOptions);
|
|
107
|
+
var status = response.status;
|
|
108
|
+
if (status >= 200 && status < 300) {
|
|
109
|
+
var result;
|
|
110
|
+
var responseHeaders = {};
|
|
111
|
+
var availableHeaders = response.headers.get('access-control-expose-headers') || '';
|
|
112
|
+
availableHeaders.split(', ').forEach(function (header) {
|
|
113
|
+
if (response.headers.has(header)) {
|
|
114
|
+
responseHeaders[header] = response.headers.get(header);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
if (options && typeof options.progress === 'function' && response.body) {
|
|
118
|
+
var reader = response.body.getReader();
|
|
119
|
+
var length = +response.headers.get('Content-Length') || 0;
|
|
120
|
+
if (length === 0) {
|
|
121
|
+
options.progress(null, null, null);
|
|
122
|
+
result = yield response.json();
|
|
123
|
+
} else {
|
|
124
|
+
var recieved = 0;
|
|
125
|
+
var chunks = [];
|
|
126
|
+
while (true) {
|
|
127
|
+
var _yield$reader$read = yield reader.read(),
|
|
128
|
+
done = _yield$reader$read.done,
|
|
129
|
+
value = _yield$reader$read.value;
|
|
130
|
+
if (done) {
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
chunks.push(value);
|
|
134
|
+
recieved += (value == null ? void 0 : value.length) || 0;
|
|
135
|
+
options.progress(recieved / length, recieved, length);
|
|
136
|
+
}
|
|
137
|
+
var body = new Uint8Array(recieved);
|
|
138
|
+
var offset = 0;
|
|
139
|
+
for (var chunk of chunks) {
|
|
140
|
+
body.set(chunk, offset);
|
|
141
|
+
offset += chunk.length;
|
|
142
|
+
}
|
|
143
|
+
var jsonString = new TextDecoder().decode(body);
|
|
144
|
+
result = JSON.parse(jsonString);
|
|
87
145
|
}
|
|
146
|
+
} else {
|
|
147
|
+
result = yield response.json();
|
|
148
|
+
}
|
|
149
|
+
promise.resolve({
|
|
150
|
+
status: status,
|
|
151
|
+
response: result,
|
|
152
|
+
headers: responseHeaders
|
|
153
|
+
});
|
|
154
|
+
} else if (status >= 400 && status < 500) {
|
|
155
|
+
var error = yield response.json();
|
|
156
|
+
promise.reject(error);
|
|
157
|
+
} else if ([301, 302, 303, 307, 308].includes(status)) {
|
|
158
|
+
var location = response.headers.get('location');
|
|
159
|
+
promise.resolve({
|
|
160
|
+
status: status,
|
|
161
|
+
location: location,
|
|
162
|
+
method: status === 303 ? 'GET' : method,
|
|
163
|
+
dropBody: status === 303
|
|
88
164
|
});
|
|
165
|
+
} else if (status >= 500 || status === 0) {
|
|
166
|
+
if (++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
167
|
+
var delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
168
|
+
setTimeout(_dispatch, delay);
|
|
169
|
+
} else if (status === 0) {
|
|
170
|
+
promise.reject('Unable to connect to the Parse API');
|
|
171
|
+
} else {
|
|
172
|
+
promise.reject(response);
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
promise.reject(response);
|
|
176
|
+
}
|
|
177
|
+
} catch (error) {
|
|
178
|
+
var _error$cause;
|
|
179
|
+
if (error.name === 'AbortError') {
|
|
180
|
+
promise.resolve({
|
|
181
|
+
response: {
|
|
182
|
+
results: []
|
|
183
|
+
},
|
|
184
|
+
status: 0
|
|
185
|
+
});
|
|
186
|
+
} else if (((_error$cause = error.cause) == null ? void 0 : _error$cause.code) === 'ECONNREFUSED') {
|
|
187
|
+
promise.reject('Unable to connect to the Parse API');
|
|
188
|
+
} else {
|
|
189
|
+
promise.reject(error);
|
|
89
190
|
}
|
|
90
|
-
} catch (e) {
|
|
91
|
-
promise.reject(e.toString());
|
|
92
|
-
}
|
|
93
|
-
if (response) {
|
|
94
|
-
promise.resolve({
|
|
95
|
-
response: response,
|
|
96
|
-
headers: headers,
|
|
97
|
-
status: xhr.status,
|
|
98
|
-
xhr: xhr
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
} else if (xhr.status >= 500 || xhr.status === 0) {
|
|
102
|
-
if (++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
103
|
-
var delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
104
|
-
setTimeout(_dispatch, delay);
|
|
105
|
-
} else if (xhr.status === 0) {
|
|
106
|
-
promise.reject('Unable to connect to the Parse API');
|
|
107
|
-
} else {
|
|
108
|
-
promise.reject(xhr);
|
|
109
|
-
}
|
|
110
|
-
} else {
|
|
111
|
-
promise.reject(xhr);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
headers = headers || {};
|
|
115
|
-
if (typeof headers['Content-Type'] !== 'string') {
|
|
116
|
-
headers['Content-Type'] = 'text/plain';
|
|
117
|
-
}
|
|
118
|
-
if (_CoreManager.default.get('IS_NODE')) {
|
|
119
|
-
headers['User-Agent'] = 'Parse/' + _CoreManager.default.get('VERSION') + ' (NodeJS ' + process.versions.node + ')';
|
|
120
|
-
}
|
|
121
|
-
if (isIdempotent) {
|
|
122
|
-
headers['X-Parse-Request-Id'] = requestId;
|
|
123
|
-
}
|
|
124
|
-
if (_CoreManager.default.get('SERVER_AUTH_TYPE') && _CoreManager.default.get('SERVER_AUTH_TOKEN')) {
|
|
125
|
-
headers['Authorization'] = _CoreManager.default.get('SERVER_AUTH_TYPE') + ' ' + _CoreManager.default.get('SERVER_AUTH_TOKEN');
|
|
126
|
-
}
|
|
127
|
-
var customHeaders = _CoreManager.default.get('REQUEST_HEADERS');
|
|
128
|
-
for (var key in customHeaders) {
|
|
129
|
-
headers[key] = customHeaders[key];
|
|
130
|
-
}
|
|
131
|
-
if (options && typeof options.progress === 'function') {
|
|
132
|
-
var handleProgress = function (type, event) {
|
|
133
|
-
if (event.lengthComputable) {
|
|
134
|
-
options.progress(event.loaded / event.total, event.loaded, event.total, {
|
|
135
|
-
type: type
|
|
136
|
-
});
|
|
137
|
-
} else {
|
|
138
|
-
options.progress(null, null, null, {
|
|
139
|
-
type: type
|
|
140
|
-
});
|
|
141
191
|
}
|
|
142
|
-
};
|
|
143
|
-
xhr.onprogress = function (event) {
|
|
144
|
-
handleProgress('download', event);
|
|
145
|
-
};
|
|
146
|
-
if (xhr.upload) {
|
|
147
|
-
xhr.upload.onprogress = function (event) {
|
|
148
|
-
handleProgress('upload', event);
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
xhr.open(method, url, true);
|
|
153
|
-
for (var h in headers) {
|
|
154
|
-
xhr.setRequestHeader(h, headers[h]);
|
|
155
|
-
}
|
|
156
|
-
xhr.onabort = function () {
|
|
157
|
-
promise.resolve({
|
|
158
|
-
response: {
|
|
159
|
-
results: []
|
|
160
|
-
},
|
|
161
|
-
status: 0,
|
|
162
|
-
xhr: xhr
|
|
163
192
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
193
|
+
return function () {
|
|
194
|
+
return _ref.apply(this, arguments);
|
|
195
|
+
};
|
|
196
|
+
}();
|
|
197
|
+
_dispatch();
|
|
198
|
+
return promise;
|
|
199
|
+
});
|
|
200
|
+
function ajax() {
|
|
201
|
+
return _ajax.apply(this, arguments);
|
|
202
|
+
}
|
|
203
|
+
return ajax;
|
|
204
|
+
}(),
|
|
173
205
|
request: function (method, path, data, options) {
|
|
174
206
|
options = options || {};
|
|
175
|
-
var url = _CoreManager.default.get('SERVER_URL');
|
|
176
|
-
if (url[url.length - 1] !== '/') {
|
|
177
|
-
url += '/';
|
|
178
|
-
}
|
|
179
|
-
url += path;
|
|
207
|
+
var url = getPath(_CoreManager.default.get('SERVER_URL'), path);
|
|
180
208
|
var payload = {};
|
|
181
209
|
if (data && typeof data === 'object') {
|
|
182
210
|
for (var k in data) {
|
|
@@ -242,43 +270,50 @@ var RESTController = {
|
|
|
242
270
|
payload._SessionToken = token;
|
|
243
271
|
}
|
|
244
272
|
var payloadString = JSON.stringify(payload);
|
|
245
|
-
return RESTController.ajax(method, url, payloadString, {}, options).then(function (
|
|
246
|
-
var
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
273
|
+
return RESTController.ajax(method, url, payloadString, {}, options).then(function () {
|
|
274
|
+
var _ref2 = (0, _asyncToGenerator2.default)(function* (result) {
|
|
275
|
+
if (result.location) {
|
|
276
|
+
var newURL = getPath(result.location, path);
|
|
277
|
+
var newMethod = result.method;
|
|
278
|
+
var newBody = result.dropBody ? undefined : payloadString;
|
|
279
|
+
for (var i = 0; i < 5; i += 1) {
|
|
280
|
+
var r = yield RESTController.ajax(newMethod, newURL, newBody, {}, options);
|
|
281
|
+
if (!r.location) {
|
|
282
|
+
result = r;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
newURL = getPath(r.location, path);
|
|
286
|
+
newMethod = r.method;
|
|
287
|
+
newBody = r.dropBody ? undefined : payloadString;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
var _result = result,
|
|
291
|
+
response = _result.response,
|
|
292
|
+
status = _result.status,
|
|
293
|
+
headers = _result.headers;
|
|
294
|
+
if (options.returnStatus) {
|
|
295
|
+
return Object.assign({}, response, {
|
|
296
|
+
_status: status,
|
|
297
|
+
_headers: headers
|
|
298
|
+
});
|
|
299
|
+
} else {
|
|
300
|
+
return response;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
return function () {
|
|
304
|
+
return _ref2.apply(this, arguments);
|
|
305
|
+
};
|
|
306
|
+
}());
|
|
260
307
|
}).catch(RESTController.handleError);
|
|
261
308
|
},
|
|
262
|
-
handleError: function (
|
|
309
|
+
handleError: function (errorJSON) {
|
|
263
310
|
var error;
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
var errorJSON = JSON.parse(response.responseText);
|
|
267
|
-
error = new _ParseError.default(errorJSON.code, errorJSON.error || errorJSON.message);
|
|
268
|
-
} catch (_) {
|
|
269
|
-
error = new _ParseError.default(_ParseError.default.INVALID_JSON, 'Received an error with invalid JSON from Parse: ' + response.responseText);
|
|
270
|
-
}
|
|
311
|
+
if (errorJSON.code || errorJSON.error || errorJSON.message) {
|
|
312
|
+
error = new _ParseError.default(errorJSON.code, errorJSON.error || errorJSON.message);
|
|
271
313
|
} else {
|
|
272
|
-
|
|
273
|
-
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + JSON.stringify(message));
|
|
314
|
+
error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, 'XMLHttpRequest failed: ' + JSON.stringify(errorJSON));
|
|
274
315
|
}
|
|
275
316
|
return Promise.reject(error);
|
|
276
|
-
},
|
|
277
|
-
_setXHR: function (xhr) {
|
|
278
|
-
XHR = xhr;
|
|
279
|
-
},
|
|
280
|
-
_getXHR: function () {
|
|
281
|
-
return XHR;
|
|
282
317
|
}
|
|
283
318
|
};
|
|
284
319
|
var _default = exports.default = RESTController;
|
|
@@ -19,32 +19,27 @@ exports.removeState = removeState;
|
|
|
19
19
|
exports.setPendingOp = setPendingOp;
|
|
20
20
|
exports.setServerData = setServerData;
|
|
21
21
|
var ObjectStateMutations = _interopRequireWildcard(require("./ObjectStateMutations"));
|
|
22
|
-
function
|
|
23
|
-
if ("function"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
44
|
-
}
|
|
45
|
-
return n.default = e, t && t.set(e, n), n;
|
|
46
|
-
}
|
|
47
|
-
var objectState = {};
|
|
22
|
+
function _interopRequireWildcard(e, t) {
|
|
23
|
+
if ("function" == typeof WeakMap) var r = new WeakMap(),
|
|
24
|
+
n = new WeakMap();
|
|
25
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
26
|
+
if (!t && e && e.__esModule) return e;
|
|
27
|
+
var o,
|
|
28
|
+
i,
|
|
29
|
+
f = {
|
|
30
|
+
__proto__: null,
|
|
31
|
+
default: e
|
|
32
|
+
};
|
|
33
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return f;
|
|
34
|
+
if (o = t ? n : r) {
|
|
35
|
+
if (o.has(e)) return o.get(e);
|
|
36
|
+
o.set(e, f);
|
|
37
|
+
}
|
|
38
|
+
for (var _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]);
|
|
39
|
+
return f;
|
|
40
|
+
})(e, t);
|
|
41
|
+
}
|
|
42
|
+
var objectState = Object.create(null);
|
|
48
43
|
function getState(obj) {
|
|
49
44
|
var classData = objectState[obj.className];
|
|
50
45
|
if (classData) {
|
|
@@ -58,7 +53,7 @@ function initializeState(obj, initial) {
|
|
|
58
53
|
return state;
|
|
59
54
|
}
|
|
60
55
|
if (!objectState[obj.className]) {
|
|
61
|
-
objectState[obj.className] =
|
|
56
|
+
objectState[obj.className] = Object.create(null);
|
|
62
57
|
}
|
|
63
58
|
if (!initial) {
|
|
64
59
|
initial = ObjectStateMutations.defaultState();
|
|
@@ -134,7 +129,7 @@ function enqueueTask(obj, task) {
|
|
|
134
129
|
return state.tasks.enqueue(task);
|
|
135
130
|
}
|
|
136
131
|
function clearAllState() {
|
|
137
|
-
objectState =
|
|
132
|
+
objectState = Object.create(null);
|
|
138
133
|
}
|
|
139
134
|
function duplicateState(source, dest) {
|
|
140
135
|
dest.id = source.id;
|
|
@@ -21,30 +21,25 @@ exports.setPendingOp = setPendingOp;
|
|
|
21
21
|
exports.setServerData = setServerData;
|
|
22
22
|
var ObjectStateMutations = _interopRequireWildcard(require("./ObjectStateMutations"));
|
|
23
23
|
var _TaskQueue = _interopRequireDefault(require("./TaskQueue"));
|
|
24
|
-
function
|
|
25
|
-
if ("function"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
44
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
45
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
46
|
-
}
|
|
47
|
-
return n.default = e, t && t.set(e, n), n;
|
|
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 (var _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);
|
|
48
43
|
}
|
|
49
44
|
var objectState = new WeakMap();
|
|
50
45
|
function getState(obj) {
|
|
@@ -1,102 +1,70 @@
|
|
|
1
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
2
1
|
Object.defineProperty(exports, "__esModule", {
|
|
3
2
|
value: true
|
|
4
3
|
});
|
|
5
|
-
exports.
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.readyState = this.DONE;
|
|
18
|
-
this.status = 0;
|
|
19
|
-
this.response = '';
|
|
20
|
-
this.responseType = '';
|
|
21
|
-
this.responseText = '';
|
|
22
|
-
this.responseHeader = {};
|
|
23
|
-
this.method = '';
|
|
24
|
-
this.url = '';
|
|
25
|
-
this.onabort = function () {};
|
|
26
|
-
this.onprogress = function () {};
|
|
27
|
-
this.onerror = function () {};
|
|
28
|
-
this.onreadystatechange = function () {};
|
|
29
|
-
this.requestTask = null;
|
|
30
|
-
}
|
|
31
|
-
return (0, _createClass2.default)(XhrWeapp, [{
|
|
32
|
-
key: "getAllResponseHeaders",
|
|
33
|
-
value: function () {
|
|
34
|
-
var header = '';
|
|
35
|
-
for (var key in this.responseHeader) {
|
|
36
|
-
header += key + ':' + this.getResponseHeader(key) + '\r\n';
|
|
4
|
+
exports.polyfillFetch = polyfillFetch;
|
|
5
|
+
function parseResponse(res) {
|
|
6
|
+
var headers = res.header || {};
|
|
7
|
+
headers = Object.keys(headers).reduce(function (map, key) {
|
|
8
|
+
map[key.toLowerCase()] = headers[key];
|
|
9
|
+
return map;
|
|
10
|
+
}, {});
|
|
11
|
+
return {
|
|
12
|
+
status: res.statusCode,
|
|
13
|
+
json: function json() {
|
|
14
|
+
if (typeof res.data === 'object') {
|
|
15
|
+
return Promise.resolve(res.data);
|
|
37
16
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return this.responseHeader[key];
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
46
|
-
key: "setRequestHeader",
|
|
47
|
-
value: function (key, value) {
|
|
48
|
-
this.header[key] = value;
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
key: "open",
|
|
52
|
-
value: function (method, url) {
|
|
53
|
-
this.method = method;
|
|
54
|
-
this.url = url;
|
|
55
|
-
}
|
|
56
|
-
}, {
|
|
57
|
-
key: "abort",
|
|
58
|
-
value: function () {
|
|
59
|
-
if (!this.requestTask) {
|
|
60
|
-
return;
|
|
17
|
+
var json = {};
|
|
18
|
+
try {
|
|
19
|
+
json = JSON.parse(res.data);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
console.error(err);
|
|
61
22
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
_this.response = res.data;
|
|
81
|
-
_this.responseHeader = res.header;
|
|
82
|
-
_this.responseText = JSON.stringify(res.data);
|
|
83
|
-
_this.requestTask = null;
|
|
84
|
-
_this.onreadystatechange();
|
|
85
|
-
},
|
|
86
|
-
fail: function (err) {
|
|
87
|
-
_this.requestTask = null;
|
|
88
|
-
_this.onerror(err);
|
|
23
|
+
return Promise.resolve(json);
|
|
24
|
+
},
|
|
25
|
+
headers: {
|
|
26
|
+
keys: function () {
|
|
27
|
+
return Object.keys(headers);
|
|
28
|
+
},
|
|
29
|
+
get: function (n) {
|
|
30
|
+
return headers[n.toLowerCase()];
|
|
31
|
+
},
|
|
32
|
+
has: function (n) {
|
|
33
|
+
return n.toLowerCase() in headers;
|
|
34
|
+
},
|
|
35
|
+
entries: function () {
|
|
36
|
+
var all = [];
|
|
37
|
+
for (var key in headers) {
|
|
38
|
+
if (headers[key]) {
|
|
39
|
+
all.push([key, headers[key]]);
|
|
40
|
+
}
|
|
89
41
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
var event = {
|
|
93
|
-
lengthComputable: res.totalBytesExpectedToWrite !== 0,
|
|
94
|
-
loaded: res.totalBytesWritten,
|
|
95
|
-
total: res.totalBytesExpectedToWrite
|
|
96
|
-
};
|
|
97
|
-
_this.onprogress(event);
|
|
98
|
-
});
|
|
42
|
+
return all;
|
|
43
|
+
}
|
|
99
44
|
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function polyfillFetch() {
|
|
48
|
+
var typedGlobal = global;
|
|
49
|
+
if (typeof typedGlobal.fetch !== 'function') {
|
|
50
|
+
typedGlobal.fetch = function (url, options) {
|
|
51
|
+
var dataType = url.match(/\.(txt|json|html|txt|csv)/) ? 'text' : 'arraybuffer';
|
|
52
|
+
return new Promise(function (resolve, reject) {
|
|
53
|
+
wx.request({
|
|
54
|
+
url: url,
|
|
55
|
+
method: options.method || 'GET',
|
|
56
|
+
data: options.body,
|
|
57
|
+
header: options.headers,
|
|
58
|
+
dataType: dataType,
|
|
59
|
+
responseType: dataType,
|
|
60
|
+
success: function (response) {
|
|
61
|
+
return resolve(parseResponse(response));
|
|
62
|
+
},
|
|
63
|
+
fail: function (error) {
|
|
64
|
+
return reject(error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|