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
package/lib/weapp/CoreManager.js
CHANGED
|
@@ -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/weapp/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);
|
package/lib/weapp/ParseQuery.js
CHANGED
|
@@ -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
|
*/
|
|
@@ -154,6 +154,9 @@ const RESTController = {
|
|
|
154
154
|
};
|
|
155
155
|
if (data) {
|
|
156
156
|
fetchOptions.body = data;
|
|
157
|
+
if (typeof ReadableStream !== 'undefined' && data instanceof ReadableStream) {
|
|
158
|
+
fetchOptions.duplex = 'half';
|
|
159
|
+
}
|
|
157
160
|
}
|
|
158
161
|
const response = await fetch(url, fetchOptions);
|
|
159
162
|
const {
|
|
@@ -220,7 +223,9 @@ const RESTController = {
|
|
|
220
223
|
});
|
|
221
224
|
} else if (status >= 500 || status === 0) {
|
|
222
225
|
// retry on 5XX or library error
|
|
223
|
-
|
|
226
|
+
// ReadableStream bodies cannot be retried because they are consumed by the first fetch
|
|
227
|
+
const isStream = typeof ReadableStream !== 'undefined' && data instanceof ReadableStream;
|
|
228
|
+
if (!isStream && ++attempts < _CoreManager.default.get('REQUEST_ATTEMPT_LIMIT')) {
|
|
224
229
|
// Exponentially-growing random delay
|
|
225
230
|
const delay = Math.round(Math.random() * 125 * Math.pow(2, attempts));
|
|
226
231
|
(0, _setTimeout2.default)(dispatch, delay);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parse",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0-alpha.2",
|
|
4
4
|
"description": "Parse JavaScript SDK",
|
|
5
5
|
"homepage": "https://parseplatform.org",
|
|
6
6
|
"keywords": [
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"lint-staged": "16.2.7",
|
|
115
115
|
"madge": "8.0.0",
|
|
116
116
|
"metro-react-native-babel-preset": "0.77.0",
|
|
117
|
-
"mongodb-runner": "6.6.
|
|
117
|
+
"mongodb-runner": "6.6.1",
|
|
118
118
|
"parse-server": "9.2.0",
|
|
119
119
|
"puppeteer": "24.37.2",
|
|
120
120
|
"regenerator-runtime": "0.14.1",
|
package/types/CoreManager.d.ts
CHANGED
|
@@ -38,6 +38,10 @@ export interface FileController {
|
|
|
38
38
|
name: string;
|
|
39
39
|
url: string;
|
|
40
40
|
}>;
|
|
41
|
+
saveBinary?: (name: string, source: FileSource, options?: FileSaveOptions) => Promise<{
|
|
42
|
+
name: string;
|
|
43
|
+
url: string;
|
|
44
|
+
}>;
|
|
41
45
|
download: (uri: string, options?: any) => Promise<{
|
|
42
46
|
base64?: string;
|
|
43
47
|
contentType?: string;
|
package/types/ParseFile.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ export type FileSource = {
|
|
|
22
22
|
format: 'uri';
|
|
23
23
|
uri: string;
|
|
24
24
|
type: string | undefined;
|
|
25
|
+
} | {
|
|
26
|
+
format: 'buffer';
|
|
27
|
+
buffer: any;
|
|
28
|
+
type: string | undefined;
|
|
29
|
+
} | {
|
|
30
|
+
format: 'stream';
|
|
31
|
+
stream: any;
|
|
32
|
+
type: string | undefined;
|
|
25
33
|
};
|
|
26
34
|
export declare function b64Digit(number: number): string;
|
|
27
35
|
/**
|
|
@@ -48,8 +56,13 @@ declare class ParseFile {
|
|
|
48
56
|
* 1. an Array of byte value Numbers or Uint8Array.
|
|
49
57
|
* 2. an Object like { base64: "..." } with a base64-encoded String.
|
|
50
58
|
* 3. an Object like { uri: "..." } with a uri String.
|
|
51
|
-
* 4. a File object selected with a file upload control.
|
|
52
|
-
*
|
|
59
|
+
* 4. a File object selected with a file upload control.
|
|
60
|
+
* 5. (Node.js only) a Buffer. Uploaded as raw binary data instead of
|
|
61
|
+
* base64-encoding, reducing memory usage. Falls back to base64
|
|
62
|
+
* JSON encoding if metadata or tags are set.
|
|
63
|
+
* 6. (Node.js only) a Readable stream, or a Web ReadableStream.
|
|
64
|
+
* Streamed as raw binary data directly into the upload request.
|
|
65
|
+
* Throws if metadata or tags are set.
|
|
53
66
|
* For example:
|
|
54
67
|
* <pre>
|
|
55
68
|
* var fileUploadControl = $("#profilePhotoFileUpload")[0];
|
|
@@ -126,6 +139,12 @@ declare class ParseFile {
|
|
|
126
139
|
/**
|
|
127
140
|
* Saves the file to the Parse cloud.
|
|
128
141
|
*
|
|
142
|
+
* In Node.js, files created with Buffer or ReadableStream are uploaded as
|
|
143
|
+
* raw binary data, avoiding base64 encoding overhead. If metadata
|
|
144
|
+
* or tags are set on a Buffer-backed file, the upload falls back to base64
|
|
145
|
+
* JSON encoding (since the binary endpoint does not support metadata).
|
|
146
|
+
* Stream-backed files with metadata or tags will throw an error.
|
|
147
|
+
*
|
|
129
148
|
* @param {object} options
|
|
130
149
|
* Valid options are:<ul>
|
|
131
150
|
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
|
package/types/ParseQuery.d.ts
CHANGED
|
@@ -812,6 +812,11 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
|
|
|
812
812
|
* provided keys. If this is called multiple times, then all of the keys
|
|
813
813
|
* specified in each of the calls will be included.
|
|
814
814
|
*
|
|
815
|
+
* When selecting `authData` on `Parse.User`, only auth data of currently
|
|
816
|
+
* configured auth providers is returned. Auth data of providers that are no
|
|
817
|
+
* longer configured is not included. To return all auth data regardless of
|
|
818
|
+
* the provider configuration, do not select `authData`.
|
|
819
|
+
*
|
|
815
820
|
* @param {...string|Array<string>} keys The name(s) of the key(s) to include.
|
|
816
821
|
* @returns {Parse.Query} Returns the query, so you can chain this call.
|
|
817
822
|
*/
|