parse 8.3.0-alpha.1 → 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-alpha.1",
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];
@@ -9661,6 +9661,7 @@
9661
9661
  }
9662
9662
  /**
9663
9663
  * Gets the directory of the file.
9664
+ * Requires Parse Server >= 9.4.0.
9664
9665
  *
9665
9666
  * @returns {string | undefined}
9666
9667
  */
@@ -9673,8 +9674,8 @@
9673
9674
  * In Node.js, files created with Buffer or ReadableStream are uploaded as
9674
9675
  * raw binary data, avoiding base64 encoding overhead. If metadata
9675
9676
  * or tags are set on a Buffer-backed file, the upload falls back to base64
9676
- * JSON encoding (since the binary endpoint does not support metadata).
9677
- * 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.
9678
9679
  *
9679
9680
  * @param {object} options
9680
9681
  * Valid options are:<ul>
@@ -9705,18 +9706,13 @@
9705
9706
  const controller = CoreManager.getFileController();
9706
9707
  if (!this._previousSave) {
9707
9708
  if (this._source.format === "buffer" || this._source.format === "stream") {
9708
- const hasFileData = this._metadata && Object.keys(this._metadata).length > 0 || this._tags && Object.keys(this._tags).length > 0 || !!this._directory;
9709
- if (this._source.format === "stream" && hasFileData) {
9710
- throw new Error(
9711
- "Cannot save a stream-based file with metadata, tags, or directory. Use a Buffer instead."
9712
- );
9713
- }
9714
9709
  if (this._source.format === "stream" && !controller.saveBinary) {
9715
9710
  throw new Error(
9716
9711
  "Cannot save a stream-based file without saveBinary support on the FileController."
9717
9712
  );
9718
9713
  }
9719
- 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)) {
9720
9716
  this._previousSave = controller.saveBinary(this._name, this._source, options).then((res) => {
9721
9717
  this._name = res.name;
9722
9718
  this._url = res.url;
@@ -9827,7 +9823,8 @@
9827
9823
  return other instanceof ParseFile && this.name() === other.name() && this.url() === other.url() && typeof this.url() !== "undefined";
9828
9824
  }
9829
9825
  /**
9830
- * 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.
9831
9828
  *
9832
9829
  * @param {object} metadata Key value pairs to be stored with file object
9833
9830
  */
@@ -9840,6 +9837,7 @@
9840
9837
  }
9841
9838
  /**
9842
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.
9843
9841
  *
9844
9842
  * @param {string} key key to store the metadata
9845
9843
  * @param {*} value metadata
@@ -9850,7 +9848,8 @@
9850
9848
  }
9851
9849
  }
9852
9850
  /**
9853
- * 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.
9854
9853
  *
9855
9854
  * @param {object} tags Key value pairs to be stored with file object
9856
9855
  */
@@ -9863,6 +9862,7 @@
9863
9862
  }
9864
9863
  /**
9865
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.
9866
9866
  *
9867
9867
  * @param {string} key key to store tags
9868
9868
  * @param {*} value tag
@@ -9875,6 +9875,7 @@
9875
9875
  /**
9876
9876
  * Sets the directory where the file will be stored.
9877
9877
  * Requires the Master Key when saving.
9878
+ * Requires Parse Server >= 9.4.0; when used with a stream-based file, requires Parse Server >= 9.5.0.
9878
9879
  *
9879
9880
  * @param {string} directory the directory path
9880
9881
  */
@@ -9960,6 +9961,15 @@
9960
9961
  "X-Parse-Upload-Mode": "stream"
9961
9962
  };
9962
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
+ }
9963
9973
  const jsKey = CoreManager.get("JAVASCRIPT_KEY");
9964
9974
  if (jsKey) {
9965
9975
  headers["X-Parse-JavaScript-Key"] = jsKey;