@supabase/storage-js 2.79.1-canary.1 → 2.80.0

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.
Files changed (197) hide show
  1. package/README.md +920 -12
  2. package/dist/main/StorageClient.d.ts +28 -0
  3. package/dist/main/StorageClient.d.ts.map +1 -1
  4. package/dist/main/StorageClient.js +38 -5
  5. package/dist/main/StorageClient.js.map +1 -1
  6. package/dist/main/index.d.ts +2 -0
  7. package/dist/main/index.d.ts.map +1 -1
  8. package/dist/main/index.js +7 -17
  9. package/dist/main/index.js.map +1 -1
  10. package/dist/main/lib/constants.d.ts.map +1 -1
  11. package/dist/main/lib/constants.js +3 -1
  12. package/dist/main/lib/constants.js.map +1 -1
  13. package/dist/main/lib/fetch.d.ts.map +1 -1
  14. package/dist/main/lib/fetch.js +16 -17
  15. package/dist/main/lib/fetch.js.map +1 -1
  16. package/dist/main/lib/helpers.d.ts +1 -1
  17. package/dist/main/lib/helpers.d.ts.map +1 -1
  18. package/dist/main/lib/helpers.js +4 -57
  19. package/dist/main/lib/helpers.js.map +1 -1
  20. package/dist/main/lib/index.d.ts +1 -0
  21. package/dist/main/lib/index.d.ts.map +1 -1
  22. package/dist/main/lib/index.js +6 -18
  23. package/dist/main/lib/index.js.map +1 -1
  24. package/dist/main/lib/types.d.ts +74 -4
  25. package/dist/main/lib/types.d.ts.map +1 -1
  26. package/dist/main/lib/vectors/StorageVectorsClient.d.ts +310 -0
  27. package/dist/main/lib/vectors/StorageVectorsClient.d.ts.map +1 -0
  28. package/dist/main/lib/vectors/StorageVectorsClient.js +366 -0
  29. package/dist/main/lib/vectors/StorageVectorsClient.js.map +1 -0
  30. package/dist/main/lib/vectors/VectorBucketApi.d.ts +129 -0
  31. package/dist/main/lib/vectors/VectorBucketApi.d.ts.map +1 -0
  32. package/dist/main/lib/vectors/VectorBucketApi.js +199 -0
  33. package/dist/main/lib/vectors/VectorBucketApi.js.map +1 -0
  34. package/dist/main/lib/vectors/VectorDataApi.d.ts +221 -0
  35. package/dist/main/lib/vectors/VectorDataApi.d.ts.map +1 -0
  36. package/dist/main/lib/vectors/VectorDataApi.js +336 -0
  37. package/dist/main/lib/vectors/VectorDataApi.js.map +1 -0
  38. package/dist/main/lib/vectors/VectorIndexApi.d.ts +157 -0
  39. package/dist/main/lib/vectors/VectorIndexApi.d.ts.map +1 -0
  40. package/dist/main/lib/vectors/VectorIndexApi.js +218 -0
  41. package/dist/main/lib/vectors/VectorIndexApi.js.map +1 -0
  42. package/dist/main/lib/vectors/constants.d.ts +5 -0
  43. package/dist/main/lib/vectors/constants.d.ts.map +1 -0
  44. package/dist/main/lib/vectors/constants.js +9 -0
  45. package/dist/main/lib/vectors/constants.js.map +1 -0
  46. package/dist/main/lib/vectors/errors.d.ts +55 -0
  47. package/dist/main/lib/vectors/errors.d.ts.map +1 -0
  48. package/dist/main/lib/vectors/errors.js +76 -0
  49. package/dist/main/lib/vectors/errors.js.map +1 -0
  50. package/dist/main/lib/vectors/fetch.d.ts +57 -0
  51. package/dist/main/lib/vectors/fetch.d.ts.map +1 -0
  52. package/dist/main/lib/vectors/fetch.js +167 -0
  53. package/dist/main/lib/vectors/fetch.js.map +1 -0
  54. package/dist/main/lib/vectors/helpers.d.ts +46 -0
  55. package/dist/main/lib/vectors/helpers.d.ts.map +1 -0
  56. package/dist/main/lib/vectors/helpers.js +74 -0
  57. package/dist/main/lib/vectors/helpers.js.map +1 -0
  58. package/dist/main/lib/vectors/index.d.ts +11 -0
  59. package/dist/main/lib/vectors/index.d.ts.map +1 -0
  60. package/dist/main/lib/vectors/index.js +31 -0
  61. package/dist/main/lib/vectors/index.js.map +1 -0
  62. package/dist/main/lib/vectors/types.d.ts +277 -0
  63. package/dist/main/lib/vectors/types.d.ts.map +1 -0
  64. package/dist/main/lib/vectors/types.js +3 -0
  65. package/dist/main/lib/vectors/types.js.map +1 -0
  66. package/dist/main/lib/version.d.ts +1 -1
  67. package/dist/main/lib/version.d.ts.map +1 -1
  68. package/dist/main/lib/version.js +1 -1
  69. package/dist/main/lib/version.js.map +1 -1
  70. package/dist/main/packages/BlobDownloadBuilder.d.ts +6 -1
  71. package/dist/main/packages/BlobDownloadBuilder.d.ts.map +1 -1
  72. package/dist/main/packages/BlobDownloadBuilder.js +20 -15
  73. package/dist/main/packages/BlobDownloadBuilder.js.map +1 -1
  74. package/dist/main/packages/StorageAnalyticsApi.d.ts +123 -0
  75. package/dist/main/packages/StorageAnalyticsApi.d.ts.map +1 -0
  76. package/dist/main/packages/StorageAnalyticsApi.js +164 -0
  77. package/dist/main/packages/StorageAnalyticsApi.js.map +1 -0
  78. package/dist/main/packages/StorageBucketApi.d.ts +3 -2
  79. package/dist/main/packages/StorageBucketApi.d.ts.map +1 -1
  80. package/dist/main/packages/StorageBucketApi.js +34 -18
  81. package/dist/main/packages/StorageBucketApi.js.map +1 -1
  82. package/dist/main/packages/StorageFileApi.d.ts.map +1 -1
  83. package/dist/main/packages/StorageFileApi.js +28 -29
  84. package/dist/main/packages/StorageFileApi.js.map +1 -1
  85. package/dist/main/packages/StreamDownloadBuilder.js +2 -10
  86. package/dist/main/packages/StreamDownloadBuilder.js.map +1 -1
  87. package/dist/module/StorageClient.d.ts +28 -0
  88. package/dist/module/StorageClient.d.ts.map +1 -1
  89. package/dist/module/StorageClient.js +35 -0
  90. package/dist/module/StorageClient.js.map +1 -1
  91. package/dist/module/index.d.ts +2 -0
  92. package/dist/module/index.d.ts.map +1 -1
  93. package/dist/module/index.js +2 -0
  94. package/dist/module/index.js.map +1 -1
  95. package/dist/module/lib/constants.d.ts.map +1 -1
  96. package/dist/module/lib/constants.js +3 -1
  97. package/dist/module/lib/constants.js.map +1 -1
  98. package/dist/module/lib/fetch.d.ts.map +1 -1
  99. package/dist/module/lib/fetch.js +9 -10
  100. package/dist/module/lib/fetch.js.map +1 -1
  101. package/dist/module/lib/helpers.d.ts +1 -1
  102. package/dist/module/lib/helpers.d.ts.map +1 -1
  103. package/dist/module/lib/helpers.js +4 -24
  104. package/dist/module/lib/helpers.js.map +1 -1
  105. package/dist/module/lib/index.d.ts +1 -0
  106. package/dist/module/lib/index.d.ts.map +1 -1
  107. package/dist/module/lib/index.js +1 -0
  108. package/dist/module/lib/index.js.map +1 -1
  109. package/dist/module/lib/types.d.ts +74 -4
  110. package/dist/module/lib/types.d.ts.map +1 -1
  111. package/dist/module/lib/vectors/StorageVectorsClient.d.ts +310 -0
  112. package/dist/module/lib/vectors/StorageVectorsClient.d.ts.map +1 -0
  113. package/dist/module/lib/vectors/StorageVectorsClient.js +360 -0
  114. package/dist/module/lib/vectors/StorageVectorsClient.js.map +1 -0
  115. package/dist/module/lib/vectors/VectorBucketApi.d.ts +129 -0
  116. package/dist/module/lib/vectors/VectorBucketApi.d.ts.map +1 -0
  117. package/dist/module/lib/vectors/VectorBucketApi.js +196 -0
  118. package/dist/module/lib/vectors/VectorBucketApi.js.map +1 -0
  119. package/dist/module/lib/vectors/VectorDataApi.d.ts +221 -0
  120. package/dist/module/lib/vectors/VectorDataApi.d.ts.map +1 -0
  121. package/dist/module/lib/vectors/VectorDataApi.js +333 -0
  122. package/dist/module/lib/vectors/VectorDataApi.js.map +1 -0
  123. package/dist/module/lib/vectors/VectorIndexApi.d.ts +157 -0
  124. package/dist/module/lib/vectors/VectorIndexApi.d.ts.map +1 -0
  125. package/dist/module/lib/vectors/VectorIndexApi.js +215 -0
  126. package/dist/module/lib/vectors/VectorIndexApi.js.map +1 -0
  127. package/dist/module/lib/vectors/constants.d.ts +5 -0
  128. package/dist/module/lib/vectors/constants.d.ts.map +1 -0
  129. package/dist/module/lib/vectors/constants.js +6 -0
  130. package/dist/module/lib/vectors/constants.js.map +1 -0
  131. package/dist/module/lib/vectors/errors.d.ts +55 -0
  132. package/dist/module/lib/vectors/errors.d.ts.map +1 -0
  133. package/dist/module/lib/vectors/errors.js +69 -0
  134. package/dist/module/lib/vectors/errors.js.map +1 -0
  135. package/dist/module/lib/vectors/fetch.d.ts +57 -0
  136. package/dist/module/lib/vectors/fetch.d.ts.map +1 -0
  137. package/dist/module/lib/vectors/fetch.js +161 -0
  138. package/dist/module/lib/vectors/fetch.js.map +1 -0
  139. package/dist/module/lib/vectors/helpers.d.ts +46 -0
  140. package/dist/module/lib/vectors/helpers.d.ts.map +1 -0
  141. package/dist/module/lib/vectors/helpers.js +66 -0
  142. package/dist/module/lib/vectors/helpers.js.map +1 -0
  143. package/dist/module/lib/vectors/index.d.ts +11 -0
  144. package/dist/module/lib/vectors/index.d.ts.map +1 -0
  145. package/dist/module/lib/vectors/index.js +11 -0
  146. package/dist/module/lib/vectors/index.js.map +1 -0
  147. package/dist/module/lib/vectors/types.d.ts +277 -0
  148. package/dist/module/lib/vectors/types.d.ts.map +1 -0
  149. package/dist/module/lib/vectors/types.js +2 -0
  150. package/dist/module/lib/vectors/types.js.map +1 -0
  151. package/dist/module/lib/version.d.ts +1 -1
  152. package/dist/module/lib/version.d.ts.map +1 -1
  153. package/dist/module/lib/version.js +1 -1
  154. package/dist/module/lib/version.js.map +1 -1
  155. package/dist/module/packages/BlobDownloadBuilder.d.ts +6 -1
  156. package/dist/module/packages/BlobDownloadBuilder.d.ts.map +1 -1
  157. package/dist/module/packages/BlobDownloadBuilder.js +20 -11
  158. package/dist/module/packages/BlobDownloadBuilder.js.map +1 -1
  159. package/dist/module/packages/StorageAnalyticsApi.d.ts +123 -0
  160. package/dist/module/packages/StorageAnalyticsApi.d.ts.map +1 -0
  161. package/dist/module/packages/StorageAnalyticsApi.js +161 -0
  162. package/dist/module/packages/StorageAnalyticsApi.js.map +1 -0
  163. package/dist/module/packages/StorageBucketApi.d.ts +3 -2
  164. package/dist/module/packages/StorageBucketApi.d.ts.map +1 -1
  165. package/dist/module/packages/StorageBucketApi.js +28 -12
  166. package/dist/module/packages/StorageBucketApi.js.map +1 -1
  167. package/dist/module/packages/StorageFileApi.d.ts.map +1 -1
  168. package/dist/module/packages/StorageFileApi.js +13 -11
  169. package/dist/module/packages/StorageFileApi.js.map +1 -1
  170. package/dist/module/packages/StreamDownloadBuilder.js +1 -9
  171. package/dist/module/packages/StreamDownloadBuilder.js.map +1 -1
  172. package/dist/tsconfig.module.tsbuildinfo +1 -0
  173. package/dist/tsconfig.tsbuildinfo +1 -0
  174. package/dist/umd/supabase.js +1 -1
  175. package/package.json +6 -13
  176. package/src/StorageClient.ts +37 -0
  177. package/src/index.ts +2 -0
  178. package/src/lib/constants.ts +3 -1
  179. package/src/lib/fetch.ts +5 -1
  180. package/src/lib/helpers.ts +3 -14
  181. package/src/lib/index.ts +1 -0
  182. package/src/lib/types.ts +83 -2
  183. package/src/lib/vectors/StorageVectorsClient.ts +405 -0
  184. package/src/lib/vectors/VectorBucketApi.ts +217 -0
  185. package/src/lib/vectors/VectorDataApi.ts +341 -0
  186. package/src/lib/vectors/VectorIndexApi.ts +245 -0
  187. package/src/lib/vectors/constants.ts +5 -0
  188. package/src/lib/vectors/errors.ts +78 -0
  189. package/src/lib/vectors/fetch.ts +218 -0
  190. package/src/lib/vectors/helpers.ts +79 -0
  191. package/src/lib/vectors/index.ts +66 -0
  192. package/src/lib/vectors/types.ts +299 -0
  193. package/src/lib/version.ts +1 -1
  194. package/src/packages/BlobDownloadBuilder.ts +22 -2
  195. package/src/packages/StorageAnalyticsApi.ts +199 -0
  196. package/src/packages/StorageBucketApi.ts +29 -4
  197. package/src/packages/StorageFileApi.ts +15 -2
