@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
package/src/lib/index.ts
CHANGED
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,23 @@ export interface Bucket {
|
|
|
14
19
|
public: boolean
|
|
15
20
|
}
|
|
16
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Represents an Analytics Bucket using Apache Iceberg table format.
|
|
24
|
+
* Analytics buckets are optimized for analytical queries and data processing.
|
|
25
|
+
*/
|
|
26
|
+
export interface AnalyticBucket {
|
|
27
|
+
/** Unique identifier for the bucket */
|
|
28
|
+
id: string
|
|
29
|
+
/** Bucket type - always 'ANALYTICS' for analytics buckets */
|
|
30
|
+
type: 'ANALYTICS'
|
|
31
|
+
/** Storage format used (e.g., 'iceberg') */
|
|
32
|
+
format: string
|
|
33
|
+
/** ISO 8601 timestamp of bucket creation */
|
|
34
|
+
created_at: string
|
|
35
|
+
/** ISO 8601 timestamp of last update */
|
|
36
|
+
updated_at: string
|
|
37
|
+
}
|
|
38
|
+
|
|
17
39
|
export interface FileObject {
|
|
18
40
|
name: string
|
|
19
41
|
bucket_id: string
|
|
@@ -143,10 +165,25 @@ export interface SearchV2Options {
|
|
|
143
165
|
sortBy?: SortByV2
|
|
144
166
|
}
|
|
145
167
|
|
|
168
|
+
export interface SearchV2Object {
|
|
169
|
+
id: string
|
|
170
|
+
key: string
|
|
171
|
+
name: string
|
|
172
|
+
updated_at: string
|
|
173
|
+
created_at: string
|
|
174
|
+
metadata: Record<string, any>
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated
|
|
177
|
+
*/
|
|
178
|
+
last_accessed_at: string
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export type SearchV2Folder = Omit<SearchV2Object, 'id' | 'metadata' | 'last_accessed_at'>
|
|
182
|
+
|
|
146
183
|
export interface SearchV2Result {
|
|
147
184
|
hasNext: boolean
|
|
148
|
-
folders:
|
|
149
|
-
objects:
|
|
185
|
+
folders: SearchV2Folder[]
|
|
186
|
+
objects: SearchV2Object[]
|
|
150
187
|
nextCursor?: string
|
|
151
188
|
}
|
|
152
189
|
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { DEFAULT_HEADERS } from './constants'
|
|
2
|
+
import { isStorageVectorsError } from './errors'
|
|
3
|
+
import { Fetch, post } from './fetch'
|
|
4
|
+
import { resolveFetch } from './helpers'
|
|
5
|
+
import {
|
|
6
|
+
ApiResponse,
|
|
7
|
+
VectorBucket,
|
|
8
|
+
ListVectorBucketsOptions,
|
|
9
|
+
ListVectorBucketsResponse,
|
|
10
|
+
} from './types'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* API class for managing Vector Buckets
|
|
14
|
+
* Provides methods for creating, reading, listing, and deleting vector buckets
|
|
15
|
+
*/
|
|
16
|
+
export default class VectorBucketApi {
|
|
17
|
+
protected url: string
|
|
18
|
+
protected headers: { [key: string]: string }
|
|
19
|
+
protected fetch: Fetch
|
|
20
|
+
protected shouldThrowOnError = false
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new VectorBucketApi instance
|
|
24
|
+
* @param url - The base URL for the storage vectors API
|
|
25
|
+
* @param headers - HTTP headers to include in requests
|
|
26
|
+
* @param fetch - Optional custom fetch implementation
|
|
27
|
+
*/
|
|
28
|
+
constructor(url: string, headers: { [key: string]: string } = {}, fetch?: Fetch) {
|
|
29
|
+
this.url = url.replace(/\/$/, '')
|
|
30
|
+
this.headers = { ...DEFAULT_HEADERS, ...headers }
|
|
31
|
+
this.fetch = resolveFetch(fetch)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Enable throwing errors instead of returning them in the response
|
|
36
|
+
* When enabled, failed operations will throw instead of returning { data: null, error }
|
|
37
|
+
*
|
|
38
|
+
* @returns This instance for method chaining
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const client = new VectorBucketApi(url, headers)
|
|
42
|
+
* client.throwOnError()
|
|
43
|
+
* const { data } = await client.createBucket('my-bucket') // throws on error
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
public throwOnError(): this {
|
|
47
|
+
this.shouldThrowOnError = true
|
|
48
|
+
return this
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new vector bucket
|
|
53
|
+
* Vector buckets are containers for vector indexes and their data
|
|
54
|
+
*
|
|
55
|
+
* @param vectorBucketName - Unique name for the vector bucket
|
|
56
|
+
* @returns Promise with empty response on success or error
|
|
57
|
+
*
|
|
58
|
+
* @throws {StorageVectorsApiError} With code:
|
|
59
|
+
* - `S3VectorConflictException` if bucket already exists (HTTP 409)
|
|
60
|
+
* - `S3VectorMaxBucketsExceeded` if quota exceeded (HTTP 400)
|
|
61
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const { data, error } = await client.createBucket('embeddings-prod')
|
|
66
|
+
* if (error) {
|
|
67
|
+
* console.error('Failed to create bucket:', error.message)
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
async createBucket(vectorBucketName: string): Promise<ApiResponse<undefined>> {
|
|
72
|
+
try {
|
|
73
|
+
const data = await post(
|
|
74
|
+
this.fetch,
|
|
75
|
+
`${this.url}/CreateVectorBucket`,
|
|
76
|
+
{ vectorBucketName },
|
|
77
|
+
{ headers: this.headers }
|
|
78
|
+
)
|
|
79
|
+
return { data: data || {}, error: null }
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (this.shouldThrowOnError) {
|
|
82
|
+
throw error
|
|
83
|
+
}
|
|
84
|
+
if (isStorageVectorsError(error)) {
|
|
85
|
+
return { data: null, error }
|
|
86
|
+
}
|
|
87
|
+
throw error
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Retrieves metadata for a specific vector bucket
|
|
93
|
+
* Returns bucket configuration including encryption settings and creation time
|
|
94
|
+
*
|
|
95
|
+
* @param vectorBucketName - Name of the vector bucket to retrieve
|
|
96
|
+
* @returns Promise with bucket metadata or error
|
|
97
|
+
*
|
|
98
|
+
* @throws {StorageVectorsApiError} With code:
|
|
99
|
+
* - `S3VectorNotFoundException` if bucket doesn't exist (HTTP 404)
|
|
100
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const { data, error } = await client.getBucket('embeddings-prod')
|
|
105
|
+
* if (data) {
|
|
106
|
+
* console.log('Bucket created at:', new Date(data.vectorBucket.creationTime! * 1000))
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
async getBucket(
|
|
111
|
+
vectorBucketName: string
|
|
112
|
+
): Promise<ApiResponse<{ vectorBucket: VectorBucket }>> {
|
|
113
|
+
try {
|
|
114
|
+
const data = await post(
|
|
115
|
+
this.fetch,
|
|
116
|
+
`${this.url}/GetVectorBucket`,
|
|
117
|
+
{ vectorBucketName },
|
|
118
|
+
{ headers: this.headers }
|
|
119
|
+
)
|
|
120
|
+
return { data, error: null }
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (this.shouldThrowOnError) {
|
|
123
|
+
throw error
|
|
124
|
+
}
|
|
125
|
+
if (isStorageVectorsError(error)) {
|
|
126
|
+
return { data: null, error }
|
|
127
|
+
}
|
|
128
|
+
throw error
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Lists vector buckets with optional filtering and pagination
|
|
134
|
+
* Supports prefix-based filtering and paginated results
|
|
135
|
+
*
|
|
136
|
+
* @param options - Listing options
|
|
137
|
+
* @param options.prefix - Filter buckets by name prefix
|
|
138
|
+
* @param options.maxResults - Maximum results per page (default: 100)
|
|
139
|
+
* @param options.nextToken - Pagination token from previous response
|
|
140
|
+
* @returns Promise with list of buckets and pagination token
|
|
141
|
+
*
|
|
142
|
+
* @throws {StorageVectorsApiError} With code:
|
|
143
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* // List all buckets with prefix 'prod-'
|
|
148
|
+
* const { data, error } = await client.listBuckets({ prefix: 'prod-' })
|
|
149
|
+
* if (data) {
|
|
150
|
+
* console.log('Found buckets:', data.buckets.length)
|
|
151
|
+
* // Fetch next page if available
|
|
152
|
+
* if (data.nextToken) {
|
|
153
|
+
* const next = await client.listBuckets({ nextToken: data.nextToken })
|
|
154
|
+
* }
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
async listBuckets(
|
|
159
|
+
options: ListVectorBucketsOptions = {}
|
|
160
|
+
): Promise<ApiResponse<ListVectorBucketsResponse>> {
|
|
161
|
+
try {
|
|
162
|
+
const data = await post(this.fetch, `${this.url}/ListVectorBuckets`, options, {
|
|
163
|
+
headers: this.headers,
|
|
164
|
+
})
|
|
165
|
+
return { data, error: null }
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (this.shouldThrowOnError) {
|
|
168
|
+
throw error
|
|
169
|
+
}
|
|
170
|
+
if (isStorageVectorsError(error)) {
|
|
171
|
+
return { data: null, error }
|
|
172
|
+
}
|
|
173
|
+
throw error
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Deletes a vector bucket
|
|
179
|
+
* Bucket must be empty before deletion (all indexes must be removed first)
|
|
180
|
+
*
|
|
181
|
+
* @param vectorBucketName - Name of the vector bucket to delete
|
|
182
|
+
* @returns Promise with empty response on success or error
|
|
183
|
+
*
|
|
184
|
+
* @throws {StorageVectorsApiError} With code:
|
|
185
|
+
* - `S3VectorBucketNotEmpty` if bucket contains indexes (HTTP 400)
|
|
186
|
+
* - `S3VectorNotFoundException` if bucket doesn't exist (HTTP 404)
|
|
187
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* // Delete all indexes first, then delete bucket
|
|
192
|
+
* const { error } = await client.deleteBucket('old-bucket')
|
|
193
|
+
* if (error?.statusCode === 'S3VectorBucketNotEmpty') {
|
|
194
|
+
* console.error('Must delete all indexes first')
|
|
195
|
+
* }
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
async deleteBucket(vectorBucketName: string): Promise<ApiResponse<undefined>> {
|
|
199
|
+
try {
|
|
200
|
+
const data = await post(
|
|
201
|
+
this.fetch,
|
|
202
|
+
`${this.url}/DeleteVectorBucket`,
|
|
203
|
+
{ vectorBucketName },
|
|
204
|
+
{ headers: this.headers }
|
|
205
|
+
)
|
|
206
|
+
return { data: data || {}, error: null }
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (this.shouldThrowOnError) {
|
|
209
|
+
throw error
|
|
210
|
+
}
|
|
211
|
+
if (isStorageVectorsError(error)) {
|
|
212
|
+
return { data: null, error }
|
|
213
|
+
}
|
|
214
|
+
throw error
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|