@supabase/storage-js 2.91.1 → 2.91.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/index.cjs +476 -865
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +1441 -1491
  4. package/dist/index.d.cts.map +1 -1
  5. package/dist/index.d.mts +1441 -1491
  6. package/dist/index.d.mts.map +1 -1
  7. package/dist/index.mjs +477 -861
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/umd/supabase.js +1 -1
  10. package/package.json +1 -1
  11. package/src/StorageClient.ts +2 -2
  12. package/src/index.ts +15 -2
  13. package/src/lib/common/BaseApiClient.ts +90 -0
  14. package/src/lib/common/errors.ts +144 -0
  15. package/src/lib/common/fetch.ts +286 -0
  16. package/src/lib/{helpers.ts → common/helpers.ts} +71 -17
  17. package/src/lib/types.ts +304 -1
  18. package/src/lib/version.ts +1 -1
  19. package/src/packages/BlobDownloadBuilder.ts +1 -1
  20. package/src/packages/StorageAnalyticsClient.ts +17 -68
  21. package/src/packages/StorageBucketApi.ts +25 -109
  22. package/src/packages/StorageFileApi.ts +44 -172
  23. package/src/{lib/vectors → packages}/StorageVectorsClient.ts +2 -2
  24. package/src/packages/StreamDownloadBuilder.ts +1 -1
  25. package/src/packages/VectorBucketApi.ts +73 -0
  26. package/src/packages/VectorDataApi.ts +98 -0
  27. package/src/{lib/vectors → packages}/VectorIndexApi.ts +21 -66
  28. package/src/lib/errors.ts +0 -43
  29. package/src/lib/fetch.ts +0 -148
  30. package/src/lib/index.ts +0 -5
  31. package/src/lib/vectors/VectorBucketApi.ts +0 -118
  32. package/src/lib/vectors/VectorDataApi.ts +0 -152
  33. package/src/lib/vectors/constants.ts +0 -5
  34. package/src/lib/vectors/errors.ts +0 -78
  35. package/src/lib/vectors/fetch.ts +0 -218
  36. package/src/lib/vectors/helpers.ts +0 -79
  37. package/src/lib/vectors/index.ts +0 -66
  38. package/src/lib/vectors/types.ts +0 -301