@@ -1,6 +1,8 @@
1
1
  import StorageFileApi from './packages/StorageFileApi'
2
2
  import StorageBucketApi from './packages/StorageBucketApi'
3
+ import StorageAnalyticsApi from './packages/StorageAnalyticsApi'
3
4
  import { Fetch } from './lib/fetch'
5
+ import { StorageVectorsClient } from './lib/vectors'
4
6
 
5
7
  export interface StorageClientOptions {
6
8
  useNewHostname?: boolean
@@ -24,4 +26,39 @@ export class StorageClient extends StorageBucketApi {
24
26
  from(id: string): StorageFileApi {
25
27
  return new StorageFileApi(this.url, this.headers, id, this.fetch)
26
28
  }
29
+
30
+ /**
31
+ * Access vector storage operations.
32
+ *
33
+ * @returns A StorageVectorsClient instance configured with the current storage settings.
34
+ */
35
+ get vectors(): StorageVectorsClient {
36
+ return new StorageVectorsClient(this.url + '/vector', {
37
+ headers: this.headers,
38
+ fetch: this.fetch,
39
+ })
40
+ }
41
+
42
+ /**
43
+ * Access analytics storage operations using Iceberg tables.
44
+ *
45
+ * @returns A StorageAnalyticsApi instance configured with the current storage settings.
46
+ * @example
47
+ * ```typescript
48
+ * const client = createClient(url, key)
49
+ * const analytics = client.storage.analytics
50
+ *
51
+ * // Create an analytics bucket
52
+ * await analytics.createBucket('my-analytics-bucket')
53
+ *
54
+ * // List all analytics buckets
55
+ * const { data: buckets } = await analytics.listBuckets()
56
+ *
57
+ * // Delete an analytics bucket
58
+ * await analytics.deleteBucket('old-analytics-bucket')
59
+ * ```
60
+ */
61
+ get analytics(): StorageAnalyticsApi {
62
+ return new StorageAnalyticsApi(this.url + '/iceberg', this.headers, this.fetch)
63
+ }
27
64
  }
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { StorageClient } from './StorageClient'
2
2
  export type { StorageClientOptions } from './StorageClient'
3
+ export { default as StorageAnalyticsApi } from './packages/StorageAnalyticsApi'
3
4
  export * from './lib/types'
4
5
  export * from './lib/errors'
6
+ export * from './lib/vectors'
@@ -1,2 +1,4 @@
1
1
  import { version } from './version'
2
- export const DEFAULT_HEADERS = { 'X-Client-Info': `storage-js/${version}` }
2
+ export const DEFAULT_HEADERS = {
3
+ 'X-Client-Info': `storage-js/${version}`,
4
+ }
package/src/lib/fetch.ts CHANGED
@@ -15,7 +15,11 @@ export interface FetchOptions {
15
15
  export type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD'
16
16
 
17
17
  const _getErrorMessage = (err: any): string =>
18
- err.msg || err.message || err.error_description || err.error || JSON.stringify(err)
18
+ err.msg ||
19
+ err.message ||
20
+ err.error_description ||
21
+ (typeof err.error === 'string' ? err.error : err.error?.message) ||
22
+ JSON.stringify(err)
19
23
 
20
24
  const handleError = async (
21
25
  error: unknown,
@@ -1,24 +1,13 @@
1
1
  type Fetch = typeof fetch
2
2
 
3
3
  export const resolveFetch = (customFetch?: Fetch): Fetch => {
4
- let _fetch: Fetch
5
4
  if (customFetch) {
6
- _fetch = customFetch
7
- } else if (typeof fetch === 'undefined') {
8
- _fetch = (...args) =>
9
- import('@supabase/node-fetch' as any).then(({ default: fetch }) => fetch(...args))
10
- } else {
11
- _fetch = fetch
5
+ return (...args) => customFetch(...args)
12
6
  }
13
- return (...args) => _fetch(...args)
7
+ return (...args) => fetch(...args)
14
8
  }
15
9
 
16
- export const resolveResponse = async (): Promise<typeof Response> => {
17
- if (typeof Response === 'undefined') {
18
- // @ts-ignore
19
- return (await import('@supabase/node-fetch' as any)).Response
20
- }
21
-
10
+ export const resolveResponse = (): typeof Response => {
22
11
  return Response
23
12
  }
24
13
 
package/src/lib/index.ts CHANGED
@@ -2,3 +2,4 @@ export * from '../packages/StorageBucketApi'
2
2
  export * from '../packages/StorageFileApi'
3
3
  export * from './types'
4
4
  export * from './constants'
5
+ export * from './vectors'
package/src/lib/types.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { StorageError } from './errors'
2
2
 
3
+ /**
4
+ * Type of storage bucket
5
+ * - STANDARD: Regular file storage buckets
6
+ * - ANALYTICS: Iceberg table-based buckets for analytical workloads
7
+ */
3
8
  export type BucketType = 'STANDARD' | 'ANALYTICS'
4
9
 
5
10
  export interface Bucket {
@@ -14,6 +19,31 @@ export interface Bucket {
14
19
  public: boolean
15
20
  }
16
21
 
22
+ export interface ListBucketOptions {
23
+ limit?: number
24
+ offset?: number
25
+ sortColumn?: 'id' | 'name' | 'created_at' | 'updated_at'
26
+ sortOrder?: 'asc' | 'desc'
27
+ search?: string
28
+ }
29
+
30
+ /**
31
+ * Represents an Analytics Bucket using Apache Iceberg table format.
32
+ * Analytics buckets are optimized for analytical queries and data processing.
33
+ */
34
+ export interface AnalyticBucket {
35
+ /** Unique identifier for the bucket */
36
+ id: string
37
+ /** Bucket type - always 'ANALYTICS' for analytics buckets */
38
+ type: 'ANALYTICS'
39
+ /** Storage format used (e.g., 'iceberg') */
40
+ format: string
41
+ /** ISO 8601 timestamp of bucket creation */
42
+ created_at: string
43
+ /** ISO 8601 timestamp of last update */
44
+ updated_at: string
45
+ }
46
+
17
47
  export interface FileObject {
18
48
  name: string
19
49
  bucket_id: string
@@ -21,6 +51,7 @@ export interface FileObject {
21
51
  id: string
22
52
  updated_at: string
23
53
  created_at: string
54
+ /** @deprecated */
24
55
  last_accessed_at: string
25
56
  metadata: Record<string, any>
26
57
  buckets: Bucket
@@ -33,6 +64,7 @@ export interface FileObjectV2 {
33
64
  bucket_id: string
34
65
  updated_at: string
35
66
  created_at: string
67
+ /** @deprecated */
36
68
  last_accessed_at: string
37
69
  size?: number
38
70
  cache_control?: string
@@ -103,17 +135,66 @@ export interface SearchOptions {
103
135
  search?: string
104
136
  }
105
137
 
138
+ export interface SortByV2 {
139
+ column: 'name' | 'updated_at' | 'created_at'
140
+ order?: 'asc' | 'desc'
141
+ }
142
+
106
143
  export interface SearchV2Options {
144
+ /**
145
+ * The number of files you want to be returned.
146
+ * @default 1000
147
+ */
107
148
  limit?: number
149
+
150
+ /**
151
+ * The prefix search string to filter files by.
152
+ */
108
153
  prefix?: string
154
+
155
+ /**
156
+ * The cursor used for pagination. Pass the value received from nextCursor of the previous request.
157
+ */
109
158
  cursor?: string
159
+
160
+ /**
161
+ * Whether to emulate a hierarchical listing of objects using delimiters.
162
+ *
163
+ * - When `false` (default), all objects are listed as flat key/value pairs.
164
+ * - When `true`, the response groups objects by delimiter, making it appear
165
+ * like a file/folder hierarchy.
166
+ *
167
+ * @default false
168
+ */
110
169
  with_delimiter?: boolean
170
+
171
+ /**
172
+ * The column and order to sort by
173
+ * @default 'name asc'
174
+ */
175
+ sortBy?: SortByV2
176
+ }
177
+
178
+ export interface SearchV2Object {
179
+ id: string
180
+ key: string
181
+ name: string
182
+ updated_at: string
183
+ created_at: string
184
+ metadata: Record<string, any>
185
+ /**
186
+ * @deprecated
187
+ */
188
+ last_accessed_at: string
111
189
  }
112
190
 
191
+ export type SearchV2Folder = Omit<SearchV2Object, 'id' | 'metadata' | 'last_accessed_at'>
192
+
113
193
  export interface SearchV2Result {
114
194
  hasNext: boolean
115
- folders: { name: string }[]
116
- objects: FileObject[]
195
+ folders: SearchV2Folder[]
196
+ objects: SearchV2Object[]
197
+ nextCursor?: string
117
198
  }
118
199
 
119
200
  export interface FetchParameters {
@@ -0,0 +1,405 @@
1
+ import VectorIndexApi, { CreateIndexOptions } from './VectorIndexApi'
2
+ import VectorDataApi from './VectorDataApi'
3
+ import { Fetch } from './fetch'
4
+ import VectorBucketApi from './VectorBucketApi'
5
+ import {
6
+ DeleteVectorsOptions,
7
+ GetVectorsOptions,
8
+ ListIndexesOptions,
9
+ ListVectorsOptions,
10
+ PutVectorsOptions,
11
+ QueryVectorsOptions,
12
+ } from './types'
13
+
14
+ /**
15
+ * Configuration options for the Storage Vectors client
16
+ */
17
+ export interface StorageVectorsClientOptions {
18
+ /**
19
+ * Custom headers to include in all requests
20
+ */
21
+ headers?: { [key: string]: string }
22
+ /**
23
+ * Custom fetch implementation (optional)
24
+ * Useful for testing or custom request handling
25
+ */
26
+ fetch?: Fetch
27
+ }
28
+
29
+ /**
30
+ * Main client for interacting with S3 Vectors API
31
+ * Provides access to bucket, index, and vector data operations
32
+ *
33
+ * **Usage Patterns:**
34
+ *
35
+ * 1. **Via StorageClient (recommended for most use cases):**
36
+ * ```typescript
37
+ * import { StorageClient } from '@supabase/storage-js'
38
+ *
39
+ * const storageClient = new StorageClient(url, headers)
40
+ * const vectors = storageClient.vectors
41
+ *
42
+ * // Use vector operations
43
+ * await vectors.createBucket('embeddings-prod')
44
+ * const bucket = vectors.from('embeddings-prod')
45
+ * await bucket.createIndex({ ... })
46
+ * ```
47
+ *
48
+ * 2. **Standalone (for vector-only applications):**
49
+ * ```typescript
50
+ * import { StorageVectorsClient } from '@supabase/storage-js'
51
+ *
52
+ * const vectorsClient = new StorageVectorsClient('https://api.example.com', {
53
+ * headers: { 'Authorization': 'Bearer token' }
54
+ * })
55
+ *
56
+ * // Access bucket operations
57
+ * await vectorsClient.createBucket('embeddings-prod')
58
+ *
59
+ * // Access index operations via buckets
60
+ * const bucket = vectorsClient.from('embeddings-prod')
61
+ * await bucket.createIndex({
62
+ * indexName: 'documents',
63
+ * dataType: 'float32',
64
+ * dimension: 1536,
65
+ * distanceMetric: 'cosine'
66
+ * })
67
+ *
68
+ * // Access vector operations via index
69
+ * const index = bucket.index('documents')
70
+ * await index.putVectors({
71
+ * vectors: [
72
+ * { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } }
73
+ * ]
74
+ * })
75
+ *
76
+ * // Query similar vectors
77
+ * const { data } = await index.queryVectors({
78
+ * queryVector: { float32: [...] },
79
+ * topK: 5,
80
+ * returnDistance: true
81
+ * })
82
+ * ```
83
+ */
84
+ export class StorageVectorsClient extends VectorBucketApi {
85
+ constructor(url: string, options: StorageVectorsClientOptions = {}) {
86
+ super(url, options.headers || {}, options.fetch)
87
+ }
88
+
89
+ /**
90
+ * Access operations for a specific vector bucket
91
+ * Returns a scoped client for index and vector operations within the bucket
92
+ *
93
+ * @param vectorBucketName - Name of the vector bucket
94
+ * @returns Bucket-scoped client with index and vector operations
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const bucket = client.bucket('embeddings-prod')
99
+ *
100
+ * // Create an index in this bucket
101
+ * await bucket.createIndex({
102
+ * indexName: 'documents-openai',
103
+ * dataType: 'float32',
104
+ * dimension: 1536,
105
+ * distanceMetric: 'cosine'
106
+ * })
107
+ *
108
+ * // List indexes in this bucket
109
+ * const { data } = await bucket.listIndexes()
110
+ * ```
111
+ */
112
+ from(vectorBucketName: string): VectorBucketScope {
113
+ return new VectorBucketScope(this.url, this.headers, vectorBucketName, this.fetch)
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Scoped client for operations within a specific vector bucket
119
+ * Provides index management and access to vector operations
120
+ */
121
+ export class VectorBucketScope extends VectorIndexApi {
122
+ private vectorBucketName: string
123
+
124
+ constructor(
125
+ url: string,
126
+ headers: { [key: string]: string },
127
+ vectorBucketName: string,
128
+ fetch?: Fetch
129
+ ) {
130
+ super(url, headers, fetch)
131
+ this.vectorBucketName = vectorBucketName
132
+ }
133
+
134
+ /**
135
+ * Creates a new vector index in this bucket
136
+ * Convenience method that automatically includes the bucket name
137
+ *
138
+ * @param options - Index configuration (vectorBucketName is automatically set)
139
+ * @returns Promise with empty response on success or error
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const bucket = client.bucket('embeddings-prod')
144
+ * await bucket.createIndex({
145
+ * indexName: 'documents-openai',
146
+ * dataType: 'float32',
147
+ * dimension: 1536,
148
+ * distanceMetric: 'cosine',
149
+ * metadataConfiguration: {
150
+ * nonFilterableMetadataKeys: ['raw_text']
151
+ * }
152
+ * })
153
+ * ```
154
+ */
155
+ override async createIndex(options: Omit<CreateIndexOptions, 'vectorBucketName'>) {
156
+ return super.createIndex({
157
+ ...options,
158
+ vectorBucketName: this.vectorBucketName,
159
+ })
160
+ }
161
+
162
+ /**
163
+ * Lists indexes in this bucket
164
+ * Convenience method that automatically includes the bucket name
165
+ *
166
+ * @param options - Listing options (vectorBucketName is automatically set)
167
+ * @returns Promise with list of indexes or error
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const bucket = client.bucket('embeddings-prod')
172
+ * const { data } = await bucket.listIndexes({ prefix: 'documents-' })
173
+ * ```
174
+ */
175
+ override async listIndexes(options: Omit<ListIndexesOptions, 'vectorBucketName'> = {}) {
176
+ return super.listIndexes({
177
+ ...options,
178
+ vectorBucketName: this.vectorBucketName,
179
+ })
180
+ }
181
+
182
+ /**
183
+ * Retrieves metadata for a specific index in this bucket
184
+ * Convenience method that automatically includes the bucket name
185
+ *
186
+ * @param indexName - Name of the index to retrieve
187
+ * @returns Promise with index metadata or error
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * const bucket = client.bucket('embeddings-prod')
192
+ * const { data } = await bucket.getIndex('documents-openai')
193
+ * console.log('Dimension:', data?.index.dimension)
194
+ * ```
195
+ */
196
+ override async getIndex(indexName: string) {
197
+ return super.getIndex(this.vectorBucketName, indexName)
198
+ }
199
+
200
+ /**
201
+ * Deletes an index from this bucket
202
+ * Convenience method that automatically includes the bucket name
203
+ *
204
+ * @param indexName - Name of the index to delete
205
+ * @returns Promise with empty response on success or error
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * const bucket = client.bucket('embeddings-prod')
210
+ * await bucket.deleteIndex('old-index')
211
+ * ```
212
+ */
213
+ override async deleteIndex(indexName: string) {
214
+ return super.deleteIndex(this.vectorBucketName, indexName)
215
+ }
216
+
217
+ /**
218
+ * Access operations for a specific index within this bucket
219
+ * Returns a scoped client for vector data operations
220
+ *
221
+ * @param indexName - Name of the index
222
+ * @returns Index-scoped client with vector data operations
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * const index = client.bucket('embeddings-prod').index('documents-openai')
227
+ *
228
+ * // Insert vectors
229
+ * await index.putVectors({
230
+ * vectors: [
231
+ * { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } }
232
+ * ]
233
+ * })
234
+ *
235
+ * // Query similar vectors
236
+ * const { data } = await index.queryVectors({
237
+ * queryVector: { float32: [...] },
238
+ * topK: 5
239
+ * })
240
+ * ```
241
+ */
242
+ index(indexName: string): VectorIndexScope {
243
+ return new VectorIndexScope(
244
+ this.url,
245
+ this.headers,
246
+ this.vectorBucketName,
247
+ indexName,
248
+ this.fetch
249
+ )
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Scoped client for operations within a specific vector index
255
+ * Provides vector data operations (put, get, list, query, delete)
256
+ */
257
+ export class VectorIndexScope extends VectorDataApi {
258
+ private vectorBucketName: string
259
+ private indexName: string
260
+
261
+ constructor(
262
+ url: string,
263
+ headers: { [key: string]: string },
264
+ vectorBucketName: string,
265
+ indexName: string,
266
+ fetch?: Fetch
267
+ ) {
268
+ super(url, headers, fetch)
269
+ this.vectorBucketName = vectorBucketName
270
+ this.indexName = indexName
271
+ }
272
+
273
+ /**
274
+ * Inserts or updates vectors in this index
275
+ * Convenience method that automatically includes bucket and index names
276
+ *
277
+ * @param options - Vector insertion options (bucket and index names automatically set)
278
+ * @returns Promise with empty response on success or error
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * const index = client.bucket('embeddings-prod').index('documents-openai')
283
+ * await index.putVectors({
284
+ * vectors: [
285
+ * {
286
+ * key: 'doc-1',
287
+ * data: { float32: [0.1, 0.2, ...] },
288
+ * metadata: { title: 'Introduction', page: 1 }
289
+ * }
290
+ * ]
291
+ * })
292
+ * ```
293
+ */
294
+ override async putVectors(options: Omit<PutVectorsOptions, 'vectorBucketName' | 'indexName'>) {
295
+ return super.putVectors({
296
+ ...options,
297
+ vectorBucketName: this.vectorBucketName,
298
+ indexName: this.indexName,
299
+ })
300
+ }
301
+
302
+ /**
303
+ * Retrieves vectors by keys from this index
304
+ * Convenience method that automatically includes bucket and index names
305
+ *
306
+ * @param options - Vector retrieval options (bucket and index names automatically set)
307
+ * @returns Promise with array of vectors or error
308
+ *
309
+ * @example
310
+ * ```typescript
311
+ * const index = client.bucket('embeddings-prod').index('documents-openai')
312
+ * const { data } = await index.getVectors({
313
+ * keys: ['doc-1', 'doc-2'],
314
+ * returnMetadata: true
315
+ * })
316
+ * ```
317
+ */
318
+ override async getVectors(options: Omit<GetVectorsOptions, 'vectorBucketName' | 'indexName'>) {
319
+ return super.getVectors({
320
+ ...options,
321
+ vectorBucketName: this.vectorBucketName,
322
+ indexName: this.indexName,
323
+ })
324
+ }
325
+
326
+ /**
327
+ * Lists vectors in this index with pagination
328
+ * Convenience method that automatically includes bucket and index names
329
+ *
330
+ * @param options - Listing options (bucket and index names automatically set)
331
+ * @returns Promise with array of vectors and pagination token
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * const index = client.bucket('embeddings-prod').index('documents-openai')
336
+ * const { data } = await index.listVectors({
337
+ * maxResults: 500,
338
+ * returnMetadata: true
339
+ * })
340
+ * ```
341
+ */
342
+ override async listVectors(
343
+ options: Omit<ListVectorsOptions, 'vectorBucketName' | 'indexName'> = {}
344
+ ) {
345
+ return super.listVectors({
346
+ ...options,
347
+ vectorBucketName: this.vectorBucketName,
348
+ indexName: this.indexName,
349
+ })
350
+ }
351
+
352
+ /**
353
+ * Queries for similar vectors in this index
354
+ * Convenience method that automatically includes bucket and index names
355
+ *
356
+ * @param options - Query options (bucket and index names automatically set)
357
+ * @returns Promise with array of similar vectors ordered by distance
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * const index = client.bucket('embeddings-prod').index('documents-openai')
362
+ * const { data } = await index.queryVectors({
363
+ * queryVector: { float32: [0.1, 0.2, ...] },
364
+ * topK: 5,
365
+ * filter: { category: 'technical' },
366
+ * returnDistance: true,
367
+ * returnMetadata: true
368
+ * })
369
+ * ```
370
+ */
371
+ override async queryVectors(
372
+ options: Omit<QueryVectorsOptions, 'vectorBucketName' | 'indexName'>
373
+ ) {
374
+ return super.queryVectors({
375
+ ...options,
376
+ vectorBucketName: this.vectorBucketName,
377
+ indexName: this.indexName,
378
+ })
379
+ }
380
+
381
+ /**
382
+ * Deletes vectors by keys from this index
383
+ * Convenience method that automatically includes bucket and index names
384
+ *
385
+ * @param options - Deletion options (bucket and index names automatically set)
386
+ * @returns Promise with empty response on success or error
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * const index = client.bucket('embeddings-prod').index('documents-openai')
391
+ * await index.deleteVectors({
392
+ * keys: ['doc-1', 'doc-2', 'doc-3']
393
+ * })
394
+ * ```
395
+ */
396
+ override async deleteVectors(
397
+ options: Omit<DeleteVectorsOptions, 'vectorBucketName' | 'indexName'>
398
+ ) {
399
+ return super.deleteVectors({
400
+ ...options,
401
+ vectorBucketName: this.vectorBucketName,
402
+ indexName: this.indexName,
403
+ })
404
+ }
405
+ }