@supabase/storage-js 2.79.1-canary.1 → 2.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +920 -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.d.ts.map +1 -1
- package/dist/main/lib/fetch.js +16 -17
- package/dist/main/lib/fetch.js.map +1 -1
- package/dist/main/lib/helpers.d.ts +1 -1
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +4 -57
- 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 +74 -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 +46 -0
- package/dist/main/lib/vectors/helpers.d.ts.map +1 -0
- package/dist/main/lib/vectors/helpers.js +74 -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.d.ts +6 -1
- package/dist/main/packages/BlobDownloadBuilder.d.ts.map +1 -1
- package/dist/main/packages/BlobDownloadBuilder.js +20 -15
- 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 +164 -0
- package/dist/main/packages/StorageAnalyticsApi.js.map +1 -0
- package/dist/main/packages/StorageBucketApi.d.ts +3 -2
- package/dist/main/packages/StorageBucketApi.d.ts.map +1 -1
- package/dist/main/packages/StorageBucketApi.js +34 -18
- package/dist/main/packages/StorageBucketApi.js.map +1 -1
- package/dist/main/packages/StorageFileApi.d.ts.map +1 -1
- package/dist/main/packages/StorageFileApi.js +28 -29
- 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.d.ts.map +1 -1
- package/dist/module/lib/fetch.js +9 -10
- package/dist/module/lib/fetch.js.map +1 -1
- package/dist/module/lib/helpers.d.ts +1 -1
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js +4 -24
- 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 +74 -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 +46 -0
- package/dist/module/lib/vectors/helpers.d.ts.map +1 -0
- package/dist/module/lib/vectors/helpers.js +66 -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.d.ts +6 -1
- package/dist/module/packages/BlobDownloadBuilder.d.ts.map +1 -1
- package/dist/module/packages/BlobDownloadBuilder.js +20 -11
- 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 +161 -0
- package/dist/module/packages/StorageAnalyticsApi.js.map +1 -0
- package/dist/module/packages/StorageBucketApi.d.ts +3 -2
- package/dist/module/packages/StorageBucketApi.d.ts.map +1 -1
- package/dist/module/packages/StorageBucketApi.js +28 -12
- package/dist/module/packages/StorageBucketApi.js.map +1 -1
- package/dist/module/packages/StorageFileApi.d.ts.map +1 -1
- package/dist/module/packages/StorageFileApi.js +13 -11
- 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 +6 -13
- package/src/StorageClient.ts +37 -0
- package/src/index.ts +2 -0
- package/src/lib/constants.ts +3 -1
- package/src/lib/fetch.ts +5 -1
- package/src/lib/helpers.ts +3 -14
- package/src/lib/index.ts +1 -0
- package/src/lib/types.ts +83 -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 +79 -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/BlobDownloadBuilder.ts +22 -2
- package/src/packages/StorageAnalyticsApi.ts +199 -0
- package/src/packages/StorageBucketApi.ts +29 -4
- package/src/packages/StorageFileApi.ts +15 -2
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { StorageVectorsError } from './errors'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for encryption at rest
|
|
5
|
+
* @property kmsKeyArn - ARN of the KMS key used for encryption
|
|
6
|
+
* @property sseType - Server-side encryption type (e.g., 'KMS')
|
|
7
|
+
*/
|
|
8
|
+
export interface EncryptionConfiguration {
|
|
9
|
+
kmsKeyArn?: string
|
|
10
|
+
sseType?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Vector bucket metadata
|
|
15
|
+
* @property vectorBucketName - Unique name of the vector bucket
|
|
16
|
+
* @property creationTime - Unix timestamp of when the bucket was created
|
|
17
|
+
* @property encryptionConfiguration - Optional encryption settings
|
|
18
|
+
*/
|
|
19
|
+
export interface VectorBucket {
|
|
20
|
+
vectorBucketName: string
|
|
21
|
+
creationTime?: number
|
|
22
|
+
encryptionConfiguration?: EncryptionConfiguration
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Metadata configuration for vector index
|
|
27
|
+
* Defines which metadata keys should not be indexed for filtering
|
|
28
|
+
* @property nonFilterableMetadataKeys - Array of metadata keys that cannot be used in filters
|
|
29
|
+
*/
|
|
30
|
+
export interface MetadataConfiguration {
|
|
31
|
+
nonFilterableMetadataKeys?: string[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Supported data types for vectors
|
|
36
|
+
* Currently only float32 is supported
|
|
37
|
+
*/
|
|
38
|
+
export type VectorDataType = 'float32'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Distance metrics for vector similarity search
|
|
42
|
+
*/
|
|
43
|
+
export type DistanceMetric = 'cosine' | 'euclidean' | 'dotproduct'
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Vector index configuration and metadata
|
|
47
|
+
* @property indexName - Unique name of the index within the bucket
|
|
48
|
+
* @property vectorBucketName - Name of the parent vector bucket
|
|
49
|
+
* @property dataType - Data type of vector components (currently only 'float32')
|
|
50
|
+
* @property dimension - Dimensionality of vectors (e.g., 384, 768, 1536)
|
|
51
|
+
* @property distanceMetric - Similarity metric used for queries
|
|
52
|
+
* @property metadataConfiguration - Configuration for metadata filtering
|
|
53
|
+
* @property creationTime - Unix timestamp of when the index was created
|
|
54
|
+
*/
|
|
55
|
+
export interface VectorIndex {
|
|
56
|
+
indexName: string
|
|
57
|
+
vectorBucketName: string
|
|
58
|
+
dataType: VectorDataType
|
|
59
|
+
dimension: number
|
|
60
|
+
distanceMetric: DistanceMetric
|
|
61
|
+
metadataConfiguration?: MetadataConfiguration
|
|
62
|
+
creationTime?: number
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Vector data representation
|
|
67
|
+
* Vectors must be float32 arrays with dimensions matching the index
|
|
68
|
+
* @property float32 - Array of 32-bit floating point numbers
|
|
69
|
+
*/
|
|
70
|
+
export interface VectorData {
|
|
71
|
+
float32: number[]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Arbitrary JSON metadata attached to vectors
|
|
76
|
+
* Keys configured as non-filterable in the index can be stored but not queried
|
|
77
|
+
*/
|
|
78
|
+
export type VectorMetadata = Record<string, any>
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Single vector object for insertion/update
|
|
82
|
+
* @property key - Unique identifier for the vector
|
|
83
|
+
* @property data - Vector embedding data
|
|
84
|
+
* @property metadata - Optional arbitrary metadata
|
|
85
|
+
*/
|
|
86
|
+
export interface VectorObject {
|
|
87
|
+
key: string
|
|
88
|
+
data: VectorData
|
|
89
|
+
metadata?: VectorMetadata
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Vector object returned from queries with optional distance
|
|
94
|
+
* @property key - Unique identifier for the vector
|
|
95
|
+
* @property data - Vector embedding data (if requested)
|
|
96
|
+
* @property metadata - Arbitrary metadata (if requested)
|
|
97
|
+
* @property distance - Similarity distance from query vector (if requested)
|
|
98
|
+
*/
|
|
99
|
+
export interface VectorMatch {
|
|
100
|
+
key: string
|
|
101
|
+
data?: VectorData
|
|
102
|
+
metadata?: VectorMetadata
|
|
103
|
+
distance?: number
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Options for fetching vector buckets
|
|
108
|
+
* @property prefix - Filter buckets by name prefix
|
|
109
|
+
* @property maxResults - Maximum number of results to return (default: 100)
|
|
110
|
+
* @property nextToken - Token for pagination from previous response
|
|
111
|
+
*/
|
|
112
|
+
export interface ListVectorBucketsOptions {
|
|
113
|
+
prefix?: string
|
|
114
|
+
maxResults?: number
|
|
115
|
+
nextToken?: string
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Response from listing vector buckets
|
|
120
|
+
* @property vectorBuckets - Array of bucket names
|
|
121
|
+
* @property nextToken - Token for fetching next page (if more results exist)
|
|
122
|
+
*/
|
|
123
|
+
export interface ListVectorBucketsResponse {
|
|
124
|
+
vectorBuckets: { vectorBucketName: string }[]
|
|
125
|
+
nextToken?: string
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Options for listing indexes within a bucket
|
|
130
|
+
* @property vectorBucketName - Name of the parent vector bucket
|
|
131
|
+
* @property prefix - Filter indexes by name prefix
|
|
132
|
+
* @property maxResults - Maximum number of results to return (default: 100)
|
|
133
|
+
* @property nextToken - Token for pagination from previous response
|
|
134
|
+
*/
|
|
135
|
+
export interface ListIndexesOptions {
|
|
136
|
+
vectorBucketName: string
|
|
137
|
+
prefix?: string
|
|
138
|
+
maxResults?: number
|
|
139
|
+
nextToken?: string
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Response from listing indexes
|
|
144
|
+
* @property indexes - Array of index names
|
|
145
|
+
* @property nextToken - Token for fetching next page (if more results exist)
|
|
146
|
+
*/
|
|
147
|
+
export interface ListIndexesResponse {
|
|
148
|
+
indexes: { indexName: string }[]
|
|
149
|
+
nextToken?: string
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Options for batch reading vectors
|
|
154
|
+
* @property vectorBucketName - Name of the vector bucket
|
|
155
|
+
* @property indexName - Name of the index
|
|
156
|
+
* @property keys - Array of vector keys to retrieve
|
|
157
|
+
* @property returnData - Whether to include vector data in response
|
|
158
|
+
* @property returnMetadata - Whether to include metadata in response
|
|
159
|
+
*/
|
|
160
|
+
export interface GetVectorsOptions {
|
|
161
|
+
vectorBucketName: string
|
|
162
|
+
indexName: string
|
|
163
|
+
keys: string[]
|
|
164
|
+
returnData?: boolean
|
|
165
|
+
returnMetadata?: boolean
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Response from getting vectors
|
|
170
|
+
* @property vectors - Array of retrieved vector objects
|
|
171
|
+
*/
|
|
172
|
+
export interface GetVectorsResponse {
|
|
173
|
+
vectors: VectorMatch[]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Options for batch inserting/updating vectors
|
|
178
|
+
* @property vectorBucketName - Name of the vector bucket
|
|
179
|
+
* @property indexName - Name of the index
|
|
180
|
+
* @property vectors - Array of vectors to insert/upsert (1-500 items)
|
|
181
|
+
*/
|
|
182
|
+
export interface PutVectorsOptions {
|
|
183
|
+
vectorBucketName: string
|
|
184
|
+
indexName: string
|
|
185
|
+
vectors: VectorObject[]
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Options for batch deleting vectors
|
|
190
|
+
* @property vectorBucketName - Name of the vector bucket
|
|
191
|
+
* @property indexName - Name of the index
|
|
192
|
+
* @property keys - Array of vector keys to delete (1-500 items)
|
|
193
|
+
*/
|
|
194
|
+
export interface DeleteVectorsOptions {
|
|
195
|
+
vectorBucketName: string
|
|
196
|
+
indexName: string
|
|
197
|
+
keys: string[]
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Options for listing/scanning vectors in an index
|
|
202
|
+
* Supports parallel scanning via segment configuration
|
|
203
|
+
* @property vectorBucketName - Name of the vector bucket
|
|
204
|
+
* @property indexName - Name of the index
|
|
205
|
+
* @property maxResults - Maximum number of results to return (default: 500, max: 1000)
|
|
206
|
+
* @property nextToken - Token for pagination from previous response
|
|
207
|
+
* @property returnData - Whether to include vector data in response
|
|
208
|
+
* @property returnMetadata - Whether to include metadata in response
|
|
209
|
+
* @property segmentCount - Total number of parallel segments (1-16)
|
|
210
|
+
* @property segmentIndex - Zero-based index of this segment (0 to segmentCount-1)
|
|
211
|
+
*/
|
|
212
|
+
export interface ListVectorsOptions {
|
|
213
|
+
vectorBucketName: string
|
|
214
|
+
indexName: string
|
|
215
|
+
maxResults?: number
|
|
216
|
+
nextToken?: string
|
|
217
|
+
returnData?: boolean
|
|
218
|
+
returnMetadata?: boolean
|
|
219
|
+
segmentCount?: number
|
|
220
|
+
segmentIndex?: number
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Response from listing vectors
|
|
225
|
+
* @property vectors - Array of vector objects
|
|
226
|
+
* @property nextToken - Token for fetching next page (if more results exist)
|
|
227
|
+
*/
|
|
228
|
+
export interface ListVectorsResponse {
|
|
229
|
+
vectors: VectorMatch[]
|
|
230
|
+
nextToken?: string
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* JSON filter expression for metadata filtering
|
|
235
|
+
* Format and syntax depend on the S3 Vectors service implementation
|
|
236
|
+
*/
|
|
237
|
+
export type VectorFilter = Record<string, any>
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Options for querying similar vectors (ANN search)
|
|
241
|
+
* @property vectorBucketName - Name of the vector bucket
|
|
242
|
+
* @property indexName - Name of the index
|
|
243
|
+
* @property queryVector - Query vector to find similar vectors
|
|
244
|
+
* @property topK - Number of nearest neighbors to return (default: 10)
|
|
245
|
+
* @property filter - Optional JSON filter for metadata
|
|
246
|
+
* @property returnDistance - Whether to include distance scores
|
|
247
|
+
* @property returnMetadata - Whether to include metadata in results
|
|
248
|
+
*/
|
|
249
|
+
export interface QueryVectorsOptions {
|
|
250
|
+
vectorBucketName: string
|
|
251
|
+
indexName: string
|
|
252
|
+
queryVector: VectorData
|
|
253
|
+
topK?: number
|
|
254
|
+
filter?: VectorFilter
|
|
255
|
+
returnDistance?: boolean
|
|
256
|
+
returnMetadata?: boolean
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Response from vector similarity query
|
|
261
|
+
* @property matches - Array of similar vectors ordered by distance
|
|
262
|
+
*/
|
|
263
|
+
export interface QueryVectorsResponse {
|
|
264
|
+
matches: VectorMatch[]
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Fetch-specific parameters like abort signals
|
|
269
|
+
* @property signal - AbortSignal for cancelling requests
|
|
270
|
+
*/
|
|
271
|
+
export interface VectorFetchParameters {
|
|
272
|
+
signal?: AbortSignal
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Standard response wrapper for successful operations
|
|
277
|
+
* @property data - Response data of type T
|
|
278
|
+
* @property error - Null on success
|
|
279
|
+
*/
|
|
280
|
+
export interface SuccessResponse<T> {
|
|
281
|
+
data: T
|
|
282
|
+
error: null
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Standard response wrapper for failed operations
|
|
287
|
+
* @property data - Null on error
|
|
288
|
+
* @property error - StorageVectorsError with details
|
|
289
|
+
*/
|
|
290
|
+
export interface ErrorResponse {
|
|
291
|
+
data: null
|
|
292
|
+
error: StorageVectorsError
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Union type for all API responses
|
|
297
|
+
* Follows the pattern: { data: T, error: null } | { data: null, error: Error }
|
|
298
|
+
*/
|
|
299
|
+
export type ApiResponse<T> = SuccessResponse<T> | ErrorResponse
|
package/src/lib/version.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
// - Debugging and support (identifying which version is running)
|
|
5
5
|
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
6
|
// - Ensuring build artifacts match the published package version
|
|
7
|
-
export const version = '2.
|
|
7
|
+
export const version = '2.80.0'
|
|
@@ -2,7 +2,10 @@ import { isStorageError } from '../lib/errors'
|
|
|
2
2
|
import { DownloadResult } from '../lib/types'
|
|
3
3
|
import StreamDownloadBuilder from './StreamDownloadBuilder'
|
|
4
4
|
|
|
5
|
-
export default class BlobDownloadBuilder implements
|
|
5
|
+
export default class BlobDownloadBuilder implements Promise<DownloadResult<Blob>> {
|
|
6
|
+
readonly [Symbol.toStringTag]: string = 'BlobDownloadBuilder'
|
|
7
|
+
private promise: Promise<DownloadResult<Blob>> | null = null
|
|
8
|
+
|
|
6
9
|
constructor(
|
|
7
10
|
private downloadFn: () => Promise<Response>,
|
|
8
11
|
private shouldThrowOnError: boolean
|
|
@@ -16,7 +19,24 @@ export default class BlobDownloadBuilder implements PromiseLike<DownloadResult<B
|
|
|
16
19
|
onfulfilled?: ((value: DownloadResult<Blob>) => TResult1 | PromiseLike<TResult1>) | null,
|
|
17
20
|
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
|
18
21
|
): Promise<TResult1 | TResult2> {
|
|
19
|
-
return this.
|
|
22
|
+
return this.getPromise().then(onfulfilled, onrejected)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
catch<TResult = never>(
|
|
26
|
+
onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
|
|
27
|
+
): Promise<DownloadResult<Blob> | TResult> {
|
|
28
|
+
return this.getPromise().catch(onrejected)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
finally(onfinally?: (() => void) | null): Promise<DownloadResult<Blob>> {
|
|
32
|
+
return this.getPromise().finally(onfinally)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private getPromise(): Promise<DownloadResult<Blob>> {
|
|
36
|
+
if (!this.promise) {
|
|
37
|
+
this.promise = this.execute()
|
|
38
|
+
}
|
|
39
|
+
return this.promise
|
|
20
40
|
}
|
|
21
41
|
|
|
22
42
|
private async execute(): Promise<DownloadResult<Blob>> {
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { DEFAULT_HEADERS } from '../lib/constants'
|
|
2
|
+
import { isStorageError, StorageError } from '../lib/errors'
|
|
3
|
+
import { Fetch, get, post, remove } from '../lib/fetch'
|
|
4
|
+
import { resolveFetch } from '../lib/helpers'
|
|
5
|
+
import { AnalyticBucket, Bucket } from '../lib/types'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* API class for managing Analytics Buckets using Iceberg tables
|
|
9
|
+
* Provides methods for creating, listing, and deleting analytics buckets
|
|
10
|
+
*/
|
|
11
|
+
export default class StorageAnalyticsApi {
|
|
12
|
+
protected url: string
|
|
13
|
+
protected headers: { [key: string]: string }
|
|
14
|
+
protected fetch: Fetch
|
|
15
|
+
protected shouldThrowOnError = false
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new StorageAnalyticsApi instance
|
|
19
|
+
* @param url - The base URL for the storage API
|
|
20
|
+
* @param headers - HTTP headers to include in requests
|
|
21
|
+
* @param fetch - Optional custom fetch implementation
|
|
22
|
+
*/
|
|
23
|
+
constructor(url: string, headers: { [key: string]: string } = {}, fetch?: Fetch) {
|
|
24
|
+
this.url = url.replace(/\/$/, '')
|
|
25
|
+
this.headers = { ...DEFAULT_HEADERS, ...headers }
|
|
26
|
+
this.fetch = resolveFetch(fetch)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Enable throwing errors instead of returning them in the response
|
|
31
|
+
* When enabled, failed operations will throw instead of returning { data: null, error }
|
|
32
|
+
*
|
|
33
|
+
* @returns This instance for method chaining
|
|
34
|
+
*/
|
|
35
|
+
public throwOnError(): this {
|
|
36
|
+
this.shouldThrowOnError = true
|
|
37
|
+
return this
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new analytics bucket using Iceberg tables
|
|
42
|
+
* Analytics buckets are optimized for analytical queries and data processing
|
|
43
|
+
*
|
|
44
|
+
* @param name A unique name for the bucket you are creating
|
|
45
|
+
* @returns Promise with newly created bucket name or error
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const { data, error } = await storage.analytics.createBucket('analytics-data')
|
|
50
|
+
* if (error) {
|
|
51
|
+
* console.error('Failed to create analytics bucket:', error.message)
|
|
52
|
+
* } else {
|
|
53
|
+
* console.log('Created bucket:', data.name)
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
async createBucket(name: string): Promise<
|
|
58
|
+
| {
|
|
59
|
+
data: AnalyticBucket
|
|
60
|
+
error: null
|
|
61
|
+
}
|
|
62
|
+
| {
|
|
63
|
+
data: null
|
|
64
|
+
error: StorageError
|
|
65
|
+
}
|
|
66
|
+
> {
|
|
67
|
+
try {
|
|
68
|
+
const data = await post(this.fetch, `${this.url}/bucket`, { name }, { headers: this.headers })
|
|
69
|
+
return { data, error: null }
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (this.shouldThrowOnError) {
|
|
72
|
+
throw error
|
|
73
|
+
}
|
|
74
|
+
if (isStorageError(error)) {
|
|
75
|
+
return { data: null, error }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
throw error
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves the details of all Analytics Storage buckets within an existing project
|
|
84
|
+
* Only returns buckets of type 'ANALYTICS'
|
|
85
|
+
*
|
|
86
|
+
* @param options Query parameters for listing buckets
|
|
87
|
+
* @param options.limit Maximum number of buckets to return
|
|
88
|
+
* @param options.offset Number of buckets to skip
|
|
89
|
+
* @param options.sortColumn Column to sort by ('id', 'name', 'created_at', 'updated_at')
|
|
90
|
+
* @param options.sortOrder Sort order ('asc' or 'desc')
|
|
91
|
+
* @param options.search Search term to filter bucket names
|
|
92
|
+
* @returns Promise with list of analytics buckets or error
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const { data, error } = await storage.analytics.listBuckets({
|
|
97
|
+
* limit: 10,
|
|
98
|
+
* offset: 0,
|
|
99
|
+
* sortColumn: 'created_at',
|
|
100
|
+
* sortOrder: 'desc',
|
|
101
|
+
* search: 'analytics'
|
|
102
|
+
* })
|
|
103
|
+
* if (data) {
|
|
104
|
+
* console.log('Found analytics buckets:', data.length)
|
|
105
|
+
* data.forEach(bucket => console.log(`- ${bucket.name}`))
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
async listBuckets(options?: {
|
|
110
|
+
limit?: number
|
|
111
|
+
offset?: number
|
|
112
|
+
sortColumn?: 'id' | 'name' | 'created_at' | 'updated_at'
|
|
113
|
+
sortOrder?: 'asc' | 'desc'
|
|
114
|
+
search?: string
|
|
115
|
+
}): Promise<
|
|
116
|
+
| {
|
|
117
|
+
data: AnalyticBucket[]
|
|
118
|
+
error: null
|
|
119
|
+
}
|
|
120
|
+
| {
|
|
121
|
+
data: null
|
|
122
|
+
error: StorageError
|
|
123
|
+
}
|
|
124
|
+
> {
|
|
125
|
+
try {
|
|
126
|
+
// Build query string from options
|
|
127
|
+
const queryParams = new URLSearchParams()
|
|
128
|
+
if (options?.limit !== undefined) queryParams.set('limit', options.limit.toString())
|
|
129
|
+
if (options?.offset !== undefined) queryParams.set('offset', options.offset.toString())
|
|
130
|
+
if (options?.sortColumn) queryParams.set('sortColumn', options.sortColumn)
|
|
131
|
+
if (options?.sortOrder) queryParams.set('sortOrder', options.sortOrder)
|
|
132
|
+
if (options?.search) queryParams.set('search', options.search)
|
|
133
|
+
|
|
134
|
+
const queryString = queryParams.toString()
|
|
135
|
+
const url = queryString ? `${this.url}/bucket?${queryString}` : `${this.url}/bucket`
|
|
136
|
+
|
|
137
|
+
const data = await get(this.fetch, url, { headers: this.headers })
|
|
138
|
+
|
|
139
|
+
return { data: data, error: null }
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (this.shouldThrowOnError) {
|
|
142
|
+
throw error
|
|
143
|
+
}
|
|
144
|
+
if (isStorageError(error)) {
|
|
145
|
+
return { data: null, error }
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
throw error
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Deletes an existing analytics bucket
|
|
154
|
+
* A bucket can't be deleted with existing objects inside it
|
|
155
|
+
* You must first empty the bucket before deletion
|
|
156
|
+
*
|
|
157
|
+
* @param bucketId The unique identifier of the bucket you would like to delete
|
|
158
|
+
* @returns Promise with success message or error
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const { data, error } = await analyticsApi.deleteBucket('old-analytics-bucket')
|
|
163
|
+
* if (error) {
|
|
164
|
+
* console.error('Failed to delete bucket:', error.message)
|
|
165
|
+
* } else {
|
|
166
|
+
* console.log('Bucket deleted successfully:', data.message)
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
async deleteBucket(bucketId: string): Promise<
|
|
171
|
+
| {
|
|
172
|
+
data: { message: string }
|
|
173
|
+
error: null
|
|
174
|
+
}
|
|
175
|
+
| {
|
|
176
|
+
data: null
|
|
177
|
+
error: StorageError
|
|
178
|
+
}
|
|
179
|
+
> {
|
|
180
|
+
try {
|
|
181
|
+
const data = await remove(
|
|
182
|
+
this.fetch,
|
|
183
|
+
`${this.url}/bucket/${bucketId}`,
|
|
184
|
+
{},
|
|
185
|
+
{ headers: this.headers }
|
|
186
|
+
)
|
|
187
|
+
return { data, error: null }
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (this.shouldThrowOnError) {
|
|
190
|
+
throw error
|
|
191
|
+
}
|
|
192
|
+
if (isStorageError(error)) {
|
|
193
|
+
return { data: null, error }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
throw error
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -2,7 +2,7 @@ import { DEFAULT_HEADERS } from '../lib/constants'
|
|
|
2
2
|
import { isStorageError, StorageError } from '../lib/errors'
|
|
3
3
|
import { Fetch, get, post, put, remove } from '../lib/fetch'
|
|
4
4
|
import { resolveFetch } from '../lib/helpers'
|
|
5
|
-
import { Bucket, BucketType } from '../lib/types'
|
|
5
|
+
import { Bucket, BucketType, ListBucketOptions } from '../lib/types'
|
|
6
6
|
import { StorageClientOptions } from '../StorageClient'
|
|
7
7
|
|
|
8
8
|
export default class StorageBucketApi {
|
|
@@ -28,7 +28,7 @@ export default class StorageBucketApi {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
this.url = baseUrl.href
|
|
31
|
+
this.url = baseUrl.href.replace(/\/$/, '')
|
|
32
32
|
this.headers = { ...DEFAULT_HEADERS, ...headers }
|
|
33
33
|
this.fetch = resolveFetch(fetch)
|
|
34
34
|
}
|
|
@@ -44,7 +44,7 @@ export default class StorageBucketApi {
|
|
|
44
44
|
/**
|
|
45
45
|
* Retrieves the details of all Storage buckets within an existing project.
|
|
46
46
|
*/
|
|
47
|
-
async listBuckets(): Promise<
|
|
47
|
+
async listBuckets(options?: ListBucketOptions): Promise<
|
|
48
48
|
| {
|
|
49
49
|
data: Bucket[]
|
|
50
50
|
error: null
|
|
@@ -55,7 +55,10 @@ export default class StorageBucketApi {
|
|
|
55
55
|
}
|
|
56
56
|
> {
|
|
57
57
|
try {
|
|
58
|
-
const
|
|
58
|
+
const queryString = this.listBucketOptionsToQueryString(options)
|
|
59
|
+
const data = await get(this.fetch, `${this.url}/bucket${queryString}`, {
|
|
60
|
+
headers: this.headers,
|
|
61
|
+
})
|
|
59
62
|
return { data, error: null }
|
|
60
63
|
} catch (error) {
|
|
61
64
|
if (this.shouldThrowOnError) {
|
|
@@ -286,4 +289,26 @@ export default class StorageBucketApi {
|
|
|
286
289
|
throw error
|
|
287
290
|
}
|
|
288
291
|
}
|
|
292
|
+
|
|
293
|
+
private listBucketOptionsToQueryString(options?: ListBucketOptions): string {
|
|
294
|
+
const params: Record<string, string> = {}
|
|
295
|
+
if (options) {
|
|
296
|
+
if ('limit' in options) {
|
|
297
|
+
params.limit = String(options.limit)
|
|
298
|
+
}
|
|
299
|
+
if ('offset' in options) {
|
|
300
|
+
params.offset = String(options.offset)
|
|
301
|
+
}
|
|
302
|
+
if (options.search) {
|
|
303
|
+
params.search = options.search
|
|
304
|
+
}
|
|
305
|
+
if (options.sortColumn) {
|
|
306
|
+
params.sortColumn = options.sortColumn
|
|
307
|
+
}
|
|
308
|
+
if (options.sortOrder) {
|
|
309
|
+
params.sortOrder = options.sortOrder
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return Object.keys(params).length > 0 ? '?' + new URLSearchParams(params).toString() : ''
|
|
313
|
+
}
|
|
289
314
|
}
|
|
@@ -110,8 +110,11 @@ export default class StorageFileApi {
|
|
|
110
110
|
body.append('', fileBody)
|
|
111
111
|
} else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
|
|
112
112
|
body = fileBody
|
|
113
|
-
|
|
114
|
-
if (
|
|
113
|
+
// Only append if not already present
|
|
114
|
+
if (!body.has('cacheControl')) {
|
|
115
|
+
body.append('cacheControl', options.cacheControl as string)
|
|
116
|
+
}
|
|
117
|
+
if (metadata && !body.has('metadata')) {
|
|
115
118
|
body.append('metadata', this.encodeMetadata(metadata))
|
|
116
119
|
}
|
|
117
120
|
} else {
|
|
@@ -122,6 +125,16 @@ export default class StorageFileApi {
|
|
|
122
125
|
if (metadata) {
|
|
123
126
|
headers['x-metadata'] = this.toBase64(this.encodeMetadata(metadata))
|
|
124
127
|
}
|
|
128
|
+
|
|
129
|
+
// Node.js streams require duplex option for fetch in Node 20+
|
|
130
|
+
// Check for both web ReadableStream and Node.js streams
|
|
131
|
+
const isStream =
|
|
132
|
+
(typeof ReadableStream !== 'undefined' && body instanceof ReadableStream) ||
|
|
133
|
+
(body && typeof body === 'object' && 'pipe' in body && typeof body.pipe === 'function')
|
|
134
|
+
|
|
135
|
+
if (isStream && !options.duplex) {
|
|
136
|
+
options.duplex = 'half'
|
|
137
|
+
}
|
|
125
138
|
}
|
|
126
139
|
|
|
127
140
|
if (fileOptions?.headers) {
|