parse 8.3.0 → 8.4.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 CHANGED
@@ -191,7 +191,7 @@
191
191
  SERVER_URL: "https://api.parse.com/1",
192
192
  LIVEQUERY_SERVER_URL: null,
193
193
  ENCRYPTED_KEY: null,
194
- VERSION: "js8.3.0",
194
+ VERSION: "js8.4.0-alpha.1",
195
195
  APPLICATION_ID: null,
196
196
  JAVASCRIPT_KEY: null,
197
197
  MAINTENANCE_KEY: null,
@@ -9500,7 +9500,7 @@
9500
9500
  * JSON encoding if metadata or tags are set.
9501
9501
  * 6. (Node.js only) a Readable stream, or a Web ReadableStream.
9502
9502
  * Streamed as raw binary data directly into the upload request.
9503
- * Throws if metadata or tags are set.
9503
+ * Supports metadata, tags, and directory when Parse Server >= 9.5.0.
9504
9504
  * For example:
9505
9505
  * <pre>
9506
9506
  * var fileUploadControl = $("#profilePhotoFileUpload")[0];
@@ -9674,8 +9674,8 @@
9674
9674
  * In Node.js, files created with Buffer or ReadableStream are uploaded as
9675
9675
  * raw binary data, avoiding base64 encoding overhead. If metadata
9676
9676
  * or tags are set on a Buffer-backed file, the upload falls back to base64
9677
- * JSON encoding (since the binary endpoint does not support metadata).
9678
- * Stream-backed files with metadata or tags will throw an error.
9677
+ * JSON encoding. Stream-backed files support metadata, tags, and directory
9678
+ * when Parse Server >= 9.5.0.
9679
9679
  *
9680
9680
  * @param {object} options
9681
9681
  * Valid options are:<ul>
@@ -9706,18 +9706,13 @@
9706
9706
  const controller = CoreManager.getFileController();
9707
9707
  if (!this._previousSave) {
9708
9708
  if (this._source.format === "buffer" || this._source.format === "stream") {
9709
- const hasFileData = this._metadata && Object.keys(this._metadata).length > 0 || this._tags && Object.keys(this._tags).length > 0 || !!this._directory;
9710
- if (this._source.format === "stream" && hasFileData) {
9711
- throw new Error(
9712
- "Cannot save a stream-based file with metadata, tags, or directory. Use a Buffer instead."
9713
- );
9714
- }
9715
9709
  if (this._source.format === "stream" && !controller.saveBinary) {
9716
9710
  throw new Error(
9717
9711
  "Cannot save a stream-based file without saveBinary support on the FileController."
9718
9712
  );
9719
9713
  }
9720
- if (!hasFileData && controller.saveBinary) {
9714
+ const hasFileData = this._metadata && Object.keys(this._metadata).length > 0 || this._tags && Object.keys(this._tags).length > 0 || !!this._directory;
9715
+ if (controller.saveBinary && (this._source.format === "stream" || !hasFileData)) {
9721
9716
  this._previousSave = controller.saveBinary(this._name, this._source, options).then((res) => {
9722
9717
  this._name = res.name;
9723
9718
  this._url = res.url;
@@ -9828,7 +9823,8 @@
9828
9823
  return other instanceof ParseFile && this.name() === other.name() && this.url() === other.url() && typeof this.url() !== "undefined";
9829
9824
  }
9830
9825
  /**
9831
- * Sets metadata to be saved with file object. Overwrites existing metadata
9826
+ * Sets metadata to be saved with file object. Overwrites existing metadata.
9827
+ * When used with a stream-based file, requires Parse Server >= 9.5.0.
9832
9828
  *
9833
9829
  * @param {object} metadata Key value pairs to be stored with file object
9834
9830
  */
@@ -9841,6 +9837,7 @@
9841
9837
  }
9842
9838
  /**
9843
9839
  * Sets metadata to be saved with file object. Adds to existing metadata.
9840
+ * When used with a stream-based file, requires Parse Server >= 9.5.0.
9844
9841
  *
9845
9842
  * @param {string} key key to store the metadata
9846
9843
  * @param {*} value metadata
@@ -9851,7 +9848,8 @@
9851
9848
  }
9852
9849
  }
9853
9850
  /**
9854
- * Sets tags to be saved with file object. Overwrites existing tags
9851
+ * Sets tags to be saved with file object. Overwrites existing tags.
9852
+ * When used with a stream-based file, requires Parse Server >= 9.5.0.
9855
9853
  *
9856
9854
  * @param {object} tags Key value pairs to be stored with file object
9857
9855
  */
@@ -9864,6 +9862,7 @@
9864
9862
  }
9865
9863
  /**
9866
9864
  * Sets tags to be saved with file object. Adds to existing tags.
9865
+ * When used with a stream-based file, requires Parse Server >= 9.5.0.
9867
9866
  *
9868
9867
  * @param {string} key key to store tags
9869
9868
  * @param {*} value tag
@@ -9876,7 +9875,7 @@
9876
9875
  /**
9877
9876
  * Sets the directory where the file will be stored.
9878
9877
  * Requires the Master Key when saving.
9879
- * Requires Parse Server >= 9.4.0.
9878
+ * Requires Parse Server >= 9.4.0; when used with a stream-based file, requires Parse Server >= 9.5.0.
9880
9879
  *
9881
9880
  * @param {string} directory the directory path
9882
9881
  */
@@ -9962,6 +9961,15 @@
9962
9961
  "X-Parse-Upload-Mode": "stream"
9963
9962
  };
9964
9963
  headers["Content-Type"] = (source.type || "application/octet-stream").replace(/[\r\n]/g, "");
9964
+ if (options.directory) {
9965
+ headers["X-Parse-File-Directory"] = options.directory.replace(/[\r\n]/g, "");
9966
+ }
9967
+ if (options.metadata && Object.keys(options.metadata).length > 0) {
9968
+ headers["X-Parse-File-Metadata"] = JSON.stringify(options.metadata);
9969
+ }
9970
+ if (options.tags && Object.keys(options.tags).length > 0) {
9971
+ headers["X-Parse-File-Tags"] = JSON.stringify(options.tags);
9972
+ }
9965
9973
  const jsKey = CoreManager.get("JAVASCRIPT_KEY");
9966
9974
  if (jsKey) {
9967
9975
  headers["X-Parse-JavaScript-Key"] = jsKey;