@supabase/storage-js 2.87.4-canary.2 → 2.87.4-canary.4
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/README.md +2 -106
- package/dist/index.cjs +3019 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2601 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +2601 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2998 -0
- package/dist/index.mjs.map +1 -0
- package/dist/umd/supabase.js +1 -1
- package/package.json +21 -12
- package/src/lib/version.ts +1 -1
- package/dist/main/StorageClient.d.ts +0 -64
- package/dist/main/StorageClient.d.ts.map +0 -1
- package/dist/main/StorageClient.js +0 -74
- package/dist/main/StorageClient.js.map +0 -1
- package/dist/main/index.d.ts +0 -7
- package/dist/main/index.d.ts.map +0 -1
- package/dist/main/index.js +0 -12
- package/dist/main/index.js.map +0 -1
- package/dist/main/lib/constants.d.ts +0 -4
- package/dist/main/lib/constants.d.ts.map +0 -1
- package/dist/main/lib/constants.js +0 -8
- package/dist/main/lib/constants.js.map +0 -1
- package/dist/main/lib/errors.d.ts +0 -21
- package/dist/main/lib/errors.d.ts.map +0 -1
- package/dist/main/lib/errors.js +0 -41
- package/dist/main/lib/errors.js.map +0 -1
- package/dist/main/lib/fetch.d.ts +0 -16
- package/dist/main/lib/fetch.d.ts.map +0 -1
- package/dist/main/lib/fetch.js +0 -95
- package/dist/main/lib/fetch.js.map +0 -1
- package/dist/main/lib/helpers.d.ts +0 -28
- package/dist/main/lib/helpers.d.ts.map +0 -1
- package/dist/main/lib/helpers.js +0 -87
- package/dist/main/lib/helpers.js.map +0 -1
- package/dist/main/lib/index.d.ts +0 -6
- package/dist/main/lib/index.d.ts.map +0 -1
- package/dist/main/lib/index.js +0 -9
- package/dist/main/lib/index.js.map +0 -1
- package/dist/main/lib/types.d.ts +0 -226
- package/dist/main/lib/types.d.ts.map +0 -1
- package/dist/main/lib/types.js +0 -3
- package/dist/main/lib/types.js.map +0 -1
- package/dist/main/lib/vectors/StorageVectorsClient.d.ts +0 -505
- package/dist/main/lib/vectors/StorageVectorsClient.d.ts.map +0 -1
- package/dist/main/lib/vectors/StorageVectorsClient.js +0 -582
- package/dist/main/lib/vectors/StorageVectorsClient.js.map +0 -1
- package/dist/main/lib/vectors/VectorBucketApi.d.ts +0 -32
- package/dist/main/lib/vectors/VectorBucketApi.d.ts.map +0 -1
- package/dist/main/lib/vectors/VectorBucketApi.js +0 -102
- package/dist/main/lib/vectors/VectorBucketApi.js.map +0 -1
- package/dist/main/lib/vectors/VectorDataApi.d.ts +0 -32
- package/dist/main/lib/vectors/VectorDataApi.d.ts.map +0 -1
- package/dist/main/lib/vectors/VectorDataApi.js +0 -147
- package/dist/main/lib/vectors/VectorDataApi.js.map +0 -1
- package/dist/main/lib/vectors/VectorIndexApi.d.ts +0 -47
- package/dist/main/lib/vectors/VectorIndexApi.d.ts.map +0 -1
- package/dist/main/lib/vectors/VectorIndexApi.js +0 -104
- package/dist/main/lib/vectors/VectorIndexApi.js.map +0 -1
- package/dist/main/lib/vectors/constants.d.ts +0 -5
- package/dist/main/lib/vectors/constants.d.ts.map +0 -1
- package/dist/main/lib/vectors/constants.js +0 -9
- package/dist/main/lib/vectors/constants.js.map +0 -1
- package/dist/main/lib/vectors/errors.d.ts +0 -55
- package/dist/main/lib/vectors/errors.d.ts.map +0 -1
- package/dist/main/lib/vectors/errors.js +0 -76
- package/dist/main/lib/vectors/errors.js.map +0 -1
- package/dist/main/lib/vectors/fetch.d.ts +0 -57
- package/dist/main/lib/vectors/fetch.d.ts.map +0 -1
- package/dist/main/lib/vectors/fetch.js +0 -167
- package/dist/main/lib/vectors/fetch.js.map +0 -1
- package/dist/main/lib/vectors/helpers.d.ts +0 -46
- package/dist/main/lib/vectors/helpers.d.ts.map +0 -1
- package/dist/main/lib/vectors/helpers.js +0 -74
- package/dist/main/lib/vectors/helpers.js.map +0 -1
- package/dist/main/lib/vectors/index.d.ts +0 -11
- package/dist/main/lib/vectors/index.d.ts.map +0 -1
- package/dist/main/lib/vectors/index.js +0 -31
- package/dist/main/lib/vectors/index.js.map +0 -1
- package/dist/main/lib/vectors/types.d.ts +0 -279
- package/dist/main/lib/vectors/types.d.ts.map +0 -1
- package/dist/main/lib/vectors/types.js +0 -3
- package/dist/main/lib/vectors/types.js.map +0 -1
- package/dist/main/lib/version.d.ts +0 -2
- package/dist/main/lib/version.d.ts.map +0 -1
- package/dist/main/lib/version.js +0 -11
- package/dist/main/lib/version.js.map +0 -1
- package/dist/main/packages/BlobDownloadBuilder.d.ts +0 -16
- package/dist/main/packages/BlobDownloadBuilder.d.ts.map +0 -1
- package/dist/main/packages/BlobDownloadBuilder.js +0 -55
- package/dist/main/packages/BlobDownloadBuilder.js.map +0 -1
- package/dist/main/packages/StorageAnalyticsClient.d.ts +0 -324
- package/dist/main/packages/StorageAnalyticsClient.d.ts.map +0 -1
- package/dist/main/packages/StorageAnalyticsClient.js +0 -395
- package/dist/main/packages/StorageAnalyticsClient.js.map +0 -1
- package/dist/main/packages/StorageBucketApi.d.ts +0 -266
- package/dist/main/packages/StorageBucketApi.d.ts.map +0 -1
- package/dist/main/packages/StorageBucketApi.js +0 -362
- package/dist/main/packages/StorageBucketApi.js.map +0 -1
- package/dist/main/packages/StorageFileApi.d.ts +0 -680
- package/dist/main/packages/StorageFileApi.d.ts.map +0 -1
- package/dist/main/packages/StorageFileApi.js +0 -1002
- package/dist/main/packages/StorageFileApi.js.map +0 -1
- package/dist/main/packages/StreamDownloadBuilder.d.ts +0 -9
- package/dist/main/packages/StreamDownloadBuilder.d.ts.map +0 -1
- package/dist/main/packages/StreamDownloadBuilder.js +0 -35
- package/dist/main/packages/StreamDownloadBuilder.js.map +0 -1
- package/dist/module/StorageClient.d.ts +0 -64
- package/dist/module/StorageClient.d.ts.map +0 -1
- package/dist/module/StorageClient.js +0 -69
- package/dist/module/StorageClient.js.map +0 -1
- package/dist/module/index.d.ts +0 -7
- package/dist/module/index.d.ts.map +0 -1
- package/dist/module/index.js +0 -6
- package/dist/module/index.js.map +0 -1
- package/dist/module/lib/constants.d.ts +0 -4
- package/dist/module/lib/constants.d.ts.map +0 -1
- package/dist/module/lib/constants.js +0 -5
- package/dist/module/lib/constants.js.map +0 -1
- package/dist/module/lib/errors.d.ts +0 -21
- package/dist/module/lib/errors.d.ts.map +0 -1
- package/dist/module/lib/errors.js +0 -34
- package/dist/module/lib/errors.js.map +0 -1
- package/dist/module/lib/fetch.d.ts +0 -16
- package/dist/module/lib/fetch.d.ts.map +0 -1
- package/dist/module/lib/fetch.js +0 -88
- package/dist/module/lib/fetch.js.map +0 -1
- package/dist/module/lib/helpers.d.ts +0 -28
- package/dist/module/lib/helpers.d.ts.map +0 -1
- package/dist/module/lib/helpers.js +0 -79
- package/dist/module/lib/helpers.js.map +0 -1
- package/dist/module/lib/index.d.ts +0 -6
- package/dist/module/lib/index.d.ts.map +0 -1
- package/dist/module/lib/index.js +0 -6
- package/dist/module/lib/index.js.map +0 -1
- package/dist/module/lib/types.d.ts +0 -226
- package/dist/module/lib/types.d.ts.map +0 -1
- package/dist/module/lib/types.js +0 -2
- package/dist/module/lib/types.js.map +0 -1
- package/dist/module/lib/vectors/StorageVectorsClient.d.ts +0 -505
- package/dist/module/lib/vectors/StorageVectorsClient.d.ts.map +0 -1
- package/dist/module/lib/vectors/StorageVectorsClient.js +0 -576
- package/dist/module/lib/vectors/StorageVectorsClient.js.map +0 -1
- package/dist/module/lib/vectors/VectorBucketApi.d.ts +0 -32
- package/dist/module/lib/vectors/VectorBucketApi.d.ts.map +0 -1
- package/dist/module/lib/vectors/VectorBucketApi.js +0 -99
- package/dist/module/lib/vectors/VectorBucketApi.js.map +0 -1
- package/dist/module/lib/vectors/VectorDataApi.d.ts +0 -32
- package/dist/module/lib/vectors/VectorDataApi.d.ts.map +0 -1
- package/dist/module/lib/vectors/VectorDataApi.js +0 -144
- package/dist/module/lib/vectors/VectorDataApi.js.map +0 -1
- package/dist/module/lib/vectors/VectorIndexApi.d.ts +0 -47
- package/dist/module/lib/vectors/VectorIndexApi.d.ts.map +0 -1
- package/dist/module/lib/vectors/VectorIndexApi.js +0 -101
- package/dist/module/lib/vectors/VectorIndexApi.js.map +0 -1
- package/dist/module/lib/vectors/constants.d.ts +0 -5
- package/dist/module/lib/vectors/constants.d.ts.map +0 -1
- package/dist/module/lib/vectors/constants.js +0 -6
- package/dist/module/lib/vectors/constants.js.map +0 -1
- package/dist/module/lib/vectors/errors.d.ts +0 -55
- package/dist/module/lib/vectors/errors.d.ts.map +0 -1
- package/dist/module/lib/vectors/errors.js +0 -69
- package/dist/module/lib/vectors/errors.js.map +0 -1
- package/dist/module/lib/vectors/fetch.d.ts +0 -57
- package/dist/module/lib/vectors/fetch.d.ts.map +0 -1
- package/dist/module/lib/vectors/fetch.js +0 -161
- package/dist/module/lib/vectors/fetch.js.map +0 -1
- package/dist/module/lib/vectors/helpers.d.ts +0 -46
- package/dist/module/lib/vectors/helpers.d.ts.map +0 -1
- package/dist/module/lib/vectors/helpers.js +0 -66
- package/dist/module/lib/vectors/helpers.js.map +0 -1
- package/dist/module/lib/vectors/index.d.ts +0 -11
- package/dist/module/lib/vectors/index.d.ts.map +0 -1
- package/dist/module/lib/vectors/index.js +0 -11
- package/dist/module/lib/vectors/index.js.map +0 -1
- package/dist/module/lib/vectors/types.d.ts +0 -279
- package/dist/module/lib/vectors/types.d.ts.map +0 -1
- package/dist/module/lib/vectors/types.js +0 -2
- package/dist/module/lib/vectors/types.js.map +0 -1
- package/dist/module/lib/version.d.ts +0 -2
- package/dist/module/lib/version.d.ts.map +0 -1
- package/dist/module/lib/version.js +0 -8
- package/dist/module/lib/version.js.map +0 -1
- package/dist/module/packages/BlobDownloadBuilder.d.ts +0 -16
- package/dist/module/packages/BlobDownloadBuilder.d.ts.map +0 -1
- package/dist/module/packages/BlobDownloadBuilder.js +0 -53
- package/dist/module/packages/BlobDownloadBuilder.js.map +0 -1
- package/dist/module/packages/StorageAnalyticsClient.d.ts +0 -324
- package/dist/module/packages/StorageAnalyticsClient.d.ts.map +0 -1
- package/dist/module/packages/StorageAnalyticsClient.js +0 -392
- package/dist/module/packages/StorageAnalyticsClient.js.map +0 -1
- package/dist/module/packages/StorageBucketApi.d.ts +0 -266
- package/dist/module/packages/StorageBucketApi.d.ts.map +0 -1
- package/dist/module/packages/StorageBucketApi.js +0 -359
- package/dist/module/packages/StorageBucketApi.js.map +0 -1
- package/dist/module/packages/StorageFileApi.d.ts +0 -680
- package/dist/module/packages/StorageFileApi.d.ts.map +0 -1
- package/dist/module/packages/StorageFileApi.js +0 -999
- package/dist/module/packages/StorageFileApi.js.map +0 -1
- package/dist/module/packages/StreamDownloadBuilder.d.ts +0 -9
- package/dist/module/packages/StreamDownloadBuilder.d.ts.map +0 -1
- package/dist/module/packages/StreamDownloadBuilder.js +0 -32
- package/dist/module/packages/StreamDownloadBuilder.js.map +0 -1
- package/dist/tsconfig.module.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2998 @@
|
|
|
1
|
+
import { IcebergRestCatalog } from "iceberg-js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/errors.ts
|
|
4
|
+
var StorageError = class extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.__isStorageError = true;
|
|
8
|
+
this.name = "StorageError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
function isStorageError(error) {
|
|
12
|
+
return typeof error === "object" && error !== null && "__isStorageError" in error;
|
|
13
|
+
}
|
|
14
|
+
var StorageApiError = class extends StorageError {
|
|
15
|
+
constructor(message, status, statusCode) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "StorageApiError";
|
|
18
|
+
this.status = status;
|
|
19
|
+
this.statusCode = statusCode;
|
|
20
|
+
}
|
|
21
|
+
toJSON() {
|
|
22
|
+
return {
|
|
23
|
+
name: this.name,
|
|
24
|
+
message: this.message,
|
|
25
|
+
status: this.status,
|
|
26
|
+
statusCode: this.statusCode
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var StorageUnknownError = class extends StorageError {
|
|
31
|
+
constructor(message, originalError) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "StorageUnknownError";
|
|
34
|
+
this.originalError = originalError;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/lib/helpers.ts
|
|
40
|
+
const resolveFetch$1 = (customFetch) => {
|
|
41
|
+
if (customFetch) return (...args) => customFetch(...args);
|
|
42
|
+
return (...args) => fetch(...args);
|
|
43
|
+
};
|
|
44
|
+
const resolveResponse$1 = () => {
|
|
45
|
+
return Response;
|
|
46
|
+
};
|
|
47
|
+
const recursiveToCamel = (item) => {
|
|
48
|
+
if (Array.isArray(item)) return item.map((el) => recursiveToCamel(el));
|
|
49
|
+
else if (typeof item === "function" || item !== Object(item)) return item;
|
|
50
|
+
const result = {};
|
|
51
|
+
Object.entries(item).forEach(([key, value]) => {
|
|
52
|
+
const newKey = key.replace(/([-_][a-z])/gi, (c) => c.toUpperCase().replace(/[-_]/g, ""));
|
|
53
|
+
result[newKey] = recursiveToCamel(value);
|
|
54
|
+
});
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Determine if input is a plain object
|
|
59
|
+
* An object is plain if it's created by either {}, new Object(), or Object.create(null)
|
|
60
|
+
* source: https://github.com/sindresorhus/is-plain-obj
|
|
61
|
+
*/
|
|
62
|
+
const isPlainObject$1 = (value) => {
|
|
63
|
+
if (typeof value !== "object" || value === null) return false;
|
|
64
|
+
const prototype = Object.getPrototypeOf(value);
|
|
65
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Validates if a given bucket name is valid according to Supabase Storage API rules
|
|
69
|
+
* Mirrors backend validation from: storage/src/storage/limits.ts:isValidBucketName()
|
|
70
|
+
*
|
|
71
|
+
* Rules:
|
|
72
|
+
* - Length: 1-100 characters
|
|
73
|
+
* - Allowed characters: alphanumeric (a-z, A-Z, 0-9), underscore (_), and safe special characters
|
|
74
|
+
* - Safe special characters: ! - . * ' ( ) space & $ @ = ; : + , ?
|
|
75
|
+
* - Forbidden: path separators (/, \), path traversal (..), leading/trailing whitespace
|
|
76
|
+
*
|
|
77
|
+
* AWS S3 Reference: https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html
|
|
78
|
+
*
|
|
79
|
+
* @param bucketName - The bucket name to validate
|
|
80
|
+
* @returns true if valid, false otherwise
|
|
81
|
+
*/
|
|
82
|
+
const isValidBucketName = (bucketName) => {
|
|
83
|
+
if (!bucketName || typeof bucketName !== "string") return false;
|
|
84
|
+
if (bucketName.length === 0 || bucketName.length > 100) return false;
|
|
85
|
+
if (bucketName.trim() !== bucketName) return false;
|
|
86
|
+
if (bucketName.includes("/") || bucketName.includes("\\")) return false;
|
|
87
|
+
return /^[\w!.\*'() &$@=;:+,?-]+$/.test(bucketName);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/typeof.js
|
|
92
|
+
function _typeof(o) {
|
|
93
|
+
"@babel/helpers - typeof";
|
|
94
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
95
|
+
return typeof o$1;
|
|
96
|
+
} : function(o$1) {
|
|
97
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
98
|
+
}, _typeof(o);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/toPrimitive.js
|
|
103
|
+
function toPrimitive(t, r) {
|
|
104
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
105
|
+
var e = t[Symbol.toPrimitive];
|
|
106
|
+
if (void 0 !== e) {
|
|
107
|
+
var i = e.call(t, r || "default");
|
|
108
|
+
if ("object" != _typeof(i)) return i;
|
|
109
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
110
|
+
}
|
|
111
|
+
return ("string" === r ? String : Number)(t);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/toPropertyKey.js
|
|
116
|
+
function toPropertyKey(t) {
|
|
117
|
+
var i = toPrimitive(t, "string");
|
|
118
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/defineProperty.js
|
|
123
|
+
function _defineProperty(e, r, t) {
|
|
124
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
125
|
+
value: t,
|
|
126
|
+
enumerable: !0,
|
|
127
|
+
configurable: !0,
|
|
128
|
+
writable: !0
|
|
129
|
+
}) : e[r] = t, e;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/objectSpread2.js
|
|
134
|
+
function ownKeys(e, r) {
|
|
135
|
+
var t = Object.keys(e);
|
|
136
|
+
if (Object.getOwnPropertySymbols) {
|
|
137
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
138
|
+
r && (o = o.filter(function(r$1) {
|
|
139
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
140
|
+
})), t.push.apply(t, o);
|
|
141
|
+
}
|
|
142
|
+
return t;
|
|
143
|
+
}
|
|
144
|
+
function _objectSpread2(e) {
|
|
145
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
146
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
147
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
148
|
+
_defineProperty(e, r$1, t[r$1]);
|
|
149
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
150
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return e;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/lib/fetch.ts
|
|
158
|
+
const _getErrorMessage$1 = (err) => {
|
|
159
|
+
var _err$error;
|
|
160
|
+
return err.msg || err.message || err.error_description || (typeof err.error === "string" ? err.error : (_err$error = err.error) === null || _err$error === void 0 ? void 0 : _err$error.message) || JSON.stringify(err);
|
|
161
|
+
};
|
|
162
|
+
const handleError$1 = async (error, reject, options) => {
|
|
163
|
+
if (error instanceof await resolveResponse$1() && !(options === null || options === void 0 ? void 0 : options.noResolveJson)) error.json().then((err) => {
|
|
164
|
+
const status = error.status || 500;
|
|
165
|
+
const statusCode = (err === null || err === void 0 ? void 0 : err.statusCode) || status + "";
|
|
166
|
+
reject(new StorageApiError(_getErrorMessage$1(err), status, statusCode));
|
|
167
|
+
}).catch((err) => {
|
|
168
|
+
reject(new StorageUnknownError(_getErrorMessage$1(err), err));
|
|
169
|
+
});
|
|
170
|
+
else reject(new StorageUnknownError(_getErrorMessage$1(error), error));
|
|
171
|
+
};
|
|
172
|
+
const _getRequestParams$1 = (method, options, parameters, body) => {
|
|
173
|
+
const params = {
|
|
174
|
+
method,
|
|
175
|
+
headers: (options === null || options === void 0 ? void 0 : options.headers) || {}
|
|
176
|
+
};
|
|
177
|
+
if (method === "GET" || !body) return params;
|
|
178
|
+
if (isPlainObject$1(body)) {
|
|
179
|
+
params.headers = _objectSpread2({ "Content-Type": "application/json" }, options === null || options === void 0 ? void 0 : options.headers);
|
|
180
|
+
params.body = JSON.stringify(body);
|
|
181
|
+
} else params.body = body;
|
|
182
|
+
if (options === null || options === void 0 ? void 0 : options.duplex) params.duplex = options.duplex;
|
|
183
|
+
return _objectSpread2(_objectSpread2({}, params), parameters);
|
|
184
|
+
};
|
|
185
|
+
async function _handleRequest$1(fetcher, method, url, options, parameters, body) {
|
|
186
|
+
return new Promise((resolve, reject) => {
|
|
187
|
+
fetcher(url, _getRequestParams$1(method, options, parameters, body)).then((result) => {
|
|
188
|
+
if (!result.ok) throw result;
|
|
189
|
+
if (options === null || options === void 0 ? void 0 : options.noResolveJson) return result;
|
|
190
|
+
return result.json();
|
|
191
|
+
}).then((data) => resolve(data)).catch((error) => handleError$1(error, reject, options));
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
async function get(fetcher, url, options, parameters) {
|
|
195
|
+
return _handleRequest$1(fetcher, "GET", url, options, parameters);
|
|
196
|
+
}
|
|
197
|
+
async function post$1(fetcher, url, body, options, parameters) {
|
|
198
|
+
return _handleRequest$1(fetcher, "POST", url, options, parameters, body);
|
|
199
|
+
}
|
|
200
|
+
async function put(fetcher, url, body, options, parameters) {
|
|
201
|
+
return _handleRequest$1(fetcher, "PUT", url, options, parameters, body);
|
|
202
|
+
}
|
|
203
|
+
async function head(fetcher, url, options, parameters) {
|
|
204
|
+
return _handleRequest$1(fetcher, "HEAD", url, _objectSpread2(_objectSpread2({}, options), {}, { noResolveJson: true }), parameters);
|
|
205
|
+
}
|
|
206
|
+
async function remove(fetcher, url, body, options, parameters) {
|
|
207
|
+
return _handleRequest$1(fetcher, "DELETE", url, options, parameters, body);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/packages/StreamDownloadBuilder.ts
|
|
212
|
+
var StreamDownloadBuilder = class {
|
|
213
|
+
constructor(downloadFn, shouldThrowOnError) {
|
|
214
|
+
this.downloadFn = downloadFn;
|
|
215
|
+
this.shouldThrowOnError = shouldThrowOnError;
|
|
216
|
+
}
|
|
217
|
+
then(onfulfilled, onrejected) {
|
|
218
|
+
return this.execute().then(onfulfilled, onrejected);
|
|
219
|
+
}
|
|
220
|
+
async execute() {
|
|
221
|
+
var _this = this;
|
|
222
|
+
try {
|
|
223
|
+
return {
|
|
224
|
+
data: (await _this.downloadFn()).body,
|
|
225
|
+
error: null
|
|
226
|
+
};
|
|
227
|
+
} catch (error) {
|
|
228
|
+
if (_this.shouldThrowOnError) throw error;
|
|
229
|
+
if (isStorageError(error)) return {
|
|
230
|
+
data: null,
|
|
231
|
+
error
|
|
232
|
+
};
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/packages/BlobDownloadBuilder.ts
|
|
240
|
+
let _Symbol$toStringTag;
|
|
241
|
+
_Symbol$toStringTag = Symbol.toStringTag;
|
|
242
|
+
var BlobDownloadBuilder = class {
|
|
243
|
+
constructor(downloadFn, shouldThrowOnError) {
|
|
244
|
+
this.downloadFn = downloadFn;
|
|
245
|
+
this.shouldThrowOnError = shouldThrowOnError;
|
|
246
|
+
this[_Symbol$toStringTag] = "BlobDownloadBuilder";
|
|
247
|
+
this.promise = null;
|
|
248
|
+
}
|
|
249
|
+
asStream() {
|
|
250
|
+
return new StreamDownloadBuilder(this.downloadFn, this.shouldThrowOnError);
|
|
251
|
+
}
|
|
252
|
+
then(onfulfilled, onrejected) {
|
|
253
|
+
return this.getPromise().then(onfulfilled, onrejected);
|
|
254
|
+
}
|
|
255
|
+
catch(onrejected) {
|
|
256
|
+
return this.getPromise().catch(onrejected);
|
|
257
|
+
}
|
|
258
|
+
finally(onfinally) {
|
|
259
|
+
return this.getPromise().finally(onfinally);
|
|
260
|
+
}
|
|
261
|
+
getPromise() {
|
|
262
|
+
if (!this.promise) this.promise = this.execute();
|
|
263
|
+
return this.promise;
|
|
264
|
+
}
|
|
265
|
+
async execute() {
|
|
266
|
+
var _this = this;
|
|
267
|
+
try {
|
|
268
|
+
return {
|
|
269
|
+
data: await (await _this.downloadFn()).blob(),
|
|
270
|
+
error: null
|
|
271
|
+
};
|
|
272
|
+
} catch (error) {
|
|
273
|
+
if (_this.shouldThrowOnError) throw error;
|
|
274
|
+
if (isStorageError(error)) return {
|
|
275
|
+
data: null,
|
|
276
|
+
error
|
|
277
|
+
};
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/packages/StorageFileApi.ts
|
|
285
|
+
const DEFAULT_SEARCH_OPTIONS = {
|
|
286
|
+
limit: 100,
|
|
287
|
+
offset: 0,
|
|
288
|
+
sortBy: {
|
|
289
|
+
column: "name",
|
|
290
|
+
order: "asc"
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
const DEFAULT_FILE_OPTIONS = {
|
|
294
|
+
cacheControl: "3600",
|
|
295
|
+
contentType: "text/plain;charset=UTF-8",
|
|
296
|
+
upsert: false
|
|
297
|
+
};
|
|
298
|
+
var StorageFileApi = class {
|
|
299
|
+
constructor(url, headers = {}, bucketId, fetch$1) {
|
|
300
|
+
this.shouldThrowOnError = false;
|
|
301
|
+
this.url = url;
|
|
302
|
+
this.headers = headers;
|
|
303
|
+
this.bucketId = bucketId;
|
|
304
|
+
this.fetch = resolveFetch$1(fetch$1);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Enable throwing errors instead of returning them.
|
|
308
|
+
*
|
|
309
|
+
* @category File Buckets
|
|
310
|
+
*/
|
|
311
|
+
throwOnError() {
|
|
312
|
+
this.shouldThrowOnError = true;
|
|
313
|
+
return this;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one.
|
|
317
|
+
*
|
|
318
|
+
* @param method HTTP method.
|
|
319
|
+
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
320
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
321
|
+
*/
|
|
322
|
+
async uploadOrUpdate(method, path, fileBody, fileOptions) {
|
|
323
|
+
var _this = this;
|
|
324
|
+
try {
|
|
325
|
+
let body;
|
|
326
|
+
const options = _objectSpread2(_objectSpread2({}, DEFAULT_FILE_OPTIONS), fileOptions);
|
|
327
|
+
let headers = _objectSpread2(_objectSpread2({}, _this.headers), method === "POST" && { "x-upsert": String(options.upsert) });
|
|
328
|
+
const metadata = options.metadata;
|
|
329
|
+
if (typeof Blob !== "undefined" && fileBody instanceof Blob) {
|
|
330
|
+
body = new FormData();
|
|
331
|
+
body.append("cacheControl", options.cacheControl);
|
|
332
|
+
if (metadata) body.append("metadata", _this.encodeMetadata(metadata));
|
|
333
|
+
body.append("", fileBody);
|
|
334
|
+
} else if (typeof FormData !== "undefined" && fileBody instanceof FormData) {
|
|
335
|
+
body = fileBody;
|
|
336
|
+
if (!body.has("cacheControl")) body.append("cacheControl", options.cacheControl);
|
|
337
|
+
if (metadata && !body.has("metadata")) body.append("metadata", _this.encodeMetadata(metadata));
|
|
338
|
+
} else {
|
|
339
|
+
body = fileBody;
|
|
340
|
+
headers["cache-control"] = `max-age=${options.cacheControl}`;
|
|
341
|
+
headers["content-type"] = options.contentType;
|
|
342
|
+
if (metadata) headers["x-metadata"] = _this.toBase64(_this.encodeMetadata(metadata));
|
|
343
|
+
if ((typeof ReadableStream !== "undefined" && body instanceof ReadableStream || body && typeof body === "object" && "pipe" in body && typeof body.pipe === "function") && !options.duplex) options.duplex = "half";
|
|
344
|
+
}
|
|
345
|
+
if (fileOptions === null || fileOptions === void 0 ? void 0 : fileOptions.headers) headers = _objectSpread2(_objectSpread2({}, headers), fileOptions.headers);
|
|
346
|
+
const cleanPath = _this._removeEmptyFolders(path);
|
|
347
|
+
const _path = _this._getFinalPath(cleanPath);
|
|
348
|
+
const data = await (method == "PUT" ? put : post$1)(_this.fetch, `${_this.url}/object/${_path}`, body, _objectSpread2({ headers }, (options === null || options === void 0 ? void 0 : options.duplex) ? { duplex: options.duplex } : {}));
|
|
349
|
+
return {
|
|
350
|
+
data: {
|
|
351
|
+
path: cleanPath,
|
|
352
|
+
id: data.Id,
|
|
353
|
+
fullPath: data.Key
|
|
354
|
+
},
|
|
355
|
+
error: null
|
|
356
|
+
};
|
|
357
|
+
} catch (error) {
|
|
358
|
+
if (_this.shouldThrowOnError) throw error;
|
|
359
|
+
if (isStorageError(error)) return {
|
|
360
|
+
data: null,
|
|
361
|
+
error
|
|
362
|
+
};
|
|
363
|
+
throw error;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Uploads a file to an existing bucket.
|
|
368
|
+
*
|
|
369
|
+
* @category File Buckets
|
|
370
|
+
* @param path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
371
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
372
|
+
* @param fileOptions Optional file upload options including cacheControl, contentType, upsert, and metadata.
|
|
373
|
+
* @returns Promise with response containing file path, id, and fullPath or error
|
|
374
|
+
*
|
|
375
|
+
* @example Upload file
|
|
376
|
+
* ```js
|
|
377
|
+
* const avatarFile = event.target.files[0]
|
|
378
|
+
* const { data, error } = await supabase
|
|
379
|
+
* .storage
|
|
380
|
+
* .from('avatars')
|
|
381
|
+
* .upload('public/avatar1.png', avatarFile, {
|
|
382
|
+
* cacheControl: '3600',
|
|
383
|
+
* upsert: false
|
|
384
|
+
* })
|
|
385
|
+
* ```
|
|
386
|
+
*
|
|
387
|
+
* Response:
|
|
388
|
+
* ```json
|
|
389
|
+
* {
|
|
390
|
+
* "data": {
|
|
391
|
+
* "path": "public/avatar1.png",
|
|
392
|
+
* "fullPath": "avatars/public/avatar1.png"
|
|
393
|
+
* },
|
|
394
|
+
* "error": null
|
|
395
|
+
* }
|
|
396
|
+
* ```
|
|
397
|
+
*
|
|
398
|
+
* @example Upload file using `ArrayBuffer` from base64 file data
|
|
399
|
+
* ```js
|
|
400
|
+
* import { decode } from 'base64-arraybuffer'
|
|
401
|
+
*
|
|
402
|
+
* const { data, error } = await supabase
|
|
403
|
+
* .storage
|
|
404
|
+
* .from('avatars')
|
|
405
|
+
* .upload('public/avatar1.png', decode('base64FileData'), {
|
|
406
|
+
* contentType: 'image/png'
|
|
407
|
+
* })
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
async upload(path, fileBody, fileOptions) {
|
|
411
|
+
return this.uploadOrUpdate("POST", path, fileBody, fileOptions);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Upload a file with a token generated from `createSignedUploadUrl`.
|
|
415
|
+
*
|
|
416
|
+
* @category File Buckets
|
|
417
|
+
* @param path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
418
|
+
* @param token The token generated from `createSignedUploadUrl`
|
|
419
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
420
|
+
* @param fileOptions HTTP headers (cacheControl, contentType, etc.).
|
|
421
|
+
* **Note:** The `upsert` option has no effect here. To enable upsert behavior,
|
|
422
|
+
* pass `{ upsert: true }` when calling `createSignedUploadUrl()` instead.
|
|
423
|
+
* @returns Promise with response containing file path and fullPath or error
|
|
424
|
+
*
|
|
425
|
+
* @example Upload to a signed URL
|
|
426
|
+
* ```js
|
|
427
|
+
* const { data, error } = await supabase
|
|
428
|
+
* .storage
|
|
429
|
+
* .from('avatars')
|
|
430
|
+
* .uploadToSignedUrl('folder/cat.jpg', 'token-from-createSignedUploadUrl', file)
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* Response:
|
|
434
|
+
* ```json
|
|
435
|
+
* {
|
|
436
|
+
* "data": {
|
|
437
|
+
* "path": "folder/cat.jpg",
|
|
438
|
+
* "fullPath": "avatars/folder/cat.jpg"
|
|
439
|
+
* },
|
|
440
|
+
* "error": null
|
|
441
|
+
* }
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
async uploadToSignedUrl(path, token, fileBody, fileOptions) {
|
|
445
|
+
var _this3 = this;
|
|
446
|
+
const cleanPath = _this3._removeEmptyFolders(path);
|
|
447
|
+
const _path = _this3._getFinalPath(cleanPath);
|
|
448
|
+
const url = new URL(_this3.url + `/object/upload/sign/${_path}`);
|
|
449
|
+
url.searchParams.set("token", token);
|
|
450
|
+
try {
|
|
451
|
+
let body;
|
|
452
|
+
const options = _objectSpread2({ upsert: DEFAULT_FILE_OPTIONS.upsert }, fileOptions);
|
|
453
|
+
const headers = _objectSpread2(_objectSpread2({}, _this3.headers), { "x-upsert": String(options.upsert) });
|
|
454
|
+
if (typeof Blob !== "undefined" && fileBody instanceof Blob) {
|
|
455
|
+
body = new FormData();
|
|
456
|
+
body.append("cacheControl", options.cacheControl);
|
|
457
|
+
body.append("", fileBody);
|
|
458
|
+
} else if (typeof FormData !== "undefined" && fileBody instanceof FormData) {
|
|
459
|
+
body = fileBody;
|
|
460
|
+
body.append("cacheControl", options.cacheControl);
|
|
461
|
+
} else {
|
|
462
|
+
body = fileBody;
|
|
463
|
+
headers["cache-control"] = `max-age=${options.cacheControl}`;
|
|
464
|
+
headers["content-type"] = options.contentType;
|
|
465
|
+
}
|
|
466
|
+
return {
|
|
467
|
+
data: {
|
|
468
|
+
path: cleanPath,
|
|
469
|
+
fullPath: (await put(_this3.fetch, url.toString(), body, { headers })).Key
|
|
470
|
+
},
|
|
471
|
+
error: null
|
|
472
|
+
};
|
|
473
|
+
} catch (error) {
|
|
474
|
+
if (_this3.shouldThrowOnError) throw error;
|
|
475
|
+
if (isStorageError(error)) return {
|
|
476
|
+
data: null,
|
|
477
|
+
error
|
|
478
|
+
};
|
|
479
|
+
throw error;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Creates a signed upload URL.
|
|
484
|
+
* Signed upload URLs can be used to upload files to the bucket without further authentication.
|
|
485
|
+
* They are valid for 2 hours.
|
|
486
|
+
*
|
|
487
|
+
* @category File Buckets
|
|
488
|
+
* @param path The file path, including the current file name. For example `folder/image.png`.
|
|
489
|
+
* @param options.upsert If set to true, allows the file to be overwritten if it already exists.
|
|
490
|
+
* @returns Promise with response containing signed upload URL, token, and path or error
|
|
491
|
+
*
|
|
492
|
+
* @example Create Signed Upload URL
|
|
493
|
+
* ```js
|
|
494
|
+
* const { data, error } = await supabase
|
|
495
|
+
* .storage
|
|
496
|
+
* .from('avatars')
|
|
497
|
+
* .createSignedUploadUrl('folder/cat.jpg')
|
|
498
|
+
* ```
|
|
499
|
+
*
|
|
500
|
+
* Response:
|
|
501
|
+
* ```json
|
|
502
|
+
* {
|
|
503
|
+
* "data": {
|
|
504
|
+
* "signedUrl": "https://example.supabase.co/storage/v1/object/upload/sign/avatars/folder/cat.jpg?token=<TOKEN>",
|
|
505
|
+
* "path": "folder/cat.jpg",
|
|
506
|
+
* "token": "<TOKEN>"
|
|
507
|
+
* },
|
|
508
|
+
* "error": null
|
|
509
|
+
* }
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
async createSignedUploadUrl(path, options) {
|
|
513
|
+
var _this4 = this;
|
|
514
|
+
try {
|
|
515
|
+
let _path = _this4._getFinalPath(path);
|
|
516
|
+
const headers = _objectSpread2({}, _this4.headers);
|
|
517
|
+
if (options === null || options === void 0 ? void 0 : options.upsert) headers["x-upsert"] = "true";
|
|
518
|
+
const data = await post$1(_this4.fetch, `${_this4.url}/object/upload/sign/${_path}`, {}, { headers });
|
|
519
|
+
const url = new URL(_this4.url + data.url);
|
|
520
|
+
const token = url.searchParams.get("token");
|
|
521
|
+
if (!token) throw new StorageError("No token returned by API");
|
|
522
|
+
return {
|
|
523
|
+
data: {
|
|
524
|
+
signedUrl: url.toString(),
|
|
525
|
+
path,
|
|
526
|
+
token
|
|
527
|
+
},
|
|
528
|
+
error: null
|
|
529
|
+
};
|
|
530
|
+
} catch (error) {
|
|
531
|
+
if (_this4.shouldThrowOnError) throw error;
|
|
532
|
+
if (isStorageError(error)) return {
|
|
533
|
+
data: null,
|
|
534
|
+
error
|
|
535
|
+
};
|
|
536
|
+
throw error;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Replaces an existing file at the specified path with a new one.
|
|
541
|
+
*
|
|
542
|
+
* @category File Buckets
|
|
543
|
+
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to update.
|
|
544
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
545
|
+
* @param fileOptions Optional file upload options including cacheControl, contentType, upsert, and metadata.
|
|
546
|
+
* @returns Promise with response containing file path, id, and fullPath or error
|
|
547
|
+
*
|
|
548
|
+
* @example Update file
|
|
549
|
+
* ```js
|
|
550
|
+
* const avatarFile = event.target.files[0]
|
|
551
|
+
* const { data, error } = await supabase
|
|
552
|
+
* .storage
|
|
553
|
+
* .from('avatars')
|
|
554
|
+
* .update('public/avatar1.png', avatarFile, {
|
|
555
|
+
* cacheControl: '3600',
|
|
556
|
+
* upsert: true
|
|
557
|
+
* })
|
|
558
|
+
* ```
|
|
559
|
+
*
|
|
560
|
+
* Response:
|
|
561
|
+
* ```json
|
|
562
|
+
* {
|
|
563
|
+
* "data": {
|
|
564
|
+
* "path": "public/avatar1.png",
|
|
565
|
+
* "fullPath": "avatars/public/avatar1.png"
|
|
566
|
+
* },
|
|
567
|
+
* "error": null
|
|
568
|
+
* }
|
|
569
|
+
* ```
|
|
570
|
+
*
|
|
571
|
+
* @example Update file using `ArrayBuffer` from base64 file data
|
|
572
|
+
* ```js
|
|
573
|
+
* import {decode} from 'base64-arraybuffer'
|
|
574
|
+
*
|
|
575
|
+
* const { data, error } = await supabase
|
|
576
|
+
* .storage
|
|
577
|
+
* .from('avatars')
|
|
578
|
+
* .update('public/avatar1.png', decode('base64FileData'), {
|
|
579
|
+
* contentType: 'image/png'
|
|
580
|
+
* })
|
|
581
|
+
* ```
|
|
582
|
+
*/
|
|
583
|
+
async update(path, fileBody, fileOptions) {
|
|
584
|
+
return this.uploadOrUpdate("PUT", path, fileBody, fileOptions);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Moves an existing file to a new path in the same bucket.
|
|
588
|
+
*
|
|
589
|
+
* @category File Buckets
|
|
590
|
+
* @param fromPath The original file path, including the current file name. For example `folder/image.png`.
|
|
591
|
+
* @param toPath The new file path, including the new file name. For example `folder/image-new.png`.
|
|
592
|
+
* @param options The destination options.
|
|
593
|
+
* @returns Promise with response containing success message or error
|
|
594
|
+
*
|
|
595
|
+
* @example Move file
|
|
596
|
+
* ```js
|
|
597
|
+
* const { data, error } = await supabase
|
|
598
|
+
* .storage
|
|
599
|
+
* .from('avatars')
|
|
600
|
+
* .move('public/avatar1.png', 'private/avatar2.png')
|
|
601
|
+
* ```
|
|
602
|
+
*
|
|
603
|
+
* Response:
|
|
604
|
+
* ```json
|
|
605
|
+
* {
|
|
606
|
+
* "data": {
|
|
607
|
+
* "message": "Successfully moved"
|
|
608
|
+
* },
|
|
609
|
+
* "error": null
|
|
610
|
+
* }
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
async move(fromPath, toPath, options) {
|
|
614
|
+
var _this6 = this;
|
|
615
|
+
try {
|
|
616
|
+
return {
|
|
617
|
+
data: await post$1(_this6.fetch, `${_this6.url}/object/move`, {
|
|
618
|
+
bucketId: _this6.bucketId,
|
|
619
|
+
sourceKey: fromPath,
|
|
620
|
+
destinationKey: toPath,
|
|
621
|
+
destinationBucket: options === null || options === void 0 ? void 0 : options.destinationBucket
|
|
622
|
+
}, { headers: _this6.headers }),
|
|
623
|
+
error: null
|
|
624
|
+
};
|
|
625
|
+
} catch (error) {
|
|
626
|
+
if (_this6.shouldThrowOnError) throw error;
|
|
627
|
+
if (isStorageError(error)) return {
|
|
628
|
+
data: null,
|
|
629
|
+
error
|
|
630
|
+
};
|
|
631
|
+
throw error;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Copies an existing file to a new path in the same bucket.
|
|
636
|
+
*
|
|
637
|
+
* @category File Buckets
|
|
638
|
+
* @param fromPath The original file path, including the current file name. For example `folder/image.png`.
|
|
639
|
+
* @param toPath The new file path, including the new file name. For example `folder/image-copy.png`.
|
|
640
|
+
* @param options The destination options.
|
|
641
|
+
* @returns Promise with response containing copied file path or error
|
|
642
|
+
*
|
|
643
|
+
* @example Copy file
|
|
644
|
+
* ```js
|
|
645
|
+
* const { data, error } = await supabase
|
|
646
|
+
* .storage
|
|
647
|
+
* .from('avatars')
|
|
648
|
+
* .copy('public/avatar1.png', 'private/avatar2.png')
|
|
649
|
+
* ```
|
|
650
|
+
*
|
|
651
|
+
* Response:
|
|
652
|
+
* ```json
|
|
653
|
+
* {
|
|
654
|
+
* "data": {
|
|
655
|
+
* "path": "avatars/private/avatar2.png"
|
|
656
|
+
* },
|
|
657
|
+
* "error": null
|
|
658
|
+
* }
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
async copy(fromPath, toPath, options) {
|
|
662
|
+
var _this7 = this;
|
|
663
|
+
try {
|
|
664
|
+
return {
|
|
665
|
+
data: { path: (await post$1(_this7.fetch, `${_this7.url}/object/copy`, {
|
|
666
|
+
bucketId: _this7.bucketId,
|
|
667
|
+
sourceKey: fromPath,
|
|
668
|
+
destinationKey: toPath,
|
|
669
|
+
destinationBucket: options === null || options === void 0 ? void 0 : options.destinationBucket
|
|
670
|
+
}, { headers: _this7.headers })).Key },
|
|
671
|
+
error: null
|
|
672
|
+
};
|
|
673
|
+
} catch (error) {
|
|
674
|
+
if (_this7.shouldThrowOnError) throw error;
|
|
675
|
+
if (isStorageError(error)) return {
|
|
676
|
+
data: null,
|
|
677
|
+
error
|
|
678
|
+
};
|
|
679
|
+
throw error;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Creates a signed URL. Use a signed URL to share a file for a fixed amount of time.
|
|
684
|
+
*
|
|
685
|
+
* @category File Buckets
|
|
686
|
+
* @param path The file path, including the current file name. For example `folder/image.png`.
|
|
687
|
+
* @param expiresIn The number of seconds until the signed URL expires. For example, `60` for a URL which is valid for one minute.
|
|
688
|
+
* @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
|
|
689
|
+
* @param options.transform Transform the asset before serving it to the client.
|
|
690
|
+
* @returns Promise with response containing signed URL or error
|
|
691
|
+
*
|
|
692
|
+
* @example Create Signed URL
|
|
693
|
+
* ```js
|
|
694
|
+
* const { data, error } = await supabase
|
|
695
|
+
* .storage
|
|
696
|
+
* .from('avatars')
|
|
697
|
+
* .createSignedUrl('folder/avatar1.png', 60)
|
|
698
|
+
* ```
|
|
699
|
+
*
|
|
700
|
+
* Response:
|
|
701
|
+
* ```json
|
|
702
|
+
* {
|
|
703
|
+
* "data": {
|
|
704
|
+
* "signedUrl": "https://example.supabase.co/storage/v1/object/sign/avatars/folder/avatar1.png?token=<TOKEN>"
|
|
705
|
+
* },
|
|
706
|
+
* "error": null
|
|
707
|
+
* }
|
|
708
|
+
* ```
|
|
709
|
+
*
|
|
710
|
+
* @example Create a signed URL for an asset with transformations
|
|
711
|
+
* ```js
|
|
712
|
+
* const { data } = await supabase
|
|
713
|
+
* .storage
|
|
714
|
+
* .from('avatars')
|
|
715
|
+
* .createSignedUrl('folder/avatar1.png', 60, {
|
|
716
|
+
* transform: {
|
|
717
|
+
* width: 100,
|
|
718
|
+
* height: 100,
|
|
719
|
+
* }
|
|
720
|
+
* })
|
|
721
|
+
* ```
|
|
722
|
+
*
|
|
723
|
+
* @example Create a signed URL which triggers the download of the asset
|
|
724
|
+
* ```js
|
|
725
|
+
* const { data } = await supabase
|
|
726
|
+
* .storage
|
|
727
|
+
* .from('avatars')
|
|
728
|
+
* .createSignedUrl('folder/avatar1.png', 60, {
|
|
729
|
+
* download: true,
|
|
730
|
+
* })
|
|
731
|
+
* ```
|
|
732
|
+
*/
|
|
733
|
+
async createSignedUrl(path, expiresIn, options) {
|
|
734
|
+
var _this8 = this;
|
|
735
|
+
try {
|
|
736
|
+
let _path = _this8._getFinalPath(path);
|
|
737
|
+
let data = await post$1(_this8.fetch, `${_this8.url}/object/sign/${_path}`, _objectSpread2({ expiresIn }, (options === null || options === void 0 ? void 0 : options.transform) ? { transform: options.transform } : {}), { headers: _this8.headers });
|
|
738
|
+
const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download) ? `&download=${options.download === true ? "" : options.download}` : "";
|
|
739
|
+
data = { signedUrl: encodeURI(`${_this8.url}${data.signedURL}${downloadQueryParam}`) };
|
|
740
|
+
return {
|
|
741
|
+
data,
|
|
742
|
+
error: null
|
|
743
|
+
};
|
|
744
|
+
} catch (error) {
|
|
745
|
+
if (_this8.shouldThrowOnError) throw error;
|
|
746
|
+
if (isStorageError(error)) return {
|
|
747
|
+
data: null,
|
|
748
|
+
error
|
|
749
|
+
};
|
|
750
|
+
throw error;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Creates multiple signed URLs. Use a signed URL to share a file for a fixed amount of time.
|
|
755
|
+
*
|
|
756
|
+
* @category File Buckets
|
|
757
|
+
* @param paths The file paths to be downloaded, including the current file names. For example `['folder/image.png', 'folder2/image2.png']`.
|
|
758
|
+
* @param expiresIn The number of seconds until the signed URLs expire. For example, `60` for URLs which are valid for one minute.
|
|
759
|
+
* @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
|
|
760
|
+
* @returns Promise with response containing array of objects with signedUrl, path, and error or error
|
|
761
|
+
*
|
|
762
|
+
* @example Create Signed URLs
|
|
763
|
+
* ```js
|
|
764
|
+
* const { data, error } = await supabase
|
|
765
|
+
* .storage
|
|
766
|
+
* .from('avatars')
|
|
767
|
+
* .createSignedUrls(['folder/avatar1.png', 'folder/avatar2.png'], 60)
|
|
768
|
+
* ```
|
|
769
|
+
*
|
|
770
|
+
* Response:
|
|
771
|
+
* ```json
|
|
772
|
+
* {
|
|
773
|
+
* "data": [
|
|
774
|
+
* {
|
|
775
|
+
* "error": null,
|
|
776
|
+
* "path": "folder/avatar1.png",
|
|
777
|
+
* "signedURL": "/object/sign/avatars/folder/avatar1.png?token=<TOKEN>",
|
|
778
|
+
* "signedUrl": "https://example.supabase.co/storage/v1/object/sign/avatars/folder/avatar1.png?token=<TOKEN>"
|
|
779
|
+
* },
|
|
780
|
+
* {
|
|
781
|
+
* "error": null,
|
|
782
|
+
* "path": "folder/avatar2.png",
|
|
783
|
+
* "signedURL": "/object/sign/avatars/folder/avatar2.png?token=<TOKEN>",
|
|
784
|
+
* "signedUrl": "https://example.supabase.co/storage/v1/object/sign/avatars/folder/avatar2.png?token=<TOKEN>"
|
|
785
|
+
* }
|
|
786
|
+
* ],
|
|
787
|
+
* "error": null
|
|
788
|
+
* }
|
|
789
|
+
* ```
|
|
790
|
+
*/
|
|
791
|
+
async createSignedUrls(paths, expiresIn, options) {
|
|
792
|
+
var _this9 = this;
|
|
793
|
+
try {
|
|
794
|
+
const data = await post$1(_this9.fetch, `${_this9.url}/object/sign/${_this9.bucketId}`, {
|
|
795
|
+
expiresIn,
|
|
796
|
+
paths
|
|
797
|
+
}, { headers: _this9.headers });
|
|
798
|
+
const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download) ? `&download=${options.download === true ? "" : options.download}` : "";
|
|
799
|
+
return {
|
|
800
|
+
data: data.map((datum) => _objectSpread2(_objectSpread2({}, datum), {}, { signedUrl: datum.signedURL ? encodeURI(`${_this9.url}${datum.signedURL}${downloadQueryParam}`) : null })),
|
|
801
|
+
error: null
|
|
802
|
+
};
|
|
803
|
+
} catch (error) {
|
|
804
|
+
if (_this9.shouldThrowOnError) throw error;
|
|
805
|
+
if (isStorageError(error)) return {
|
|
806
|
+
data: null,
|
|
807
|
+
error
|
|
808
|
+
};
|
|
809
|
+
throw error;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Downloads a file from a private bucket. For public buckets, make a request to the URL returned from `getPublicUrl` instead.
|
|
814
|
+
*
|
|
815
|
+
* @category File Buckets
|
|
816
|
+
* @param path The full path and file name of the file to be downloaded. For example `folder/image.png`.
|
|
817
|
+
* @param options.transform Transform the asset before serving it to the client.
|
|
818
|
+
* @returns BlobDownloadBuilder instance for downloading the file
|
|
819
|
+
*
|
|
820
|
+
* @example Download file
|
|
821
|
+
* ```js
|
|
822
|
+
* const { data, error } = await supabase
|
|
823
|
+
* .storage
|
|
824
|
+
* .from('avatars')
|
|
825
|
+
* .download('folder/avatar1.png')
|
|
826
|
+
* ```
|
|
827
|
+
*
|
|
828
|
+
* Response:
|
|
829
|
+
* ```json
|
|
830
|
+
* {
|
|
831
|
+
* "data": <BLOB>,
|
|
832
|
+
* "error": null
|
|
833
|
+
* }
|
|
834
|
+
* ```
|
|
835
|
+
*
|
|
836
|
+
* @example Download file with transformations
|
|
837
|
+
* ```js
|
|
838
|
+
* const { data, error } = await supabase
|
|
839
|
+
* .storage
|
|
840
|
+
* .from('avatars')
|
|
841
|
+
* .download('folder/avatar1.png', {
|
|
842
|
+
* transform: {
|
|
843
|
+
* width: 100,
|
|
844
|
+
* height: 100,
|
|
845
|
+
* quality: 80
|
|
846
|
+
* }
|
|
847
|
+
* })
|
|
848
|
+
* ```
|
|
849
|
+
*/
|
|
850
|
+
download(path, options) {
|
|
851
|
+
const renderPath = typeof (options === null || options === void 0 ? void 0 : options.transform) !== "undefined" ? "render/image/authenticated" : "object";
|
|
852
|
+
const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {});
|
|
853
|
+
const queryString = transformationQuery ? `?${transformationQuery}` : "";
|
|
854
|
+
const _path = this._getFinalPath(path);
|
|
855
|
+
const downloadFn = () => get(this.fetch, `${this.url}/${renderPath}/${_path}${queryString}`, {
|
|
856
|
+
headers: this.headers,
|
|
857
|
+
noResolveJson: true
|
|
858
|
+
});
|
|
859
|
+
return new BlobDownloadBuilder(downloadFn, this.shouldThrowOnError);
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Retrieves the details of an existing file.
|
|
863
|
+
*
|
|
864
|
+
* @category File Buckets
|
|
865
|
+
* @param path The file path, including the file name. For example `folder/image.png`.
|
|
866
|
+
* @returns Promise with response containing file metadata or error
|
|
867
|
+
*
|
|
868
|
+
* @example Get file info
|
|
869
|
+
* ```js
|
|
870
|
+
* const { data, error } = await supabase
|
|
871
|
+
* .storage
|
|
872
|
+
* .from('avatars')
|
|
873
|
+
* .info('folder/avatar1.png')
|
|
874
|
+
* ```
|
|
875
|
+
*/
|
|
876
|
+
async info(path) {
|
|
877
|
+
var _this10 = this;
|
|
878
|
+
const _path = _this10._getFinalPath(path);
|
|
879
|
+
try {
|
|
880
|
+
return {
|
|
881
|
+
data: recursiveToCamel(await get(_this10.fetch, `${_this10.url}/object/info/${_path}`, { headers: _this10.headers })),
|
|
882
|
+
error: null
|
|
883
|
+
};
|
|
884
|
+
} catch (error) {
|
|
885
|
+
if (_this10.shouldThrowOnError) throw error;
|
|
886
|
+
if (isStorageError(error)) return {
|
|
887
|
+
data: null,
|
|
888
|
+
error
|
|
889
|
+
};
|
|
890
|
+
throw error;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Checks the existence of a file.
|
|
895
|
+
*
|
|
896
|
+
* @category File Buckets
|
|
897
|
+
* @param path The file path, including the file name. For example `folder/image.png`.
|
|
898
|
+
* @returns Promise with response containing boolean indicating file existence or error
|
|
899
|
+
*
|
|
900
|
+
* @example Check file existence
|
|
901
|
+
* ```js
|
|
902
|
+
* const { data, error } = await supabase
|
|
903
|
+
* .storage
|
|
904
|
+
* .from('avatars')
|
|
905
|
+
* .exists('folder/avatar1.png')
|
|
906
|
+
* ```
|
|
907
|
+
*/
|
|
908
|
+
async exists(path) {
|
|
909
|
+
var _this11 = this;
|
|
910
|
+
const _path = _this11._getFinalPath(path);
|
|
911
|
+
try {
|
|
912
|
+
await head(_this11.fetch, `${_this11.url}/object/${_path}`, { headers: _this11.headers });
|
|
913
|
+
return {
|
|
914
|
+
data: true,
|
|
915
|
+
error: null
|
|
916
|
+
};
|
|
917
|
+
} catch (error) {
|
|
918
|
+
if (_this11.shouldThrowOnError) throw error;
|
|
919
|
+
if (isStorageError(error) && error instanceof StorageUnknownError) {
|
|
920
|
+
const originalError = error.originalError;
|
|
921
|
+
if ([400, 404].includes(originalError === null || originalError === void 0 ? void 0 : originalError.status)) return {
|
|
922
|
+
data: false,
|
|
923
|
+
error
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
throw error;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* 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.
|
|
931
|
+
* This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.
|
|
932
|
+
*
|
|
933
|
+
* @category File Buckets
|
|
934
|
+
* @param path The path and name of the file to generate the public URL for. For example `folder/image.png`.
|
|
935
|
+
* @param options.download Triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
|
|
936
|
+
* @param options.transform Transform the asset before serving it to the client.
|
|
937
|
+
* @returns Object with public URL
|
|
938
|
+
*
|
|
939
|
+
* @example Returns the URL for an asset in a public bucket
|
|
940
|
+
* ```js
|
|
941
|
+
* const { data } = supabase
|
|
942
|
+
* .storage
|
|
943
|
+
* .from('public-bucket')
|
|
944
|
+
* .getPublicUrl('folder/avatar1.png')
|
|
945
|
+
* ```
|
|
946
|
+
*
|
|
947
|
+
* Response:
|
|
948
|
+
* ```json
|
|
949
|
+
* {
|
|
950
|
+
* "data": {
|
|
951
|
+
* "publicUrl": "https://example.supabase.co/storage/v1/object/public/public-bucket/folder/avatar1.png"
|
|
952
|
+
* }
|
|
953
|
+
* }
|
|
954
|
+
* ```
|
|
955
|
+
*
|
|
956
|
+
* @example Returns the URL for an asset in a public bucket with transformations
|
|
957
|
+
* ```js
|
|
958
|
+
* const { data } = supabase
|
|
959
|
+
* .storage
|
|
960
|
+
* .from('public-bucket')
|
|
961
|
+
* .getPublicUrl('folder/avatar1.png', {
|
|
962
|
+
* transform: {
|
|
963
|
+
* width: 100,
|
|
964
|
+
* height: 100,
|
|
965
|
+
* }
|
|
966
|
+
* })
|
|
967
|
+
* ```
|
|
968
|
+
*
|
|
969
|
+
* @example Returns the URL which triggers the download of an asset in a public bucket
|
|
970
|
+
* ```js
|
|
971
|
+
* const { data } = supabase
|
|
972
|
+
* .storage
|
|
973
|
+
* .from('public-bucket')
|
|
974
|
+
* .getPublicUrl('folder/avatar1.png', {
|
|
975
|
+
* download: true,
|
|
976
|
+
* })
|
|
977
|
+
* ```
|
|
978
|
+
*/
|
|
979
|
+
getPublicUrl(path, options) {
|
|
980
|
+
const _path = this._getFinalPath(path);
|
|
981
|
+
const _queryString = [];
|
|
982
|
+
const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download) ? `download=${options.download === true ? "" : options.download}` : "";
|
|
983
|
+
if (downloadQueryParam !== "") _queryString.push(downloadQueryParam);
|
|
984
|
+
const renderPath = typeof (options === null || options === void 0 ? void 0 : options.transform) !== "undefined" ? "render/image" : "object";
|
|
985
|
+
const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {});
|
|
986
|
+
if (transformationQuery !== "") _queryString.push(transformationQuery);
|
|
987
|
+
let queryString = _queryString.join("&");
|
|
988
|
+
if (queryString !== "") queryString = `?${queryString}`;
|
|
989
|
+
return { data: { publicUrl: encodeURI(`${this.url}/${renderPath}/public/${_path}${queryString}`) } };
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Deletes files within the same bucket
|
|
993
|
+
*
|
|
994
|
+
* @category File Buckets
|
|
995
|
+
* @param paths An array of files to delete, including the path and file name. For example [`'folder/image.png'`].
|
|
996
|
+
* @returns Promise with response containing array of deleted file objects or error
|
|
997
|
+
*
|
|
998
|
+
* @example Delete file
|
|
999
|
+
* ```js
|
|
1000
|
+
* const { data, error } = await supabase
|
|
1001
|
+
* .storage
|
|
1002
|
+
* .from('avatars')
|
|
1003
|
+
* .remove(['folder/avatar1.png'])
|
|
1004
|
+
* ```
|
|
1005
|
+
*
|
|
1006
|
+
* Response:
|
|
1007
|
+
* ```json
|
|
1008
|
+
* {
|
|
1009
|
+
* "data": [],
|
|
1010
|
+
* "error": null
|
|
1011
|
+
* }
|
|
1012
|
+
* ```
|
|
1013
|
+
*/
|
|
1014
|
+
async remove(paths) {
|
|
1015
|
+
var _this12 = this;
|
|
1016
|
+
try {
|
|
1017
|
+
return {
|
|
1018
|
+
data: await remove(_this12.fetch, `${_this12.url}/object/${_this12.bucketId}`, { prefixes: paths }, { headers: _this12.headers }),
|
|
1019
|
+
error: null
|
|
1020
|
+
};
|
|
1021
|
+
} catch (error) {
|
|
1022
|
+
if (_this12.shouldThrowOnError) throw error;
|
|
1023
|
+
if (isStorageError(error)) return {
|
|
1024
|
+
data: null,
|
|
1025
|
+
error
|
|
1026
|
+
};
|
|
1027
|
+
throw error;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Get file metadata
|
|
1032
|
+
* @param id the file id to retrieve metadata
|
|
1033
|
+
*/
|
|
1034
|
+
/**
|
|
1035
|
+
* Update file metadata
|
|
1036
|
+
* @param id the file id to update metadata
|
|
1037
|
+
* @param meta the new file metadata
|
|
1038
|
+
*/
|
|
1039
|
+
/**
|
|
1040
|
+
* Lists all the files and folders within a path of the bucket.
|
|
1041
|
+
*
|
|
1042
|
+
* @category File Buckets
|
|
1043
|
+
* @param path The folder path.
|
|
1044
|
+
* @param options Search options including limit (defaults to 100), offset, sortBy, and search
|
|
1045
|
+
* @param parameters Optional fetch parameters including signal for cancellation
|
|
1046
|
+
* @returns Promise with response containing array of files or error
|
|
1047
|
+
*
|
|
1048
|
+
* @example List files in a bucket
|
|
1049
|
+
* ```js
|
|
1050
|
+
* const { data, error } = await supabase
|
|
1051
|
+
* .storage
|
|
1052
|
+
* .from('avatars')
|
|
1053
|
+
* .list('folder', {
|
|
1054
|
+
* limit: 100,
|
|
1055
|
+
* offset: 0,
|
|
1056
|
+
* sortBy: { column: 'name', order: 'asc' },
|
|
1057
|
+
* })
|
|
1058
|
+
* ```
|
|
1059
|
+
*
|
|
1060
|
+
* Response:
|
|
1061
|
+
* ```json
|
|
1062
|
+
* {
|
|
1063
|
+
* "data": [
|
|
1064
|
+
* {
|
|
1065
|
+
* "name": "avatar1.png",
|
|
1066
|
+
* "id": "e668cf7f-821b-4a2f-9dce-7dfa5dd1cfd2",
|
|
1067
|
+
* "updated_at": "2024-05-22T23:06:05.580Z",
|
|
1068
|
+
* "created_at": "2024-05-22T23:04:34.443Z",
|
|
1069
|
+
* "last_accessed_at": "2024-05-22T23:04:34.443Z",
|
|
1070
|
+
* "metadata": {
|
|
1071
|
+
* "eTag": "\"c5e8c553235d9af30ef4f6e280790b92\"",
|
|
1072
|
+
* "size": 32175,
|
|
1073
|
+
* "mimetype": "image/png",
|
|
1074
|
+
* "cacheControl": "max-age=3600",
|
|
1075
|
+
* "lastModified": "2024-05-22T23:06:05.574Z",
|
|
1076
|
+
* "contentLength": 32175,
|
|
1077
|
+
* "httpStatusCode": 200
|
|
1078
|
+
* }
|
|
1079
|
+
* }
|
|
1080
|
+
* ],
|
|
1081
|
+
* "error": null
|
|
1082
|
+
* }
|
|
1083
|
+
* ```
|
|
1084
|
+
*
|
|
1085
|
+
* @example Search files in a bucket
|
|
1086
|
+
* ```js
|
|
1087
|
+
* const { data, error } = await supabase
|
|
1088
|
+
* .storage
|
|
1089
|
+
* .from('avatars')
|
|
1090
|
+
* .list('folder', {
|
|
1091
|
+
* limit: 100,
|
|
1092
|
+
* offset: 0,
|
|
1093
|
+
* sortBy: { column: 'name', order: 'asc' },
|
|
1094
|
+
* search: 'jon'
|
|
1095
|
+
* })
|
|
1096
|
+
* ```
|
|
1097
|
+
*/
|
|
1098
|
+
async list(path, options, parameters) {
|
|
1099
|
+
var _this13 = this;
|
|
1100
|
+
try {
|
|
1101
|
+
const body = _objectSpread2(_objectSpread2(_objectSpread2({}, DEFAULT_SEARCH_OPTIONS), options), {}, { prefix: path || "" });
|
|
1102
|
+
return {
|
|
1103
|
+
data: await post$1(_this13.fetch, `${_this13.url}/object/list/${_this13.bucketId}`, body, { headers: _this13.headers }, parameters),
|
|
1104
|
+
error: null
|
|
1105
|
+
};
|
|
1106
|
+
} catch (error) {
|
|
1107
|
+
if (_this13.shouldThrowOnError) throw error;
|
|
1108
|
+
if (isStorageError(error)) return {
|
|
1109
|
+
data: null,
|
|
1110
|
+
error
|
|
1111
|
+
};
|
|
1112
|
+
throw error;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* @experimental this method signature might change in the future
|
|
1117
|
+
*
|
|
1118
|
+
* @category File Buckets
|
|
1119
|
+
* @param options search options
|
|
1120
|
+
* @param parameters
|
|
1121
|
+
*/
|
|
1122
|
+
async listV2(options, parameters) {
|
|
1123
|
+
var _this14 = this;
|
|
1124
|
+
try {
|
|
1125
|
+
const body = _objectSpread2({}, options);
|
|
1126
|
+
return {
|
|
1127
|
+
data: await post$1(_this14.fetch, `${_this14.url}/object/list-v2/${_this14.bucketId}`, body, { headers: _this14.headers }, parameters),
|
|
1128
|
+
error: null
|
|
1129
|
+
};
|
|
1130
|
+
} catch (error) {
|
|
1131
|
+
if (_this14.shouldThrowOnError) throw error;
|
|
1132
|
+
if (isStorageError(error)) return {
|
|
1133
|
+
data: null,
|
|
1134
|
+
error
|
|
1135
|
+
};
|
|
1136
|
+
throw error;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
encodeMetadata(metadata) {
|
|
1140
|
+
return JSON.stringify(metadata);
|
|
1141
|
+
}
|
|
1142
|
+
toBase64(data) {
|
|
1143
|
+
if (typeof Buffer !== "undefined") return Buffer.from(data).toString("base64");
|
|
1144
|
+
return btoa(data);
|
|
1145
|
+
}
|
|
1146
|
+
_getFinalPath(path) {
|
|
1147
|
+
return `${this.bucketId}/${path.replace(/^\/+/, "")}`;
|
|
1148
|
+
}
|
|
1149
|
+
_removeEmptyFolders(path) {
|
|
1150
|
+
return path.replace(/^\/|\/$/g, "").replace(/\/+/g, "/");
|
|
1151
|
+
}
|
|
1152
|
+
transformOptsToQueryString(transform) {
|
|
1153
|
+
const params = [];
|
|
1154
|
+
if (transform.width) params.push(`width=${transform.width}`);
|
|
1155
|
+
if (transform.height) params.push(`height=${transform.height}`);
|
|
1156
|
+
if (transform.resize) params.push(`resize=${transform.resize}`);
|
|
1157
|
+
if (transform.format) params.push(`format=${transform.format}`);
|
|
1158
|
+
if (transform.quality) params.push(`quality=${transform.quality}`);
|
|
1159
|
+
return params.join("&");
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
//#endregion
|
|
1164
|
+
//#region src/lib/version.ts
|
|
1165
|
+
const version = "2.87.4-canary.4";
|
|
1166
|
+
|
|
1167
|
+
//#endregion
|
|
1168
|
+
//#region src/lib/constants.ts
|
|
1169
|
+
const DEFAULT_HEADERS$1 = { "X-Client-Info": `storage-js/${version}` };
|
|
1170
|
+
|
|
1171
|
+
//#endregion
|
|
1172
|
+
//#region src/packages/StorageBucketApi.ts
|
|
1173
|
+
var StorageBucketApi = class {
|
|
1174
|
+
constructor(url, headers = {}, fetch$1, opts) {
|
|
1175
|
+
this.shouldThrowOnError = false;
|
|
1176
|
+
const baseUrl = new URL(url);
|
|
1177
|
+
if (opts === null || opts === void 0 ? void 0 : opts.useNewHostname) {
|
|
1178
|
+
if (/supabase\.(co|in|red)$/.test(baseUrl.hostname) && !baseUrl.hostname.includes("storage.supabase.")) baseUrl.hostname = baseUrl.hostname.replace("supabase.", "storage.supabase.");
|
|
1179
|
+
}
|
|
1180
|
+
this.url = baseUrl.href.replace(/\/$/, "");
|
|
1181
|
+
this.headers = _objectSpread2(_objectSpread2({}, DEFAULT_HEADERS$1), headers);
|
|
1182
|
+
this.fetch = resolveFetch$1(fetch$1);
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Enable throwing errors instead of returning them.
|
|
1186
|
+
*
|
|
1187
|
+
* @category File Buckets
|
|
1188
|
+
*/
|
|
1189
|
+
throwOnError() {
|
|
1190
|
+
this.shouldThrowOnError = true;
|
|
1191
|
+
return this;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Retrieves the details of all Storage buckets within an existing project.
|
|
1195
|
+
*
|
|
1196
|
+
* @category File Buckets
|
|
1197
|
+
* @param options Query parameters for listing buckets
|
|
1198
|
+
* @param options.limit Maximum number of buckets to return
|
|
1199
|
+
* @param options.offset Number of buckets to skip
|
|
1200
|
+
* @param options.sortColumn Column to sort by ('id', 'name', 'created_at', 'updated_at')
|
|
1201
|
+
* @param options.sortOrder Sort order ('asc' or 'desc')
|
|
1202
|
+
* @param options.search Search term to filter bucket names
|
|
1203
|
+
* @returns Promise with response containing array of buckets or error
|
|
1204
|
+
*
|
|
1205
|
+
* @example List buckets
|
|
1206
|
+
* ```js
|
|
1207
|
+
* const { data, error } = await supabase
|
|
1208
|
+
* .storage
|
|
1209
|
+
* .listBuckets()
|
|
1210
|
+
* ```
|
|
1211
|
+
*
|
|
1212
|
+
* @example List buckets with options
|
|
1213
|
+
* ```js
|
|
1214
|
+
* const { data, error } = await supabase
|
|
1215
|
+
* .storage
|
|
1216
|
+
* .listBuckets({
|
|
1217
|
+
* limit: 10,
|
|
1218
|
+
* offset: 0,
|
|
1219
|
+
* sortColumn: 'created_at',
|
|
1220
|
+
* sortOrder: 'desc',
|
|
1221
|
+
* search: 'prod'
|
|
1222
|
+
* })
|
|
1223
|
+
* ```
|
|
1224
|
+
*/
|
|
1225
|
+
async listBuckets(options) {
|
|
1226
|
+
var _this = this;
|
|
1227
|
+
try {
|
|
1228
|
+
const queryString = _this.listBucketOptionsToQueryString(options);
|
|
1229
|
+
return {
|
|
1230
|
+
data: await get(_this.fetch, `${_this.url}/bucket${queryString}`, { headers: _this.headers }),
|
|
1231
|
+
error: null
|
|
1232
|
+
};
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
if (_this.shouldThrowOnError) throw error;
|
|
1235
|
+
if (isStorageError(error)) return {
|
|
1236
|
+
data: null,
|
|
1237
|
+
error
|
|
1238
|
+
};
|
|
1239
|
+
throw error;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Retrieves the details of an existing Storage bucket.
|
|
1244
|
+
*
|
|
1245
|
+
* @category File Buckets
|
|
1246
|
+
* @param id The unique identifier of the bucket you would like to retrieve.
|
|
1247
|
+
* @returns Promise with response containing bucket details or error
|
|
1248
|
+
*
|
|
1249
|
+
* @example Get bucket
|
|
1250
|
+
* ```js
|
|
1251
|
+
* const { data, error } = await supabase
|
|
1252
|
+
* .storage
|
|
1253
|
+
* .getBucket('avatars')
|
|
1254
|
+
* ```
|
|
1255
|
+
*
|
|
1256
|
+
* Response:
|
|
1257
|
+
* ```json
|
|
1258
|
+
* {
|
|
1259
|
+
* "data": {
|
|
1260
|
+
* "id": "avatars",
|
|
1261
|
+
* "name": "avatars",
|
|
1262
|
+
* "owner": "",
|
|
1263
|
+
* "public": false,
|
|
1264
|
+
* "file_size_limit": 1024,
|
|
1265
|
+
* "allowed_mime_types": [
|
|
1266
|
+
* "image/png"
|
|
1267
|
+
* ],
|
|
1268
|
+
* "created_at": "2024-05-22T22:26:05.100Z",
|
|
1269
|
+
* "updated_at": "2024-05-22T22:26:05.100Z"
|
|
1270
|
+
* },
|
|
1271
|
+
* "error": null
|
|
1272
|
+
* }
|
|
1273
|
+
* ```
|
|
1274
|
+
*/
|
|
1275
|
+
async getBucket(id) {
|
|
1276
|
+
var _this2 = this;
|
|
1277
|
+
try {
|
|
1278
|
+
return {
|
|
1279
|
+
data: await get(_this2.fetch, `${_this2.url}/bucket/${id}`, { headers: _this2.headers }),
|
|
1280
|
+
error: null
|
|
1281
|
+
};
|
|
1282
|
+
} catch (error) {
|
|
1283
|
+
if (_this2.shouldThrowOnError) throw error;
|
|
1284
|
+
if (isStorageError(error)) return {
|
|
1285
|
+
data: null,
|
|
1286
|
+
error
|
|
1287
|
+
};
|
|
1288
|
+
throw error;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Creates a new Storage bucket
|
|
1293
|
+
*
|
|
1294
|
+
* @category File Buckets
|
|
1295
|
+
* @param id A unique identifier for the bucket you are creating.
|
|
1296
|
+
* @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. By default, buckets are private.
|
|
1297
|
+
* @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
|
|
1298
|
+
* The global file size limit takes precedence over this value.
|
|
1299
|
+
* The default value is null, which doesn't set a per bucket file size limit.
|
|
1300
|
+
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
1301
|
+
* The default value is null, which allows files with all mime types to be uploaded.
|
|
1302
|
+
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
1303
|
+
* @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details.
|
|
1304
|
+
* - default bucket type is `STANDARD`
|
|
1305
|
+
* @returns Promise with response containing newly created bucket name or error
|
|
1306
|
+
*
|
|
1307
|
+
* @example Create bucket
|
|
1308
|
+
* ```js
|
|
1309
|
+
* const { data, error } = await supabase
|
|
1310
|
+
* .storage
|
|
1311
|
+
* .createBucket('avatars', {
|
|
1312
|
+
* public: false,
|
|
1313
|
+
* allowedMimeTypes: ['image/png'],
|
|
1314
|
+
* fileSizeLimit: 1024
|
|
1315
|
+
* })
|
|
1316
|
+
* ```
|
|
1317
|
+
*
|
|
1318
|
+
* Response:
|
|
1319
|
+
* ```json
|
|
1320
|
+
* {
|
|
1321
|
+
* "data": {
|
|
1322
|
+
* "name": "avatars"
|
|
1323
|
+
* },
|
|
1324
|
+
* "error": null
|
|
1325
|
+
* }
|
|
1326
|
+
* ```
|
|
1327
|
+
*/
|
|
1328
|
+
async createBucket(id, options = { public: false }) {
|
|
1329
|
+
var _this3 = this;
|
|
1330
|
+
try {
|
|
1331
|
+
return {
|
|
1332
|
+
data: await post$1(_this3.fetch, `${_this3.url}/bucket`, {
|
|
1333
|
+
id,
|
|
1334
|
+
name: id,
|
|
1335
|
+
type: options.type,
|
|
1336
|
+
public: options.public,
|
|
1337
|
+
file_size_limit: options.fileSizeLimit,
|
|
1338
|
+
allowed_mime_types: options.allowedMimeTypes
|
|
1339
|
+
}, { headers: _this3.headers }),
|
|
1340
|
+
error: null
|
|
1341
|
+
};
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
if (_this3.shouldThrowOnError) throw error;
|
|
1344
|
+
if (isStorageError(error)) return {
|
|
1345
|
+
data: null,
|
|
1346
|
+
error
|
|
1347
|
+
};
|
|
1348
|
+
throw error;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Updates a Storage bucket
|
|
1353
|
+
*
|
|
1354
|
+
* @category File Buckets
|
|
1355
|
+
* @param id A unique identifier for the bucket you are updating.
|
|
1356
|
+
* @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations.
|
|
1357
|
+
* @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
|
|
1358
|
+
* The global file size limit takes precedence over this value.
|
|
1359
|
+
* The default value is null, which doesn't set a per bucket file size limit.
|
|
1360
|
+
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
1361
|
+
* The default value is null, which allows files with all mime types to be uploaded.
|
|
1362
|
+
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
1363
|
+
* @returns Promise with response containing success message or error
|
|
1364
|
+
*
|
|
1365
|
+
* @example Update bucket
|
|
1366
|
+
* ```js
|
|
1367
|
+
* const { data, error } = await supabase
|
|
1368
|
+
* .storage
|
|
1369
|
+
* .updateBucket('avatars', {
|
|
1370
|
+
* public: false,
|
|
1371
|
+
* allowedMimeTypes: ['image/png'],
|
|
1372
|
+
* fileSizeLimit: 1024
|
|
1373
|
+
* })
|
|
1374
|
+
* ```
|
|
1375
|
+
*
|
|
1376
|
+
* Response:
|
|
1377
|
+
* ```json
|
|
1378
|
+
* {
|
|
1379
|
+
* "data": {
|
|
1380
|
+
* "message": "Successfully updated"
|
|
1381
|
+
* },
|
|
1382
|
+
* "error": null
|
|
1383
|
+
* }
|
|
1384
|
+
* ```
|
|
1385
|
+
*/
|
|
1386
|
+
async updateBucket(id, options) {
|
|
1387
|
+
var _this4 = this;
|
|
1388
|
+
try {
|
|
1389
|
+
return {
|
|
1390
|
+
data: await put(_this4.fetch, `${_this4.url}/bucket/${id}`, {
|
|
1391
|
+
id,
|
|
1392
|
+
name: id,
|
|
1393
|
+
public: options.public,
|
|
1394
|
+
file_size_limit: options.fileSizeLimit,
|
|
1395
|
+
allowed_mime_types: options.allowedMimeTypes
|
|
1396
|
+
}, { headers: _this4.headers }),
|
|
1397
|
+
error: null
|
|
1398
|
+
};
|
|
1399
|
+
} catch (error) {
|
|
1400
|
+
if (_this4.shouldThrowOnError) throw error;
|
|
1401
|
+
if (isStorageError(error)) return {
|
|
1402
|
+
data: null,
|
|
1403
|
+
error
|
|
1404
|
+
};
|
|
1405
|
+
throw error;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
/**
|
|
1409
|
+
* Removes all objects inside a single bucket.
|
|
1410
|
+
*
|
|
1411
|
+
* @category File Buckets
|
|
1412
|
+
* @param id The unique identifier of the bucket you would like to empty.
|
|
1413
|
+
* @returns Promise with success message or error
|
|
1414
|
+
*
|
|
1415
|
+
* @example Empty bucket
|
|
1416
|
+
* ```js
|
|
1417
|
+
* const { data, error } = await supabase
|
|
1418
|
+
* .storage
|
|
1419
|
+
* .emptyBucket('avatars')
|
|
1420
|
+
* ```
|
|
1421
|
+
*
|
|
1422
|
+
* Response:
|
|
1423
|
+
* ```json
|
|
1424
|
+
* {
|
|
1425
|
+
* "data": {
|
|
1426
|
+
* "message": "Successfully emptied"
|
|
1427
|
+
* },
|
|
1428
|
+
* "error": null
|
|
1429
|
+
* }
|
|
1430
|
+
* ```
|
|
1431
|
+
*/
|
|
1432
|
+
async emptyBucket(id) {
|
|
1433
|
+
var _this5 = this;
|
|
1434
|
+
try {
|
|
1435
|
+
return {
|
|
1436
|
+
data: await post$1(_this5.fetch, `${_this5.url}/bucket/${id}/empty`, {}, { headers: _this5.headers }),
|
|
1437
|
+
error: null
|
|
1438
|
+
};
|
|
1439
|
+
} catch (error) {
|
|
1440
|
+
if (_this5.shouldThrowOnError) throw error;
|
|
1441
|
+
if (isStorageError(error)) return {
|
|
1442
|
+
data: null,
|
|
1443
|
+
error
|
|
1444
|
+
};
|
|
1445
|
+
throw error;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* Deletes an existing bucket. A bucket can't be deleted with existing objects inside it.
|
|
1450
|
+
* You must first `empty()` the bucket.
|
|
1451
|
+
*
|
|
1452
|
+
* @category File Buckets
|
|
1453
|
+
* @param id The unique identifier of the bucket you would like to delete.
|
|
1454
|
+
* @returns Promise with success message or error
|
|
1455
|
+
*
|
|
1456
|
+
* @example Delete bucket
|
|
1457
|
+
* ```js
|
|
1458
|
+
* const { data, error } = await supabase
|
|
1459
|
+
* .storage
|
|
1460
|
+
* .deleteBucket('avatars')
|
|
1461
|
+
* ```
|
|
1462
|
+
*
|
|
1463
|
+
* Response:
|
|
1464
|
+
* ```json
|
|
1465
|
+
* {
|
|
1466
|
+
* "data": {
|
|
1467
|
+
* "message": "Successfully deleted"
|
|
1468
|
+
* },
|
|
1469
|
+
* "error": null
|
|
1470
|
+
* }
|
|
1471
|
+
* ```
|
|
1472
|
+
*/
|
|
1473
|
+
async deleteBucket(id) {
|
|
1474
|
+
var _this6 = this;
|
|
1475
|
+
try {
|
|
1476
|
+
return {
|
|
1477
|
+
data: await remove(_this6.fetch, `${_this6.url}/bucket/${id}`, {}, { headers: _this6.headers }),
|
|
1478
|
+
error: null
|
|
1479
|
+
};
|
|
1480
|
+
} catch (error) {
|
|
1481
|
+
if (_this6.shouldThrowOnError) throw error;
|
|
1482
|
+
if (isStorageError(error)) return {
|
|
1483
|
+
data: null,
|
|
1484
|
+
error
|
|
1485
|
+
};
|
|
1486
|
+
throw error;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
listBucketOptionsToQueryString(options) {
|
|
1490
|
+
const params = {};
|
|
1491
|
+
if (options) {
|
|
1492
|
+
if ("limit" in options) params.limit = String(options.limit);
|
|
1493
|
+
if ("offset" in options) params.offset = String(options.offset);
|
|
1494
|
+
if (options.search) params.search = options.search;
|
|
1495
|
+
if (options.sortColumn) params.sortColumn = options.sortColumn;
|
|
1496
|
+
if (options.sortOrder) params.sortOrder = options.sortOrder;
|
|
1497
|
+
}
|
|
1498
|
+
return Object.keys(params).length > 0 ? "?" + new URLSearchParams(params).toString() : "";
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
|
|
1502
|
+
//#endregion
|
|
1503
|
+
//#region src/packages/StorageAnalyticsClient.ts
|
|
1504
|
+
/**
|
|
1505
|
+
* Client class for managing Analytics Buckets using Iceberg tables
|
|
1506
|
+
* Provides methods for creating, listing, and deleting analytics buckets
|
|
1507
|
+
*/
|
|
1508
|
+
var StorageAnalyticsClient = class {
|
|
1509
|
+
/**
|
|
1510
|
+
* @alpha
|
|
1511
|
+
*
|
|
1512
|
+
* Creates a new StorageAnalyticsClient instance
|
|
1513
|
+
*
|
|
1514
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
1515
|
+
*
|
|
1516
|
+
* @category Analytics Buckets
|
|
1517
|
+
* @param url - The base URL for the storage API
|
|
1518
|
+
* @param headers - HTTP headers to include in requests
|
|
1519
|
+
* @param fetch - Optional custom fetch implementation
|
|
1520
|
+
*
|
|
1521
|
+
* @example
|
|
1522
|
+
* ```typescript
|
|
1523
|
+
* const client = new StorageAnalyticsClient(url, headers)
|
|
1524
|
+
* ```
|
|
1525
|
+
*/
|
|
1526
|
+
constructor(url, headers = {}, fetch$1) {
|
|
1527
|
+
this.shouldThrowOnError = false;
|
|
1528
|
+
this.url = url.replace(/\/$/, "");
|
|
1529
|
+
this.headers = _objectSpread2(_objectSpread2({}, DEFAULT_HEADERS$1), headers);
|
|
1530
|
+
this.fetch = resolveFetch$1(fetch$1);
|
|
1531
|
+
}
|
|
1532
|
+
/**
|
|
1533
|
+
* @alpha
|
|
1534
|
+
*
|
|
1535
|
+
* Enable throwing errors instead of returning them in the response
|
|
1536
|
+
* When enabled, failed operations will throw instead of returning { data: null, error }
|
|
1537
|
+
*
|
|
1538
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
1539
|
+
*
|
|
1540
|
+
* @category Analytics Buckets
|
|
1541
|
+
* @returns This instance for method chaining
|
|
1542
|
+
*/
|
|
1543
|
+
throwOnError() {
|
|
1544
|
+
this.shouldThrowOnError = true;
|
|
1545
|
+
return this;
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* @alpha
|
|
1549
|
+
*
|
|
1550
|
+
* Creates a new analytics bucket using Iceberg tables
|
|
1551
|
+
* Analytics buckets are optimized for analytical queries and data processing
|
|
1552
|
+
*
|
|
1553
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
1554
|
+
*
|
|
1555
|
+
* @category Analytics Buckets
|
|
1556
|
+
* @param name A unique name for the bucket you are creating
|
|
1557
|
+
* @returns Promise with response containing newly created analytics bucket or error
|
|
1558
|
+
*
|
|
1559
|
+
* @example Create analytics bucket
|
|
1560
|
+
* ```js
|
|
1561
|
+
* const { data, error } = await supabase
|
|
1562
|
+
* .storage
|
|
1563
|
+
* .analytics
|
|
1564
|
+
* .createBucket('analytics-data')
|
|
1565
|
+
* ```
|
|
1566
|
+
*
|
|
1567
|
+
* Response:
|
|
1568
|
+
* ```json
|
|
1569
|
+
* {
|
|
1570
|
+
* "data": {
|
|
1571
|
+
* "name": "analytics-data",
|
|
1572
|
+
* "type": "ANALYTICS",
|
|
1573
|
+
* "format": "iceberg",
|
|
1574
|
+
* "created_at": "2024-05-22T22:26:05.100Z",
|
|
1575
|
+
* "updated_at": "2024-05-22T22:26:05.100Z"
|
|
1576
|
+
* },
|
|
1577
|
+
* "error": null
|
|
1578
|
+
* }
|
|
1579
|
+
* ```
|
|
1580
|
+
*/
|
|
1581
|
+
async createBucket(name) {
|
|
1582
|
+
var _this = this;
|
|
1583
|
+
try {
|
|
1584
|
+
return {
|
|
1585
|
+
data: await post$1(_this.fetch, `${_this.url}/bucket`, { name }, { headers: _this.headers }),
|
|
1586
|
+
error: null
|
|
1587
|
+
};
|
|
1588
|
+
} catch (error) {
|
|
1589
|
+
if (_this.shouldThrowOnError) throw error;
|
|
1590
|
+
if (isStorageError(error)) return {
|
|
1591
|
+
data: null,
|
|
1592
|
+
error
|
|
1593
|
+
};
|
|
1594
|
+
throw error;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* @alpha
|
|
1599
|
+
*
|
|
1600
|
+
* Retrieves the details of all Analytics Storage buckets within an existing project
|
|
1601
|
+
* Only returns buckets of type 'ANALYTICS'
|
|
1602
|
+
*
|
|
1603
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
1604
|
+
*
|
|
1605
|
+
* @category Analytics Buckets
|
|
1606
|
+
* @param options Query parameters for listing buckets
|
|
1607
|
+
* @param options.limit Maximum number of buckets to return
|
|
1608
|
+
* @param options.offset Number of buckets to skip
|
|
1609
|
+
* @param options.sortColumn Column to sort by ('name', 'created_at', 'updated_at')
|
|
1610
|
+
* @param options.sortOrder Sort order ('asc' or 'desc')
|
|
1611
|
+
* @param options.search Search term to filter bucket names
|
|
1612
|
+
* @returns Promise with response containing array of analytics buckets or error
|
|
1613
|
+
*
|
|
1614
|
+
* @example List analytics buckets
|
|
1615
|
+
* ```js
|
|
1616
|
+
* const { data, error } = await supabase
|
|
1617
|
+
* .storage
|
|
1618
|
+
* .analytics
|
|
1619
|
+
* .listBuckets({
|
|
1620
|
+
* limit: 10,
|
|
1621
|
+
* offset: 0,
|
|
1622
|
+
* sortColumn: 'created_at',
|
|
1623
|
+
* sortOrder: 'desc'
|
|
1624
|
+
* })
|
|
1625
|
+
* ```
|
|
1626
|
+
*
|
|
1627
|
+
* Response:
|
|
1628
|
+
* ```json
|
|
1629
|
+
* {
|
|
1630
|
+
* "data": [
|
|
1631
|
+
* {
|
|
1632
|
+
* "name": "analytics-data",
|
|
1633
|
+
* "type": "ANALYTICS",
|
|
1634
|
+
* "format": "iceberg",
|
|
1635
|
+
* "created_at": "2024-05-22T22:26:05.100Z",
|
|
1636
|
+
* "updated_at": "2024-05-22T22:26:05.100Z"
|
|
1637
|
+
* }
|
|
1638
|
+
* ],
|
|
1639
|
+
* "error": null
|
|
1640
|
+
* }
|
|
1641
|
+
* ```
|
|
1642
|
+
*/
|
|
1643
|
+
async listBuckets(options) {
|
|
1644
|
+
var _this2 = this;
|
|
1645
|
+
try {
|
|
1646
|
+
const queryParams = new URLSearchParams();
|
|
1647
|
+
if ((options === null || options === void 0 ? void 0 : options.limit) !== void 0) queryParams.set("limit", options.limit.toString());
|
|
1648
|
+
if ((options === null || options === void 0 ? void 0 : options.offset) !== void 0) queryParams.set("offset", options.offset.toString());
|
|
1649
|
+
if (options === null || options === void 0 ? void 0 : options.sortColumn) queryParams.set("sortColumn", options.sortColumn);
|
|
1650
|
+
if (options === null || options === void 0 ? void 0 : options.sortOrder) queryParams.set("sortOrder", options.sortOrder);
|
|
1651
|
+
if (options === null || options === void 0 ? void 0 : options.search) queryParams.set("search", options.search);
|
|
1652
|
+
const queryString = queryParams.toString();
|
|
1653
|
+
const url = queryString ? `${_this2.url}/bucket?${queryString}` : `${_this2.url}/bucket`;
|
|
1654
|
+
return {
|
|
1655
|
+
data: await get(_this2.fetch, url, { headers: _this2.headers }),
|
|
1656
|
+
error: null
|
|
1657
|
+
};
|
|
1658
|
+
} catch (error) {
|
|
1659
|
+
if (_this2.shouldThrowOnError) throw error;
|
|
1660
|
+
if (isStorageError(error)) return {
|
|
1661
|
+
data: null,
|
|
1662
|
+
error
|
|
1663
|
+
};
|
|
1664
|
+
throw error;
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* @alpha
|
|
1669
|
+
*
|
|
1670
|
+
* Deletes an existing analytics bucket
|
|
1671
|
+
* A bucket can't be deleted with existing objects inside it
|
|
1672
|
+
* You must first empty the bucket before deletion
|
|
1673
|
+
*
|
|
1674
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
1675
|
+
*
|
|
1676
|
+
* @category Analytics Buckets
|
|
1677
|
+
* @param bucketName The unique identifier of the bucket you would like to delete
|
|
1678
|
+
* @returns Promise with response containing success message or error
|
|
1679
|
+
*
|
|
1680
|
+
* @example Delete analytics bucket
|
|
1681
|
+
* ```js
|
|
1682
|
+
* const { data, error } = await supabase
|
|
1683
|
+
* .storage
|
|
1684
|
+
* .analytics
|
|
1685
|
+
* .deleteBucket('analytics-data')
|
|
1686
|
+
* ```
|
|
1687
|
+
*
|
|
1688
|
+
* Response:
|
|
1689
|
+
* ```json
|
|
1690
|
+
* {
|
|
1691
|
+
* "data": {
|
|
1692
|
+
* "message": "Successfully deleted"
|
|
1693
|
+
* },
|
|
1694
|
+
* "error": null
|
|
1695
|
+
* }
|
|
1696
|
+
* ```
|
|
1697
|
+
*/
|
|
1698
|
+
async deleteBucket(bucketName) {
|
|
1699
|
+
var _this3 = this;
|
|
1700
|
+
try {
|
|
1701
|
+
return {
|
|
1702
|
+
data: await remove(_this3.fetch, `${_this3.url}/bucket/${bucketName}`, {}, { headers: _this3.headers }),
|
|
1703
|
+
error: null
|
|
1704
|
+
};
|
|
1705
|
+
} catch (error) {
|
|
1706
|
+
if (_this3.shouldThrowOnError) throw error;
|
|
1707
|
+
if (isStorageError(error)) return {
|
|
1708
|
+
data: null,
|
|
1709
|
+
error
|
|
1710
|
+
};
|
|
1711
|
+
throw error;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* @alpha
|
|
1716
|
+
*
|
|
1717
|
+
* Get an Iceberg REST Catalog client configured for a specific analytics bucket
|
|
1718
|
+
* Use this to perform advanced table and namespace operations within the bucket
|
|
1719
|
+
* The returned client provides full access to the Apache Iceberg REST Catalog API
|
|
1720
|
+
* with the Supabase `{ data, error }` pattern for consistent error handling on all operations.
|
|
1721
|
+
*
|
|
1722
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
1723
|
+
*
|
|
1724
|
+
* @category Analytics Buckets
|
|
1725
|
+
* @param bucketName - The name of the analytics bucket (warehouse) to connect to
|
|
1726
|
+
* @returns The wrapped Iceberg catalog client
|
|
1727
|
+
* @throws {StorageError} If the bucket name is invalid
|
|
1728
|
+
*
|
|
1729
|
+
* @example Get catalog and create table
|
|
1730
|
+
* ```js
|
|
1731
|
+
* // First, create an analytics bucket
|
|
1732
|
+
* const { data: bucket, error: bucketError } = await supabase
|
|
1733
|
+
* .storage
|
|
1734
|
+
* .analytics
|
|
1735
|
+
* .createBucket('analytics-data')
|
|
1736
|
+
*
|
|
1737
|
+
* // Get the Iceberg catalog for that bucket
|
|
1738
|
+
* const catalog = supabase.storage.analytics.from('analytics-data')
|
|
1739
|
+
*
|
|
1740
|
+
* // Create a namespace
|
|
1741
|
+
* const { error: nsError } = await catalog.createNamespace({ namespace: ['default'] })
|
|
1742
|
+
*
|
|
1743
|
+
* // Create a table with schema
|
|
1744
|
+
* const { data: tableMetadata, error: tableError } = await catalog.createTable(
|
|
1745
|
+
* { namespace: ['default'] },
|
|
1746
|
+
* {
|
|
1747
|
+
* name: 'events',
|
|
1748
|
+
* schema: {
|
|
1749
|
+
* type: 'struct',
|
|
1750
|
+
* fields: [
|
|
1751
|
+
* { id: 1, name: 'id', type: 'long', required: true },
|
|
1752
|
+
* { id: 2, name: 'timestamp', type: 'timestamp', required: true },
|
|
1753
|
+
* { id: 3, name: 'user_id', type: 'string', required: false }
|
|
1754
|
+
* ],
|
|
1755
|
+
* 'schema-id': 0,
|
|
1756
|
+
* 'identifier-field-ids': [1]
|
|
1757
|
+
* },
|
|
1758
|
+
* 'partition-spec': {
|
|
1759
|
+
* 'spec-id': 0,
|
|
1760
|
+
* fields: []
|
|
1761
|
+
* },
|
|
1762
|
+
* 'write-order': {
|
|
1763
|
+
* 'order-id': 0,
|
|
1764
|
+
* fields: []
|
|
1765
|
+
* },
|
|
1766
|
+
* properties: {
|
|
1767
|
+
* 'write.format.default': 'parquet'
|
|
1768
|
+
* }
|
|
1769
|
+
* }
|
|
1770
|
+
* )
|
|
1771
|
+
* ```
|
|
1772
|
+
*
|
|
1773
|
+
* @example List tables in namespace
|
|
1774
|
+
* ```js
|
|
1775
|
+
* const catalog = supabase.storage.analytics.from('analytics-data')
|
|
1776
|
+
*
|
|
1777
|
+
* // List all tables in the default namespace
|
|
1778
|
+
* const { data: tables, error: listError } = await catalog.listTables({ namespace: ['default'] })
|
|
1779
|
+
* if (listError) {
|
|
1780
|
+
* if (listError.isNotFound()) {
|
|
1781
|
+
* console.log('Namespace not found')
|
|
1782
|
+
* }
|
|
1783
|
+
* return
|
|
1784
|
+
* }
|
|
1785
|
+
* console.log(tables) // [{ namespace: ['default'], name: 'events' }]
|
|
1786
|
+
* ```
|
|
1787
|
+
*
|
|
1788
|
+
* @example Working with namespaces
|
|
1789
|
+
* ```js
|
|
1790
|
+
* const catalog = supabase.storage.analytics.from('analytics-data')
|
|
1791
|
+
*
|
|
1792
|
+
* // List all namespaces
|
|
1793
|
+
* const { data: namespaces } = await catalog.listNamespaces()
|
|
1794
|
+
*
|
|
1795
|
+
* // Create namespace with properties
|
|
1796
|
+
* await catalog.createNamespace(
|
|
1797
|
+
* { namespace: ['production'] },
|
|
1798
|
+
* { properties: { owner: 'data-team', env: 'prod' } }
|
|
1799
|
+
* )
|
|
1800
|
+
* ```
|
|
1801
|
+
*
|
|
1802
|
+
* @example Cleanup operations
|
|
1803
|
+
* ```js
|
|
1804
|
+
* const catalog = supabase.storage.analytics.from('analytics-data')
|
|
1805
|
+
*
|
|
1806
|
+
* // Drop table with purge option (removes all data)
|
|
1807
|
+
* const { error: dropError } = await catalog.dropTable(
|
|
1808
|
+
* { namespace: ['default'], name: 'events' },
|
|
1809
|
+
* { purge: true }
|
|
1810
|
+
* )
|
|
1811
|
+
*
|
|
1812
|
+
* if (dropError?.isNotFound()) {
|
|
1813
|
+
* console.log('Table does not exist')
|
|
1814
|
+
* }
|
|
1815
|
+
*
|
|
1816
|
+
* // Drop namespace (must be empty)
|
|
1817
|
+
* await catalog.dropNamespace({ namespace: ['default'] })
|
|
1818
|
+
* ```
|
|
1819
|
+
*
|
|
1820
|
+
* @remarks
|
|
1821
|
+
* This method provides a bridge between Supabase's bucket management and the standard
|
|
1822
|
+
* Apache Iceberg REST Catalog API. The bucket name maps to the Iceberg warehouse parameter.
|
|
1823
|
+
* All authentication and configuration is handled automatically using your Supabase credentials.
|
|
1824
|
+
*
|
|
1825
|
+
* **Error Handling**: Invalid bucket names throw immediately. All catalog
|
|
1826
|
+
* operations return `{ data, error }` where errors are `IcebergError` instances from iceberg-js.
|
|
1827
|
+
* Use helper methods like `error.isNotFound()` or check `error.status` for specific error handling.
|
|
1828
|
+
* Use `.throwOnError()` on the analytics client if you prefer exceptions for catalog operations.
|
|
1829
|
+
*
|
|
1830
|
+
* **Cleanup Operations**: When using `dropTable`, the `purge: true` option permanently
|
|
1831
|
+
* deletes all table data. Without it, the table is marked as deleted but data remains.
|
|
1832
|
+
*
|
|
1833
|
+
* **Library Dependency**: The returned catalog wraps `IcebergRestCatalog` from iceberg-js.
|
|
1834
|
+
* For complete API documentation and advanced usage, refer to the
|
|
1835
|
+
* [iceberg-js documentation](https://supabase.github.io/iceberg-js/).
|
|
1836
|
+
*/
|
|
1837
|
+
from(bucketName) {
|
|
1838
|
+
var _this4 = this;
|
|
1839
|
+
if (!isValidBucketName(bucketName)) throw new StorageError("Invalid bucket name: File, folder, and bucket names must follow AWS object key naming guidelines and should avoid the use of any other characters.");
|
|
1840
|
+
const catalog = new IcebergRestCatalog({
|
|
1841
|
+
baseUrl: this.url,
|
|
1842
|
+
catalogName: bucketName,
|
|
1843
|
+
auth: {
|
|
1844
|
+
type: "custom",
|
|
1845
|
+
getHeaders: async () => _this4.headers
|
|
1846
|
+
},
|
|
1847
|
+
fetch: this.fetch
|
|
1848
|
+
});
|
|
1849
|
+
const shouldThrowOnError = this.shouldThrowOnError;
|
|
1850
|
+
return new Proxy(catalog, { get(target, prop) {
|
|
1851
|
+
const value = target[prop];
|
|
1852
|
+
if (typeof value !== "function") return value;
|
|
1853
|
+
return async (...args) => {
|
|
1854
|
+
try {
|
|
1855
|
+
return {
|
|
1856
|
+
data: await value.apply(target, args),
|
|
1857
|
+
error: null
|
|
1858
|
+
};
|
|
1859
|
+
} catch (error) {
|
|
1860
|
+
if (shouldThrowOnError) throw error;
|
|
1861
|
+
return {
|
|
1862
|
+
data: null,
|
|
1863
|
+
error
|
|
1864
|
+
};
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
} });
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
|
|
1871
|
+
//#endregion
|
|
1872
|
+
//#region src/lib/vectors/constants.ts
|
|
1873
|
+
const DEFAULT_HEADERS = {
|
|
1874
|
+
"X-Client-Info": `storage-js/${version}`,
|
|
1875
|
+
"Content-Type": "application/json"
|
|
1876
|
+
};
|
|
1877
|
+
|
|
1878
|
+
//#endregion
|
|
1879
|
+
//#region src/lib/vectors/errors.ts
|
|
1880
|
+
/**
|
|
1881
|
+
* Base error class for all Storage Vectors errors
|
|
1882
|
+
*/
|
|
1883
|
+
var StorageVectorsError = class extends Error {
|
|
1884
|
+
constructor(message) {
|
|
1885
|
+
super(message);
|
|
1886
|
+
this.__isStorageVectorsError = true;
|
|
1887
|
+
this.name = "StorageVectorsError";
|
|
1888
|
+
}
|
|
1889
|
+
};
|
|
1890
|
+
/**
|
|
1891
|
+
* Type guard to check if an error is a StorageVectorsError
|
|
1892
|
+
* @param error - The error to check
|
|
1893
|
+
* @returns True if the error is a StorageVectorsError
|
|
1894
|
+
*/
|
|
1895
|
+
function isStorageVectorsError(error) {
|
|
1896
|
+
return typeof error === "object" && error !== null && "__isStorageVectorsError" in error;
|
|
1897
|
+
}
|
|
1898
|
+
/**
|
|
1899
|
+
* API error returned from S3 Vectors service
|
|
1900
|
+
* Includes HTTP status code and service-specific error code
|
|
1901
|
+
*/
|
|
1902
|
+
var StorageVectorsApiError = class extends StorageVectorsError {
|
|
1903
|
+
constructor(message, status, statusCode) {
|
|
1904
|
+
super(message);
|
|
1905
|
+
this.name = "StorageVectorsApiError";
|
|
1906
|
+
this.status = status;
|
|
1907
|
+
this.statusCode = statusCode;
|
|
1908
|
+
}
|
|
1909
|
+
toJSON() {
|
|
1910
|
+
return {
|
|
1911
|
+
name: this.name,
|
|
1912
|
+
message: this.message,
|
|
1913
|
+
status: this.status,
|
|
1914
|
+
statusCode: this.statusCode
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
};
|
|
1918
|
+
/**
|
|
1919
|
+
* Unknown error that doesn't match expected error patterns
|
|
1920
|
+
* Wraps the original error for debugging
|
|
1921
|
+
*/
|
|
1922
|
+
var StorageVectorsUnknownError = class extends StorageVectorsError {
|
|
1923
|
+
constructor(message, originalError) {
|
|
1924
|
+
super(message);
|
|
1925
|
+
this.name = "StorageVectorsUnknownError";
|
|
1926
|
+
this.originalError = originalError;
|
|
1927
|
+
}
|
|
1928
|
+
};
|
|
1929
|
+
/**
|
|
1930
|
+
* Error codes specific to S3 Vectors API
|
|
1931
|
+
* Maps AWS service errors to application-friendly error codes
|
|
1932
|
+
*/
|
|
1933
|
+
let StorageVectorsErrorCode = /* @__PURE__ */ function(StorageVectorsErrorCode$1) {
|
|
1934
|
+
/** Internal server fault (HTTP 500) */
|
|
1935
|
+
StorageVectorsErrorCode$1["InternalError"] = "InternalError";
|
|
1936
|
+
/** Resource already exists / conflict (HTTP 409) */
|
|
1937
|
+
StorageVectorsErrorCode$1["S3VectorConflictException"] = "S3VectorConflictException";
|
|
1938
|
+
/** Resource not found (HTTP 404) */
|
|
1939
|
+
StorageVectorsErrorCode$1["S3VectorNotFoundException"] = "S3VectorNotFoundException";
|
|
1940
|
+
/** Delete bucket while not empty (HTTP 400) */
|
|
1941
|
+
StorageVectorsErrorCode$1["S3VectorBucketNotEmpty"] = "S3VectorBucketNotEmpty";
|
|
1942
|
+
/** Exceeds bucket quota/limit (HTTP 400) */
|
|
1943
|
+
StorageVectorsErrorCode$1["S3VectorMaxBucketsExceeded"] = "S3VectorMaxBucketsExceeded";
|
|
1944
|
+
/** Exceeds index quota/limit (HTTP 400) */
|
|
1945
|
+
StorageVectorsErrorCode$1["S3VectorMaxIndexesExceeded"] = "S3VectorMaxIndexesExceeded";
|
|
1946
|
+
return StorageVectorsErrorCode$1;
|
|
1947
|
+
}({});
|
|
1948
|
+
|
|
1949
|
+
//#endregion
|
|
1950
|
+
//#region src/lib/vectors/helpers.ts
|
|
1951
|
+
/**
|
|
1952
|
+
* Resolves the fetch implementation to use
|
|
1953
|
+
* Uses custom fetch if provided, otherwise uses native fetch
|
|
1954
|
+
*
|
|
1955
|
+
* @param customFetch - Optional custom fetch implementation
|
|
1956
|
+
* @returns Resolved fetch function
|
|
1957
|
+
*/
|
|
1958
|
+
const resolveFetch = (customFetch) => {
|
|
1959
|
+
if (customFetch) return (...args) => customFetch(...args);
|
|
1960
|
+
return (...args) => fetch(...args);
|
|
1961
|
+
};
|
|
1962
|
+
/**
|
|
1963
|
+
* Resolves the Response constructor to use
|
|
1964
|
+
* Returns native Response constructor
|
|
1965
|
+
*
|
|
1966
|
+
* @returns Response constructor
|
|
1967
|
+
*/
|
|
1968
|
+
const resolveResponse = () => {
|
|
1969
|
+
return Response;
|
|
1970
|
+
};
|
|
1971
|
+
/**
|
|
1972
|
+
* Determine if input is a plain object
|
|
1973
|
+
* An object is plain if it's created by either {}, new Object(), or Object.create(null)
|
|
1974
|
+
*
|
|
1975
|
+
* @param value - Value to check
|
|
1976
|
+
* @returns True if value is a plain object
|
|
1977
|
+
* @source https://github.com/sindresorhus/is-plain-obj
|
|
1978
|
+
*/
|
|
1979
|
+
const isPlainObject = (value) => {
|
|
1980
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1981
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1982
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
1983
|
+
};
|
|
1984
|
+
/**
|
|
1985
|
+
* Normalizes a number array to float32 format
|
|
1986
|
+
* Ensures all vector values are valid 32-bit floats
|
|
1987
|
+
*
|
|
1988
|
+
* @param values - Array of numbers to normalize
|
|
1989
|
+
* @returns Normalized float32 array
|
|
1990
|
+
*/
|
|
1991
|
+
const normalizeToFloat32 = (values) => {
|
|
1992
|
+
return Array.from(new Float32Array(values));
|
|
1993
|
+
};
|
|
1994
|
+
/**
|
|
1995
|
+
* Validates vector dimensions match expected dimension
|
|
1996
|
+
* Throws error if dimensions don't match
|
|
1997
|
+
*
|
|
1998
|
+
* @param vector - Vector data to validate
|
|
1999
|
+
* @param expectedDimension - Expected vector dimension
|
|
2000
|
+
* @throws Error if dimensions don't match
|
|
2001
|
+
*/
|
|
2002
|
+
const validateVectorDimension = (vector, expectedDimension) => {
|
|
2003
|
+
if (expectedDimension !== void 0 && vector.float32.length !== expectedDimension) throw new Error(`Vector dimension mismatch: expected ${expectedDimension}, got ${vector.float32.length}`);
|
|
2004
|
+
};
|
|
2005
|
+
|
|
2006
|
+
//#endregion
|
|
2007
|
+
//#region src/lib/vectors/fetch.ts
|
|
2008
|
+
/**
|
|
2009
|
+
* Extracts error message from various error response formats
|
|
2010
|
+
* @param err - Error object from API
|
|
2011
|
+
* @returns Human-readable error message
|
|
2012
|
+
*/
|
|
2013
|
+
const _getErrorMessage = (err) => err.msg || err.message || err.error_description || err.error || JSON.stringify(err);
|
|
2014
|
+
/**
|
|
2015
|
+
* Handles fetch errors and converts them to StorageVectors error types
|
|
2016
|
+
* @param error - The error caught from fetch
|
|
2017
|
+
* @param reject - Promise rejection function
|
|
2018
|
+
* @param options - Fetch options that may affect error handling
|
|
2019
|
+
*/
|
|
2020
|
+
const handleError = async (error, reject, options) => {
|
|
2021
|
+
if (error && typeof error === "object" && "status" in error && "ok" in error && typeof error.status === "number" && !(options === null || options === void 0 ? void 0 : options.noResolveJson)) {
|
|
2022
|
+
const status = error.status || 500;
|
|
2023
|
+
const responseError = error;
|
|
2024
|
+
if (typeof responseError.json === "function") responseError.json().then((err) => {
|
|
2025
|
+
const statusCode = (err === null || err === void 0 ? void 0 : err.statusCode) || (err === null || err === void 0 ? void 0 : err.code) || status + "";
|
|
2026
|
+
reject(new StorageVectorsApiError(_getErrorMessage(err), status, statusCode));
|
|
2027
|
+
}).catch(() => {
|
|
2028
|
+
const statusCode = status + "";
|
|
2029
|
+
reject(new StorageVectorsApiError(responseError.statusText || `HTTP ${status} error`, status, statusCode));
|
|
2030
|
+
});
|
|
2031
|
+
else {
|
|
2032
|
+
const statusCode = status + "";
|
|
2033
|
+
reject(new StorageVectorsApiError(responseError.statusText || `HTTP ${status} error`, status, statusCode));
|
|
2034
|
+
}
|
|
2035
|
+
} else reject(new StorageVectorsUnknownError(_getErrorMessage(error), error));
|
|
2036
|
+
};
|
|
2037
|
+
/**
|
|
2038
|
+
* Builds request parameters for fetch calls
|
|
2039
|
+
* @param method - HTTP method
|
|
2040
|
+
* @param options - Custom fetch options
|
|
2041
|
+
* @param parameters - Additional fetch parameters like AbortSignal
|
|
2042
|
+
* @param body - Request body (will be JSON stringified if plain object)
|
|
2043
|
+
* @returns Complete fetch request parameters
|
|
2044
|
+
*/
|
|
2045
|
+
const _getRequestParams = (method, options, parameters, body) => {
|
|
2046
|
+
const params = {
|
|
2047
|
+
method,
|
|
2048
|
+
headers: (options === null || options === void 0 ? void 0 : options.headers) || {}
|
|
2049
|
+
};
|
|
2050
|
+
if (method === "GET" || !body) return params;
|
|
2051
|
+
if (isPlainObject(body)) {
|
|
2052
|
+
params.headers = _objectSpread2({ "Content-Type": "application/json" }, options === null || options === void 0 ? void 0 : options.headers);
|
|
2053
|
+
params.body = JSON.stringify(body);
|
|
2054
|
+
} else params.body = body;
|
|
2055
|
+
return _objectSpread2(_objectSpread2({}, params), parameters);
|
|
2056
|
+
};
|
|
2057
|
+
/**
|
|
2058
|
+
* Internal request handler that wraps fetch with error handling
|
|
2059
|
+
* @param fetcher - Fetch function to use
|
|
2060
|
+
* @param method - HTTP method
|
|
2061
|
+
* @param url - Request URL
|
|
2062
|
+
* @param options - Custom fetch options
|
|
2063
|
+
* @param parameters - Additional fetch parameters
|
|
2064
|
+
* @param body - Request body
|
|
2065
|
+
* @returns Promise with parsed response or error
|
|
2066
|
+
*/
|
|
2067
|
+
async function _handleRequest(fetcher, method, url, options, parameters, body) {
|
|
2068
|
+
return new Promise((resolve, reject) => {
|
|
2069
|
+
fetcher(url, _getRequestParams(method, options, parameters, body)).then((result) => {
|
|
2070
|
+
if (!result.ok) throw result;
|
|
2071
|
+
if (options === null || options === void 0 ? void 0 : options.noResolveJson) return result;
|
|
2072
|
+
const contentType = result.headers.get("content-type");
|
|
2073
|
+
if (!contentType || !contentType.includes("application/json")) return {};
|
|
2074
|
+
return result.json();
|
|
2075
|
+
}).then((data) => resolve(data)).catch((error) => handleError(error, reject, options));
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2078
|
+
/**
|
|
2079
|
+
* Performs a POST request
|
|
2080
|
+
* @param fetcher - Fetch function to use
|
|
2081
|
+
* @param url - Request URL
|
|
2082
|
+
* @param body - Request body to be JSON stringified
|
|
2083
|
+
* @param options - Custom fetch options
|
|
2084
|
+
* @param parameters - Additional fetch parameters
|
|
2085
|
+
* @returns Promise with parsed response
|
|
2086
|
+
*/
|
|
2087
|
+
async function post(fetcher, url, body, options, parameters) {
|
|
2088
|
+
return _handleRequest(fetcher, "POST", url, options, parameters, body);
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
//#endregion
|
|
2092
|
+
//#region src/lib/vectors/VectorIndexApi.ts
|
|
2093
|
+
/**
|
|
2094
|
+
* @hidden
|
|
2095
|
+
* Base implementation for vector index operations.
|
|
2096
|
+
* Use {@link VectorBucketScope} via `supabase.storage.vectors.from('bucket')` instead.
|
|
2097
|
+
*/
|
|
2098
|
+
var VectorIndexApi = class {
|
|
2099
|
+
/** Creates a new VectorIndexApi instance */
|
|
2100
|
+
constructor(url, headers = {}, fetch$1) {
|
|
2101
|
+
this.shouldThrowOnError = false;
|
|
2102
|
+
this.url = url.replace(/\/$/, "");
|
|
2103
|
+
this.headers = _objectSpread2(_objectSpread2({}, DEFAULT_HEADERS), headers);
|
|
2104
|
+
this.fetch = resolveFetch(fetch$1);
|
|
2105
|
+
}
|
|
2106
|
+
/** Enable throwing errors instead of returning them in the response */
|
|
2107
|
+
throwOnError() {
|
|
2108
|
+
this.shouldThrowOnError = true;
|
|
2109
|
+
return this;
|
|
2110
|
+
}
|
|
2111
|
+
/** Creates a new vector index within a bucket */
|
|
2112
|
+
async createIndex(options) {
|
|
2113
|
+
var _this = this;
|
|
2114
|
+
try {
|
|
2115
|
+
return {
|
|
2116
|
+
data: await post(_this.fetch, `${_this.url}/CreateIndex`, options, { headers: _this.headers }) || {},
|
|
2117
|
+
error: null
|
|
2118
|
+
};
|
|
2119
|
+
} catch (error) {
|
|
2120
|
+
if (_this.shouldThrowOnError) throw error;
|
|
2121
|
+
if (isStorageVectorsError(error)) return {
|
|
2122
|
+
data: null,
|
|
2123
|
+
error
|
|
2124
|
+
};
|
|
2125
|
+
throw error;
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
/** Retrieves metadata for a specific vector index */
|
|
2129
|
+
async getIndex(vectorBucketName, indexName) {
|
|
2130
|
+
var _this2 = this;
|
|
2131
|
+
try {
|
|
2132
|
+
return {
|
|
2133
|
+
data: await post(_this2.fetch, `${_this2.url}/GetIndex`, {
|
|
2134
|
+
vectorBucketName,
|
|
2135
|
+
indexName
|
|
2136
|
+
}, { headers: _this2.headers }),
|
|
2137
|
+
error: null
|
|
2138
|
+
};
|
|
2139
|
+
} catch (error) {
|
|
2140
|
+
if (_this2.shouldThrowOnError) throw error;
|
|
2141
|
+
if (isStorageVectorsError(error)) return {
|
|
2142
|
+
data: null,
|
|
2143
|
+
error
|
|
2144
|
+
};
|
|
2145
|
+
throw error;
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
/** Lists vector indexes within a bucket with optional filtering and pagination */
|
|
2149
|
+
async listIndexes(options) {
|
|
2150
|
+
var _this3 = this;
|
|
2151
|
+
try {
|
|
2152
|
+
return {
|
|
2153
|
+
data: await post(_this3.fetch, `${_this3.url}/ListIndexes`, options, { headers: _this3.headers }),
|
|
2154
|
+
error: null
|
|
2155
|
+
};
|
|
2156
|
+
} catch (error) {
|
|
2157
|
+
if (_this3.shouldThrowOnError) throw error;
|
|
2158
|
+
if (isStorageVectorsError(error)) return {
|
|
2159
|
+
data: null,
|
|
2160
|
+
error
|
|
2161
|
+
};
|
|
2162
|
+
throw error;
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
/** Deletes a vector index and all its data */
|
|
2166
|
+
async deleteIndex(vectorBucketName, indexName) {
|
|
2167
|
+
var _this4 = this;
|
|
2168
|
+
try {
|
|
2169
|
+
return {
|
|
2170
|
+
data: await post(_this4.fetch, `${_this4.url}/DeleteIndex`, {
|
|
2171
|
+
vectorBucketName,
|
|
2172
|
+
indexName
|
|
2173
|
+
}, { headers: _this4.headers }) || {},
|
|
2174
|
+
error: null
|
|
2175
|
+
};
|
|
2176
|
+
} catch (error) {
|
|
2177
|
+
if (_this4.shouldThrowOnError) throw error;
|
|
2178
|
+
if (isStorageVectorsError(error)) return {
|
|
2179
|
+
data: null,
|
|
2180
|
+
error
|
|
2181
|
+
};
|
|
2182
|
+
throw error;
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
};
|
|
2186
|
+
|
|
2187
|
+
//#endregion
|
|
2188
|
+
//#region src/lib/vectors/VectorDataApi.ts
|
|
2189
|
+
/**
|
|
2190
|
+
* @hidden
|
|
2191
|
+
* Base implementation for vector data operations.
|
|
2192
|
+
* Use {@link VectorIndexScope} via `supabase.storage.vectors.from('bucket').index('idx')` instead.
|
|
2193
|
+
*/
|
|
2194
|
+
var VectorDataApi = class {
|
|
2195
|
+
/** Creates a new VectorDataApi instance */
|
|
2196
|
+
constructor(url, headers = {}, fetch$1) {
|
|
2197
|
+
this.shouldThrowOnError = false;
|
|
2198
|
+
this.url = url.replace(/\/$/, "");
|
|
2199
|
+
this.headers = _objectSpread2(_objectSpread2({}, DEFAULT_HEADERS), headers);
|
|
2200
|
+
this.fetch = resolveFetch(fetch$1);
|
|
2201
|
+
}
|
|
2202
|
+
/** Enable throwing errors instead of returning them in the response */
|
|
2203
|
+
throwOnError() {
|
|
2204
|
+
this.shouldThrowOnError = true;
|
|
2205
|
+
return this;
|
|
2206
|
+
}
|
|
2207
|
+
/** Inserts or updates vectors in batch (1-500 per request) */
|
|
2208
|
+
async putVectors(options) {
|
|
2209
|
+
var _this = this;
|
|
2210
|
+
try {
|
|
2211
|
+
if (options.vectors.length < 1 || options.vectors.length > 500) throw new Error("Vector batch size must be between 1 and 500 items");
|
|
2212
|
+
return {
|
|
2213
|
+
data: await post(_this.fetch, `${_this.url}/PutVectors`, options, { headers: _this.headers }) || {},
|
|
2214
|
+
error: null
|
|
2215
|
+
};
|
|
2216
|
+
} catch (error) {
|
|
2217
|
+
if (_this.shouldThrowOnError) throw error;
|
|
2218
|
+
if (isStorageVectorsError(error)) return {
|
|
2219
|
+
data: null,
|
|
2220
|
+
error
|
|
2221
|
+
};
|
|
2222
|
+
throw error;
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
/** Retrieves vectors by their keys in batch */
|
|
2226
|
+
async getVectors(options) {
|
|
2227
|
+
var _this2 = this;
|
|
2228
|
+
try {
|
|
2229
|
+
return {
|
|
2230
|
+
data: await post(_this2.fetch, `${_this2.url}/GetVectors`, options, { headers: _this2.headers }),
|
|
2231
|
+
error: null
|
|
2232
|
+
};
|
|
2233
|
+
} catch (error) {
|
|
2234
|
+
if (_this2.shouldThrowOnError) throw error;
|
|
2235
|
+
if (isStorageVectorsError(error)) return {
|
|
2236
|
+
data: null,
|
|
2237
|
+
error
|
|
2238
|
+
};
|
|
2239
|
+
throw error;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
/** Lists vectors in an index with pagination */
|
|
2243
|
+
async listVectors(options) {
|
|
2244
|
+
var _this3 = this;
|
|
2245
|
+
try {
|
|
2246
|
+
if (options.segmentCount !== void 0) {
|
|
2247
|
+
if (options.segmentCount < 1 || options.segmentCount > 16) throw new Error("segmentCount must be between 1 and 16");
|
|
2248
|
+
if (options.segmentIndex !== void 0) {
|
|
2249
|
+
if (options.segmentIndex < 0 || options.segmentIndex >= options.segmentCount) throw new Error(`segmentIndex must be between 0 and ${options.segmentCount - 1}`);
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
return {
|
|
2253
|
+
data: await post(_this3.fetch, `${_this3.url}/ListVectors`, options, { headers: _this3.headers }),
|
|
2254
|
+
error: null
|
|
2255
|
+
};
|
|
2256
|
+
} catch (error) {
|
|
2257
|
+
if (_this3.shouldThrowOnError) throw error;
|
|
2258
|
+
if (isStorageVectorsError(error)) return {
|
|
2259
|
+
data: null,
|
|
2260
|
+
error
|
|
2261
|
+
};
|
|
2262
|
+
throw error;
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
/** Queries for similar vectors using approximate nearest neighbor search */
|
|
2266
|
+
async queryVectors(options) {
|
|
2267
|
+
var _this4 = this;
|
|
2268
|
+
try {
|
|
2269
|
+
return {
|
|
2270
|
+
data: await post(_this4.fetch, `${_this4.url}/QueryVectors`, options, { headers: _this4.headers }),
|
|
2271
|
+
error: null
|
|
2272
|
+
};
|
|
2273
|
+
} catch (error) {
|
|
2274
|
+
if (_this4.shouldThrowOnError) throw error;
|
|
2275
|
+
if (isStorageVectorsError(error)) return {
|
|
2276
|
+
data: null,
|
|
2277
|
+
error
|
|
2278
|
+
};
|
|
2279
|
+
throw error;
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
/** Deletes vectors by their keys in batch (1-500 per request) */
|
|
2283
|
+
async deleteVectors(options) {
|
|
2284
|
+
var _this5 = this;
|
|
2285
|
+
try {
|
|
2286
|
+
if (options.keys.length < 1 || options.keys.length > 500) throw new Error("Keys batch size must be between 1 and 500 items");
|
|
2287
|
+
return {
|
|
2288
|
+
data: await post(_this5.fetch, `${_this5.url}/DeleteVectors`, options, { headers: _this5.headers }) || {},
|
|
2289
|
+
error: null
|
|
2290
|
+
};
|
|
2291
|
+
} catch (error) {
|
|
2292
|
+
if (_this5.shouldThrowOnError) throw error;
|
|
2293
|
+
if (isStorageVectorsError(error)) return {
|
|
2294
|
+
data: null,
|
|
2295
|
+
error
|
|
2296
|
+
};
|
|
2297
|
+
throw error;
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
};
|
|
2301
|
+
|
|
2302
|
+
//#endregion
|
|
2303
|
+
//#region src/lib/vectors/VectorBucketApi.ts
|
|
2304
|
+
/**
|
|
2305
|
+
* @hidden
|
|
2306
|
+
* Base implementation for vector bucket operations.
|
|
2307
|
+
* Use {@link StorageVectorsClient} via `supabase.storage.vectors` instead.
|
|
2308
|
+
*/
|
|
2309
|
+
var VectorBucketApi = class {
|
|
2310
|
+
/** Creates a new VectorBucketApi instance */
|
|
2311
|
+
constructor(url, headers = {}, fetch$1) {
|
|
2312
|
+
this.shouldThrowOnError = false;
|
|
2313
|
+
this.url = url.replace(/\/$/, "");
|
|
2314
|
+
this.headers = _objectSpread2(_objectSpread2({}, DEFAULT_HEADERS), headers);
|
|
2315
|
+
this.fetch = resolveFetch(fetch$1);
|
|
2316
|
+
}
|
|
2317
|
+
/** Enable throwing errors instead of returning them in the response */
|
|
2318
|
+
throwOnError() {
|
|
2319
|
+
this.shouldThrowOnError = true;
|
|
2320
|
+
return this;
|
|
2321
|
+
}
|
|
2322
|
+
/** Creates a new vector bucket */
|
|
2323
|
+
async createBucket(vectorBucketName) {
|
|
2324
|
+
var _this = this;
|
|
2325
|
+
try {
|
|
2326
|
+
return {
|
|
2327
|
+
data: await post(_this.fetch, `${_this.url}/CreateVectorBucket`, { vectorBucketName }, { headers: _this.headers }) || {},
|
|
2328
|
+
error: null
|
|
2329
|
+
};
|
|
2330
|
+
} catch (error) {
|
|
2331
|
+
if (_this.shouldThrowOnError) throw error;
|
|
2332
|
+
if (isStorageVectorsError(error)) return {
|
|
2333
|
+
data: null,
|
|
2334
|
+
error
|
|
2335
|
+
};
|
|
2336
|
+
throw error;
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
/** Retrieves metadata for a specific vector bucket */
|
|
2340
|
+
async getBucket(vectorBucketName) {
|
|
2341
|
+
var _this2 = this;
|
|
2342
|
+
try {
|
|
2343
|
+
return {
|
|
2344
|
+
data: await post(_this2.fetch, `${_this2.url}/GetVectorBucket`, { vectorBucketName }, { headers: _this2.headers }),
|
|
2345
|
+
error: null
|
|
2346
|
+
};
|
|
2347
|
+
} catch (error) {
|
|
2348
|
+
if (_this2.shouldThrowOnError) throw error;
|
|
2349
|
+
if (isStorageVectorsError(error)) return {
|
|
2350
|
+
data: null,
|
|
2351
|
+
error
|
|
2352
|
+
};
|
|
2353
|
+
throw error;
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
/** Lists vector buckets with optional filtering and pagination */
|
|
2357
|
+
async listBuckets(options = {}) {
|
|
2358
|
+
var _this3 = this;
|
|
2359
|
+
try {
|
|
2360
|
+
return {
|
|
2361
|
+
data: await post(_this3.fetch, `${_this3.url}/ListVectorBuckets`, options, { headers: _this3.headers }),
|
|
2362
|
+
error: null
|
|
2363
|
+
};
|
|
2364
|
+
} catch (error) {
|
|
2365
|
+
if (_this3.shouldThrowOnError) throw error;
|
|
2366
|
+
if (isStorageVectorsError(error)) return {
|
|
2367
|
+
data: null,
|
|
2368
|
+
error
|
|
2369
|
+
};
|
|
2370
|
+
throw error;
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
/** Deletes a vector bucket (must be empty first) */
|
|
2374
|
+
async deleteBucket(vectorBucketName) {
|
|
2375
|
+
var _this4 = this;
|
|
2376
|
+
try {
|
|
2377
|
+
return {
|
|
2378
|
+
data: await post(_this4.fetch, `${_this4.url}/DeleteVectorBucket`, { vectorBucketName }, { headers: _this4.headers }) || {},
|
|
2379
|
+
error: null
|
|
2380
|
+
};
|
|
2381
|
+
} catch (error) {
|
|
2382
|
+
if (_this4.shouldThrowOnError) throw error;
|
|
2383
|
+
if (isStorageVectorsError(error)) return {
|
|
2384
|
+
data: null,
|
|
2385
|
+
error
|
|
2386
|
+
};
|
|
2387
|
+
throw error;
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
|
|
2392
|
+
//#endregion
|
|
2393
|
+
//#region src/lib/vectors/StorageVectorsClient.ts
|
|
2394
|
+
/**
|
|
2395
|
+
*
|
|
2396
|
+
* @alpha
|
|
2397
|
+
*
|
|
2398
|
+
* Main client for interacting with S3 Vectors API
|
|
2399
|
+
* Provides access to bucket, index, and vector data operations
|
|
2400
|
+
*
|
|
2401
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2402
|
+
*
|
|
2403
|
+
* **Usage Patterns:**
|
|
2404
|
+
*
|
|
2405
|
+
* ```typescript
|
|
2406
|
+
* const { data, error } = await supabase
|
|
2407
|
+
* .storage
|
|
2408
|
+
* .vectors
|
|
2409
|
+
* .createBucket('embeddings-prod')
|
|
2410
|
+
*
|
|
2411
|
+
* // Access index operations via buckets
|
|
2412
|
+
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
2413
|
+
* await bucket.createIndex({
|
|
2414
|
+
* indexName: 'documents',
|
|
2415
|
+
* dataType: 'float32',
|
|
2416
|
+
* dimension: 1536,
|
|
2417
|
+
* distanceMetric: 'cosine'
|
|
2418
|
+
* })
|
|
2419
|
+
*
|
|
2420
|
+
* // Access vector operations via index
|
|
2421
|
+
* const index = bucket.index('documents')
|
|
2422
|
+
* await index.putVectors({
|
|
2423
|
+
* vectors: [
|
|
2424
|
+
* { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } }
|
|
2425
|
+
* ]
|
|
2426
|
+
* })
|
|
2427
|
+
*
|
|
2428
|
+
* // Query similar vectors
|
|
2429
|
+
* const { data } = await index.queryVectors({
|
|
2430
|
+
* queryVector: { float32: [...] },
|
|
2431
|
+
* topK: 5,
|
|
2432
|
+
* returnDistance: true
|
|
2433
|
+
* })
|
|
2434
|
+
* ```
|
|
2435
|
+
*/
|
|
2436
|
+
var StorageVectorsClient = class extends VectorBucketApi {
|
|
2437
|
+
/**
|
|
2438
|
+
* @alpha
|
|
2439
|
+
*
|
|
2440
|
+
* Creates a StorageVectorsClient that can manage buckets, indexes, and vectors.
|
|
2441
|
+
*
|
|
2442
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2443
|
+
*
|
|
2444
|
+
* @category Vector Buckets
|
|
2445
|
+
* @param url - Base URL of the Storage Vectors REST API.
|
|
2446
|
+
* @param options.headers - Optional headers (for example `Authorization`) applied to every request.
|
|
2447
|
+
* @param options.fetch - Optional custom `fetch` implementation for non-browser runtimes.
|
|
2448
|
+
*
|
|
2449
|
+
* @example
|
|
2450
|
+
* ```typescript
|
|
2451
|
+
* const client = new StorageVectorsClient(url, options)
|
|
2452
|
+
* ```
|
|
2453
|
+
*/
|
|
2454
|
+
constructor(url, options = {}) {
|
|
2455
|
+
super(url, options.headers || {}, options.fetch);
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
*
|
|
2459
|
+
* @alpha
|
|
2460
|
+
*
|
|
2461
|
+
* Access operations for a specific vector bucket
|
|
2462
|
+
* Returns a scoped client for index and vector operations within the bucket
|
|
2463
|
+
*
|
|
2464
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2465
|
+
*
|
|
2466
|
+
* @category Vector Buckets
|
|
2467
|
+
* @param vectorBucketName - Name of the vector bucket
|
|
2468
|
+
* @returns Bucket-scoped client with index and vector operations
|
|
2469
|
+
*
|
|
2470
|
+
* @example
|
|
2471
|
+
* ```typescript
|
|
2472
|
+
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
2473
|
+
* ```
|
|
2474
|
+
*/
|
|
2475
|
+
from(vectorBucketName) {
|
|
2476
|
+
return new VectorBucketScope(this.url, this.headers, vectorBucketName, this.fetch);
|
|
2477
|
+
}
|
|
2478
|
+
/**
|
|
2479
|
+
*
|
|
2480
|
+
* @alpha
|
|
2481
|
+
*
|
|
2482
|
+
* Creates a new vector bucket
|
|
2483
|
+
* Vector buckets are containers for vector indexes and their data
|
|
2484
|
+
*
|
|
2485
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2486
|
+
*
|
|
2487
|
+
* @category Vector Buckets
|
|
2488
|
+
* @param vectorBucketName - Unique name for the vector bucket
|
|
2489
|
+
* @returns Promise with empty response on success or error
|
|
2490
|
+
*
|
|
2491
|
+
* @example
|
|
2492
|
+
* ```typescript
|
|
2493
|
+
* const { data, error } = await supabase
|
|
2494
|
+
* .storage
|
|
2495
|
+
* .vectors
|
|
2496
|
+
* .createBucket('embeddings-prod')
|
|
2497
|
+
* ```
|
|
2498
|
+
*/
|
|
2499
|
+
async createBucket(vectorBucketName) {
|
|
2500
|
+
var _superprop_getCreateBucket = () => super.createBucket, _this = this;
|
|
2501
|
+
return _superprop_getCreateBucket().call(_this, vectorBucketName);
|
|
2502
|
+
}
|
|
2503
|
+
/**
|
|
2504
|
+
*
|
|
2505
|
+
* @alpha
|
|
2506
|
+
*
|
|
2507
|
+
* Retrieves metadata for a specific vector bucket
|
|
2508
|
+
*
|
|
2509
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2510
|
+
*
|
|
2511
|
+
* @category Vector Buckets
|
|
2512
|
+
* @param vectorBucketName - Name of the vector bucket
|
|
2513
|
+
* @returns Promise with bucket metadata or error
|
|
2514
|
+
*
|
|
2515
|
+
* @example
|
|
2516
|
+
* ```typescript
|
|
2517
|
+
* const { data, error } = await supabase
|
|
2518
|
+
* .storage
|
|
2519
|
+
* .vectors
|
|
2520
|
+
* .getBucket('embeddings-prod')
|
|
2521
|
+
*
|
|
2522
|
+
* console.log('Bucket created:', data?.vectorBucket.creationTime)
|
|
2523
|
+
* ```
|
|
2524
|
+
*/
|
|
2525
|
+
async getBucket(vectorBucketName) {
|
|
2526
|
+
var _superprop_getGetBucket = () => super.getBucket, _this2 = this;
|
|
2527
|
+
return _superprop_getGetBucket().call(_this2, vectorBucketName);
|
|
2528
|
+
}
|
|
2529
|
+
/**
|
|
2530
|
+
*
|
|
2531
|
+
* @alpha
|
|
2532
|
+
*
|
|
2533
|
+
* Lists all vector buckets with optional filtering and pagination
|
|
2534
|
+
*
|
|
2535
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2536
|
+
*
|
|
2537
|
+
* @category Vector Buckets
|
|
2538
|
+
* @param options - Optional filters (prefix, maxResults, nextToken)
|
|
2539
|
+
* @returns Promise with list of buckets or error
|
|
2540
|
+
*
|
|
2541
|
+
* @example
|
|
2542
|
+
* ```typescript
|
|
2543
|
+
* const { data, error } = await supabase
|
|
2544
|
+
* .storage
|
|
2545
|
+
* .vectors
|
|
2546
|
+
* .listBuckets({ prefix: 'embeddings-' })
|
|
2547
|
+
*
|
|
2548
|
+
* data?.vectorBuckets.forEach(bucket => {
|
|
2549
|
+
* console.log(bucket.vectorBucketName)
|
|
2550
|
+
* })
|
|
2551
|
+
* ```
|
|
2552
|
+
*/
|
|
2553
|
+
async listBuckets(options = {}) {
|
|
2554
|
+
var _superprop_getListBuckets = () => super.listBuckets, _this3 = this;
|
|
2555
|
+
return _superprop_getListBuckets().call(_this3, options);
|
|
2556
|
+
}
|
|
2557
|
+
/**
|
|
2558
|
+
*
|
|
2559
|
+
* @alpha
|
|
2560
|
+
*
|
|
2561
|
+
* Deletes a vector bucket (bucket must be empty)
|
|
2562
|
+
* All indexes must be deleted before deleting the bucket
|
|
2563
|
+
*
|
|
2564
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2565
|
+
*
|
|
2566
|
+
* @category Vector Buckets
|
|
2567
|
+
* @param vectorBucketName - Name of the vector bucket to delete
|
|
2568
|
+
* @returns Promise with empty response on success or error
|
|
2569
|
+
*
|
|
2570
|
+
* @example
|
|
2571
|
+
* ```typescript
|
|
2572
|
+
* const { data, error } = await supabase
|
|
2573
|
+
* .storage
|
|
2574
|
+
* .vectors
|
|
2575
|
+
* .deleteBucket('embeddings-old')
|
|
2576
|
+
* ```
|
|
2577
|
+
*/
|
|
2578
|
+
async deleteBucket(vectorBucketName) {
|
|
2579
|
+
var _superprop_getDeleteBucket = () => super.deleteBucket, _this4 = this;
|
|
2580
|
+
return _superprop_getDeleteBucket().call(_this4, vectorBucketName);
|
|
2581
|
+
}
|
|
2582
|
+
};
|
|
2583
|
+
/**
|
|
2584
|
+
*
|
|
2585
|
+
* @alpha
|
|
2586
|
+
*
|
|
2587
|
+
* Scoped client for operations within a specific vector bucket
|
|
2588
|
+
* Provides index management and access to vector operations
|
|
2589
|
+
*
|
|
2590
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2591
|
+
*/
|
|
2592
|
+
var VectorBucketScope = class extends VectorIndexApi {
|
|
2593
|
+
/**
|
|
2594
|
+
* @alpha
|
|
2595
|
+
*
|
|
2596
|
+
* Creates a helper that automatically scopes all index operations to the provided bucket.
|
|
2597
|
+
*
|
|
2598
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2599
|
+
*
|
|
2600
|
+
* @category Vector Buckets
|
|
2601
|
+
* @example
|
|
2602
|
+
* ```typescript
|
|
2603
|
+
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
2604
|
+
* ```
|
|
2605
|
+
*/
|
|
2606
|
+
constructor(url, headers, vectorBucketName, fetch$1) {
|
|
2607
|
+
super(url, headers, fetch$1);
|
|
2608
|
+
this.vectorBucketName = vectorBucketName;
|
|
2609
|
+
}
|
|
2610
|
+
/**
|
|
2611
|
+
*
|
|
2612
|
+
* @alpha
|
|
2613
|
+
*
|
|
2614
|
+
* Creates a new vector index in this bucket
|
|
2615
|
+
* Convenience method that automatically includes the bucket name
|
|
2616
|
+
*
|
|
2617
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2618
|
+
*
|
|
2619
|
+
* @category Vector Buckets
|
|
2620
|
+
* @param options - Index configuration (vectorBucketName is automatically set)
|
|
2621
|
+
* @returns Promise with empty response on success or error
|
|
2622
|
+
*
|
|
2623
|
+
* @example
|
|
2624
|
+
* ```typescript
|
|
2625
|
+
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
2626
|
+
* await bucket.createIndex({
|
|
2627
|
+
* indexName: 'documents-openai',
|
|
2628
|
+
* dataType: 'float32',
|
|
2629
|
+
* dimension: 1536,
|
|
2630
|
+
* distanceMetric: 'cosine',
|
|
2631
|
+
* metadataConfiguration: {
|
|
2632
|
+
* nonFilterableMetadataKeys: ['raw_text']
|
|
2633
|
+
* }
|
|
2634
|
+
* })
|
|
2635
|
+
* ```
|
|
2636
|
+
*/
|
|
2637
|
+
async createIndex(options) {
|
|
2638
|
+
var _superprop_getCreateIndex = () => super.createIndex, _this5 = this;
|
|
2639
|
+
return _superprop_getCreateIndex().call(_this5, _objectSpread2(_objectSpread2({}, options), {}, { vectorBucketName: _this5.vectorBucketName }));
|
|
2640
|
+
}
|
|
2641
|
+
/**
|
|
2642
|
+
*
|
|
2643
|
+
* @alpha
|
|
2644
|
+
*
|
|
2645
|
+
* Lists indexes in this bucket
|
|
2646
|
+
* Convenience method that automatically includes the bucket name
|
|
2647
|
+
*
|
|
2648
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2649
|
+
*
|
|
2650
|
+
* @category Vector Buckets
|
|
2651
|
+
* @param options - Listing options (vectorBucketName is automatically set)
|
|
2652
|
+
* @returns Promise with response containing indexes array and pagination token or error
|
|
2653
|
+
*
|
|
2654
|
+
* @example
|
|
2655
|
+
* ```typescript
|
|
2656
|
+
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
2657
|
+
* const { data } = await bucket.listIndexes({ prefix: 'documents-' })
|
|
2658
|
+
* ```
|
|
2659
|
+
*/
|
|
2660
|
+
async listIndexes(options = {}) {
|
|
2661
|
+
var _superprop_getListIndexes = () => super.listIndexes, _this6 = this;
|
|
2662
|
+
return _superprop_getListIndexes().call(_this6, _objectSpread2(_objectSpread2({}, options), {}, { vectorBucketName: _this6.vectorBucketName }));
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
*
|
|
2666
|
+
* @alpha
|
|
2667
|
+
*
|
|
2668
|
+
* Retrieves metadata for a specific index in this bucket
|
|
2669
|
+
* Convenience method that automatically includes the bucket name
|
|
2670
|
+
*
|
|
2671
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2672
|
+
*
|
|
2673
|
+
* @category Vector Buckets
|
|
2674
|
+
* @param indexName - Name of the index to retrieve
|
|
2675
|
+
* @returns Promise with index metadata or error
|
|
2676
|
+
*
|
|
2677
|
+
* @example
|
|
2678
|
+
* ```typescript
|
|
2679
|
+
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
2680
|
+
* const { data } = await bucket.getIndex('documents-openai')
|
|
2681
|
+
* console.log('Dimension:', data?.index.dimension)
|
|
2682
|
+
* ```
|
|
2683
|
+
*/
|
|
2684
|
+
async getIndex(indexName) {
|
|
2685
|
+
var _superprop_getGetIndex = () => super.getIndex, _this7 = this;
|
|
2686
|
+
return _superprop_getGetIndex().call(_this7, _this7.vectorBucketName, indexName);
|
|
2687
|
+
}
|
|
2688
|
+
/**
|
|
2689
|
+
*
|
|
2690
|
+
* @alpha
|
|
2691
|
+
*
|
|
2692
|
+
* Deletes an index from this bucket
|
|
2693
|
+
* Convenience method that automatically includes the bucket name
|
|
2694
|
+
*
|
|
2695
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2696
|
+
*
|
|
2697
|
+
* @category Vector Buckets
|
|
2698
|
+
* @param indexName - Name of the index to delete
|
|
2699
|
+
* @returns Promise with empty response on success or error
|
|
2700
|
+
*
|
|
2701
|
+
* @example
|
|
2702
|
+
* ```typescript
|
|
2703
|
+
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
2704
|
+
* await bucket.deleteIndex('old-index')
|
|
2705
|
+
* ```
|
|
2706
|
+
*/
|
|
2707
|
+
async deleteIndex(indexName) {
|
|
2708
|
+
var _superprop_getDeleteIndex = () => super.deleteIndex, _this8 = this;
|
|
2709
|
+
return _superprop_getDeleteIndex().call(_this8, _this8.vectorBucketName, indexName);
|
|
2710
|
+
}
|
|
2711
|
+
/**
|
|
2712
|
+
*
|
|
2713
|
+
* @alpha
|
|
2714
|
+
*
|
|
2715
|
+
* Access operations for a specific index within this bucket
|
|
2716
|
+
* Returns a scoped client for vector data operations
|
|
2717
|
+
*
|
|
2718
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2719
|
+
*
|
|
2720
|
+
* @category Vector Buckets
|
|
2721
|
+
* @param indexName - Name of the index
|
|
2722
|
+
* @returns Index-scoped client with vector data operations
|
|
2723
|
+
*
|
|
2724
|
+
* @example
|
|
2725
|
+
* ```typescript
|
|
2726
|
+
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
2727
|
+
*
|
|
2728
|
+
* // Insert vectors
|
|
2729
|
+
* await index.putVectors({
|
|
2730
|
+
* vectors: [
|
|
2731
|
+
* { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } }
|
|
2732
|
+
* ]
|
|
2733
|
+
* })
|
|
2734
|
+
*
|
|
2735
|
+
* // Query similar vectors
|
|
2736
|
+
* const { data } = await index.queryVectors({
|
|
2737
|
+
* queryVector: { float32: [...] },
|
|
2738
|
+
* topK: 5
|
|
2739
|
+
* })
|
|
2740
|
+
* ```
|
|
2741
|
+
*/
|
|
2742
|
+
index(indexName) {
|
|
2743
|
+
return new VectorIndexScope(this.url, this.headers, this.vectorBucketName, indexName, this.fetch);
|
|
2744
|
+
}
|
|
2745
|
+
};
|
|
2746
|
+
/**
|
|
2747
|
+
*
|
|
2748
|
+
* @alpha
|
|
2749
|
+
*
|
|
2750
|
+
* Scoped client for operations within a specific vector index
|
|
2751
|
+
* Provides vector data operations (put, get, list, query, delete)
|
|
2752
|
+
*
|
|
2753
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2754
|
+
*/
|
|
2755
|
+
var VectorIndexScope = class extends VectorDataApi {
|
|
2756
|
+
/**
|
|
2757
|
+
*
|
|
2758
|
+
* @alpha
|
|
2759
|
+
*
|
|
2760
|
+
* Creates a helper that automatically scopes all vector operations to the provided bucket/index names.
|
|
2761
|
+
*
|
|
2762
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2763
|
+
*
|
|
2764
|
+
* @category Vector Buckets
|
|
2765
|
+
* @example
|
|
2766
|
+
* ```typescript
|
|
2767
|
+
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
2768
|
+
* ```
|
|
2769
|
+
*/
|
|
2770
|
+
constructor(url, headers, vectorBucketName, indexName, fetch$1) {
|
|
2771
|
+
super(url, headers, fetch$1);
|
|
2772
|
+
this.vectorBucketName = vectorBucketName;
|
|
2773
|
+
this.indexName = indexName;
|
|
2774
|
+
}
|
|
2775
|
+
/**
|
|
2776
|
+
*
|
|
2777
|
+
* @alpha
|
|
2778
|
+
*
|
|
2779
|
+
* Inserts or updates vectors in this index
|
|
2780
|
+
* Convenience method that automatically includes bucket and index names
|
|
2781
|
+
*
|
|
2782
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2783
|
+
*
|
|
2784
|
+
* @category Vector Buckets
|
|
2785
|
+
* @param options - Vector insertion options (bucket and index names automatically set)
|
|
2786
|
+
* @returns Promise with empty response on success or error
|
|
2787
|
+
*
|
|
2788
|
+
* @example
|
|
2789
|
+
* ```typescript
|
|
2790
|
+
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
2791
|
+
* await index.putVectors({
|
|
2792
|
+
* vectors: [
|
|
2793
|
+
* {
|
|
2794
|
+
* key: 'doc-1',
|
|
2795
|
+
* data: { float32: [0.1, 0.2, ...] },
|
|
2796
|
+
* metadata: { title: 'Introduction', page: 1 }
|
|
2797
|
+
* }
|
|
2798
|
+
* ]
|
|
2799
|
+
* })
|
|
2800
|
+
* ```
|
|
2801
|
+
*/
|
|
2802
|
+
async putVectors(options) {
|
|
2803
|
+
var _superprop_getPutVectors = () => super.putVectors, _this9 = this;
|
|
2804
|
+
return _superprop_getPutVectors().call(_this9, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
2805
|
+
vectorBucketName: _this9.vectorBucketName,
|
|
2806
|
+
indexName: _this9.indexName
|
|
2807
|
+
}));
|
|
2808
|
+
}
|
|
2809
|
+
/**
|
|
2810
|
+
*
|
|
2811
|
+
* @alpha
|
|
2812
|
+
*
|
|
2813
|
+
* Retrieves vectors by keys from this index
|
|
2814
|
+
* Convenience method that automatically includes bucket and index names
|
|
2815
|
+
*
|
|
2816
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2817
|
+
*
|
|
2818
|
+
* @category Vector Buckets
|
|
2819
|
+
* @param options - Vector retrieval options (bucket and index names automatically set)
|
|
2820
|
+
* @returns Promise with response containing vectors array or error
|
|
2821
|
+
*
|
|
2822
|
+
* @example
|
|
2823
|
+
* ```typescript
|
|
2824
|
+
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
2825
|
+
* const { data } = await index.getVectors({
|
|
2826
|
+
* keys: ['doc-1', 'doc-2'],
|
|
2827
|
+
* returnMetadata: true
|
|
2828
|
+
* })
|
|
2829
|
+
* ```
|
|
2830
|
+
*/
|
|
2831
|
+
async getVectors(options) {
|
|
2832
|
+
var _superprop_getGetVectors = () => super.getVectors, _this10 = this;
|
|
2833
|
+
return _superprop_getGetVectors().call(_this10, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
2834
|
+
vectorBucketName: _this10.vectorBucketName,
|
|
2835
|
+
indexName: _this10.indexName
|
|
2836
|
+
}));
|
|
2837
|
+
}
|
|
2838
|
+
/**
|
|
2839
|
+
*
|
|
2840
|
+
* @alpha
|
|
2841
|
+
*
|
|
2842
|
+
* Lists vectors in this index with pagination
|
|
2843
|
+
* Convenience method that automatically includes bucket and index names
|
|
2844
|
+
*
|
|
2845
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2846
|
+
*
|
|
2847
|
+
* @category Vector Buckets
|
|
2848
|
+
* @param options - Listing options (bucket and index names automatically set)
|
|
2849
|
+
* @returns Promise with response containing vectors array and pagination token or error
|
|
2850
|
+
*
|
|
2851
|
+
* @example
|
|
2852
|
+
* ```typescript
|
|
2853
|
+
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
2854
|
+
* const { data } = await index.listVectors({
|
|
2855
|
+
* maxResults: 500,
|
|
2856
|
+
* returnMetadata: true
|
|
2857
|
+
* })
|
|
2858
|
+
* ```
|
|
2859
|
+
*/
|
|
2860
|
+
async listVectors(options = {}) {
|
|
2861
|
+
var _superprop_getListVectors = () => super.listVectors, _this11 = this;
|
|
2862
|
+
return _superprop_getListVectors().call(_this11, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
2863
|
+
vectorBucketName: _this11.vectorBucketName,
|
|
2864
|
+
indexName: _this11.indexName
|
|
2865
|
+
}));
|
|
2866
|
+
}
|
|
2867
|
+
/**
|
|
2868
|
+
*
|
|
2869
|
+
* @alpha
|
|
2870
|
+
*
|
|
2871
|
+
* Queries for similar vectors in this index
|
|
2872
|
+
* Convenience method that automatically includes bucket and index names
|
|
2873
|
+
*
|
|
2874
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2875
|
+
*
|
|
2876
|
+
* @category Vector Buckets
|
|
2877
|
+
* @param options - Query options (bucket and index names automatically set)
|
|
2878
|
+
* @returns Promise with response containing matches array of similar vectors ordered by distance or error
|
|
2879
|
+
*
|
|
2880
|
+
* @example
|
|
2881
|
+
* ```typescript
|
|
2882
|
+
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
2883
|
+
* const { data } = await index.queryVectors({
|
|
2884
|
+
* queryVector: { float32: [0.1, 0.2, ...] },
|
|
2885
|
+
* topK: 5,
|
|
2886
|
+
* filter: { category: 'technical' },
|
|
2887
|
+
* returnDistance: true,
|
|
2888
|
+
* returnMetadata: true
|
|
2889
|
+
* })
|
|
2890
|
+
* ```
|
|
2891
|
+
*/
|
|
2892
|
+
async queryVectors(options) {
|
|
2893
|
+
var _superprop_getQueryVectors = () => super.queryVectors, _this12 = this;
|
|
2894
|
+
return _superprop_getQueryVectors().call(_this12, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
2895
|
+
vectorBucketName: _this12.vectorBucketName,
|
|
2896
|
+
indexName: _this12.indexName
|
|
2897
|
+
}));
|
|
2898
|
+
}
|
|
2899
|
+
/**
|
|
2900
|
+
*
|
|
2901
|
+
* @alpha
|
|
2902
|
+
*
|
|
2903
|
+
* Deletes vectors by keys from this index
|
|
2904
|
+
* Convenience method that automatically includes bucket and index names
|
|
2905
|
+
*
|
|
2906
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2907
|
+
*
|
|
2908
|
+
* @category Vector Buckets
|
|
2909
|
+
* @param options - Deletion options (bucket and index names automatically set)
|
|
2910
|
+
* @returns Promise with empty response on success or error
|
|
2911
|
+
*
|
|
2912
|
+
* @example
|
|
2913
|
+
* ```typescript
|
|
2914
|
+
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
2915
|
+
* await index.deleteVectors({
|
|
2916
|
+
* keys: ['doc-1', 'doc-2', 'doc-3']
|
|
2917
|
+
* })
|
|
2918
|
+
* ```
|
|
2919
|
+
*/
|
|
2920
|
+
async deleteVectors(options) {
|
|
2921
|
+
var _superprop_getDeleteVectors = () => super.deleteVectors, _this13 = this;
|
|
2922
|
+
return _superprop_getDeleteVectors().call(_this13, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
2923
|
+
vectorBucketName: _this13.vectorBucketName,
|
|
2924
|
+
indexName: _this13.indexName
|
|
2925
|
+
}));
|
|
2926
|
+
}
|
|
2927
|
+
};
|
|
2928
|
+
|
|
2929
|
+
//#endregion
|
|
2930
|
+
//#region src/StorageClient.ts
|
|
2931
|
+
var StorageClient = class extends StorageBucketApi {
|
|
2932
|
+
/**
|
|
2933
|
+
* Creates a client for Storage buckets, files, analytics, and vectors.
|
|
2934
|
+
*
|
|
2935
|
+
* @category File Buckets
|
|
2936
|
+
* @example
|
|
2937
|
+
* ```ts
|
|
2938
|
+
* import { StorageClient } from '@supabase/storage-js'
|
|
2939
|
+
*
|
|
2940
|
+
* const storage = new StorageClient('https://xyzcompany.supabase.co/storage/v1', {
|
|
2941
|
+
* apikey: 'public-anon-key',
|
|
2942
|
+
* })
|
|
2943
|
+
* const avatars = storage.from('avatars')
|
|
2944
|
+
* ```
|
|
2945
|
+
*/
|
|
2946
|
+
constructor(url, headers = {}, fetch$1, opts) {
|
|
2947
|
+
super(url, headers, fetch$1, opts);
|
|
2948
|
+
}
|
|
2949
|
+
/**
|
|
2950
|
+
* Perform file operation in a bucket.
|
|
2951
|
+
*
|
|
2952
|
+
* @category File Buckets
|
|
2953
|
+
* @param id The bucket id to operate on.
|
|
2954
|
+
*
|
|
2955
|
+
* @example
|
|
2956
|
+
* ```typescript
|
|
2957
|
+
* const avatars = supabase.storage.from('avatars')
|
|
2958
|
+
* ```
|
|
2959
|
+
*/
|
|
2960
|
+
from(id) {
|
|
2961
|
+
return new StorageFileApi(this.url, this.headers, id, this.fetch);
|
|
2962
|
+
}
|
|
2963
|
+
/**
|
|
2964
|
+
*
|
|
2965
|
+
* @alpha
|
|
2966
|
+
*
|
|
2967
|
+
* Access vector storage operations.
|
|
2968
|
+
*
|
|
2969
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2970
|
+
*
|
|
2971
|
+
* @category Vector Buckets
|
|
2972
|
+
* @returns A StorageVectorsClient instance configured with the current storage settings.
|
|
2973
|
+
*/
|
|
2974
|
+
get vectors() {
|
|
2975
|
+
return new StorageVectorsClient(this.url + "/vector", {
|
|
2976
|
+
headers: this.headers,
|
|
2977
|
+
fetch: this.fetch
|
|
2978
|
+
});
|
|
2979
|
+
}
|
|
2980
|
+
/**
|
|
2981
|
+
*
|
|
2982
|
+
* @alpha
|
|
2983
|
+
*
|
|
2984
|
+
* Access analytics storage operations using Iceberg tables.
|
|
2985
|
+
*
|
|
2986
|
+
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
2987
|
+
*
|
|
2988
|
+
* @category Analytics Buckets
|
|
2989
|
+
* @returns A StorageAnalyticsClient instance configured with the current storage settings.
|
|
2990
|
+
*/
|
|
2991
|
+
get analytics() {
|
|
2992
|
+
return new StorageAnalyticsClient(this.url + "/iceberg", this.headers, this.fetch);
|
|
2993
|
+
}
|
|
2994
|
+
};
|
|
2995
|
+
|
|
2996
|
+
//#endregion
|
|
2997
|
+
export { StorageAnalyticsClient, StorageApiError, StorageClient, StorageError, StorageUnknownError, StorageVectorsApiError, StorageVectorsClient, StorageVectorsError, StorageVectorsErrorCode, StorageVectorsUnknownError, VectorBucketApi, VectorBucketScope, VectorDataApi, VectorIndexApi, VectorIndexScope, isPlainObject, isStorageError, isStorageVectorsError, normalizeToFloat32, resolveFetch, resolveResponse, validateVectorDimension };
|
|
2998
|
+
//# sourceMappingURL=index.mjs.map
|