@@ -0,0 +1,286 @@
1
+ import { StorageApiError, StorageUnknownError, ErrorNamespace } from './errors'
2
+ import { isPlainObject, resolveResponse } from './helpers'
3
+
4
+ export type Fetch = typeof fetch
5
+
6
+ /**
7
+ * Options for fetch requests
8
+ */
9
+ export interface FetchOptions {
10
+ headers?: {
11
+ [key: string]: string
12
+ }
13
+ duplex?: string
14
+ noResolveJson?: boolean
15
+ }
16
+
17
+ /**
18
+ * Additional fetch parameters (e.g., signal for cancellation)
19
+ */
20
+ export interface FetchParameters {
21
+ signal?: AbortSignal
22
+ }
23
+
24
+ /**
25
+ * HTTP methods supported by the API
26
+ */
27
+ export type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD'
28
+
29
+ /**
30
+ * Extracts error message from various error response formats
31
+ * @param err - Error object from API
32
+ * @returns Human-readable error message
33
+ */
34
+ const _getErrorMessage = (err: any): string =>
35
+ err.msg ||
36
+ err.message ||
37
+ err.error_description ||
38
+ (typeof err.error === 'string' ? err.error : err.error?.message) ||
39
+ JSON.stringify(err)
40
+
41
+ /**
42
+ * Handles fetch errors and converts them to Storage error types
43
+ * @param error - The error caught from fetch
44
+ * @param reject - Promise rejection function
45
+ * @param options - Fetch options that may affect error handling
46
+ * @param namespace - Error namespace ('storage' or 'vectors')
47
+ */
48
+ const handleError = async (
49
+ error: unknown,
50
+ reject: (reason?: any) => void,
51
+ options: FetchOptions | undefined,
52
+ namespace: ErrorNamespace
53
+ ) => {
54
+ // Check if error is a Response-like object (has status and ok properties)
55
+ // This is more reliable than instanceof which can fail across realms
56
+ const isResponseLike =
57
+ error &&
58
+ typeof error === 'object' &&
59
+ 'status' in error &&
60
+ 'ok' in error &&
61
+ typeof (error as any).status === 'number'
62
+
63
+ if (isResponseLike && !options?.noResolveJson) {
64
+ const responseError = error as any
65
+ const status = responseError.status || 500
66
+
67
+ // Try to parse JSON body if available
68
+ if (typeof responseError.json === 'function') {
69
+ responseError
70
+ .json()
71
+ .then((err: any) => {
72
+ const statusCode = err?.statusCode || err?.code || status + ''
73
+ reject(new StorageApiError(_getErrorMessage(err), status, statusCode, namespace))
74
+ })
75
+ .catch(() => {
76
+ // If JSON parsing fails for vectors, create ApiError with HTTP status
77
+ if (namespace === 'vectors') {
78
+ const statusCode = status + ''
79
+ const message = responseError.statusText || `HTTP ${status} error`
80
+ reject(new StorageApiError(message, status, statusCode, namespace))
81
+ } else {
82
+ const statusCode = status + ''
83
+ const message = responseError.statusText || `HTTP ${status} error`
84
+ reject(new StorageApiError(message, status, statusCode, namespace))
85
+ }
86
+ })
87
+ } else {
88
+ // No json() method available, create error from status
89
+ const statusCode = status + ''
90
+ const message = responseError.statusText || `HTTP ${status} error`
91
+ reject(new StorageApiError(message, status, statusCode, namespace))
92
+ }
93
+ } else {
94
+ reject(new StorageUnknownError(_getErrorMessage(error), error, namespace))
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Builds request parameters for fetch calls
100
+ * @param method - HTTP method
101
+ * @param options - Custom fetch options
102
+ * @param parameters - Additional fetch parameters like AbortSignal
103
+ * @param body - Request body (will be JSON stringified if plain object)
104
+ * @returns Complete fetch request parameters
105
+ */
106
+ const _getRequestParams = (
107
+ method: RequestMethodType,
108
+ options?: FetchOptions,
109
+ parameters?: FetchParameters,
110
+ body?: object
111
+ ) => {
112
+ const params: { [k: string]: any } = { method, headers: options?.headers || {} }
113
+
114
+ if (method === 'GET' || method === 'HEAD' || !body) {
115
+ return { ...params, ...parameters }
116
+ }
117
+
118
+ if (isPlainObject(body)) {
119
+ params.headers = { 'Content-Type': 'application/json', ...options?.headers }
120
+ params.body = JSON.stringify(body)
121
+ } else {
122
+ params.body = body
123
+ }
124
+
125
+ if (options?.duplex) {
126
+ params.duplex = options.duplex
127
+ }
128
+
129
+ return { ...params, ...parameters }
130
+ }
131
+
132
+ /**
133
+ * Internal request handler that wraps fetch with error handling
134
+ * @param fetcher - Fetch function to use
135
+ * @param method - HTTP method
136
+ * @param url - Request URL
137
+ * @param options - Custom fetch options
138
+ * @param parameters - Additional fetch parameters
139
+ * @param body - Request body
140
+ * @param namespace - Error namespace ('storage' or 'vectors')
141
+ * @returns Promise with parsed response or error
142
+ */
143
+ async function _handleRequest(
144
+ fetcher: Fetch,
145
+ method: RequestMethodType,
146
+ url: string,
147
+ options: FetchOptions | undefined,
148
+ parameters: FetchParameters | undefined,
149
+ body: object | undefined,
150
+ namespace: ErrorNamespace
151
+ ): Promise<any> {
152
+ return new Promise((resolve, reject) => {
153
+ fetcher(url, _getRequestParams(method, options, parameters, body))
154
+ .then((result) => {
155
+ if (!result.ok) throw result
156
+ if (options?.noResolveJson) return result
157
+
158
+ // Handle empty responses (204, empty body) - especially for vectors
159
+ if (namespace === 'vectors') {
160
+ const contentType = result.headers.get('content-type')
161
+ if (!contentType || !contentType.includes('application/json')) {
162
+ return {}
163
+ }
164
+ }
165
+
166
+ return result.json()
167
+ })
168
+ .then((data) => resolve(data))
169
+ .catch((error) => handleError(error, reject, options, namespace))
170
+ })
171
+ }
172
+
173
+ /**
174
+ * Creates a fetch API with the specified namespace
175
+ * @param namespace - Error namespace ('storage' or 'vectors')
176
+ * @returns Object with HTTP method functions
177
+ */
178
+ export function createFetchApi(namespace: ErrorNamespace = 'storage') {
179
+ return {
180
+ /**
181
+ * Performs a GET request
182
+ * @param fetcher - Fetch function to use
183
+ * @param url - Request URL
184
+ * @param options - Custom fetch options
185
+ * @param parameters - Additional fetch parameters
186
+ * @returns Promise with parsed response
187
+ */
188
+ get: async (
189
+ fetcher: Fetch,
190
+ url: string,
191
+ options?: FetchOptions,
192
+ parameters?: FetchParameters
193
+ ): Promise<any> => {
194
+ return _handleRequest(fetcher, 'GET', url, options, parameters, undefined, namespace)
195
+ },
196
+
197
+ /**
198
+ * Performs a POST request
199
+ * @param fetcher - Fetch function to use
200
+ * @param url - Request URL
201
+ * @param body - Request body to be JSON stringified
202
+ * @param options - Custom fetch options
203
+ * @param parameters - Additional fetch parameters
204
+ * @returns Promise with parsed response
205
+ */
206
+ post: async (
207
+ fetcher: Fetch,
208
+ url: string,
209
+ body: object,
210
+ options?: FetchOptions,
211
+ parameters?: FetchParameters
212
+ ): Promise<any> => {
213
+ return _handleRequest(fetcher, 'POST', url, options, parameters, body, namespace)
214
+ },
215
+
216
+ /**
217
+ * Performs a PUT request
218
+ * @param fetcher - Fetch function to use
219
+ * @param url - Request URL
220
+ * @param body - Request body to be JSON stringified
221
+ * @param options - Custom fetch options
222
+ * @param parameters - Additional fetch parameters
223
+ * @returns Promise with parsed response
224
+ */
225
+ put: async (
226
+ fetcher: Fetch,
227
+ url: string,
228
+ body: object,
229
+ options?: FetchOptions,
230
+ parameters?: FetchParameters
231
+ ): Promise<any> => {
232
+ return _handleRequest(fetcher, 'PUT', url, options, parameters, body, namespace)
233
+ },
234
+
235
+ /**
236
+ * Performs a HEAD request
237
+ * @param fetcher - Fetch function to use
238
+ * @param url - Request URL
239
+ * @param options - Custom fetch options
240
+ * @param parameters - Additional fetch parameters
241
+ * @returns Promise with Response object (not JSON parsed)
242
+ */
243
+ head: async (
244
+ fetcher: Fetch,
245
+ url: string,
246
+ options?: FetchOptions,
247
+ parameters?: FetchParameters
248
+ ): Promise<any> => {
249
+ return _handleRequest(
250
+ fetcher,
251
+ 'HEAD',
252
+ url,
253
+ {
254
+ ...options,
255
+ noResolveJson: true,
256
+ },
257
+ parameters,
258
+ undefined,
259
+ namespace
260
+ )
261
+ },
262
+
263
+ /**
264
+ * Performs a DELETE request
265
+ * @param fetcher - Fetch function to use
266
+ * @param url - Request URL
267
+ * @param body - Request body to be JSON stringified
268
+ * @param options - Custom fetch options
269
+ * @param parameters - Additional fetch parameters
270
+ * @returns Promise with parsed response
271
+ */
272
+ remove: async (
273
+ fetcher: Fetch,
274
+ url: string,
275
+ body: object,
276
+ options?: FetchOptions,
277
+ parameters?: FetchParameters
278
+ ): Promise<any> => {
279
+ return _handleRequest(fetcher, 'DELETE', url, options, parameters, body, namespace)
280
+ },
281
+ }
282
+ }
283
+
284
+ // Default exports for backward compatibility with 'storage' namespace
285
+ const defaultApi = createFetchApi('storage')
286
+ export const { get, post, put, head, remove } = defaultApi
@@ -1,5 +1,12 @@
1
1
  type Fetch = typeof fetch
2
2
 
3
+ /**
4
+ * Resolves the fetch implementation to use
5
+ * Uses custom fetch if provided, otherwise uses native fetch
6
+ *
7
+ * @param customFetch - Optional custom fetch implementation
8
+ * @returns Resolved fetch function
9
+ */
3
10
  export const resolveFetch = (customFetch?: Fetch): Fetch => {
4
11
  if (customFetch) {
5
12
  return (...args) => customFetch(...args)
@@ -7,30 +14,23 @@ export const resolveFetch = (customFetch?: Fetch): Fetch => {
7
14
  return (...args) => fetch(...args)
8
15
  }
9
16
 
17
+ /**
18
+ * Resolves the Response constructor to use
19
+ * Returns native Response constructor
20
+ *
21
+ * @returns Response constructor
22
+ */
10
23
  export const resolveResponse = (): typeof Response => {
11
24
  return Response
12
25
  }
13
26
 
14
- export const recursiveToCamel = (item: Record<string, any>): unknown => {
15
- if (Array.isArray(item)) {
16
- return item.map((el) => recursiveToCamel(el))
17
- } else if (typeof item === 'function' || item !== Object(item)) {
18
- return item
19
- }
20
-
21
- const result: Record<string, any> = {}
22
- Object.entries(item).forEach(([key, value]) => {
23
- const newKey = key.replace(/([-_][a-z])/gi, (c) => c.toUpperCase().replace(/[-_]/g, ''))
24
- result[newKey] = recursiveToCamel(value)
25
- })
26
-
27
- return result
28
- }
29
-
30
27
  /**
31
28
  * Determine if input is a plain object
32
29
  * An object is plain if it's created by either {}, new Object(), or Object.create(null)
33
- * source: https://github.com/sindresorhus/is-plain-obj
30
+ *
31
+ * @param value - Value to check
32
+ * @returns True if value is a plain object
33
+ * @source https://github.com/sindresorhus/is-plain-obj
34
34
  */
35
35
  export const isPlainObject = (value: object): boolean => {
36
36
  if (typeof value !== 'object' || value === null) {
@@ -47,6 +47,29 @@ export const isPlainObject = (value: object): boolean => {
47
47
  )
48
48
  }
49
49
 
50
+ /**
51
+ * Recursively converts object keys from snake_case to camelCase
52
+ * Used for normalizing API responses
53
+ *
54
+ * @param item - Object to convert
55
+ * @returns Converted object with camelCase keys
56
+ */
57
+ export const recursiveToCamel = (item: Record<string, any>): unknown => {
58
+ if (Array.isArray(item)) {
59
+ return item.map((el) => recursiveToCamel(el))
60
+ } else if (typeof item === 'function' || item !== Object(item)) {
61
+ return item
62
+ }
63
+
64
+ const result: Record<string, any> = {}
65
+ Object.entries(item).forEach(([key, value]) => {
66
+ const newKey = key.replace(/([-_][a-z])/gi, (c) => c.toUpperCase().replace(/[-_]/g, ''))
67
+ result[newKey] = recursiveToCamel(value)
68
+ })
69
+
70
+ return result
71
+ }
72
+
50
73
  /**
51
74
  * Validates if a given bucket name is valid according to Supabase Storage API rules
52
75
  * Mirrors backend validation from: storage/src/storage/limits.ts:isValidBucketName()
@@ -90,3 +113,34 @@ export const isValidBucketName = (bucketName: string): boolean => {
90
113
  const bucketNameRegex = /^[\w!.\*'() &$@=;:+,?-]+$/
91
114
  return bucketNameRegex.test(bucketName)
92
115
  }
116
+
117
+ /**
118
+ * Normalizes a number array to float32 format
119
+ * Ensures all vector values are valid 32-bit floats
120
+ *
121
+ * @param values - Array of numbers to normalize
122
+ * @returns Normalized float32 array
123
+ */
124
+ export const normalizeToFloat32 = (values: number[]): number[] => {
125
+ // Use Float32Array to ensure proper precision
126
+ return Array.from(new Float32Array(values))
127
+ }
128
+
129
+ /**
130
+ * Validates vector dimensions match expected dimension
131
+ * Throws error if dimensions don't match
132
+ *
133
+ * @param vector - Vector data to validate
134
+ * @param expectedDimension - Expected vector dimension
135
+ * @throws Error if dimensions don't match
136
+ */
137
+ export const validateVectorDimension = (
138
+ vector: { float32: number[] },
139
+ expectedDimension?: number
140
+ ): void => {
141
+ if (expectedDimension !== undefined && vector.float32.length !== expectedDimension) {
142
+ throw new Error(
143
+ `Vector dimension mismatch: expected ${expectedDimension}, got ${vector.float32.length}`
144
+ )
145
+ }
146
+ }
package/src/lib/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StorageError } from './errors'
1
+ import { StorageError } from './common/errors'
2
2
 
3
3
  /**
4
4
  * Type of storage bucket
@@ -257,3 +257,306 @@ export type DownloadResult<T> =
257
257
  data: null
258
258
  error: StorageError
259
259
  }
260
+ // ============================================================================
261
+ // VECTOR STORAGE TYPES
262
+ // ============================================================================
263
+
264
+ /**
265
+ * Configuration for encryption at rest
266
+ * @property kmsKeyArn - ARN of the KMS key used for encryption
267
+ * @property sseType - Server-side encryption type (e.g., 'KMS')
268
+ */
269
+ export interface EncryptionConfiguration {
270
+ kmsKeyArn?: string
271
+ sseType?: string
272
+ }
273
+
274
+ /**
275
+ * Vector bucket metadata
276
+ * @property vectorBucketName - Unique name of the vector bucket
277
+ * @property creationTime - Unix timestamp of when the bucket was created
278
+ * @property encryptionConfiguration - Optional encryption settings
279
+ */
280
+ export interface VectorBucket {
281
+ vectorBucketName: string
282
+ creationTime?: number
283
+ encryptionConfiguration?: EncryptionConfiguration
284
+ }
285
+
286
+ /**
287
+ * Metadata configuration for vector index
288
+ * Defines which metadata keys should not be indexed for filtering
289
+ * @property nonFilterableMetadataKeys - Array of metadata keys that cannot be used in filters
290
+ */
291
+ export interface MetadataConfiguration {
292
+ nonFilterableMetadataKeys?: string[]
293
+ }
294
+
295
+ /**
296
+ * Supported data types for vectors
297
+ * Currently only float32 is supported
298
+ */
299
+ export type VectorDataType = 'float32'
300
+
301
+ /**
302
+ * Distance metrics for vector similarity search
303
+ */
304
+ export type DistanceMetric = 'cosine' | 'euclidean' | 'dotproduct'
305
+
306
+ /**
307
+ * Vector index configuration and metadata
308
+ * @property indexName - Unique name of the index within the bucket
309
+ * @property vectorBucketName - Name of the parent vector bucket
310
+ * @property dataType - Data type of vector components (currently only 'float32')
311
+ * @property dimension - Dimensionality of vectors (e.g., 384, 768, 1536)
312
+ * @property distanceMetric - Similarity metric used for queries
313
+ * @property metadataConfiguration - Configuration for metadata filtering
314
+ * @property creationTime - Unix timestamp of when the index was created
315
+ */
316
+ export interface VectorIndex {
317
+ indexName: string
318
+ vectorBucketName: string
319
+ dataType: VectorDataType
320
+ dimension: number
321
+ distanceMetric: DistanceMetric
322
+ metadataConfiguration?: MetadataConfiguration
323
+ creationTime?: number
324
+ }
325
+
326
+ /**
327
+ * Vector data representation
328
+ * Vectors must be float32 arrays with dimensions matching the index
329
+ * @property float32 - Array of 32-bit floating point numbers
330
+ */
331
+ export interface VectorData {
332
+ float32: number[]
333
+ }
334
+
335
+ /**
336
+ * Arbitrary JSON metadata attached to vectors
337
+ * Keys configured as non-filterable in the index can be stored but not queried
338
+ */
339
+ export type VectorMetadata = Record<string, any>
340
+
341
+ /**
342
+ * Single vector object for insertion/update
343
+ * @property key - Unique identifier for the vector
344
+ * @property data - Vector embedding data
345
+ * @property metadata - Optional arbitrary metadata
346
+ */
347
+ export interface VectorObject {
348
+ key: string
349
+ data: VectorData
350
+ metadata?: VectorMetadata
351
+ }
352
+
353
+ /**
354
+ * Vector object returned from queries with optional distance
355
+ * @property key - Unique identifier for the vector
356
+ * @property data - Vector embedding data (if requested)
357
+ * @property metadata - Arbitrary metadata (if requested)
358
+ * @property distance - Similarity distance from query vector (if requested)
359
+ */
360
+ export interface VectorMatch {
361
+ key: string
362
+ data?: VectorData
363
+ metadata?: VectorMetadata
364
+ distance?: number
365
+ }
366
+
367
+ /**
368
+ * Options for fetching vector buckets
369
+ * @property prefix - Filter buckets by name prefix
370
+ * @property maxResults - Maximum number of results to return (default: 100)
371
+ * @property nextToken - Token for pagination from previous response
372
+ */
373
+ export interface ListVectorBucketsOptions {
374
+ prefix?: string
375
+ maxResults?: number
376
+ nextToken?: string
377
+ }
378
+
379
+ /**
380
+ * Response from listing vector buckets
381
+ * @property vectorBuckets - Array of bucket names
382
+ * @property nextToken - Token for fetching next page (if more results exist)
383
+ */
384
+ export interface ListVectorBucketsResponse {
385
+ vectorBuckets: { vectorBucketName: string }[]
386
+ nextToken?: string
387
+ }
388
+
389
+ /**
390
+ * Options for listing indexes within a bucket
391
+ * @property vectorBucketName - Name of the parent vector bucket
392
+ * @property prefix - Filter indexes by name prefix
393
+ * @property maxResults - Maximum number of results to return (default: 100)
394
+ * @property nextToken - Token for pagination from previous response
395
+ */
396
+ export interface ListIndexesOptions {
397
+ vectorBucketName: string
398
+ prefix?: string
399
+ maxResults?: number
400
+ nextToken?: string
401
+ }
402
+
403
+ /**
404
+ * Response from listing indexes
405
+ * @property indexes - Array of index names
406
+ * @property nextToken - Token for fetching next page (if more results exist)
407
+ */
408
+ export interface ListIndexesResponse {
409
+ indexes: { indexName: string }[]
410
+ nextToken?: string
411
+ }
412
+
413
+ /**
414
+ * Options for batch reading vectors
415
+ * @property vectorBucketName - Name of the vector bucket
416
+ * @property indexName - Name of the index
417
+ * @property keys - Array of vector keys to retrieve
418
+ * @property returnData - Whether to include vector data in response
419
+ * @property returnMetadata - Whether to include metadata in response
420
+ */
421
+ export interface GetVectorsOptions {
422
+ vectorBucketName: string
423
+ indexName: string
424
+ keys: string[]
425
+ returnData?: boolean
426
+ returnMetadata?: boolean
427
+ }
428
+
429
+ /**
430
+ * Response from getting vectors
431
+ * @property vectors - Array of retrieved vector objects
432
+ */
433
+ export interface GetVectorsResponse {
434
+ vectors: VectorMatch[]
435
+ }
436
+
437
+ /**
438
+ * Options for batch inserting/updating vectors
439
+ * @property vectorBucketName - Name of the vector bucket
440
+ * @property indexName - Name of the index
441
+ * @property vectors - Array of vectors to insert/upsert (1-500 items)
442
+ */
443
+ export interface PutVectorsOptions {
444
+ vectorBucketName: string
445
+ indexName: string
446
+ vectors: VectorObject[]
447
+ }
448
+
449
+ /**
450
+ * Options for batch deleting vectors
451
+ * @property vectorBucketName - Name of the vector bucket
452
+ * @property indexName - Name of the index
453
+ * @property keys - Array of vector keys to delete (1-500 items)
454
+ */
455
+ export interface DeleteVectorsOptions {
456
+ vectorBucketName: string
457
+ indexName: string
458
+ keys: string[]
459
+ }
460
+
461
+ /**
462
+ * Options for listing/scanning vectors in an index
463
+ * Supports parallel scanning via segment configuration
464
+ * @property vectorBucketName - Name of the vector bucket
465
+ * @property indexName - Name of the index
466
+ * @property maxResults - Maximum number of results to return (default: 500, max: 1000)
467
+ * @property nextToken - Token for pagination from previous response
468
+ * @property returnData - Whether to include vector data in response
469
+ * @property returnMetadata - Whether to include metadata in response
470
+ * @property segmentCount - Total number of parallel segments (1-16)
471
+ * @property segmentIndex - Zero-based index of this segment (0 to segmentCount-1)
472
+ */
473
+ export interface ListVectorsOptions {
474
+ vectorBucketName: string
475
+ indexName: string
476
+ maxResults?: number
477
+ nextToken?: string
478
+ returnData?: boolean
479
+ returnMetadata?: boolean
480
+ segmentCount?: number
481
+ segmentIndex?: number
482
+ }
483
+
484
+ /**
485
+ * Response from listing vectors
486
+ * @property vectors - Array of vector objects
487
+ * @property nextToken - Token for fetching next page (if more results exist)
488
+ */
489
+ export interface ListVectorsResponse {
490
+ vectors: VectorMatch[]
491
+ nextToken?: string
492
+ }
493
+
494
+ /**
495
+ * JSON filter expression for metadata filtering
496
+ * Format and syntax depend on the S3 Vectors service implementation
497
+ */
498
+ export type VectorFilter = Record<string, any>
499
+
500
+ /**
501
+ * Options for querying similar vectors (ANN search)
502
+ * @property vectorBucketName - Name of the vector bucket
503
+ * @property indexName - Name of the index
504
+ * @property queryVector - Query vector to find similar vectors
505
+ * @property topK - Number of nearest neighbors to return (default: 10)
506
+ * @property filter - Optional JSON filter for metadata
507
+ * @property returnDistance - Whether to include distance scores
508
+ * @property returnMetadata - Whether to include metadata in results
509
+ */
510
+ export interface QueryVectorsOptions {
511
+ vectorBucketName: string
512
+ indexName: string
513
+ queryVector: VectorData
514
+ topK?: number
515
+ filter?: VectorFilter
516
+ returnDistance?: boolean
517
+ returnMetadata?: boolean
518
+ }
519
+
520
+ /**
521
+ * Response from vector similarity query
522
+ * @property vectors - Array of similar vectors ordered by distance
523
+ * @property distanceMetric - The distance metric used for the similarity search
524
+ */
525
+ export interface QueryVectorsResponse {
526
+ vectors: VectorMatch[]
527
+ distanceMetric?: DistanceMetric
528
+ }
529
+
530
+ /**
531
+ * Fetch-specific parameters like abort signals
532
+ * @property signal - AbortSignal for cancelling requests
533
+ */
534
+ export interface VectorFetchParameters {
535
+ signal?: AbortSignal
536
+ }
537
+
538
+ /**
539
+ * Standard response wrapper for successful operations
540
+ * @property data - Response data of type T
541
+ * @property error - Null on success
542
+ */
543
+ export interface SuccessResponse<T> {
544
+ data: T
545
+ error: null
546
+ }
547
+
548
+ /**
549
+ * Standard response wrapper for failed operations
550
+ * @property data - Null on error
551
+ * @property error - StorageError with details (named StorageVectorsError for vector operations)
552
+ */
553
+ export interface ErrorResponse {
554
+ data: null
555
+ error: StorageError
556
+ }
557
+
558
+ /**
559
+ * Union type for all API responses
560
+ * Follows the pattern: { data: T, error: null } | { data: null, error: Error }
561
+ */
562
+ export type ApiResponse<T> = SuccessResponse<T> | ErrorResponse