@supabase/storage-js 2.75.1 → 2.75.2-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +917 -12
- package/dist/main/StorageClient.d.ts +28 -0
- package/dist/main/StorageClient.d.ts.map +1 -1
- package/dist/main/StorageClient.js +38 -5
- package/dist/main/StorageClient.js.map +1 -1
- package/dist/main/index.d.ts +2 -0
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +7 -17
- package/dist/main/index.js.map +1 -1
- package/dist/main/lib/constants.d.ts.map +1 -1
- package/dist/main/lib/constants.js +3 -1
- package/dist/main/lib/constants.js.map +1 -1
- package/dist/main/lib/fetch.js +8 -16
- package/dist/main/lib/fetch.js.map +1 -1
- package/dist/main/lib/helpers.js +4 -45
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/index.d.ts +1 -0
- package/dist/main/lib/index.d.ts.map +1 -1
- package/dist/main/lib/index.js +6 -18
- package/dist/main/lib/index.js.map +1 -1
- package/dist/main/lib/types.d.ts +36 -4
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/vectors/StorageVectorsClient.d.ts +310 -0
- package/dist/main/lib/vectors/StorageVectorsClient.d.ts.map +1 -0
- package/dist/main/lib/vectors/StorageVectorsClient.js +366 -0
- package/dist/main/lib/vectors/StorageVectorsClient.js.map +1 -0
- package/dist/main/lib/vectors/VectorBucketApi.d.ts +129 -0
- package/dist/main/lib/vectors/VectorBucketApi.d.ts.map +1 -0
- package/dist/main/lib/vectors/VectorBucketApi.js +199 -0
- package/dist/main/lib/vectors/VectorBucketApi.js.map +1 -0
- package/dist/main/lib/vectors/VectorDataApi.d.ts +221 -0
- package/dist/main/lib/vectors/VectorDataApi.d.ts.map +1 -0
- package/dist/main/lib/vectors/VectorDataApi.js +336 -0
- package/dist/main/lib/vectors/VectorDataApi.js.map +1 -0
- package/dist/main/lib/vectors/VectorIndexApi.d.ts +157 -0
- package/dist/main/lib/vectors/VectorIndexApi.d.ts.map +1 -0
- package/dist/main/lib/vectors/VectorIndexApi.js +218 -0
- package/dist/main/lib/vectors/VectorIndexApi.js.map +1 -0
- package/dist/main/lib/vectors/constants.d.ts +5 -0
- package/dist/main/lib/vectors/constants.d.ts.map +1 -0
- package/dist/main/lib/vectors/constants.js +9 -0
- package/dist/main/lib/vectors/constants.js.map +1 -0
- package/dist/main/lib/vectors/errors.d.ts +55 -0
- package/dist/main/lib/vectors/errors.d.ts.map +1 -0
- package/dist/main/lib/vectors/errors.js +76 -0
- package/dist/main/lib/vectors/errors.js.map +1 -0
- package/dist/main/lib/vectors/fetch.d.ts +57 -0
- package/dist/main/lib/vectors/fetch.d.ts.map +1 -0
- package/dist/main/lib/vectors/fetch.js +167 -0
- package/dist/main/lib/vectors/fetch.js.map +1 -0
- package/dist/main/lib/vectors/helpers.d.ts +49 -0
- package/dist/main/lib/vectors/helpers.d.ts.map +1 -0
- package/dist/main/lib/vectors/helpers.js +89 -0
- package/dist/main/lib/vectors/helpers.js.map +1 -0
- package/dist/main/lib/vectors/index.d.ts +11 -0
- package/dist/main/lib/vectors/index.d.ts.map +1 -0
- package/dist/main/lib/vectors/index.js +31 -0
- package/dist/main/lib/vectors/index.js.map +1 -0
- package/dist/main/lib/vectors/types.d.ts +277 -0
- package/dist/main/lib/vectors/types.d.ts.map +1 -0
- package/dist/main/lib/vectors/types.js +3 -0
- package/dist/main/lib/vectors/types.js.map +1 -0
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.d.ts.map +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/lib/version.js.map +1 -1
- package/dist/main/packages/BlobDownloadBuilder.js +3 -14
- package/dist/main/packages/BlobDownloadBuilder.js.map +1 -1
- package/dist/main/packages/StorageAnalyticsApi.d.ts +123 -0
- package/dist/main/packages/StorageAnalyticsApi.d.ts.map +1 -0
- package/dist/main/packages/StorageAnalyticsApi.js +168 -0
- package/dist/main/packages/StorageAnalyticsApi.js.map +1 -0
- package/dist/main/packages/StorageBucketApi.js +7 -15
- package/dist/main/packages/StorageBucketApi.js.map +1 -1
- package/dist/main/packages/StorageFileApi.js +16 -27
- package/dist/main/packages/StorageFileApi.js.map +1 -1
- package/dist/main/packages/StreamDownloadBuilder.js +2 -10
- package/dist/main/packages/StreamDownloadBuilder.js.map +1 -1
- package/dist/module/StorageClient.d.ts +28 -0
- package/dist/module/StorageClient.d.ts.map +1 -1
- package/dist/module/StorageClient.js +35 -0
- package/dist/module/StorageClient.js.map +1 -1
- package/dist/module/index.d.ts +2 -0
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +2 -0
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/constants.d.ts.map +1 -1
- package/dist/module/lib/constants.js +3 -1
- package/dist/module/lib/constants.js.map +1 -1
- package/dist/module/lib/fetch.js +1 -9
- package/dist/module/lib/fetch.js.map +1 -1
- package/dist/module/lib/helpers.js +1 -9
- package/dist/module/lib/helpers.js.map +1 -1
- package/dist/module/lib/index.d.ts +1 -0
- package/dist/module/lib/index.d.ts.map +1 -1
- package/dist/module/lib/index.js +1 -0
- package/dist/module/lib/index.js.map +1 -1
- package/dist/module/lib/types.d.ts +36 -4
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/vectors/StorageVectorsClient.d.ts +310 -0
- package/dist/module/lib/vectors/StorageVectorsClient.d.ts.map +1 -0
- package/dist/module/lib/vectors/StorageVectorsClient.js +360 -0
- package/dist/module/lib/vectors/StorageVectorsClient.js.map +1 -0
- package/dist/module/lib/vectors/VectorBucketApi.d.ts +129 -0
- package/dist/module/lib/vectors/VectorBucketApi.d.ts.map +1 -0
- package/dist/module/lib/vectors/VectorBucketApi.js +196 -0
- package/dist/module/lib/vectors/VectorBucketApi.js.map +1 -0
- package/dist/module/lib/vectors/VectorDataApi.d.ts +221 -0
- package/dist/module/lib/vectors/VectorDataApi.d.ts.map +1 -0
- package/dist/module/lib/vectors/VectorDataApi.js +333 -0
- package/dist/module/lib/vectors/VectorDataApi.js.map +1 -0
- package/dist/module/lib/vectors/VectorIndexApi.d.ts +157 -0
- package/dist/module/lib/vectors/VectorIndexApi.d.ts.map +1 -0
- package/dist/module/lib/vectors/VectorIndexApi.js +215 -0
- package/dist/module/lib/vectors/VectorIndexApi.js.map +1 -0
- package/dist/module/lib/vectors/constants.d.ts +5 -0
- package/dist/module/lib/vectors/constants.d.ts.map +1 -0
- package/dist/module/lib/vectors/constants.js +6 -0
- package/dist/module/lib/vectors/constants.js.map +1 -0
- package/dist/module/lib/vectors/errors.d.ts +55 -0
- package/dist/module/lib/vectors/errors.d.ts.map +1 -0
- package/dist/module/lib/vectors/errors.js +69 -0
- package/dist/module/lib/vectors/errors.js.map +1 -0
- package/dist/module/lib/vectors/fetch.d.ts +57 -0
- package/dist/module/lib/vectors/fetch.d.ts.map +1 -0
- package/dist/module/lib/vectors/fetch.js +161 -0
- package/dist/module/lib/vectors/fetch.js.map +1 -0
- package/dist/module/lib/vectors/helpers.d.ts +49 -0
- package/dist/module/lib/vectors/helpers.d.ts.map +1 -0
- package/dist/module/lib/vectors/helpers.js +81 -0
- package/dist/module/lib/vectors/helpers.js.map +1 -0
- package/dist/module/lib/vectors/index.d.ts +11 -0
- package/dist/module/lib/vectors/index.d.ts.map +1 -0
- package/dist/module/lib/vectors/index.js +11 -0
- package/dist/module/lib/vectors/index.js.map +1 -0
- package/dist/module/lib/vectors/types.d.ts +277 -0
- package/dist/module/lib/vectors/types.d.ts.map +1 -0
- package/dist/module/lib/vectors/types.js +2 -0
- package/dist/module/lib/vectors/types.js.map +1 -0
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.d.ts.map +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/lib/version.js.map +1 -1
- package/dist/module/packages/BlobDownloadBuilder.js +1 -9
- package/dist/module/packages/BlobDownloadBuilder.js.map +1 -1
- package/dist/module/packages/StorageAnalyticsApi.d.ts +123 -0
- package/dist/module/packages/StorageAnalyticsApi.d.ts.map +1 -0
- package/dist/module/packages/StorageAnalyticsApi.js +165 -0
- package/dist/module/packages/StorageAnalyticsApi.js.map +1 -0
- package/dist/module/packages/StorageBucketApi.js +1 -9
- package/dist/module/packages/StorageBucketApi.js.map +1 -1
- package/dist/module/packages/StorageFileApi.js +1 -9
- package/dist/module/packages/StorageFileApi.js.map +1 -1
- package/dist/module/packages/StreamDownloadBuilder.js +1 -9
- package/dist/module/packages/StreamDownloadBuilder.js.map +1 -1
- package/dist/tsconfig.module.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/umd/supabase.js +1 -1
- package/package.json +2 -2
- package/src/StorageClient.ts +37 -0
- package/src/index.ts +2 -0
- package/src/lib/constants.ts +3 -1
- package/src/lib/index.ts +1 -0
- package/src/lib/types.ts +39 -2
- package/src/lib/vectors/StorageVectorsClient.ts +405 -0
- package/src/lib/vectors/VectorBucketApi.ts +217 -0
- package/src/lib/vectors/VectorDataApi.ts +341 -0
- package/src/lib/vectors/VectorIndexApi.ts +245 -0
- package/src/lib/vectors/constants.ts +5 -0
- package/src/lib/vectors/errors.ts +78 -0
- package/src/lib/vectors/fetch.ts +218 -0
- package/src/lib/vectors/helpers.ts +93 -0
- package/src/lib/vectors/index.ts +66 -0
- package/src/lib/vectors/types.ts +299 -0
- package/src/lib/version.ts +1 -1
- package/src/packages/StorageAnalyticsApi.ts +202 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { DEFAULT_HEADERS } from '../lib/constants'
|
|
2
|
+
import { isStorageError, StorageError } from '../lib/errors'
|
|
3
|
+
import { Fetch, get, post, remove } from '../lib/fetch'
|
|
4
|
+
import { resolveFetch } from '../lib/helpers'
|
|
5
|
+
import { AnalyticBucket, Bucket } from '../lib/types'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* API class for managing Analytics Buckets using Iceberg tables
|
|
9
|
+
* Provides methods for creating, listing, and deleting analytics buckets
|
|
10
|
+
*/
|
|
11
|
+
export default class StorageAnalyticsApi {
|
|
12
|
+
protected url: string
|
|
13
|
+
protected headers: { [key: string]: string }
|
|
14
|
+
protected fetch: Fetch
|
|
15
|
+
protected shouldThrowOnError = false
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new StorageAnalyticsApi instance
|
|
19
|
+
* @param url - The base URL for the storage API
|
|
20
|
+
* @param headers - HTTP headers to include in requests
|
|
21
|
+
* @param fetch - Optional custom fetch implementation
|
|
22
|
+
*/
|
|
23
|
+
constructor(url: string, headers: { [key: string]: string } = {}, fetch?: Fetch) {
|
|
24
|
+
this.url = url.replace(/\/$/, '')
|
|
25
|
+
this.headers = { ...DEFAULT_HEADERS, ...headers }
|
|
26
|
+
this.fetch = resolveFetch(fetch)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Enable throwing errors instead of returning them in the response
|
|
31
|
+
* When enabled, failed operations will throw instead of returning { data: null, error }
|
|
32
|
+
*
|
|
33
|
+
* @returns This instance for method chaining
|
|
34
|
+
*/
|
|
35
|
+
public throwOnError(): this {
|
|
36
|
+
this.shouldThrowOnError = true
|
|
37
|
+
return this
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new analytics bucket using Iceberg tables
|
|
42
|
+
* Analytics buckets are optimized for analytical queries and data processing
|
|
43
|
+
*
|
|
44
|
+
* @param name A unique name for the bucket you are creating
|
|
45
|
+
* @returns Promise with newly created bucket name or error
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const { data, error } = await storage.analytics.createBucket('analytics-data')
|
|
50
|
+
* if (error) {
|
|
51
|
+
* console.error('Failed to create analytics bucket:', error.message)
|
|
52
|
+
* } else {
|
|
53
|
+
* console.log('Created bucket:', data.name)
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
async createBucket(name: string): Promise<
|
|
58
|
+
| {
|
|
59
|
+
data: AnalyticBucket
|
|
60
|
+
error: null
|
|
61
|
+
}
|
|
62
|
+
| {
|
|
63
|
+
data: null
|
|
64
|
+
error: StorageError
|
|
65
|
+
}
|
|
66
|
+
> {
|
|
67
|
+
try {
|
|
68
|
+
const data = await post(this.fetch, `${this.url}/bucket`, { name }, { headers: this.headers })
|
|
69
|
+
return { data, error: null }
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (this.shouldThrowOnError) {
|
|
72
|
+
throw error
|
|
73
|
+
}
|
|
74
|
+
if (isStorageError(error)) {
|
|
75
|
+
return { data: null, error }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
throw error
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves the details of all Analytics Storage buckets within an existing project
|
|
84
|
+
* Only returns buckets of type 'ANALYTICS'
|
|
85
|
+
*
|
|
86
|
+
* @param options Query parameters for listing buckets
|
|
87
|
+
* @param options.limit Maximum number of buckets to return
|
|
88
|
+
* @param options.offset Number of buckets to skip
|
|
89
|
+
* @param options.sortColumn Column to sort by ('id', 'name', 'created_at', 'updated_at')
|
|
90
|
+
* @param options.sortOrder Sort order ('asc' or 'desc')
|
|
91
|
+
* @param options.search Search term to filter bucket names
|
|
92
|
+
* @returns Promise with list of analytics buckets or error
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const { data, error } = await storage.analytics.listBuckets({
|
|
97
|
+
* limit: 10,
|
|
98
|
+
* offset: 0,
|
|
99
|
+
* sortColumn: 'created_at',
|
|
100
|
+
* sortOrder: 'desc',
|
|
101
|
+
* search: 'analytics'
|
|
102
|
+
* })
|
|
103
|
+
* if (data) {
|
|
104
|
+
* console.log('Found analytics buckets:', data.length)
|
|
105
|
+
* data.forEach(bucket => console.log(`- ${bucket.name}`))
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
async listBuckets(options?: {
|
|
110
|
+
limit?: number
|
|
111
|
+
offset?: number
|
|
112
|
+
sortColumn?: 'id' | 'name' | 'created_at' | 'updated_at'
|
|
113
|
+
sortOrder?: 'asc' | 'desc'
|
|
114
|
+
search?: string
|
|
115
|
+
}): Promise<
|
|
116
|
+
| {
|
|
117
|
+
data: AnalyticBucket[]
|
|
118
|
+
error: null
|
|
119
|
+
}
|
|
120
|
+
| {
|
|
121
|
+
data: null
|
|
122
|
+
error: StorageError
|
|
123
|
+
}
|
|
124
|
+
> {
|
|
125
|
+
try {
|
|
126
|
+
// Build query string from options
|
|
127
|
+
const queryParams = new URLSearchParams()
|
|
128
|
+
if (options?.limit !== undefined) queryParams.set('limit', options.limit.toString())
|
|
129
|
+
if (options?.offset !== undefined) queryParams.set('offset', options.offset.toString())
|
|
130
|
+
if (options?.sortColumn) queryParams.set('sortColumn', options.sortColumn)
|
|
131
|
+
if (options?.sortOrder) queryParams.set('sortOrder', options.sortOrder)
|
|
132
|
+
if (options?.search) queryParams.set('search', options.search)
|
|
133
|
+
|
|
134
|
+
const queryString = queryParams.toString()
|
|
135
|
+
const url = queryString ? `${this.url}/bucket?${queryString}` : `${this.url}/bucket`
|
|
136
|
+
|
|
137
|
+
const data = await get(this.fetch, url, { headers: this.headers })
|
|
138
|
+
// Filter to only return analytics buckets
|
|
139
|
+
const analyticsBuckets = Array.isArray(data)
|
|
140
|
+
? data.filter((bucket: Bucket) => bucket.type === 'ANALYTICS')
|
|
141
|
+
: []
|
|
142
|
+
return { data: analyticsBuckets, error: null }
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (this.shouldThrowOnError) {
|
|
145
|
+
throw error
|
|
146
|
+
}
|
|
147
|
+
if (isStorageError(error)) {
|
|
148
|
+
return { data: null, error }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
throw error
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Deletes an existing analytics bucket
|
|
157
|
+
* A bucket can't be deleted with existing objects inside it
|
|
158
|
+
* You must first empty the bucket before deletion
|
|
159
|
+
*
|
|
160
|
+
* @param bucketId The unique identifier of the bucket you would like to delete
|
|
161
|
+
* @returns Promise with success message or error
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const { data, error } = await analyticsApi.deleteBucket('old-analytics-bucket')
|
|
166
|
+
* if (error) {
|
|
167
|
+
* console.error('Failed to delete bucket:', error.message)
|
|
168
|
+
* } else {
|
|
169
|
+
* console.log('Bucket deleted successfully:', data.message)
|
|
170
|
+
* }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
async deleteBucket(bucketId: string): Promise<
|
|
174
|
+
| {
|
|
175
|
+
data: { message: string }
|
|
176
|
+
error: null
|
|
177
|
+
}
|
|
178
|
+
| {
|
|
179
|
+
data: null
|
|
180
|
+
error: StorageError
|
|
181
|
+
}
|
|
182
|
+
> {
|
|
183
|
+
try {
|
|
184
|
+
const data = await remove(
|
|
185
|
+
this.fetch,
|
|
186
|
+
`${this.url}/bucket/${bucketId}`,
|
|
187
|
+
{},
|
|
188
|
+
{ headers: this.headers }
|
|
189
|
+
)
|
|
190
|
+
return { data, error: null }
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (this.shouldThrowOnError) {
|
|
193
|
+
throw error
|
|
194
|
+
}
|
|
195
|
+
if (isStorageError(error)) {
|
|
196
|
+
return { data: null, error }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
throw error
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|