@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,360 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import VectorIndexApi from './VectorIndexApi';
|
|
3
|
+
import VectorDataApi from './VectorDataApi';
|
|
4
|
+
import VectorBucketApi from './VectorBucketApi';
|
|
5
|
+
/**
|
|
6
|
+
* Main client for interacting with S3 Vectors API
|
|
7
|
+
* Provides access to bucket, index, and vector data operations
|
|
8
|
+
*
|
|
9
|
+
* **Usage Patterns:**
|
|
10
|
+
*
|
|
11
|
+
* 1. **Via StorageClient (recommended for most use cases):**
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { StorageClient } from '@supabase/storage-js'
|
|
14
|
+
*
|
|
15
|
+
* const storageClient = new StorageClient(url, headers)
|
|
16
|
+
* const vectors = storageClient.vectors
|
|
17
|
+
*
|
|
18
|
+
* // Use vector operations
|
|
19
|
+
* await vectors.createBucket('embeddings-prod')
|
|
20
|
+
* const bucket = vectors.from('embeddings-prod')
|
|
21
|
+
* await bucket.createIndex({ ... })
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* 2. **Standalone (for vector-only applications):**
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { StorageVectorsClient } from '@supabase/storage-js'
|
|
27
|
+
*
|
|
28
|
+
* const vectorsClient = new StorageVectorsClient('https://api.example.com', {
|
|
29
|
+
* headers: { 'Authorization': 'Bearer token' }
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* // Access bucket operations
|
|
33
|
+
* await vectorsClient.createBucket('embeddings-prod')
|
|
34
|
+
*
|
|
35
|
+
* // Access index operations via buckets
|
|
36
|
+
* const bucket = vectorsClient.from('embeddings-prod')
|
|
37
|
+
* await bucket.createIndex({
|
|
38
|
+
* indexName: 'documents',
|
|
39
|
+
* dataType: 'float32',
|
|
40
|
+
* dimension: 1536,
|
|
41
|
+
* distanceMetric: 'cosine'
|
|
42
|
+
* })
|
|
43
|
+
*
|
|
44
|
+
* // Access vector operations via index
|
|
45
|
+
* const index = bucket.index('documents')
|
|
46
|
+
* await index.putVectors({
|
|
47
|
+
* vectors: [
|
|
48
|
+
* { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } }
|
|
49
|
+
* ]
|
|
50
|
+
* })
|
|
51
|
+
*
|
|
52
|
+
* // Query similar vectors
|
|
53
|
+
* const { data } = await index.queryVectors({
|
|
54
|
+
* queryVector: { float32: [...] },
|
|
55
|
+
* topK: 5,
|
|
56
|
+
* returnDistance: true
|
|
57
|
+
* })
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export class StorageVectorsClient extends VectorBucketApi {
|
|
61
|
+
constructor(url, options = {}) {
|
|
62
|
+
super(url, options.headers || {}, options.fetch);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Access operations for a specific vector bucket
|
|
66
|
+
* Returns a scoped client for index and vector operations within the bucket
|
|
67
|
+
*
|
|
68
|
+
* @param vectorBucketName - Name of the vector bucket
|
|
69
|
+
* @returns Bucket-scoped client with index and vector operations
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const bucket = client.bucket('embeddings-prod')
|
|
74
|
+
*
|
|
75
|
+
* // Create an index in this bucket
|
|
76
|
+
* await bucket.createIndex({
|
|
77
|
+
* indexName: 'documents-openai',
|
|
78
|
+
* dataType: 'float32',
|
|
79
|
+
* dimension: 1536,
|
|
80
|
+
* distanceMetric: 'cosine'
|
|
81
|
+
* })
|
|
82
|
+
*
|
|
83
|
+
* // List indexes in this bucket
|
|
84
|
+
* const { data } = await bucket.listIndexes()
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
from(vectorBucketName) {
|
|
88
|
+
return new VectorBucketScope(this.url, this.headers, vectorBucketName, this.fetch);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Scoped client for operations within a specific vector bucket
|
|
93
|
+
* Provides index management and access to vector operations
|
|
94
|
+
*/
|
|
95
|
+
export class VectorBucketScope extends VectorIndexApi {
|
|
96
|
+
constructor(url, headers, vectorBucketName, fetch) {
|
|
97
|
+
super(url, headers, fetch);
|
|
98
|
+
this.vectorBucketName = vectorBucketName;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a new vector index in this bucket
|
|
102
|
+
* Convenience method that automatically includes the bucket name
|
|
103
|
+
*
|
|
104
|
+
* @param options - Index configuration (vectorBucketName is automatically set)
|
|
105
|
+
* @returns Promise with empty response on success or error
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const bucket = client.bucket('embeddings-prod')
|
|
110
|
+
* await bucket.createIndex({
|
|
111
|
+
* indexName: 'documents-openai',
|
|
112
|
+
* dataType: 'float32',
|
|
113
|
+
* dimension: 1536,
|
|
114
|
+
* distanceMetric: 'cosine',
|
|
115
|
+
* metadataConfiguration: {
|
|
116
|
+
* nonFilterableMetadataKeys: ['raw_text']
|
|
117
|
+
* }
|
|
118
|
+
* })
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
createIndex(options) {
|
|
122
|
+
const _super = Object.create(null, {
|
|
123
|
+
createIndex: { get: () => super.createIndex }
|
|
124
|
+
});
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
return _super.createIndex.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName }));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Lists indexes in this bucket
|
|
131
|
+
* Convenience method that automatically includes the bucket name
|
|
132
|
+
*
|
|
133
|
+
* @param options - Listing options (vectorBucketName is automatically set)
|
|
134
|
+
* @returns Promise with list of indexes or error
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const bucket = client.bucket('embeddings-prod')
|
|
139
|
+
* const { data } = await bucket.listIndexes({ prefix: 'documents-' })
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
listIndexes() {
|
|
143
|
+
const _super = Object.create(null, {
|
|
144
|
+
listIndexes: { get: () => super.listIndexes }
|
|
145
|
+
});
|
|
146
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
147
|
+
return _super.listIndexes.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName }));
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Retrieves metadata for a specific index in this bucket
|
|
152
|
+
* Convenience method that automatically includes the bucket name
|
|
153
|
+
*
|
|
154
|
+
* @param indexName - Name of the index to retrieve
|
|
155
|
+
* @returns Promise with index metadata or error
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const bucket = client.bucket('embeddings-prod')
|
|
160
|
+
* const { data } = await bucket.getIndex('documents-openai')
|
|
161
|
+
* console.log('Dimension:', data?.index.dimension)
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
getIndex(indexName) {
|
|
165
|
+
const _super = Object.create(null, {
|
|
166
|
+
getIndex: { get: () => super.getIndex }
|
|
167
|
+
});
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
return _super.getIndex.call(this, this.vectorBucketName, indexName);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Deletes an index from this bucket
|
|
174
|
+
* Convenience method that automatically includes the bucket name
|
|
175
|
+
*
|
|
176
|
+
* @param indexName - Name of the index to delete
|
|
177
|
+
* @returns Promise with empty response on success or error
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const bucket = client.bucket('embeddings-prod')
|
|
182
|
+
* await bucket.deleteIndex('old-index')
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
deleteIndex(indexName) {
|
|
186
|
+
const _super = Object.create(null, {
|
|
187
|
+
deleteIndex: { get: () => super.deleteIndex }
|
|
188
|
+
});
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
return _super.deleteIndex.call(this, this.vectorBucketName, indexName);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Access operations for a specific index within this bucket
|
|
195
|
+
* Returns a scoped client for vector data operations
|
|
196
|
+
*
|
|
197
|
+
* @param indexName - Name of the index
|
|
198
|
+
* @returns Index-scoped client with vector data operations
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const index = client.bucket('embeddings-prod').index('documents-openai')
|
|
203
|
+
*
|
|
204
|
+
* // Insert vectors
|
|
205
|
+
* await index.putVectors({
|
|
206
|
+
* vectors: [
|
|
207
|
+
* { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } }
|
|
208
|
+
* ]
|
|
209
|
+
* })
|
|
210
|
+
*
|
|
211
|
+
* // Query similar vectors
|
|
212
|
+
* const { data } = await index.queryVectors({
|
|
213
|
+
* queryVector: { float32: [...] },
|
|
214
|
+
* topK: 5
|
|
215
|
+
* })
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
index(indexName) {
|
|
219
|
+
return new VectorIndexScope(this.url, this.headers, this.vectorBucketName, indexName, this.fetch);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Scoped client for operations within a specific vector index
|
|
224
|
+
* Provides vector data operations (put, get, list, query, delete)
|
|
225
|
+
*/
|
|
226
|
+
export class VectorIndexScope extends VectorDataApi {
|
|
227
|
+
constructor(url, headers, vectorBucketName, indexName, fetch) {
|
|
228
|
+
super(url, headers, fetch);
|
|
229
|
+
this.vectorBucketName = vectorBucketName;
|
|
230
|
+
this.indexName = indexName;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Inserts or updates vectors in this index
|
|
234
|
+
* Convenience method that automatically includes bucket and index names
|
|
235
|
+
*
|
|
236
|
+
* @param options - Vector insertion options (bucket and index names automatically set)
|
|
237
|
+
* @returns Promise with empty response on success or error
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const index = client.bucket('embeddings-prod').index('documents-openai')
|
|
242
|
+
* await index.putVectors({
|
|
243
|
+
* vectors: [
|
|
244
|
+
* {
|
|
245
|
+
* key: 'doc-1',
|
|
246
|
+
* data: { float32: [0.1, 0.2, ...] },
|
|
247
|
+
* metadata: { title: 'Introduction', page: 1 }
|
|
248
|
+
* }
|
|
249
|
+
* ]
|
|
250
|
+
* })
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
putVectors(options) {
|
|
254
|
+
const _super = Object.create(null, {
|
|
255
|
+
putVectors: { get: () => super.putVectors }
|
|
256
|
+
});
|
|
257
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
258
|
+
return _super.putVectors.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName, indexName: this.indexName }));
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Retrieves vectors by keys from this index
|
|
263
|
+
* Convenience method that automatically includes bucket and index names
|
|
264
|
+
*
|
|
265
|
+
* @param options - Vector retrieval options (bucket and index names automatically set)
|
|
266
|
+
* @returns Promise with array of vectors or error
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* const index = client.bucket('embeddings-prod').index('documents-openai')
|
|
271
|
+
* const { data } = await index.getVectors({
|
|
272
|
+
* keys: ['doc-1', 'doc-2'],
|
|
273
|
+
* returnMetadata: true
|
|
274
|
+
* })
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
getVectors(options) {
|
|
278
|
+
const _super = Object.create(null, {
|
|
279
|
+
getVectors: { get: () => super.getVectors }
|
|
280
|
+
});
|
|
281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
return _super.getVectors.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName, indexName: this.indexName }));
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Lists vectors in this index with pagination
|
|
287
|
+
* Convenience method that automatically includes bucket and index names
|
|
288
|
+
*
|
|
289
|
+
* @param options - Listing options (bucket and index names automatically set)
|
|
290
|
+
* @returns Promise with array of vectors and pagination token
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```typescript
|
|
294
|
+
* const index = client.bucket('embeddings-prod').index('documents-openai')
|
|
295
|
+
* const { data } = await index.listVectors({
|
|
296
|
+
* maxResults: 500,
|
|
297
|
+
* returnMetadata: true
|
|
298
|
+
* })
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
listVectors() {
|
|
302
|
+
const _super = Object.create(null, {
|
|
303
|
+
listVectors: { get: () => super.listVectors }
|
|
304
|
+
});
|
|
305
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
306
|
+
return _super.listVectors.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName, indexName: this.indexName }));
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Queries for similar vectors in this index
|
|
311
|
+
* Convenience method that automatically includes bucket and index names
|
|
312
|
+
*
|
|
313
|
+
* @param options - Query options (bucket and index names automatically set)
|
|
314
|
+
* @returns Promise with array of similar vectors ordered by distance
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* const index = client.bucket('embeddings-prod').index('documents-openai')
|
|
319
|
+
* const { data } = await index.queryVectors({
|
|
320
|
+
* queryVector: { float32: [0.1, 0.2, ...] },
|
|
321
|
+
* topK: 5,
|
|
322
|
+
* filter: { category: 'technical' },
|
|
323
|
+
* returnDistance: true,
|
|
324
|
+
* returnMetadata: true
|
|
325
|
+
* })
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
queryVectors(options) {
|
|
329
|
+
const _super = Object.create(null, {
|
|
330
|
+
queryVectors: { get: () => super.queryVectors }
|
|
331
|
+
});
|
|
332
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
333
|
+
return _super.queryVectors.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName, indexName: this.indexName }));
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Deletes vectors by keys from this index
|
|
338
|
+
* Convenience method that automatically includes bucket and index names
|
|
339
|
+
*
|
|
340
|
+
* @param options - Deletion options (bucket and index names automatically set)
|
|
341
|
+
* @returns Promise with empty response on success or error
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```typescript
|
|
345
|
+
* const index = client.bucket('embeddings-prod').index('documents-openai')
|
|
346
|
+
* await index.deleteVectors({
|
|
347
|
+
* keys: ['doc-1', 'doc-2', 'doc-3']
|
|
348
|
+
* })
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
deleteVectors(options) {
|
|
352
|
+
const _super = Object.create(null, {
|
|
353
|
+
deleteVectors: { get: () => super.deleteVectors }
|
|
354
|
+
});
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
return _super.deleteVectors.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName, indexName: this.indexName }));
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
//# sourceMappingURL=StorageVectorsClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageVectorsClient.js","sourceRoot":"","sources":["../../../../src/lib/vectors/StorageVectorsClient.ts"],"names":[],"mappings":";AAAA,OAAO,cAAsC,MAAM,kBAAkB,CAAA;AACrE,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAE3C,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAyB/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,OAAO,oBAAqB,SAAQ,eAAe;IACvD,YAAY,GAAW,EAAE,UAAuC,EAAE;QAChE,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAClD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,CAAC,gBAAwB;QAC3B,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAA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
import { ApiResponse, VectorBucket, ListVectorBucketsOptions, ListVectorBucketsResponse } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* API class for managing Vector Buckets
|
|
5
|
+
* Provides methods for creating, reading, listing, and deleting vector buckets
|
|
6
|
+
*/
|
|
7
|
+
export default class VectorBucketApi {
|
|
8
|
+
protected url: string;
|
|
9
|
+
protected headers: {
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
};
|
|
12
|
+
protected fetch: Fetch;
|
|
13
|
+
protected shouldThrowOnError: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new VectorBucketApi instance
|
|
16
|
+
* @param url - The base URL for the storage vectors API
|
|
17
|
+
* @param headers - HTTP headers to include in requests
|
|
18
|
+
* @param fetch - Optional custom fetch implementation
|
|
19
|
+
*/
|
|
20
|
+
constructor(url: string, headers?: {
|
|
21
|
+
[key: string]: string;
|
|
22
|
+
}, fetch?: Fetch);
|
|
23
|
+
/**
|
|
24
|
+
* Enable throwing errors instead of returning them in the response
|
|
25
|
+
* When enabled, failed operations will throw instead of returning { data: null, error }
|
|
26
|
+
*
|
|
27
|
+
* @returns This instance for method chaining
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const client = new VectorBucketApi(url, headers)
|
|
31
|
+
* client.throwOnError()
|
|
32
|
+
* const { data } = await client.createBucket('my-bucket') // throws on error
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
throwOnError(): this;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new vector bucket
|
|
38
|
+
* Vector buckets are containers for vector indexes and their data
|
|
39
|
+
*
|
|
40
|
+
* @param vectorBucketName - Unique name for the vector bucket
|
|
41
|
+
* @returns Promise with empty response on success or error
|
|
42
|
+
*
|
|
43
|
+
* @throws {StorageVectorsApiError} With code:
|
|
44
|
+
* - `S3VectorConflictException` if bucket already exists (HTTP 409)
|
|
45
|
+
* - `S3VectorMaxBucketsExceeded` if quota exceeded (HTTP 400)
|
|
46
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const { data, error } = await client.createBucket('embeddings-prod')
|
|
51
|
+
* if (error) {
|
|
52
|
+
* console.error('Failed to create bucket:', error.message)
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
createBucket(vectorBucketName: string): Promise<ApiResponse<undefined>>;
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves metadata for a specific vector bucket
|
|
59
|
+
* Returns bucket configuration including encryption settings and creation time
|
|
60
|
+
*
|
|
61
|
+
* @param vectorBucketName - Name of the vector bucket to retrieve
|
|
62
|
+
* @returns Promise with bucket metadata or error
|
|
63
|
+
*
|
|
64
|
+
* @throws {StorageVectorsApiError} With code:
|
|
65
|
+
* - `S3VectorNotFoundException` if bucket doesn't exist (HTTP 404)
|
|
66
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const { data, error } = await client.getBucket('embeddings-prod')
|
|
71
|
+
* if (data) {
|
|
72
|
+
* console.log('Bucket created at:', new Date(data.vectorBucket.creationTime! * 1000))
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
getBucket(vectorBucketName: string): Promise<ApiResponse<{
|
|
77
|
+
vectorBucket: VectorBucket;
|
|
78
|
+
}>>;
|
|
79
|
+
/**
|
|
80
|
+
* Lists vector buckets with optional filtering and pagination
|
|
81
|
+
* Supports prefix-based filtering and paginated results
|
|
82
|
+
*
|
|
83
|
+
* @param options - Listing options
|
|
84
|
+
* @param options.prefix - Filter buckets by name prefix
|
|
85
|
+
* @param options.maxResults - Maximum results per page (default: 100)
|
|
86
|
+
* @param options.nextToken - Pagination token from previous response
|
|
87
|
+
* @returns Promise with list of buckets and pagination token
|
|
88
|
+
*
|
|
89
|
+
* @throws {StorageVectorsApiError} With code:
|
|
90
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // List all buckets with prefix 'prod-'
|
|
95
|
+
* const { data, error } = await client.listBuckets({ prefix: 'prod-' })
|
|
96
|
+
* if (data) {
|
|
97
|
+
* console.log('Found buckets:', data.buckets.length)
|
|
98
|
+
* // Fetch next page if available
|
|
99
|
+
* if (data.nextToken) {
|
|
100
|
+
* const next = await client.listBuckets({ nextToken: data.nextToken })
|
|
101
|
+
* }
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
listBuckets(options?: ListVectorBucketsOptions): Promise<ApiResponse<ListVectorBucketsResponse>>;
|
|
106
|
+
/**
|
|
107
|
+
* Deletes a vector bucket
|
|
108
|
+
* Bucket must be empty before deletion (all indexes must be removed first)
|
|
109
|
+
*
|
|
110
|
+
* @param vectorBucketName - Name of the vector bucket to delete
|
|
111
|
+
* @returns Promise with empty response on success or error
|
|
112
|
+
*
|
|
113
|
+
* @throws {StorageVectorsApiError} With code:
|
|
114
|
+
* - `S3VectorBucketNotEmpty` if bucket contains indexes (HTTP 400)
|
|
115
|
+
* - `S3VectorNotFoundException` if bucket doesn't exist (HTTP 404)
|
|
116
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* // Delete all indexes first, then delete bucket
|
|
121
|
+
* const { error } = await client.deleteBucket('old-bucket')
|
|
122
|
+
* if (error?.statusCode === 'S3VectorBucketNotEmpty') {
|
|
123
|
+
* console.error('Must delete all indexes first')
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
deleteBucket(vectorBucketName: string): Promise<ApiResponse<undefined>>;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=VectorBucketApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { DEFAULT_HEADERS } from './constants';
|
|
3
|
+
import { isStorageVectorsError } from './errors';
|
|
4
|
+
import { post } from './fetch';
|
|
5
|
+
import { resolveFetch } from './helpers';
|
|
6
|
+
/**
|
|
7
|
+
* API class for managing Vector Buckets
|
|
8
|
+
* Provides methods for creating, reading, listing, and deleting vector buckets
|
|
9
|
+
*/
|
|
10
|
+
export default class VectorBucketApi {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new VectorBucketApi instance
|
|
13
|
+
* @param url - The base URL for the storage vectors API
|
|
14
|
+
* @param headers - HTTP headers to include in requests
|
|
15
|
+
* @param fetch - Optional custom fetch implementation
|
|
16
|
+
*/
|
|
17
|
+
constructor(url, headers = {}, fetch) {
|
|
18
|
+
this.shouldThrowOnError = false;
|
|
19
|
+
this.url = url.replace(/\/$/, '');
|
|
20
|
+
this.headers = Object.assign(Object.assign({}, DEFAULT_HEADERS), headers);
|
|
21
|
+
this.fetch = resolveFetch(fetch);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Enable throwing errors instead of returning them in the response
|
|
25
|
+
* When enabled, failed operations will throw instead of returning { data: null, error }
|
|
26
|
+
*
|
|
27
|
+
* @returns This instance for method chaining
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const client = new VectorBucketApi(url, headers)
|
|
31
|
+
* client.throwOnError()
|
|
32
|
+
* const { data } = await client.createBucket('my-bucket') // throws on error
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
throwOnError() {
|
|
36
|
+
this.shouldThrowOnError = true;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new vector bucket
|
|
41
|
+
* Vector buckets are containers for vector indexes and their data
|
|
42
|
+
*
|
|
43
|
+
* @param vectorBucketName - Unique name for the vector bucket
|
|
44
|
+
* @returns Promise with empty response on success or error
|
|
45
|
+
*
|
|
46
|
+
* @throws {StorageVectorsApiError} With code:
|
|
47
|
+
* - `S3VectorConflictException` if bucket already exists (HTTP 409)
|
|
48
|
+
* - `S3VectorMaxBucketsExceeded` if quota exceeded (HTTP 400)
|
|
49
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const { data, error } = await client.createBucket('embeddings-prod')
|
|
54
|
+
* if (error) {
|
|
55
|
+
* console.error('Failed to create bucket:', error.message)
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
createBucket(vectorBucketName) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
try {
|
|
62
|
+
const data = yield post(this.fetch, `${this.url}/CreateVectorBucket`, { vectorBucketName }, { headers: this.headers });
|
|
63
|
+
return { data: data || {}, error: null };
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (this.shouldThrowOnError) {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
if (isStorageVectorsError(error)) {
|
|
70
|
+
return { data: null, error };
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves metadata for a specific vector bucket
|
|
78
|
+
* Returns bucket configuration including encryption settings and creation time
|
|
79
|
+
*
|
|
80
|
+
* @param vectorBucketName - Name of the vector bucket to retrieve
|
|
81
|
+
* @returns Promise with bucket metadata or error
|
|
82
|
+
*
|
|
83
|
+
* @throws {StorageVectorsApiError} With code:
|
|
84
|
+
* - `S3VectorNotFoundException` if bucket doesn't exist (HTTP 404)
|
|
85
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const { data, error } = await client.getBucket('embeddings-prod')
|
|
90
|
+
* if (data) {
|
|
91
|
+
* console.log('Bucket created at:', new Date(data.vectorBucket.creationTime! * 1000))
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
getBucket(vectorBucketName) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
try {
|
|
98
|
+
const data = yield post(this.fetch, `${this.url}/GetVectorBucket`, { vectorBucketName }, { headers: this.headers });
|
|
99
|
+
return { data, error: null };
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (this.shouldThrowOnError) {
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
if (isStorageVectorsError(error)) {
|
|
106
|
+
return { data: null, error };
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Lists vector buckets with optional filtering and pagination
|
|
114
|
+
* Supports prefix-based filtering and paginated results
|
|
115
|
+
*
|
|
116
|
+
* @param options - Listing options
|
|
117
|
+
* @param options.prefix - Filter buckets by name prefix
|
|
118
|
+
* @param options.maxResults - Maximum results per page (default: 100)
|
|
119
|
+
* @param options.nextToken - Pagination token from previous response
|
|
120
|
+
* @returns Promise with list of buckets and pagination token
|
|
121
|
+
*
|
|
122
|
+
* @throws {StorageVectorsApiError} With code:
|
|
123
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* // List all buckets with prefix 'prod-'
|
|
128
|
+
* const { data, error } = await client.listBuckets({ prefix: 'prod-' })
|
|
129
|
+
* if (data) {
|
|
130
|
+
* console.log('Found buckets:', data.buckets.length)
|
|
131
|
+
* // Fetch next page if available
|
|
132
|
+
* if (data.nextToken) {
|
|
133
|
+
* const next = await client.listBuckets({ nextToken: data.nextToken })
|
|
134
|
+
* }
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
listBuckets() {
|
|
139
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
140
|
+
try {
|
|
141
|
+
const data = yield post(this.fetch, `${this.url}/ListVectorBuckets`, options, {
|
|
142
|
+
headers: this.headers,
|
|
143
|
+
});
|
|
144
|
+
return { data, error: null };
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (this.shouldThrowOnError) {
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
if (isStorageVectorsError(error)) {
|
|
151
|
+
return { data: null, error };
|
|
152
|
+
}
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Deletes a vector bucket
|
|
159
|
+
* Bucket must be empty before deletion (all indexes must be removed first)
|
|
160
|
+
*
|
|
161
|
+
* @param vectorBucketName - Name of the vector bucket to delete
|
|
162
|
+
* @returns Promise with empty response on success or error
|
|
163
|
+
*
|
|
164
|
+
* @throws {StorageVectorsApiError} With code:
|
|
165
|
+
* - `S3VectorBucketNotEmpty` if bucket contains indexes (HTTP 400)
|
|
166
|
+
* - `S3VectorNotFoundException` if bucket doesn't exist (HTTP 404)
|
|
167
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* // Delete all indexes first, then delete bucket
|
|
172
|
+
* const { error } = await client.deleteBucket('old-bucket')
|
|
173
|
+
* if (error?.statusCode === 'S3VectorBucketNotEmpty') {
|
|
174
|
+
* console.error('Must delete all indexes first')
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
deleteBucket(vectorBucketName) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
try {
|
|
181
|
+
const data = yield post(this.fetch, `${this.url}/DeleteVectorBucket`, { vectorBucketName }, { headers: this.headers });
|
|
182
|
+
return { data: data || {}, error: null };
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (this.shouldThrowOnError) {
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
if (isStorageVectorsError(error)) {
|
|
189
|
+
return { data: null, error };
|
|
190
|
+
}
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=VectorBucketApi.js.map
|