@supabase/storage-js 2.91.1 → 2.91.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +476 -865
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1441 -1491
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1441 -1491
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +477 -861
- package/dist/index.mjs.map +1 -1
- package/dist/umd/supabase.js +1 -1
- package/package.json +1 -1
- package/src/StorageClient.ts +2 -2
- package/src/index.ts +15 -2
- package/src/lib/common/BaseApiClient.ts +90 -0
- package/src/lib/common/errors.ts +144 -0
- package/src/lib/common/fetch.ts +286 -0
- package/src/lib/{helpers.ts → common/helpers.ts} +71 -17
- package/src/lib/types.ts +304 -1
- package/src/lib/version.ts +1 -1
- package/src/packages/BlobDownloadBuilder.ts +1 -1
- package/src/packages/StorageAnalyticsClient.ts +17 -68
- package/src/packages/StorageBucketApi.ts +25 -109
- package/src/packages/StorageFileApi.ts +44 -172
- package/src/{lib/vectors → packages}/StorageVectorsClient.ts +2 -2
- package/src/packages/StreamDownloadBuilder.ts +1 -1
- package/src/packages/VectorBucketApi.ts +73 -0
- package/src/packages/VectorDataApi.ts +98 -0
- package/src/{lib/vectors → packages}/VectorIndexApi.ts +21 -66
- package/src/lib/errors.ts +0 -43
- package/src/lib/fetch.ts +0 -148
- package/src/lib/index.ts +0 -5
- package/src/lib/vectors/VectorBucketApi.ts +0 -118
- package/src/lib/vectors/VectorDataApi.ts +0 -152
- package/src/lib/vectors/constants.ts +0 -5
- package/src/lib/vectors/errors.ts +0 -78
- package/src/lib/vectors/fetch.ts +0 -218
- package/src/lib/vectors/helpers.ts +0 -79
- package/src/lib/vectors/index.ts +0 -66
- package/src/lib/vectors/types.ts +0 -301
package/src/lib/version.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { IcebergRestCatalog, IcebergError } from 'iceberg-js'
|
|
2
2
|
import { DEFAULT_HEADERS } from '../lib/constants'
|
|
3
|
-
import {
|
|
4
|
-
import { Fetch, get, post, remove } from '../lib/fetch'
|
|
5
|
-
import { isValidBucketName
|
|
3
|
+
import { StorageError } from '../lib/common/errors'
|
|
4
|
+
import { Fetch, get, post, remove } from '../lib/common/fetch'
|
|
5
|
+
import { isValidBucketName } from '../lib/common/helpers'
|
|
6
|
+
import BaseApiClient from '../lib/common/BaseApiClient'
|
|
6
7
|
import { AnalyticBucket } from '../lib/types'
|
|
7
8
|
|
|
8
9
|
type WrapAsyncMethod<T> = T extends (...args: infer A) => Promise<infer R>
|
|
@@ -17,12 +18,7 @@ export type WrappedIcebergRestCatalog = {
|
|
|
17
18
|
* Client class for managing Analytics Buckets using Iceberg tables
|
|
18
19
|
* Provides methods for creating, listing, and deleting analytics buckets
|
|
19
20
|
*/
|
|
20
|
-
export default class StorageAnalyticsClient {
|
|
21
|
-
protected url: string
|
|
22
|
-
protected headers: { [key: string]: string }
|
|
23
|
-
protected fetch: Fetch
|
|
24
|
-
protected shouldThrowOnError = false
|
|
25
|
-
|
|
21
|
+
export default class StorageAnalyticsClient extends BaseApiClient<StorageError> {
|
|
26
22
|
/**
|
|
27
23
|
* @alpha
|
|
28
24
|
*
|
|
@@ -41,25 +37,9 @@ export default class StorageAnalyticsClient {
|
|
|
41
37
|
* ```
|
|
42
38
|
*/
|
|
43
39
|
constructor(url: string, headers: { [key: string]: string } = {}, fetch?: Fetch) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @alpha
|
|
51
|
-
*
|
|
52
|
-
* Enable throwing errors instead of returning them in the response
|
|
53
|
-
* When enabled, failed operations will throw instead of returning { data: null, error }
|
|
54
|
-
*
|
|
55
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
56
|
-
*
|
|
57
|
-
* @category Analytics Buckets
|
|
58
|
-
* @returns This instance for method chaining
|
|
59
|
-
*/
|
|
60
|
-
public throwOnError(): this {
|
|
61
|
-
this.shouldThrowOnError = true
|
|
62
|
-
return this
|
|
40
|
+
const finalUrl = url.replace(/\/$/, '')
|
|
41
|
+
const finalHeaders = { ...DEFAULT_HEADERS, ...headers }
|
|
42
|
+
super(finalUrl, finalHeaders, fetch, 'storage')
|
|
63
43
|
}
|
|
64
44
|
|
|
65
45
|
/**
|
|
@@ -106,19 +86,9 @@ export default class StorageAnalyticsClient {
|
|
|
106
86
|
error: StorageError
|
|
107
87
|
}
|
|
108
88
|
> {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
} catch (error) {
|
|
113
|
-
if (this.shouldThrowOnError) {
|
|
114
|
-
throw error
|
|
115
|
-
}
|
|
116
|
-
if (isStorageError(error)) {
|
|
117
|
-
return { data: null, error }
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
throw error
|
|
121
|
-
}
|
|
89
|
+
return this.handleOperation(async () => {
|
|
90
|
+
return await post(this.fetch, `${this.url}/bucket`, { name }, { headers: this.headers })
|
|
91
|
+
})
|
|
122
92
|
}
|
|
123
93
|
|
|
124
94
|
/**
|
|
@@ -183,7 +153,7 @@ export default class StorageAnalyticsClient {
|
|
|
183
153
|
error: StorageError
|
|
184
154
|
}
|
|
185
155
|
> {
|
|
186
|
-
|
|
156
|
+
return this.handleOperation(async () => {
|
|
187
157
|
// Build query string from options
|
|
188
158
|
const queryParams = new URLSearchParams()
|
|
189
159
|
if (options?.limit !== undefined) queryParams.set('limit', options.limit.toString())
|
|
@@ -195,19 +165,8 @@ export default class StorageAnalyticsClient {
|
|
|
195
165
|
const queryString = queryParams.toString()
|
|
196
166
|
const url = queryString ? `${this.url}/bucket?${queryString}` : `${this.url}/bucket`
|
|
197
167
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return { data: data, error: null }
|
|
201
|
-
} catch (error) {
|
|
202
|
-
if (this.shouldThrowOnError) {
|
|
203
|
-
throw error
|
|
204
|
-
}
|
|
205
|
-
if (isStorageError(error)) {
|
|
206
|
-
return { data: null, error }
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
throw error
|
|
210
|
-
}
|
|
168
|
+
return await get(this.fetch, url, { headers: this.headers })
|
|
169
|
+
})
|
|
211
170
|
}
|
|
212
171
|
|
|
213
172
|
/**
|
|
@@ -251,24 +210,14 @@ export default class StorageAnalyticsClient {
|
|
|
251
210
|
error: StorageError
|
|
252
211
|
}
|
|
253
212
|
> {
|
|
254
|
-
|
|
255
|
-
|
|
213
|
+
return this.handleOperation(async () => {
|
|
214
|
+
return await remove(
|
|
256
215
|
this.fetch,
|
|
257
216
|
`${this.url}/bucket/${bucketName}`,
|
|
258
217
|
{},
|
|
259
218
|
{ headers: this.headers }
|
|
260
219
|
)
|
|
261
|
-
|
|
262
|
-
} catch (error) {
|
|
263
|
-
if (this.shouldThrowOnError) {
|
|
264
|
-
throw error
|
|
265
|
-
}
|
|
266
|
-
if (isStorageError(error)) {
|
|
267
|
-
return { data: null, error }
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
throw error
|
|
271
|
-
}
|
|
220
|
+
})
|
|
272
221
|
}
|
|
273
222
|
|
|
274
223
|
/**
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { DEFAULT_HEADERS } from '../lib/constants'
|
|
2
|
-
import {
|
|
3
|
-
import { Fetch, get, post, put, remove } from '../lib/fetch'
|
|
4
|
-
import
|
|
2
|
+
import { StorageError } from '../lib/common/errors'
|
|
3
|
+
import { Fetch, get, post, put, remove } from '../lib/common/fetch'
|
|
4
|
+
import BaseApiClient from '../lib/common/BaseApiClient'
|
|
5
5
|
import { Bucket, BucketType, ListBucketOptions } from '../lib/types'
|
|
6
6
|
import { StorageClientOptions } from '../StorageClient'
|
|
7
7
|
|
|
8
|
-
export default class StorageBucketApi {
|
|
9
|
-
protected url: string
|
|
10
|
-
protected headers: { [key: string]: string }
|
|
11
|
-
protected fetch: Fetch
|
|
12
|
-
protected shouldThrowOnError = false
|
|
13
|
-
|
|
8
|
+
export default class StorageBucketApi extends BaseApiClient<StorageError> {
|
|
14
9
|
constructor(
|
|
15
10
|
url: string,
|
|
16
11
|
headers: { [key: string]: string } = {},
|
|
@@ -28,19 +23,10 @@ export default class StorageBucketApi {
|
|
|
28
23
|
}
|
|
29
24
|
}
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.fetch = resolveFetch(fetch)
|
|
34
|
-
}
|
|
26
|
+
const finalUrl = baseUrl.href.replace(/\/$/, '')
|
|
27
|
+
const finalHeaders = { ...DEFAULT_HEADERS, ...headers }
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
* Enable throwing errors instead of returning them.
|
|
38
|
-
*
|
|
39
|
-
* @category File Buckets
|
|
40
|
-
*/
|
|
41
|
-
public throwOnError(): this {
|
|
42
|
-
this.shouldThrowOnError = true
|
|
43
|
-
return this
|
|
29
|
+
super(finalUrl, finalHeaders, fetch, 'storage')
|
|
44
30
|
}
|
|
45
31
|
|
|
46
32
|
/**
|
|
@@ -85,22 +71,12 @@ export default class StorageBucketApi {
|
|
|
85
71
|
error: StorageError
|
|
86
72
|
}
|
|
87
73
|
> {
|
|
88
|
-
|
|
74
|
+
return this.handleOperation(async () => {
|
|
89
75
|
const queryString = this.listBucketOptionsToQueryString(options)
|
|
90
|
-
|
|
76
|
+
return await get(this.fetch, `${this.url}/bucket${queryString}`, {
|
|
91
77
|
headers: this.headers,
|
|
92
78
|
})
|
|
93
|
-
|
|
94
|
-
} catch (error) {
|
|
95
|
-
if (this.shouldThrowOnError) {
|
|
96
|
-
throw error
|
|
97
|
-
}
|
|
98
|
-
if (isStorageError(error)) {
|
|
99
|
-
return { data: null, error }
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
throw error
|
|
103
|
-
}
|
|
79
|
+
})
|
|
104
80
|
}
|
|
105
81
|
|
|
106
82
|
/**
|
|
@@ -146,19 +122,9 @@ export default class StorageBucketApi {
|
|
|
146
122
|
error: StorageError
|
|
147
123
|
}
|
|
148
124
|
> {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
} catch (error) {
|
|
153
|
-
if (this.shouldThrowOnError) {
|
|
154
|
-
throw error
|
|
155
|
-
}
|
|
156
|
-
if (isStorageError(error)) {
|
|
157
|
-
return { data: null, error }
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
throw error
|
|
161
|
-
}
|
|
125
|
+
return this.handleOperation(async () => {
|
|
126
|
+
return await get(this.fetch, `${this.url}/bucket/${id}`, { headers: this.headers })
|
|
127
|
+
})
|
|
162
128
|
}
|
|
163
129
|
|
|
164
130
|
/**
|
|
@@ -218,8 +184,8 @@ export default class StorageBucketApi {
|
|
|
218
184
|
error: StorageError
|
|
219
185
|
}
|
|
220
186
|
> {
|
|
221
|
-
|
|
222
|
-
|
|
187
|
+
return this.handleOperation(async () => {
|
|
188
|
+
return await post(
|
|
223
189
|
this.fetch,
|
|
224
190
|
`${this.url}/bucket`,
|
|
225
191
|
{
|
|
@@ -232,17 +198,7 @@ export default class StorageBucketApi {
|
|
|
232
198
|
},
|
|
233
199
|
{ headers: this.headers }
|
|
234
200
|
)
|
|
235
|
-
|
|
236
|
-
} catch (error) {
|
|
237
|
-
if (this.shouldThrowOnError) {
|
|
238
|
-
throw error
|
|
239
|
-
}
|
|
240
|
-
if (isStorageError(error)) {
|
|
241
|
-
return { data: null, error }
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
throw error
|
|
245
|
-
}
|
|
201
|
+
})
|
|
246
202
|
}
|
|
247
203
|
|
|
248
204
|
/**
|
|
@@ -297,8 +253,8 @@ export default class StorageBucketApi {
|
|
|
297
253
|
error: StorageError
|
|
298
254
|
}
|
|
299
255
|
> {
|
|
300
|
-
|
|
301
|
-
|
|
256
|
+
return this.handleOperation(async () => {
|
|
257
|
+
return await put(
|
|
302
258
|
this.fetch,
|
|
303
259
|
`${this.url}/bucket/${id}`,
|
|
304
260
|
{
|
|
@@ -310,17 +266,7 @@ export default class StorageBucketApi {
|
|
|
310
266
|
},
|
|
311
267
|
{ headers: this.headers }
|
|
312
268
|
)
|
|
313
|
-
|
|
314
|
-
} catch (error) {
|
|
315
|
-
if (this.shouldThrowOnError) {
|
|
316
|
-
throw error
|
|
317
|
-
}
|
|
318
|
-
if (isStorageError(error)) {
|
|
319
|
-
return { data: null, error }
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
throw error
|
|
323
|
-
}
|
|
269
|
+
})
|
|
324
270
|
}
|
|
325
271
|
|
|
326
272
|
/**
|
|
@@ -357,24 +303,9 @@ export default class StorageBucketApi {
|
|
|
357
303
|
error: StorageError
|
|
358
304
|
}
|
|
359
305
|
> {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
`${this.url}/bucket/${id}/empty`,
|
|
364
|
-
{},
|
|
365
|
-
{ headers: this.headers }
|
|
366
|
-
)
|
|
367
|
-
return { data, error: null }
|
|
368
|
-
} catch (error) {
|
|
369
|
-
if (this.shouldThrowOnError) {
|
|
370
|
-
throw error
|
|
371
|
-
}
|
|
372
|
-
if (isStorageError(error)) {
|
|
373
|
-
return { data: null, error }
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
throw error
|
|
377
|
-
}
|
|
306
|
+
return this.handleOperation(async () => {
|
|
307
|
+
return await post(this.fetch, `${this.url}/bucket/${id}/empty`, {}, { headers: this.headers })
|
|
308
|
+
})
|
|
378
309
|
}
|
|
379
310
|
|
|
380
311
|
/**
|
|
@@ -412,24 +343,9 @@ export default class StorageBucketApi {
|
|
|
412
343
|
error: StorageError
|
|
413
344
|
}
|
|
414
345
|
> {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
`${this.url}/bucket/${id}`,
|
|
419
|
-
{},
|
|
420
|
-
{ headers: this.headers }
|
|
421
|
-
)
|
|
422
|
-
return { data, error: null }
|
|
423
|
-
} catch (error) {
|
|
424
|
-
if (this.shouldThrowOnError) {
|
|
425
|
-
throw error
|
|
426
|
-
}
|
|
427
|
-
if (isStorageError(error)) {
|
|
428
|
-
return { data: null, error }
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
throw error
|
|
432
|
-
}
|
|
346
|
+
return this.handleOperation(async () => {
|
|
347
|
+
return await remove(this.fetch, `${this.url}/bucket/${id}`, {}, { headers: this.headers })
|
|
348
|
+
})
|
|
433
349
|
}
|
|
434
350
|
|
|
435
351
|
private listBucketOptionsToQueryString(options?: ListBucketOptions): string {
|