parse 8.2.0 → 8.3.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 +30 -6
- package/dist/parse.min.js +1 -1
- package/dist/parse.weapp.js +30 -6
- package/dist/parse.weapp.min.js +1 -1
- package/lib/browser/CoreManager.js +1 -1
- package/lib/browser/ParseFile.js +34 -6
- package/lib/node/CoreManager.js +1 -1
- package/lib/node/ParseFile.js +33 -5
- package/lib/react-native/CoreManager.js +1 -1
- package/lib/react-native/ParseFile.js +22 -6
- package/lib/weapp/CoreManager.js +1 -1
- package/lib/weapp/ParseFile.js +34 -6
- package/package.json +1 -1
- package/types/ParseFile.d.ts +17 -0
package/lib/browser/ParseFile.js
CHANGED
|
@@ -115,6 +115,7 @@ class ParseFile {
|
|
|
115
115
|
(0, _defineProperty2.default)(this, "_requestTask", void 0);
|
|
116
116
|
(0, _defineProperty2.default)(this, "_metadata", void 0);
|
|
117
117
|
(0, _defineProperty2.default)(this, "_tags", void 0);
|
|
118
|
+
(0, _defineProperty2.default)(this, "_directory", void 0);
|
|
118
119
|
const specifiedType = type || '';
|
|
119
120
|
this._name = name;
|
|
120
121
|
this._metadata = metadata || {};
|
|
@@ -261,6 +262,16 @@ class ParseFile {
|
|
|
261
262
|
return this._tags;
|
|
262
263
|
}
|
|
263
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Gets the directory of the file.
|
|
267
|
+
* Requires Parse Server >= 9.4.0.
|
|
268
|
+
*
|
|
269
|
+
* @returns {string | undefined}
|
|
270
|
+
*/
|
|
271
|
+
directory() {
|
|
272
|
+
return this._directory;
|
|
273
|
+
}
|
|
274
|
+
|
|
264
275
|
/**
|
|
265
276
|
* Saves the file to the Parse cloud.
|
|
266
277
|
*
|
|
@@ -295,17 +306,18 @@ class ParseFile {
|
|
|
295
306
|
options.requestTask = task => this._requestTask = task;
|
|
296
307
|
options.metadata = this._metadata;
|
|
297
308
|
options.tags = this._tags;
|
|
309
|
+
options.directory = this._directory;
|
|
298
310
|
const controller = _CoreManager.default.getFileController();
|
|
299
311
|
if (!this._previousSave) {
|
|
300
312
|
if (this._source.format === 'buffer' || this._source.format === 'stream') {
|
|
301
|
-
const
|
|
302
|
-
if (this._source.format === 'stream' &&
|
|
303
|
-
throw new Error('Cannot save a stream-based file with metadata or
|
|
313
|
+
const hasFileData = this._metadata && (0, _keys.default)(this._metadata).length > 0 || this._tags && (0, _keys.default)(this._tags).length > 0 || !!this._directory;
|
|
314
|
+
if (this._source.format === 'stream' && hasFileData) {
|
|
315
|
+
throw new Error('Cannot save a stream-based file with metadata, tags, or directory. Use a Buffer instead.');
|
|
304
316
|
}
|
|
305
317
|
if (this._source.format === 'stream' && !controller.saveBinary) {
|
|
306
318
|
throw new Error('Cannot save a stream-based file without saveBinary support on the FileController.');
|
|
307
319
|
}
|
|
308
|
-
if (!
|
|
320
|
+
if (!hasFileData && controller.saveBinary) {
|
|
309
321
|
// Binary upload via ajax
|
|
310
322
|
this._previousSave = controller.saveBinary(this._name, this._source, options).then(res => {
|
|
311
323
|
this._name = res.name;
|
|
@@ -475,6 +487,19 @@ class ParseFile {
|
|
|
475
487
|
this._tags[key] = value;
|
|
476
488
|
}
|
|
477
489
|
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Sets the directory where the file will be stored.
|
|
493
|
+
* Requires the Master Key when saving.
|
|
494
|
+
* Requires Parse Server >= 9.4.0.
|
|
495
|
+
*
|
|
496
|
+
* @param {string} directory the directory path
|
|
497
|
+
*/
|
|
498
|
+
setDirectory(directory) {
|
|
499
|
+
if (typeof directory === 'string' && directory.length > 0) {
|
|
500
|
+
this._directory = directory;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
478
503
|
static fromJSON(obj) {
|
|
479
504
|
if (obj.__type !== 'File') {
|
|
480
505
|
throw new TypeError('JSON object does not represent a ParseFile');
|
|
@@ -528,13 +553,16 @@ const DefaultController = {
|
|
|
528
553
|
}
|
|
529
554
|
const data = {
|
|
530
555
|
base64: source.base64,
|
|
531
|
-
fileData: {
|
|
556
|
+
fileData: _objectSpread({
|
|
532
557
|
metadata: _objectSpread({}, options.metadata),
|
|
533
558
|
tags: _objectSpread({}, options.tags)
|
|
534
|
-
}
|
|
559
|
+
}, options.directory ? {
|
|
560
|
+
directory: options.directory
|
|
561
|
+
} : {})
|
|
535
562
|
};
|
|
536
563
|
delete options.metadata;
|
|
537
564
|
delete options.tags;
|
|
565
|
+
delete options.directory;
|
|
538
566
|
if (source.type) {
|
|
539
567
|
data._ContentType = source.type;
|
|
540
568
|
}
|
package/lib/node/CoreManager.js
CHANGED
package/lib/node/ParseFile.js
CHANGED
|
@@ -222,6 +222,16 @@ class ParseFile {
|
|
|
222
222
|
return this._tags;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Gets the directory of the file.
|
|
227
|
+
* Requires Parse Server >= 9.4.0.
|
|
228
|
+
*
|
|
229
|
+
* @returns {string | undefined}
|
|
230
|
+
*/
|
|
231
|
+
directory() {
|
|
232
|
+
return this._directory;
|
|
233
|
+
}
|
|
234
|
+
|
|
225
235
|
/**
|
|
226
236
|
* Saves the file to the Parse cloud.
|
|
227
237
|
*
|
|
@@ -256,17 +266,18 @@ class ParseFile {
|
|
|
256
266
|
options.requestTask = task => this._requestTask = task;
|
|
257
267
|
options.metadata = this._metadata;
|
|
258
268
|
options.tags = this._tags;
|
|
269
|
+
options.directory = this._directory;
|
|
259
270
|
const controller = _CoreManager.default.getFileController();
|
|
260
271
|
if (!this._previousSave) {
|
|
261
272
|
if (this._source.format === 'buffer' || this._source.format === 'stream') {
|
|
262
|
-
const
|
|
263
|
-
if (this._source.format === 'stream' &&
|
|
264
|
-
throw new Error('Cannot save a stream-based file with metadata or
|
|
273
|
+
const hasFileData = this._metadata && Object.keys(this._metadata).length > 0 || this._tags && Object.keys(this._tags).length > 0 || !!this._directory;
|
|
274
|
+
if (this._source.format === 'stream' && hasFileData) {
|
|
275
|
+
throw new Error('Cannot save a stream-based file with metadata, tags, or directory. Use a Buffer instead.');
|
|
265
276
|
}
|
|
266
277
|
if (this._source.format === 'stream' && !controller.saveBinary) {
|
|
267
278
|
throw new Error('Cannot save a stream-based file without saveBinary support on the FileController.');
|
|
268
279
|
}
|
|
269
|
-
if (!
|
|
280
|
+
if (!hasFileData && controller.saveBinary) {
|
|
270
281
|
// Binary upload via ajax
|
|
271
282
|
this._previousSave = controller.saveBinary(this._name, this._source, options).then(res => {
|
|
272
283
|
this._name = res.name;
|
|
@@ -433,6 +444,19 @@ class ParseFile {
|
|
|
433
444
|
this._tags[key] = value;
|
|
434
445
|
}
|
|
435
446
|
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Sets the directory where the file will be stored.
|
|
450
|
+
* Requires the Master Key when saving.
|
|
451
|
+
* Requires Parse Server >= 9.4.0.
|
|
452
|
+
*
|
|
453
|
+
* @param {string} directory the directory path
|
|
454
|
+
*/
|
|
455
|
+
setDirectory(directory) {
|
|
456
|
+
if (typeof directory === 'string' && directory.length > 0) {
|
|
457
|
+
this._directory = directory;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
436
460
|
static fromJSON(obj) {
|
|
437
461
|
if (obj.__type !== 'File') {
|
|
438
462
|
throw new TypeError('JSON object does not represent a ParseFile');
|
|
@@ -491,11 +515,15 @@ const DefaultController = {
|
|
|
491
515
|
},
|
|
492
516
|
tags: {
|
|
493
517
|
...options.tags
|
|
494
|
-
}
|
|
518
|
+
},
|
|
519
|
+
...(options.directory ? {
|
|
520
|
+
directory: options.directory
|
|
521
|
+
} : {})
|
|
495
522
|
}
|
|
496
523
|
};
|
|
497
524
|
delete options.metadata;
|
|
498
525
|
delete options.tags;
|
|
526
|
+
delete options.directory;
|
|
499
527
|
if (source.type) {
|
|
500
528
|
data._ContentType = source.type;
|
|
501
529
|
}
|
|
@@ -146,6 +146,11 @@ var ParseFile = function () {
|
|
|
146
146
|
value: function () {
|
|
147
147
|
return this._tags;
|
|
148
148
|
}
|
|
149
|
+
}, {
|
|
150
|
+
key: "directory",
|
|
151
|
+
value: function () {
|
|
152
|
+
return this._directory;
|
|
153
|
+
}
|
|
149
154
|
}, {
|
|
150
155
|
key: "save",
|
|
151
156
|
value: function (options) {
|
|
@@ -156,17 +161,18 @@ var ParseFile = function () {
|
|
|
156
161
|
};
|
|
157
162
|
options.metadata = this._metadata;
|
|
158
163
|
options.tags = this._tags;
|
|
164
|
+
options.directory = this._directory;
|
|
159
165
|
var controller = _CoreManager.default.getFileController();
|
|
160
166
|
if (!this._previousSave) {
|
|
161
167
|
if (this._source.format === 'buffer' || this._source.format === 'stream') {
|
|
162
|
-
var
|
|
163
|
-
if (this._source.format === 'stream' &&
|
|
164
|
-
throw new Error('Cannot save a stream-based file with metadata or
|
|
168
|
+
var hasFileData = this._metadata && Object.keys(this._metadata).length > 0 || this._tags && Object.keys(this._tags).length > 0 || !!this._directory;
|
|
169
|
+
if (this._source.format === 'stream' && hasFileData) {
|
|
170
|
+
throw new Error('Cannot save a stream-based file with metadata, tags, or directory. Use a Buffer instead.');
|
|
165
171
|
}
|
|
166
172
|
if (this._source.format === 'stream' && !controller.saveBinary) {
|
|
167
173
|
throw new Error('Cannot save a stream-based file without saveBinary support on the FileController.');
|
|
168
174
|
}
|
|
169
|
-
if (!
|
|
175
|
+
if (!hasFileData && controller.saveBinary) {
|
|
170
176
|
this._previousSave = controller.saveBinary(this._name, this._source, options).then(function (res) {
|
|
171
177
|
_this2._name = res.name;
|
|
172
178
|
_this2._url = res.url;
|
|
@@ -308,6 +314,13 @@ var ParseFile = function () {
|
|
|
308
314
|
this._tags[key] = value;
|
|
309
315
|
}
|
|
310
316
|
}
|
|
317
|
+
}, {
|
|
318
|
+
key: "setDirectory",
|
|
319
|
+
value: function (directory) {
|
|
320
|
+
if (typeof directory === 'string' && directory.length > 0) {
|
|
321
|
+
this._directory = directory;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
311
324
|
}], [{
|
|
312
325
|
key: "fromJSON",
|
|
313
326
|
value: function (obj) {
|
|
@@ -375,13 +388,16 @@ var DefaultController = {
|
|
|
375
388
|
}
|
|
376
389
|
var data = {
|
|
377
390
|
base64: source.base64,
|
|
378
|
-
fileData: {
|
|
391
|
+
fileData: Object.assign({
|
|
379
392
|
metadata: Object.assign({}, options.metadata),
|
|
380
393
|
tags: Object.assign({}, options.tags)
|
|
381
|
-
}
|
|
394
|
+
}, options.directory ? {
|
|
395
|
+
directory: options.directory
|
|
396
|
+
} : {})
|
|
382
397
|
};
|
|
383
398
|
delete options.metadata;
|
|
384
399
|
delete options.tags;
|
|
400
|
+
delete options.directory;
|
|
385
401
|
if (source.type) {
|
|
386
402
|
data._ContentType = source.type;
|
|
387
403
|
}
|
package/lib/weapp/CoreManager.js
CHANGED
package/lib/weapp/ParseFile.js
CHANGED
|
@@ -115,6 +115,7 @@ class ParseFile {
|
|
|
115
115
|
(0, _defineProperty2.default)(this, "_requestTask", void 0);
|
|
116
116
|
(0, _defineProperty2.default)(this, "_metadata", void 0);
|
|
117
117
|
(0, _defineProperty2.default)(this, "_tags", void 0);
|
|
118
|
+
(0, _defineProperty2.default)(this, "_directory", void 0);
|
|
118
119
|
const specifiedType = type || '';
|
|
119
120
|
this._name = name;
|
|
120
121
|
this._metadata = metadata || {};
|
|
@@ -261,6 +262,16 @@ class ParseFile {
|
|
|
261
262
|
return this._tags;
|
|
262
263
|
}
|
|
263
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Gets the directory of the file.
|
|
267
|
+
* Requires Parse Server >= 9.4.0.
|
|
268
|
+
*
|
|
269
|
+
* @returns {string | undefined}
|
|
270
|
+
*/
|
|
271
|
+
directory() {
|
|
272
|
+
return this._directory;
|
|
273
|
+
}
|
|
274
|
+
|
|
264
275
|
/**
|
|
265
276
|
* Saves the file to the Parse cloud.
|
|
266
277
|
*
|
|
@@ -295,17 +306,18 @@ class ParseFile {
|
|
|
295
306
|
options.requestTask = task => this._requestTask = task;
|
|
296
307
|
options.metadata = this._metadata;
|
|
297
308
|
options.tags = this._tags;
|
|
309
|
+
options.directory = this._directory;
|
|
298
310
|
const controller = _CoreManager.default.getFileController();
|
|
299
311
|
if (!this._previousSave) {
|
|
300
312
|
if (this._source.format === 'buffer' || this._source.format === 'stream') {
|
|
301
|
-
const
|
|
302
|
-
if (this._source.format === 'stream' &&
|
|
303
|
-
throw new Error('Cannot save a stream-based file with metadata or
|
|
313
|
+
const hasFileData = this._metadata && (0, _keys.default)(this._metadata).length > 0 || this._tags && (0, _keys.default)(this._tags).length > 0 || !!this._directory;
|
|
314
|
+
if (this._source.format === 'stream' && hasFileData) {
|
|
315
|
+
throw new Error('Cannot save a stream-based file with metadata, tags, or directory. Use a Buffer instead.');
|
|
304
316
|
}
|
|
305
317
|
if (this._source.format === 'stream' && !controller.saveBinary) {
|
|
306
318
|
throw new Error('Cannot save a stream-based file without saveBinary support on the FileController.');
|
|
307
319
|
}
|
|
308
|
-
if (!
|
|
320
|
+
if (!hasFileData && controller.saveBinary) {
|
|
309
321
|
// Binary upload via ajax
|
|
310
322
|
this._previousSave = controller.saveBinary(this._name, this._source, options).then(res => {
|
|
311
323
|
this._name = res.name;
|
|
@@ -475,6 +487,19 @@ class ParseFile {
|
|
|
475
487
|
this._tags[key] = value;
|
|
476
488
|
}
|
|
477
489
|
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Sets the directory where the file will be stored.
|
|
493
|
+
* Requires the Master Key when saving.
|
|
494
|
+
* Requires Parse Server >= 9.4.0.
|
|
495
|
+
*
|
|
496
|
+
* @param {string} directory the directory path
|
|
497
|
+
*/
|
|
498
|
+
setDirectory(directory) {
|
|
499
|
+
if (typeof directory === 'string' && directory.length > 0) {
|
|
500
|
+
this._directory = directory;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
478
503
|
static fromJSON(obj) {
|
|
479
504
|
if (obj.__type !== 'File') {
|
|
480
505
|
throw new TypeError('JSON object does not represent a ParseFile');
|
|
@@ -528,13 +553,16 @@ const DefaultController = {
|
|
|
528
553
|
}
|
|
529
554
|
const data = {
|
|
530
555
|
base64: source.base64,
|
|
531
|
-
fileData: {
|
|
556
|
+
fileData: _objectSpread({
|
|
532
557
|
metadata: _objectSpread({}, options.metadata),
|
|
533
558
|
tags: _objectSpread({}, options.tags)
|
|
534
|
-
}
|
|
559
|
+
}, options.directory ? {
|
|
560
|
+
directory: options.directory
|
|
561
|
+
} : {})
|
|
535
562
|
};
|
|
536
563
|
delete options.metadata;
|
|
537
564
|
delete options.tags;
|
|
565
|
+
delete options.directory;
|
|
538
566
|
if (source.type) {
|
|
539
567
|
data._ContentType = source.type;
|
|
540
568
|
}
|
package/package.json
CHANGED
package/types/ParseFile.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ type FileData = number[] | Base64 | Blob | Uri;
|
|
|
9
9
|
export type FileSaveOptions = FullOptions & {
|
|
10
10
|
metadata?: Record<string, any>;
|
|
11
11
|
tags?: Record<string, any>;
|
|
12
|
+
directory?: string;
|
|
12
13
|
};
|
|
13
14
|
export type FileSource = {
|
|
14
15
|
format: 'file';
|
|
@@ -47,6 +48,7 @@ declare class ParseFile {
|
|
|
47
48
|
_requestTask?: any;
|
|
48
49
|
_metadata?: Record<string, any>;
|
|
49
50
|
_tags?: Record<string, any>;
|
|
51
|
+
_directory?: string;
|
|
50
52
|
/**
|
|
51
53
|
* @param name {String} The file's name. This will be prefixed by a unique
|
|
52
54
|
* value once the file has finished saving. The file name must begin with
|
|
@@ -136,6 +138,13 @@ declare class ParseFile {
|
|
|
136
138
|
* @returns {object}
|
|
137
139
|
*/
|
|
138
140
|
tags(): Record<string, any>;
|
|
141
|
+
/**
|
|
142
|
+
* Gets the directory of the file.
|
|
143
|
+
* Requires Parse Server >= 9.4.0.
|
|
144
|
+
*
|
|
145
|
+
* @returns {string | undefined}
|
|
146
|
+
*/
|
|
147
|
+
directory(): string | undefined;
|
|
139
148
|
/**
|
|
140
149
|
* Saves the file to the Parse cloud.
|
|
141
150
|
*
|
|
@@ -216,6 +225,14 @@ declare class ParseFile {
|
|
|
216
225
|
* @param {*} value tag
|
|
217
226
|
*/
|
|
218
227
|
addTag(key: string, value: string): void;
|
|
228
|
+
/**
|
|
229
|
+
* Sets the directory where the file will be stored.
|
|
230
|
+
* Requires the Master Key when saving.
|
|
231
|
+
* Requires Parse Server >= 9.4.0.
|
|
232
|
+
*
|
|
233
|
+
* @param {string} directory the directory path
|
|
234
|
+
*/
|
|
235
|
+
setDirectory(directory: string): void;
|
|
219
236
|
static fromJSON(obj: any): ParseFile;
|
|
220
237
|
static encodeBase64(bytes: number[] | Uint8Array): string;
|
|
221
238
|
}
|