@supabase/storage-js 2.119.0-canary.1 → 2.119.0-canary.3

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/index.cjs CHANGED
@@ -600,6 +600,10 @@ const DEFAULT_FILE_OPTIONS = {
600
600
  contentType: "text/plain;charset=UTF-8",
601
601
  upsert: false
602
602
  };
603
+ function mergeFileOptions(fileOptions) {
604
+ const definedOptions = Object.fromEntries(Object.entries(fileOptions !== null && fileOptions !== void 0 ? fileOptions : {}).filter(([, value]) => value !== void 0));
605
+ return _objectSpread2(_objectSpread2({}, DEFAULT_FILE_OPTIONS), definedOptions);
606
+ }
603
607
  var StorageFileApi = class extends BaseApiClient {
604
608
  constructor(url, headers = {}, bucketId, fetch$1) {
605
609
  super(url, headers, fetch$1, "storage");
@@ -616,7 +620,7 @@ var StorageFileApi = class extends BaseApiClient {
616
620
  var _this = this;
617
621
  return _this.handleOperation(async () => {
618
622
  let body;
619
- const options = _objectSpread2(_objectSpread2({}, DEFAULT_FILE_OPTIONS), fileOptions);
623
+ const options = mergeFileOptions(fileOptions);
620
624
  let headers = _objectSpread2(_objectSpread2({}, _this.headers), method === "POST" && { "x-upsert": String(options.upsert) });
621
625
  const metadata = options.metadata;
622
626
  if (typeof Blob !== "undefined" && fileBody instanceof Blob || typeof FormData !== "undefined" && fileBody instanceof FormData) body = _this.prepareUploadFormData(fileBody, options);
@@ -755,7 +759,7 @@ var StorageFileApi = class extends BaseApiClient {
755
759
  url.searchParams.set("token", token);
756
760
  return _this3.handleOperation(async () => {
757
761
  let body;
758
- const options = _objectSpread2(_objectSpread2({}, DEFAULT_FILE_OPTIONS), fileOptions);
762
+ const options = mergeFileOptions(fileOptions);
759
763
  let headers = _objectSpread2(_objectSpread2({}, _this3.headers), { "x-upsert": String(options.upsert) });
760
764
  const metadata = options.metadata;
761
765
  if (typeof Blob !== "undefined" && fileBody instanceof Blob || typeof FormData !== "undefined" && fileBody instanceof FormData) body = _this3.prepareUploadFormData(fileBody, options);
@@ -1247,6 +1251,14 @@ var StorageFileApi = class extends BaseApiClient {
1247
1251
  /**
1248
1252
  * Checks the existence of a file.
1249
1253
  *
1254
+ * This reads the object's metadata, so the result is `false` only when Storage reports that the
1255
+ * key does not exist: an error with code `NoSuchKey`, or an HTTP 404 with no error code. In that
1256
+ * case `data` is `false` and `error` holds the original error.
1257
+ *
1258
+ * Every other failure throws instead of returning `false`, including an invalid or expired JWT
1259
+ * (`InvalidJWT`), a missing bucket (`NoSuchBucket`) and network errors. With `throwOnError()`,
1260
+ * a missing key throws as well.
1261
+ *
1250
1262
  * @category Storage
1251
1263
  * @subcategory File Buckets
1252
1264
  * @param path The file path, including the file name. For example `folder/image.png`.
@@ -1261,26 +1273,16 @@ var StorageFileApi = class extends BaseApiClient {
1261
1273
  * ```
1262
1274
  */
1263
1275
  async exists(path) {
1264
- var _this11 = this;
1265
- const _path = _this11._getFinalPath(path);
1266
- try {
1267
- await head(_this11.fetch, `${_this11.url}/object/${_path}`, { headers: _this11.headers });
1268
- return {
1269
- data: true,
1270
- error: null
1271
- };
1272
- } catch (error) {
1273
- if (_this11.shouldThrowOnError) throw error;
1274
- if (isStorageError(error)) {
1275
- var _error$originalError;
1276
- const status = error instanceof StorageApiError ? error.status : error instanceof StorageUnknownError ? (_error$originalError = error.originalError) === null || _error$originalError === void 0 ? void 0 : _error$originalError.status : void 0;
1277
- if (status !== void 0 && [400, 404].includes(status)) return {
1278
- data: false,
1279
- error
1280
- };
1281
- }
1282
- throw error;
1283
- }
1276
+ const { error } = await this.info(path);
1277
+ if (!error) return {
1278
+ data: true,
1279
+ error: null
1280
+ };
1281
+ if (error instanceof StorageApiError && (error.code === "NoSuchKey" || error.status === 404 && error.code === void 0)) return {
1282
+ data: false,
1283
+ error
1284
+ };
1285
+ throw error;
1284
1286
  }
1285
1287
  /**
1286
1288
  * A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.
@@ -1649,7 +1651,7 @@ var StorageFileApi = class extends BaseApiClient {
1649
1651
 
1650
1652
  //#endregion
1651
1653
  //#region src/lib/version.ts
1652
- const version = "2.119.0-canary.1";
1654
+ const version = "2.119.0-canary.3";
1653
1655
 
1654
1656
  //#endregion
1655
1657
  //#region src/lib/constants.ts