parse 8.1.1-alpha.6 → 8.2.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/parse.js +9417 -9283
- package/dist/parse.min.js +1 -1
- package/dist/parse.weapp.js +9417 -9283
- package/dist/parse.weapp.min.js +1 -1
- package/lib/browser/CoreManager.js +1 -1
- package/lib/browser/ParseFile.js +134 -5
- package/lib/browser/ParseQuery.js +5 -0
- package/lib/browser/RESTController.js +6 -1
- package/lib/node/CoreManager.js +1 -1
- package/lib/node/ParseFile.js +129 -4
- package/lib/node/ParseQuery.js +5 -0
- package/lib/node/RESTController.js +6 -1
- package/lib/react-native/CoreManager.js +1 -1
- package/lib/react-native/ParseFile.js +123 -3
- package/lib/react-native/RESTController.js +5 -1
- package/lib/weapp/CoreManager.js +1 -1
- package/lib/weapp/ParseFile.js +134 -5
- package/lib/weapp/ParseQuery.js +5 -0
- package/lib/weapp/RESTController.js +6 -1
- package/package.json +2 -2
- package/types/CoreManager.d.ts +4 -0
- package/types/ParseFile.d.ts +21 -2
- package/types/ParseQuery.d.ts +5 -0
|
@@ -18,7 +18,7 @@ const config = {
|
|
|
18
18
|
SERVER_URL: 'https://api.parse.com/1',
|
|
19
19
|
LIVEQUERY_SERVER_URL: null,
|
|
20
20
|
ENCRYPTED_KEY: null,
|
|
21
|
-
VERSION: 'js' + "8.
|
|
21
|
+
VERSION: 'js' + "8.2.0-alpha.2",
|
|
22
22
|
APPLICATION_ID: null,
|
|
23
23
|
JAVASCRIPT_KEY: null,
|
|
24
24
|
MAINTENANCE_KEY: null,
|
package/lib/browser/ParseFile.js
CHANGED
|
@@ -16,8 +16,8 @@ exports.b64Digit = b64Digit;
|
|
|
16
16
|
exports.default = void 0;
|
|
17
17
|
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
|
|
18
18
|
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
|
|
19
|
-
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
20
19
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
20
|
+
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
21
21
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
22
22
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
23
23
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
@@ -44,6 +44,7 @@ function _objectSpread(e) {
|
|
|
44
44
|
}
|
|
45
45
|
return e;
|
|
46
46
|
} /* global Blob */
|
|
47
|
+
let NodeReadable;
|
|
47
48
|
function b64Digit(number) {
|
|
48
49
|
if (number < 26) {
|
|
49
50
|
return String.fromCharCode(65 + number);
|
|
@@ -79,8 +80,13 @@ class ParseFile {
|
|
|
79
80
|
* 1. an Array of byte value Numbers or Uint8Array.
|
|
80
81
|
* 2. an Object like { base64: "..." } with a base64-encoded String.
|
|
81
82
|
* 3. an Object like { uri: "..." } with a uri String.
|
|
82
|
-
* 4. a File object selected with a file upload control.
|
|
83
|
-
*
|
|
83
|
+
* 4. a File object selected with a file upload control.
|
|
84
|
+
* 5. (Node.js only) a Buffer. Uploaded as raw binary data instead of
|
|
85
|
+
* base64-encoding, reducing memory usage. Falls back to base64
|
|
86
|
+
* JSON encoding if metadata or tags are set.
|
|
87
|
+
* 6. (Node.js only) a Readable stream, or a Web ReadableStream.
|
|
88
|
+
* Streamed as raw binary data directly into the upload request.
|
|
89
|
+
* Throws if metadata or tags are set.
|
|
84
90
|
* For example:
|
|
85
91
|
* <pre>
|
|
86
92
|
* var fileUploadControl = $("#profilePhotoFileUpload")[0];
|
|
@@ -114,7 +120,25 @@ class ParseFile {
|
|
|
114
120
|
this._metadata = metadata || {};
|
|
115
121
|
this._tags = tags || {};
|
|
116
122
|
if (data !== undefined) {
|
|
117
|
-
if (
|
|
123
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(data)) {
|
|
124
|
+
this._source = {
|
|
125
|
+
format: 'buffer',
|
|
126
|
+
buffer: data,
|
|
127
|
+
type: specifiedType
|
|
128
|
+
};
|
|
129
|
+
} else if (data !== null && typeof data === 'object' && typeof data.pipe === 'function' && typeof data.read === 'function') {
|
|
130
|
+
this._source = {
|
|
131
|
+
format: 'stream',
|
|
132
|
+
stream: data,
|
|
133
|
+
type: specifiedType
|
|
134
|
+
};
|
|
135
|
+
} else if (typeof ReadableStream !== 'undefined' && data instanceof ReadableStream) {
|
|
136
|
+
this._source = {
|
|
137
|
+
format: 'stream',
|
|
138
|
+
stream: data,
|
|
139
|
+
type: specifiedType
|
|
140
|
+
};
|
|
141
|
+
} else if ((0, _isArray.default)(data) || data instanceof Uint8Array) {
|
|
118
142
|
this._data = ParseFile.encodeBase64(data);
|
|
119
143
|
this._source = {
|
|
120
144
|
format: 'base64',
|
|
@@ -169,10 +193,15 @@ class ParseFile {
|
|
|
169
193
|
* @returns {Promise} Promise that is resolve with base64 data
|
|
170
194
|
*/
|
|
171
195
|
async getData(options) {
|
|
196
|
+
var _this$_source;
|
|
172
197
|
options = options || {};
|
|
173
198
|
if (this._data) {
|
|
174
199
|
return this._data;
|
|
175
200
|
}
|
|
201
|
+
if (((_this$_source = this._source) === null || _this$_source === void 0 ? void 0 : _this$_source.format) === 'buffer') {
|
|
202
|
+
this._data = this._source.buffer.toString('base64');
|
|
203
|
+
return this._data;
|
|
204
|
+
}
|
|
176
205
|
if (!this._url) {
|
|
177
206
|
throw new Error('Cannot retrieve data for unsaved ParseFile.');
|
|
178
207
|
}
|
|
@@ -235,6 +264,12 @@ class ParseFile {
|
|
|
235
264
|
/**
|
|
236
265
|
* Saves the file to the Parse cloud.
|
|
237
266
|
*
|
|
267
|
+
* In Node.js, files created with Buffer or ReadableStream are uploaded as
|
|
268
|
+
* raw binary data, avoiding base64 encoding overhead. If metadata
|
|
269
|
+
* or tags are set on a Buffer-backed file, the upload falls back to base64
|
|
270
|
+
* JSON encoding (since the binary endpoint does not support metadata).
|
|
271
|
+
* Stream-backed files with metadata or tags will throw an error.
|
|
272
|
+
*
|
|
238
273
|
* @param {object} options
|
|
239
274
|
* Valid options are:<ul>
|
|
240
275
|
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
|
|
@@ -262,7 +297,38 @@ class ParseFile {
|
|
|
262
297
|
options.tags = this._tags;
|
|
263
298
|
const controller = _CoreManager.default.getFileController();
|
|
264
299
|
if (!this._previousSave) {
|
|
265
|
-
if (this._source.format === '
|
|
300
|
+
if (this._source.format === 'buffer' || this._source.format === 'stream') {
|
|
301
|
+
const hasMetadataOrTags = this._metadata && (0, _keys.default)(this._metadata).length > 0 || this._tags && (0, _keys.default)(this._tags).length > 0;
|
|
302
|
+
if (this._source.format === 'stream' && hasMetadataOrTags) {
|
|
303
|
+
throw new Error('Cannot save a stream-based file with metadata or tags. Use a Buffer instead.');
|
|
304
|
+
}
|
|
305
|
+
if (this._source.format === 'stream' && !controller.saveBinary) {
|
|
306
|
+
throw new Error('Cannot save a stream-based file without saveBinary support on the FileController.');
|
|
307
|
+
}
|
|
308
|
+
if (!hasMetadataOrTags && controller.saveBinary) {
|
|
309
|
+
// Binary upload via ajax
|
|
310
|
+
this._previousSave = controller.saveBinary(this._name, this._source, options).then(res => {
|
|
311
|
+
this._name = res.name;
|
|
312
|
+
this._url = res.url;
|
|
313
|
+
this._data = null;
|
|
314
|
+
this._requestTask = null;
|
|
315
|
+
return this;
|
|
316
|
+
});
|
|
317
|
+
} else if (this._source.format === 'buffer') {
|
|
318
|
+
// Buffer: fall back to base64 JSON encoding (metadata/tags or no saveBinary)
|
|
319
|
+
const base64Source = {
|
|
320
|
+
format: 'base64',
|
|
321
|
+
base64: this._source.buffer.toString('base64'),
|
|
322
|
+
type: this._source.type
|
|
323
|
+
};
|
|
324
|
+
this._previousSave = controller.saveBase64(this._name, base64Source, options).then(res => {
|
|
325
|
+
this._name = res.name;
|
|
326
|
+
this._url = res.url;
|
|
327
|
+
this._requestTask = null;
|
|
328
|
+
return this;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
} else if (this._source.format === 'file') {
|
|
266
332
|
this._previousSave = controller.saveFile(this._name, this._source, options).then(res => {
|
|
267
333
|
this._name = res.name;
|
|
268
334
|
this._url = res.url;
|
|
@@ -474,6 +540,69 @@ const DefaultController = {
|
|
|
474
540
|
}
|
|
475
541
|
return _CoreManager.default.getRESTController().request('POST', 'files/' + name, data, options);
|
|
476
542
|
},
|
|
543
|
+
saveBinary: async function (name, source) {
|
|
544
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
545
|
+
if (source.format !== 'buffer' && source.format !== 'stream') {
|
|
546
|
+
throw new Error('saveBinary can only be used with Buffer or Stream sources.');
|
|
547
|
+
}
|
|
548
|
+
const headers = {
|
|
549
|
+
'X-Parse-Application-ID': _CoreManager.default.get('APPLICATION_ID'),
|
|
550
|
+
'X-Parse-Upload-Mode': 'stream'
|
|
551
|
+
};
|
|
552
|
+
headers['Content-Type'] = (source.type || 'application/octet-stream').replace(/[\r\n]/g, '');
|
|
553
|
+
const jsKey = _CoreManager.default.get('JAVASCRIPT_KEY');
|
|
554
|
+
if (jsKey) {
|
|
555
|
+
headers['X-Parse-JavaScript-Key'] = jsKey;
|
|
556
|
+
}
|
|
557
|
+
let useMasterKey = options.useMasterKey;
|
|
558
|
+
if (typeof useMasterKey === 'undefined') {
|
|
559
|
+
useMasterKey = _CoreManager.default.get('USE_MASTER_KEY');
|
|
560
|
+
}
|
|
561
|
+
if (useMasterKey) {
|
|
562
|
+
if (_CoreManager.default.get('MASTER_KEY')) {
|
|
563
|
+
delete headers['X-Parse-JavaScript-Key'];
|
|
564
|
+
headers['X-Parse-Master-Key'] = _CoreManager.default.get('MASTER_KEY');
|
|
565
|
+
} else {
|
|
566
|
+
throw new Error('Cannot use the Master Key, it has not been provided.');
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (options.sessionToken) {
|
|
570
|
+
headers['X-Parse-Session-Token'] = options.sessionToken;
|
|
571
|
+
} else {
|
|
572
|
+
const userController = _CoreManager.default.getUserController();
|
|
573
|
+
if (userController) {
|
|
574
|
+
const user = await userController.currentUserAsync();
|
|
575
|
+
if (user) {
|
|
576
|
+
const token = user.getSessionToken();
|
|
577
|
+
if (token) {
|
|
578
|
+
headers['X-Parse-Session-Token'] = token;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
let body;
|
|
584
|
+
if (source.format === 'buffer') {
|
|
585
|
+
body = source.buffer;
|
|
586
|
+
} else if (source.format === 'stream') {
|
|
587
|
+
const stream = source.stream;
|
|
588
|
+
if (typeof stream.pipe === 'function' && typeof stream.read === 'function') {
|
|
589
|
+
body = NodeReadable.toWeb(stream);
|
|
590
|
+
} else {
|
|
591
|
+
body = stream;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
let url = _CoreManager.default.get('SERVER_URL');
|
|
595
|
+
if (url[url.length - 1] !== '/') {
|
|
596
|
+
url += '/';
|
|
597
|
+
}
|
|
598
|
+
url += 'files/' + encodeURIComponent(name);
|
|
599
|
+
return _CoreManager.default.getRESTController().ajax('POST', url, body, headers, options).then(_ref => {
|
|
600
|
+
let {
|
|
601
|
+
response
|
|
602
|
+
} = _ref;
|
|
603
|
+
return response;
|
|
604
|
+
});
|
|
605
|
+
},
|
|
477
606
|
download: async function (uri, options) {
|
|
478
607
|
const controller = new AbortController();
|
|
479
608
|
options.requestTask(controller);
|
|
@@ -1735,6 +1735,11 @@ class ParseQuery {
|
|
|
1735
1735
|
* provided keys. If this is called multiple times, then all of the keys
|
|
1736
1736
|
* specified in each of the calls will be included.
|
|
1737
1737
|
*
|
|
1738
|
+
* When selecting `authData` on `Parse.User`, only auth data of currently
|
|
1739
|
+
* configured auth providers is returned. Auth data of providers that are no
|
|
1740
|
+
* longer configured is not included. To return all auth data regardless of
|
|
1741
|
+
* the provider configuration, do not select `authData`.
|
|
1742
|
+
*
|
|
1738
1743
|
* @param {...string|Array<string>} keys The name(s) of the key(s) to include.
|
|
1739
1744
|
* @returns {Parse.Query} Returns the query, so you can chain this call.
|
|
1740
1745
|
*/
|
|
@@ -153,6 +153,9 @@ const RESTController = {
|
|
|
153
153
|
};
|
|
154
154
|
if (data) {
|
|
155
155
|
fetchOptions.body = data;
|
|
156
|
+
if (typeof ReadableStream !== 'undefined' && data instanceof ReadableStream) {
|
|
157
|
+
fetchOptions.duplex = 'half';
|
|
158
|
+
}
|
|
156
159
|
}
|
|
157
160
|
const response = await fetch(url, fetchOptions);
|
|
158
161
|
const {
|
|
@@ -219,7 +222,9 @@ const RESTController = {
|
|
|
219
222
|
});
|
|
220
223
|
} else if (status >= 500 || status === 0) {
|
|
221
224
|
// retry on 5XX or library error
|
|
222
|
-
|
|
225
|
+
// ReadableStream bodies cannot be retried because they are consumed by the first fetch
|
|
226
|
+
const isStream = typeof ReadableStream !== 'undefined' && data instanceof ReadableStream;
|
|
227
|
+
if (!isStream && ++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
223
228
|
// Exponentially-growing random delay
|
|
224
229
|
const delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
225
230
|
(0, _setTimeout2.default)(dispatch, delay);
|
package/lib/node/CoreManager.js
CHANGED
|
@@ -14,7 +14,7 @@ const config = {
|
|
|
14
14
|
SERVER_URL: 'https://api.parse.com/1',
|
|
15
15
|
LIVEQUERY_SERVER_URL: null,
|
|
16
16
|
ENCRYPTED_KEY: null,
|
|
17
|
-
VERSION: 'js' + "8.
|
|
17
|
+
VERSION: 'js' + "8.2.0-alpha.2",
|
|
18
18
|
APPLICATION_ID: null,
|
|
19
19
|
JAVASCRIPT_KEY: null,
|
|
20
20
|
MAINTENANCE_KEY: null,
|
package/lib/node/ParseFile.js
CHANGED
|
@@ -14,6 +14,7 @@ function _interopRequireDefault(e) {
|
|
|
14
14
|
}
|
|
15
15
|
/* global Blob */
|
|
16
16
|
|
|
17
|
+
let NodeReadable = require('stream').Readable;
|
|
17
18
|
function b64Digit(number) {
|
|
18
19
|
if (number < 26) {
|
|
19
20
|
return String.fromCharCode(65 + number);
|
|
@@ -49,8 +50,13 @@ class ParseFile {
|
|
|
49
50
|
* 1. an Array of byte value Numbers or Uint8Array.
|
|
50
51
|
* 2. an Object like { base64: "..." } with a base64-encoded String.
|
|
51
52
|
* 3. an Object like { uri: "..." } with a uri String.
|
|
52
|
-
* 4. a File object selected with a file upload control.
|
|
53
|
-
*
|
|
53
|
+
* 4. a File object selected with a file upload control.
|
|
54
|
+
* 5. (Node.js only) a Buffer. Uploaded as raw binary data instead of
|
|
55
|
+
* base64-encoding, reducing memory usage. Falls back to base64
|
|
56
|
+
* JSON encoding if metadata or tags are set.
|
|
57
|
+
* 6. (Node.js only) a Readable stream, or a Web ReadableStream.
|
|
58
|
+
* Streamed as raw binary data directly into the upload request.
|
|
59
|
+
* Throws if metadata or tags are set.
|
|
54
60
|
* For example:
|
|
55
61
|
* <pre>
|
|
56
62
|
* var fileUploadControl = $("#profilePhotoFileUpload")[0];
|
|
@@ -76,7 +82,25 @@ class ParseFile {
|
|
|
76
82
|
this._metadata = metadata || {};
|
|
77
83
|
this._tags = tags || {};
|
|
78
84
|
if (data !== undefined) {
|
|
79
|
-
if (
|
|
85
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(data)) {
|
|
86
|
+
this._source = {
|
|
87
|
+
format: 'buffer',
|
|
88
|
+
buffer: data,
|
|
89
|
+
type: specifiedType
|
|
90
|
+
};
|
|
91
|
+
} else if (data !== null && typeof data === 'object' && typeof data.pipe === 'function' && typeof data.read === 'function') {
|
|
92
|
+
this._source = {
|
|
93
|
+
format: 'stream',
|
|
94
|
+
stream: data,
|
|
95
|
+
type: specifiedType
|
|
96
|
+
};
|
|
97
|
+
} else if (typeof ReadableStream !== 'undefined' && data instanceof ReadableStream) {
|
|
98
|
+
this._source = {
|
|
99
|
+
format: 'stream',
|
|
100
|
+
stream: data,
|
|
101
|
+
type: specifiedType
|
|
102
|
+
};
|
|
103
|
+
} else if (Array.isArray(data) || data instanceof Uint8Array) {
|
|
80
104
|
this._data = ParseFile.encodeBase64(data);
|
|
81
105
|
this._source = {
|
|
82
106
|
format: 'base64',
|
|
@@ -130,10 +154,15 @@ class ParseFile {
|
|
|
130
154
|
* @returns {Promise} Promise that is resolve with base64 data
|
|
131
155
|
*/
|
|
132
156
|
async getData(options) {
|
|
157
|
+
var _this$_source;
|
|
133
158
|
options = options || {};
|
|
134
159
|
if (this._data) {
|
|
135
160
|
return this._data;
|
|
136
161
|
}
|
|
162
|
+
if (((_this$_source = this._source) === null || _this$_source === void 0 ? void 0 : _this$_source.format) === 'buffer') {
|
|
163
|
+
this._data = this._source.buffer.toString('base64');
|
|
164
|
+
return this._data;
|
|
165
|
+
}
|
|
137
166
|
if (!this._url) {
|
|
138
167
|
throw new Error('Cannot retrieve data for unsaved ParseFile.');
|
|
139
168
|
}
|
|
@@ -196,6 +225,12 @@ class ParseFile {
|
|
|
196
225
|
/**
|
|
197
226
|
* Saves the file to the Parse cloud.
|
|
198
227
|
*
|
|
228
|
+
* In Node.js, files created with Buffer or ReadableStream are uploaded as
|
|
229
|
+
* raw binary data, avoiding base64 encoding overhead. If metadata
|
|
230
|
+
* or tags are set on a Buffer-backed file, the upload falls back to base64
|
|
231
|
+
* JSON encoding (since the binary endpoint does not support metadata).
|
|
232
|
+
* Stream-backed files with metadata or tags will throw an error.
|
|
233
|
+
*
|
|
199
234
|
* @param {object} options
|
|
200
235
|
* Valid options are:<ul>
|
|
201
236
|
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
|
|
@@ -223,7 +258,38 @@ class ParseFile {
|
|
|
223
258
|
options.tags = this._tags;
|
|
224
259
|
const controller = _CoreManager.default.getFileController();
|
|
225
260
|
if (!this._previousSave) {
|
|
226
|
-
if (this._source.format === '
|
|
261
|
+
if (this._source.format === 'buffer' || this._source.format === 'stream') {
|
|
262
|
+
const hasMetadataOrTags = this._metadata && Object.keys(this._metadata).length > 0 || this._tags && Object.keys(this._tags).length > 0;
|
|
263
|
+
if (this._source.format === 'stream' && hasMetadataOrTags) {
|
|
264
|
+
throw new Error('Cannot save a stream-based file with metadata or tags. Use a Buffer instead.');
|
|
265
|
+
}
|
|
266
|
+
if (this._source.format === 'stream' && !controller.saveBinary) {
|
|
267
|
+
throw new Error('Cannot save a stream-based file without saveBinary support on the FileController.');
|
|
268
|
+
}
|
|
269
|
+
if (!hasMetadataOrTags && controller.saveBinary) {
|
|
270
|
+
// Binary upload via ajax
|
|
271
|
+
this._previousSave = controller.saveBinary(this._name, this._source, options).then(res => {
|
|
272
|
+
this._name = res.name;
|
|
273
|
+
this._url = res.url;
|
|
274
|
+
this._data = null;
|
|
275
|
+
this._requestTask = null;
|
|
276
|
+
return this;
|
|
277
|
+
});
|
|
278
|
+
} else if (this._source.format === 'buffer') {
|
|
279
|
+
// Buffer: fall back to base64 JSON encoding (metadata/tags or no saveBinary)
|
|
280
|
+
const base64Source = {
|
|
281
|
+
format: 'base64',
|
|
282
|
+
base64: this._source.buffer.toString('base64'),
|
|
283
|
+
type: this._source.type
|
|
284
|
+
};
|
|
285
|
+
this._previousSave = controller.saveBase64(this._name, base64Source, options).then(res => {
|
|
286
|
+
this._name = res.name;
|
|
287
|
+
this._url = res.url;
|
|
288
|
+
this._requestTask = null;
|
|
289
|
+
return this;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
} else if (this._source.format === 'file') {
|
|
227
293
|
this._previousSave = controller.saveFile(this._name, this._source, options).then(res => {
|
|
228
294
|
this._name = res.name;
|
|
229
295
|
this._url = res.url;
|
|
@@ -435,6 +501,65 @@ const DefaultController = {
|
|
|
435
501
|
}
|
|
436
502
|
return _CoreManager.default.getRESTController().request('POST', 'files/' + name, data, options);
|
|
437
503
|
},
|
|
504
|
+
saveBinary: async function (name, source, options = {}) {
|
|
505
|
+
if (source.format !== 'buffer' && source.format !== 'stream') {
|
|
506
|
+
throw new Error('saveBinary can only be used with Buffer or Stream sources.');
|
|
507
|
+
}
|
|
508
|
+
const headers = {
|
|
509
|
+
'X-Parse-Application-ID': _CoreManager.default.get('APPLICATION_ID'),
|
|
510
|
+
'X-Parse-Upload-Mode': 'stream'
|
|
511
|
+
};
|
|
512
|
+
headers['Content-Type'] = (source.type || 'application/octet-stream').replace(/[\r\n]/g, '');
|
|
513
|
+
const jsKey = _CoreManager.default.get('JAVASCRIPT_KEY');
|
|
514
|
+
if (jsKey) {
|
|
515
|
+
headers['X-Parse-JavaScript-Key'] = jsKey;
|
|
516
|
+
}
|
|
517
|
+
let useMasterKey = options.useMasterKey;
|
|
518
|
+
if (typeof useMasterKey === 'undefined') {
|
|
519
|
+
useMasterKey = _CoreManager.default.get('USE_MASTER_KEY');
|
|
520
|
+
}
|
|
521
|
+
if (useMasterKey) {
|
|
522
|
+
if (_CoreManager.default.get('MASTER_KEY')) {
|
|
523
|
+
delete headers['X-Parse-JavaScript-Key'];
|
|
524
|
+
headers['X-Parse-Master-Key'] = _CoreManager.default.get('MASTER_KEY');
|
|
525
|
+
} else {
|
|
526
|
+
throw new Error('Cannot use the Master Key, it has not been provided.');
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (options.sessionToken) {
|
|
530
|
+
headers['X-Parse-Session-Token'] = options.sessionToken;
|
|
531
|
+
} else {
|
|
532
|
+
const userController = _CoreManager.default.getUserController();
|
|
533
|
+
if (userController) {
|
|
534
|
+
const user = await userController.currentUserAsync();
|
|
535
|
+
if (user) {
|
|
536
|
+
const token = user.getSessionToken();
|
|
537
|
+
if (token) {
|
|
538
|
+
headers['X-Parse-Session-Token'] = token;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
let body;
|
|
544
|
+
if (source.format === 'buffer') {
|
|
545
|
+
body = source.buffer;
|
|
546
|
+
} else if (source.format === 'stream') {
|
|
547
|
+
const stream = source.stream;
|
|
548
|
+
if (typeof stream.pipe === 'function' && typeof stream.read === 'function') {
|
|
549
|
+
body = NodeReadable.toWeb(stream);
|
|
550
|
+
} else {
|
|
551
|
+
body = stream;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
let url = _CoreManager.default.get('SERVER_URL');
|
|
555
|
+
if (url[url.length - 1] !== '/') {
|
|
556
|
+
url += '/';
|
|
557
|
+
}
|
|
558
|
+
url += 'files/' + encodeURIComponent(name);
|
|
559
|
+
return _CoreManager.default.getRESTController().ajax('POST', url, body, headers, options).then(({
|
|
560
|
+
response
|
|
561
|
+
}) => response);
|
|
562
|
+
},
|
|
438
563
|
download: async function (uri, options) {
|
|
439
564
|
const controller = new AbortController();
|
|
440
565
|
options.requestTask(controller);
|
package/lib/node/ParseQuery.js
CHANGED
|
@@ -1671,6 +1671,11 @@ class ParseQuery {
|
|
|
1671
1671
|
* provided keys. If this is called multiple times, then all of the keys
|
|
1672
1672
|
* specified in each of the calls will be included.
|
|
1673
1673
|
*
|
|
1674
|
+
* When selecting `authData` on `Parse.User`, only auth data of currently
|
|
1675
|
+
* configured auth providers is returned. Auth data of providers that are no
|
|
1676
|
+
* longer configured is not included. To return all auth data regardless of
|
|
1677
|
+
* the provider configuration, do not select `authData`.
|
|
1678
|
+
*
|
|
1674
1679
|
* @param {...string|Array<string>} keys The name(s) of the key(s) to include.
|
|
1675
1680
|
* @returns {Parse.Query} Returns the query, so you can chain this call.
|
|
1676
1681
|
*/
|
|
@@ -118,6 +118,9 @@ const RESTController = {
|
|
|
118
118
|
};
|
|
119
119
|
if (data) {
|
|
120
120
|
fetchOptions.body = data;
|
|
121
|
+
if (typeof ReadableStream !== 'undefined' && data instanceof ReadableStream) {
|
|
122
|
+
fetchOptions.duplex = 'half';
|
|
123
|
+
}
|
|
121
124
|
}
|
|
122
125
|
const response = await fetch(url, fetchOptions);
|
|
123
126
|
const {
|
|
@@ -183,7 +186,9 @@ const RESTController = {
|
|
|
183
186
|
});
|
|
184
187
|
} else if (status >= 500 || status === 0) {
|
|
185
188
|
// retry on 5XX or library error
|
|
186
|
-
|
|
189
|
+
// ReadableStream bodies cannot be retried because they are consumed by the first fetch
|
|
190
|
+
const isStream = typeof ReadableStream !== 'undefined' && data instanceof ReadableStream;
|
|
191
|
+
if (!isStream && ++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
187
192
|
// Exponentially-growing random delay
|
|
188
193
|
const delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
189
194
|
setTimeout(dispatch, delay);
|
|
@@ -10,6 +10,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
10
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
11
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
12
12
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
13
|
+
var NodeReadable;
|
|
13
14
|
function b64Digit(number) {
|
|
14
15
|
if (number < 26) {
|
|
15
16
|
return String.fromCharCode(65 + number);
|
|
@@ -36,7 +37,25 @@ var ParseFile = function () {
|
|
|
36
37
|
this._metadata = metadata || {};
|
|
37
38
|
this._tags = tags || {};
|
|
38
39
|
if (data !== undefined) {
|
|
39
|
-
if (
|
|
40
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(data)) {
|
|
41
|
+
this._source = {
|
|
42
|
+
format: 'buffer',
|
|
43
|
+
buffer: data,
|
|
44
|
+
type: specifiedType
|
|
45
|
+
};
|
|
46
|
+
} else if (data !== null && typeof data === 'object' && typeof data.pipe === 'function' && typeof data.read === 'function') {
|
|
47
|
+
this._source = {
|
|
48
|
+
format: 'stream',
|
|
49
|
+
stream: data,
|
|
50
|
+
type: specifiedType
|
|
51
|
+
};
|
|
52
|
+
} else if (typeof ReadableStream !== 'undefined' && data instanceof ReadableStream) {
|
|
53
|
+
this._source = {
|
|
54
|
+
format: 'stream',
|
|
55
|
+
stream: data,
|
|
56
|
+
type: specifiedType
|
|
57
|
+
};
|
|
58
|
+
} else if (Array.isArray(data) || data instanceof Uint8Array) {
|
|
40
59
|
this._data = ParseFile.encodeBase64(data);
|
|
41
60
|
this._source = {
|
|
42
61
|
format: 'base64',
|
|
@@ -73,11 +92,16 @@ var ParseFile = function () {
|
|
|
73
92
|
key: "getData",
|
|
74
93
|
value: function () {
|
|
75
94
|
var _getData = (0, _asyncToGenerator2.default)(function* (options) {
|
|
76
|
-
var _this
|
|
95
|
+
var _this$_source,
|
|
96
|
+
_this = this;
|
|
77
97
|
options = options || {};
|
|
78
98
|
if (this._data) {
|
|
79
99
|
return this._data;
|
|
80
100
|
}
|
|
101
|
+
if (((_this$_source = this._source) == null ? void 0 : _this$_source.format) === 'buffer') {
|
|
102
|
+
this._data = this._source.buffer.toString('base64');
|
|
103
|
+
return this._data;
|
|
104
|
+
}
|
|
81
105
|
if (!this._url) {
|
|
82
106
|
throw new Error('Cannot retrieve data for unsaved ParseFile.');
|
|
83
107
|
}
|
|
@@ -134,7 +158,36 @@ var ParseFile = function () {
|
|
|
134
158
|
options.tags = this._tags;
|
|
135
159
|
var controller = _CoreManager.default.getFileController();
|
|
136
160
|
if (!this._previousSave) {
|
|
137
|
-
if (this._source.format === '
|
|
161
|
+
if (this._source.format === 'buffer' || this._source.format === 'stream') {
|
|
162
|
+
var hasMetadataOrTags = this._metadata && Object.keys(this._metadata).length > 0 || this._tags && Object.keys(this._tags).length > 0;
|
|
163
|
+
if (this._source.format === 'stream' && hasMetadataOrTags) {
|
|
164
|
+
throw new Error('Cannot save a stream-based file with metadata or tags. Use a Buffer instead.');
|
|
165
|
+
}
|
|
166
|
+
if (this._source.format === 'stream' && !controller.saveBinary) {
|
|
167
|
+
throw new Error('Cannot save a stream-based file without saveBinary support on the FileController.');
|
|
168
|
+
}
|
|
169
|
+
if (!hasMetadataOrTags && controller.saveBinary) {
|
|
170
|
+
this._previousSave = controller.saveBinary(this._name, this._source, options).then(function (res) {
|
|
171
|
+
_this2._name = res.name;
|
|
172
|
+
_this2._url = res.url;
|
|
173
|
+
_this2._data = null;
|
|
174
|
+
_this2._requestTask = null;
|
|
175
|
+
return _this2;
|
|
176
|
+
});
|
|
177
|
+
} else if (this._source.format === 'buffer') {
|
|
178
|
+
var base64Source = {
|
|
179
|
+
format: 'base64',
|
|
180
|
+
base64: this._source.buffer.toString('base64'),
|
|
181
|
+
type: this._source.type
|
|
182
|
+
};
|
|
183
|
+
this._previousSave = controller.saveBase64(this._name, base64Source, options).then(function (res) {
|
|
184
|
+
_this2._name = res.name;
|
|
185
|
+
_this2._url = res.url;
|
|
186
|
+
_this2._requestTask = null;
|
|
187
|
+
return _this2;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
} else if (this._source.format === 'file') {
|
|
138
191
|
this._previousSave = controller.saveFile(this._name, this._source, options).then(function (res) {
|
|
139
192
|
_this2._name = res.name;
|
|
140
193
|
_this2._url = res.url;
|
|
@@ -334,6 +387,73 @@ var DefaultController = {
|
|
|
334
387
|
}
|
|
335
388
|
return _CoreManager.default.getRESTController().request('POST', 'files/' + name, data, options);
|
|
336
389
|
},
|
|
390
|
+
saveBinary: function () {
|
|
391
|
+
var _saveBinary = (0, _asyncToGenerator2.default)(function* (name, source) {
|
|
392
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
393
|
+
if (source.format !== 'buffer' && source.format !== 'stream') {
|
|
394
|
+
throw new Error('saveBinary can only be used with Buffer or Stream sources.');
|
|
395
|
+
}
|
|
396
|
+
var headers = {
|
|
397
|
+
'X-Parse-Application-ID': _CoreManager.default.get('APPLICATION_ID'),
|
|
398
|
+
'X-Parse-Upload-Mode': 'stream'
|
|
399
|
+
};
|
|
400
|
+
headers['Content-Type'] = (source.type || 'application/octet-stream').replace(/[\r\n]/g, '');
|
|
401
|
+
var jsKey = _CoreManager.default.get('JAVASCRIPT_KEY');
|
|
402
|
+
if (jsKey) {
|
|
403
|
+
headers['X-Parse-JavaScript-Key'] = jsKey;
|
|
404
|
+
}
|
|
405
|
+
var useMasterKey = options.useMasterKey;
|
|
406
|
+
if (typeof useMasterKey === 'undefined') {
|
|
407
|
+
useMasterKey = _CoreManager.default.get('USE_MASTER_KEY');
|
|
408
|
+
}
|
|
409
|
+
if (useMasterKey) {
|
|
410
|
+
if (_CoreManager.default.get('MASTER_KEY')) {
|
|
411
|
+
delete headers['X-Parse-JavaScript-Key'];
|
|
412
|
+
headers['X-Parse-Master-Key'] = _CoreManager.default.get('MASTER_KEY');
|
|
413
|
+
} else {
|
|
414
|
+
throw new Error('Cannot use the Master Key, it has not been provided.');
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (options.sessionToken) {
|
|
418
|
+
headers['X-Parse-Session-Token'] = options.sessionToken;
|
|
419
|
+
} else {
|
|
420
|
+
var userController = _CoreManager.default.getUserController();
|
|
421
|
+
if (userController) {
|
|
422
|
+
var user = yield userController.currentUserAsync();
|
|
423
|
+
if (user) {
|
|
424
|
+
var token = user.getSessionToken();
|
|
425
|
+
if (token) {
|
|
426
|
+
headers['X-Parse-Session-Token'] = token;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
var body;
|
|
432
|
+
if (source.format === 'buffer') {
|
|
433
|
+
body = source.buffer;
|
|
434
|
+
} else if (source.format === 'stream') {
|
|
435
|
+
var stream = source.stream;
|
|
436
|
+
if (typeof stream.pipe === 'function' && typeof stream.read === 'function') {
|
|
437
|
+
body = NodeReadable.toWeb(stream);
|
|
438
|
+
} else {
|
|
439
|
+
body = stream;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
var url = _CoreManager.default.get('SERVER_URL');
|
|
443
|
+
if (url[url.length - 1] !== '/') {
|
|
444
|
+
url += '/';
|
|
445
|
+
}
|
|
446
|
+
url += 'files/' + encodeURIComponent(name);
|
|
447
|
+
return _CoreManager.default.getRESTController().ajax('POST', url, body, headers, options).then(function (_ref) {
|
|
448
|
+
var response = _ref.response;
|
|
449
|
+
return response;
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
function saveBinary() {
|
|
453
|
+
return _saveBinary.apply(this, arguments);
|
|
454
|
+
}
|
|
455
|
+
return saveBinary;
|
|
456
|
+
}(),
|
|
337
457
|
download: function () {
|
|
338
458
|
var _download = (0, _asyncToGenerator2.default)(function* (uri, options) {
|
|
339
459
|
var controller = new AbortController();
|
|
@@ -102,6 +102,9 @@ var RESTController = {
|
|
|
102
102
|
};
|
|
103
103
|
if (data) {
|
|
104
104
|
fetchOptions.body = data;
|
|
105
|
+
if (typeof ReadableStream !== 'undefined' && data instanceof ReadableStream) {
|
|
106
|
+
fetchOptions.duplex = 'half';
|
|
107
|
+
}
|
|
105
108
|
}
|
|
106
109
|
var response = yield fetch(url, fetchOptions);
|
|
107
110
|
var status = response.status;
|
|
@@ -163,7 +166,8 @@ var RESTController = {
|
|
|
163
166
|
dropBody: status === 303
|
|
164
167
|
});
|
|
165
168
|
} else if (status >= 500 || status === 0) {
|
|
166
|
-
|
|
169
|
+
var isStream = typeof ReadableStream !== 'undefined' && data instanceof ReadableStream;
|
|
170
|
+
if (!isStream && ++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
167
171
|
var delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
168
172
|
setTimeout(_dispatch, delay);
|
|
169
173
|
} else if (status === 0) {
|