parse 8.2.0 → 8.3.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.
@@ -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.2.0",
21
+ VERSION: 'js' + "8.3.0-alpha.1",
22
22
  APPLICATION_ID: null,
23
23
  JAVASCRIPT_KEY: null,
24
24
  MAINTENANCE_KEY: null,
@@ -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,15 @@ class ParseFile {
261
262
  return this._tags;
262
263
  }
263
264
 
265
+ /**
266
+ * Gets the directory of the file.
267
+ *
268
+ * @returns {string | undefined}
269
+ */
270
+ directory() {
271
+ return this._directory;
272
+ }
273
+
264
274
  /**
265
275
  * Saves the file to the Parse cloud.
266
276
  *
@@ -295,17 +305,18 @@ class ParseFile {
295
305
  options.requestTask = task => this._requestTask = task;
296
306
  options.metadata = this._metadata;
297
307
  options.tags = this._tags;
308
+ options.directory = this._directory;
298
309
  const controller = _CoreManager.default.getFileController();
299
310
  if (!this._previousSave) {
300
311
  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.');
312
+ const hasFileData = this._metadata && (0, _keys.default)(this._metadata).length > 0 || this._tags && (0, _keys.default)(this._tags).length > 0 || !!this._directory;
313
+ if (this._source.format === 'stream' && hasFileData) {
314
+ throw new Error('Cannot save a stream-based file with metadata, tags, or directory. Use a Buffer instead.');
304
315
  }
305
316
  if (this._source.format === 'stream' && !controller.saveBinary) {
306
317
  throw new Error('Cannot save a stream-based file without saveBinary support on the FileController.');
307
318
  }
308
- if (!hasMetadataOrTags && controller.saveBinary) {
319
+ if (!hasFileData && controller.saveBinary) {
309
320
  // Binary upload via ajax
310
321
  this._previousSave = controller.saveBinary(this._name, this._source, options).then(res => {
311
322
  this._name = res.name;
@@ -475,6 +486,18 @@ class ParseFile {
475
486
  this._tags[key] = value;
476
487
  }
477
488
  }
489
+
490
+ /**
491
+ * Sets the directory where the file will be stored.
492
+ * Requires the Master Key when saving.
493
+ *
494
+ * @param {string} directory the directory path
495
+ */
496
+ setDirectory(directory) {
497
+ if (typeof directory === 'string' && directory.length > 0) {
498
+ this._directory = directory;
499
+ }
500
+ }
478
501
  static fromJSON(obj) {
479
502
  if (obj.__type !== 'File') {
480
503
  throw new TypeError('JSON object does not represent a ParseFile');
@@ -528,13 +551,16 @@ const DefaultController = {
528
551
  }
529
552
  const data = {
530
553
  base64: source.base64,
531
- fileData: {
554
+ fileData: _objectSpread({
532
555
  metadata: _objectSpread({}, options.metadata),
533
556
  tags: _objectSpread({}, options.tags)
534
- }
557
+ }, options.directory ? {
558
+ directory: options.directory
559
+ } : {})
535
560
  };
536
561
  delete options.metadata;
537
562
  delete options.tags;
563
+ delete options.directory;
538
564
  if (source.type) {
539
565
  data._ContentType = source.type;
540
566
  }
@@ -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.2.0",
17
+ VERSION: 'js' + "8.3.0-alpha.1",
18
18
  APPLICATION_ID: null,
19
19
  JAVASCRIPT_KEY: null,
20
20
  MAINTENANCE_KEY: null,
@@ -222,6 +222,15 @@ class ParseFile {
222
222
  return this._tags;
223
223
  }
224
224
 
225
+ /**
226
+ * Gets the directory of the file.
227
+ *
228
+ * @returns {string | undefined}
229
+ */
230
+ directory() {
231
+ return this._directory;
232
+ }
233
+
225
234
  /**
226
235
  * Saves the file to the Parse cloud.
227
236
  *
@@ -256,17 +265,18 @@ class ParseFile {
256
265
  options.requestTask = task => this._requestTask = task;
257
266
  options.metadata = this._metadata;
258
267
  options.tags = this._tags;
268
+ options.directory = this._directory;
259
269
  const controller = _CoreManager.default.getFileController();
260
270
  if (!this._previousSave) {
261
271
  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.');
272
+ const hasFileData = this._metadata && Object.keys(this._metadata).length > 0 || this._tags && Object.keys(this._tags).length > 0 || !!this._directory;
273
+ if (this._source.format === 'stream' && hasFileData) {
274
+ throw new Error('Cannot save a stream-based file with metadata, tags, or directory. Use a Buffer instead.');
265
275
  }
266
276
  if (this._source.format === 'stream' && !controller.saveBinary) {
267
277
  throw new Error('Cannot save a stream-based file without saveBinary support on the FileController.');
268
278
  }
269
- if (!hasMetadataOrTags && controller.saveBinary) {
279
+ if (!hasFileData && controller.saveBinary) {
270
280
  // Binary upload via ajax
271
281
  this._previousSave = controller.saveBinary(this._name, this._source, options).then(res => {
272
282
  this._name = res.name;
@@ -433,6 +443,18 @@ class ParseFile {
433
443
  this._tags[key] = value;
434
444
  }
435
445
  }
446
+
447
+ /**
448
+ * Sets the directory where the file will be stored.
449
+ * Requires the Master Key when saving.
450
+ *
451
+ * @param {string} directory the directory path
452
+ */
453
+ setDirectory(directory) {
454
+ if (typeof directory === 'string' && directory.length > 0) {
455
+ this._directory = directory;
456
+ }
457
+ }
436
458
  static fromJSON(obj) {
437
459
  if (obj.__type !== 'File') {
438
460
  throw new TypeError('JSON object does not represent a ParseFile');
@@ -491,11 +513,15 @@ const DefaultController = {
491
513
  },
492
514
  tags: {
493
515
  ...options.tags
494
- }
516
+ },
517
+ ...(options.directory ? {
518
+ directory: options.directory
519
+ } : {})
495
520
  }
496
521
  };
497
522
  delete options.metadata;
498
523
  delete options.tags;
524
+ delete options.directory;
499
525
  if (source.type) {
500
526
  data._ContentType = source.type;
501
527
  }
@@ -10,7 +10,7 @@ var config = {
10
10
  SERVER_URL: 'https://api.parse.com/1',
11
11
  LIVEQUERY_SERVER_URL: null,
12
12
  ENCRYPTED_KEY: null,
13
- VERSION: 'js' + "8.2.0",
13
+ VERSION: 'js' + "8.3.0-alpha.1",
14
14
  APPLICATION_ID: null,
15
15
  JAVASCRIPT_KEY: null,
16
16
  MAINTENANCE_KEY: null,
@@ -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 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.');
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 (!hasMetadataOrTags && controller.saveBinary) {
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
  }
@@ -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.2.0",
21
+ VERSION: 'js' + "8.3.0-alpha.1",
22
22
  APPLICATION_ID: null,
23
23
  JAVASCRIPT_KEY: null,
24
24
  MAINTENANCE_KEY: null,
@@ -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,15 @@ class ParseFile {
261
262
  return this._tags;
262
263
  }
263
264
 
265
+ /**
266
+ * Gets the directory of the file.
267
+ *
268
+ * @returns {string | undefined}
269
+ */
270
+ directory() {
271
+ return this._directory;
272
+ }
273
+
264
274
  /**
265
275
  * Saves the file to the Parse cloud.
266
276
  *
@@ -295,17 +305,18 @@ class ParseFile {
295
305
  options.requestTask = task => this._requestTask = task;
296
306
  options.metadata = this._metadata;
297
307
  options.tags = this._tags;
308
+ options.directory = this._directory;
298
309
  const controller = _CoreManager.default.getFileController();
299
310
  if (!this._previousSave) {
300
311
  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.');
312
+ const hasFileData = this._metadata && (0, _keys.default)(this._metadata).length > 0 || this._tags && (0, _keys.default)(this._tags).length > 0 || !!this._directory;
313
+ if (this._source.format === 'stream' && hasFileData) {
314
+ throw new Error('Cannot save a stream-based file with metadata, tags, or directory. Use a Buffer instead.');
304
315
  }
305
316
  if (this._source.format === 'stream' && !controller.saveBinary) {
306
317
  throw new Error('Cannot save a stream-based file without saveBinary support on the FileController.');
307
318
  }
308
- if (!hasMetadataOrTags && controller.saveBinary) {
319
+ if (!hasFileData && controller.saveBinary) {
309
320
  // Binary upload via ajax
310
321
  this._previousSave = controller.saveBinary(this._name, this._source, options).then(res => {
311
322
  this._name = res.name;
@@ -475,6 +486,18 @@ class ParseFile {
475
486
  this._tags[key] = value;
476
487
  }
477
488
  }
489
+
490
+ /**
491
+ * Sets the directory where the file will be stored.
492
+ * Requires the Master Key when saving.
493
+ *
494
+ * @param {string} directory the directory path
495
+ */
496
+ setDirectory(directory) {
497
+ if (typeof directory === 'string' && directory.length > 0) {
498
+ this._directory = directory;
499
+ }
500
+ }
478
501
  static fromJSON(obj) {
479
502
  if (obj.__type !== 'File') {
480
503
  throw new TypeError('JSON object does not represent a ParseFile');
@@ -528,13 +551,16 @@ const DefaultController = {
528
551
  }
529
552
  const data = {
530
553
  base64: source.base64,
531
- fileData: {
554
+ fileData: _objectSpread({
532
555
  metadata: _objectSpread({}, options.metadata),
533
556
  tags: _objectSpread({}, options.tags)
534
- }
557
+ }, options.directory ? {
558
+ directory: options.directory
559
+ } : {})
535
560
  };
536
561
  delete options.metadata;
537
562
  delete options.tags;
563
+ delete options.directory;
538
564
  if (source.type) {
539
565
  data._ContentType = source.type;
540
566
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "parse",
3
- "version": "8.2.0",
3
+ "version": "8.3.0-alpha.1",
4
4
  "description": "Parse JavaScript SDK",
5
5
  "homepage": "https://parseplatform.org",
6
6
  "keywords": [
@@ -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,12 @@ declare class ParseFile {
136
138
  * @returns {object}
137
139
  */
138
140
  tags(): Record<string, any>;
141
+ /**
142
+ * Gets the directory of the file.
143
+ *
144
+ * @returns {string | undefined}
145
+ */
146
+ directory(): string | undefined;
139
147
  /**
140
148
  * Saves the file to the Parse cloud.
141
149
  *
@@ -216,6 +224,13 @@ declare class ParseFile {
216
224
  * @param {*} value tag
217
225
  */
218
226
  addTag(key: string, value: string): void;
227
+ /**
228
+ * Sets the directory where the file will be stored.
229
+ * Requires the Master Key when saving.
230
+ *
231
+ * @param {string} directory the directory path
232
+ */
233
+ setDirectory(directory: string): void;
219
234
  static fromJSON(obj: any): ParseFile;
220
235
  static encodeBase64(bytes: number[] | Uint8Array): string;
221
236
  }