@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,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
const fetch_1 = require("./fetch");
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
8
|
+
/**
|
|
9
|
+
* API class for managing Vector Indexes within Vector Buckets
|
|
10
|
+
* Provides methods for creating, reading, listing, and deleting vector indexes
|
|
11
|
+
*/
|
|
12
|
+
class VectorIndexApi {
|
|
13
|
+
constructor(url, headers = {}, fetch) {
|
|
14
|
+
this.shouldThrowOnError = false;
|
|
15
|
+
this.url = url.replace(/\/$/, '');
|
|
16
|
+
this.headers = Object.assign(Object.assign({}, constants_1.DEFAULT_HEADERS), headers);
|
|
17
|
+
this.fetch = (0, helpers_1.resolveFetch)(fetch);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Enable throwing errors instead of returning them in the response
|
|
21
|
+
* When enabled, failed operations will throw instead of returning { data: null, error }
|
|
22
|
+
*
|
|
23
|
+
* @returns This instance for method chaining
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const client = new VectorIndexApi(url, headers)
|
|
27
|
+
* client.throwOnError()
|
|
28
|
+
* const { data } = await client.createIndex(options) // throws on error
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
throwOnError() {
|
|
32
|
+
this.shouldThrowOnError = true;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new vector index within a bucket
|
|
37
|
+
* Defines the schema for vectors including dimensionality, distance metric, and metadata config
|
|
38
|
+
*
|
|
39
|
+
* @param options - Index configuration
|
|
40
|
+
* @param options.vectorBucketName - Name of the parent vector bucket
|
|
41
|
+
* @param options.indexName - Unique name for the index within the bucket
|
|
42
|
+
* @param options.dataType - Data type for vector components (currently only 'float32')
|
|
43
|
+
* @param options.dimension - Dimensionality of vectors (e.g., 384, 768, 1536)
|
|
44
|
+
* @param options.distanceMetric - Similarity metric ('cosine', 'euclidean', 'dotproduct')
|
|
45
|
+
* @param options.metadataConfiguration - Optional config for non-filterable metadata keys
|
|
46
|
+
* @returns Promise with empty response on success or error
|
|
47
|
+
*
|
|
48
|
+
* @throws {StorageVectorsApiError} With code:
|
|
49
|
+
* - `S3VectorConflictException` if index already exists (HTTP 409)
|
|
50
|
+
* - `S3VectorMaxIndexesExceeded` if quota exceeded (HTTP 400)
|
|
51
|
+
* - `S3VectorNotFoundException` if bucket doesn't exist (HTTP 404)
|
|
52
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const { data, error } = await client.createIndex({
|
|
57
|
+
* vectorBucketName: 'embeddings-prod',
|
|
58
|
+
* indexName: 'documents-openai-small',
|
|
59
|
+
* dataType: 'float32',
|
|
60
|
+
* dimension: 1536,
|
|
61
|
+
* distanceMetric: 'cosine',
|
|
62
|
+
* metadataConfiguration: {
|
|
63
|
+
* nonFilterableMetadataKeys: ['raw_text', 'internal_id']
|
|
64
|
+
* }
|
|
65
|
+
* })
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
createIndex(options) {
|
|
69
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
try {
|
|
71
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/CreateIndex`, options, {
|
|
72
|
+
headers: this.headers,
|
|
73
|
+
});
|
|
74
|
+
return { data: data || {}, error: null };
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (this.shouldThrowOnError) {
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
if ((0, errors_1.isStorageVectorsError)(error)) {
|
|
81
|
+
return { data: null, error };
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves metadata for a specific vector index
|
|
89
|
+
* Returns index configuration including dimension, distance metric, and metadata settings
|
|
90
|
+
*
|
|
91
|
+
* @param vectorBucketName - Name of the parent vector bucket
|
|
92
|
+
* @param indexName - Name of the index to retrieve
|
|
93
|
+
* @returns Promise with index metadata or error
|
|
94
|
+
*
|
|
95
|
+
* @throws {StorageVectorsApiError} With code:
|
|
96
|
+
* - `S3VectorNotFoundException` if index or bucket doesn't exist (HTTP 404)
|
|
97
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const { data, error } = await client.getIndex('embeddings-prod', 'documents-openai-small')
|
|
102
|
+
* if (data) {
|
|
103
|
+
* console.log('Index dimension:', data.index.dimension)
|
|
104
|
+
* console.log('Distance metric:', data.index.distanceMetric)
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
getIndex(vectorBucketName, indexName) {
|
|
109
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
try {
|
|
111
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/GetIndex`, { vectorBucketName, indexName }, { headers: this.headers });
|
|
112
|
+
return { data, error: null };
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (this.shouldThrowOnError) {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
if ((0, errors_1.isStorageVectorsError)(error)) {
|
|
119
|
+
return { data: null, error };
|
|
120
|
+
}
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Lists vector indexes within a bucket with optional filtering and pagination
|
|
127
|
+
* Supports prefix-based filtering and paginated results
|
|
128
|
+
*
|
|
129
|
+
* @param options - Listing options
|
|
130
|
+
* @param options.vectorBucketName - Name of the parent vector bucket
|
|
131
|
+
* @param options.prefix - Filter indexes by name prefix
|
|
132
|
+
* @param options.maxResults - Maximum results per page (default: 100)
|
|
133
|
+
* @param options.nextToken - Pagination token from previous response
|
|
134
|
+
* @returns Promise with list of indexes and pagination token
|
|
135
|
+
*
|
|
136
|
+
* @throws {StorageVectorsApiError} With code:
|
|
137
|
+
* - `S3VectorNotFoundException` if bucket doesn't exist (HTTP 404)
|
|
138
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // List all indexes in a bucket
|
|
143
|
+
* const { data, error } = await client.listIndexes({
|
|
144
|
+
* vectorBucketName: 'embeddings-prod',
|
|
145
|
+
* prefix: 'documents-'
|
|
146
|
+
* })
|
|
147
|
+
* if (data) {
|
|
148
|
+
* console.log('Found indexes:', data.indexes.map(i => i.indexName))
|
|
149
|
+
* // Fetch next page if available
|
|
150
|
+
* if (data.nextToken) {
|
|
151
|
+
* const next = await client.listIndexes({
|
|
152
|
+
* vectorBucketName: 'embeddings-prod',
|
|
153
|
+
* nextToken: data.nextToken
|
|
154
|
+
* })
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
listIndexes(options) {
|
|
160
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
try {
|
|
162
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/ListIndexes`, options, {
|
|
163
|
+
headers: this.headers,
|
|
164
|
+
});
|
|
165
|
+
return { data, error: null };
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (this.shouldThrowOnError) {
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
if ((0, errors_1.isStorageVectorsError)(error)) {
|
|
172
|
+
return { data: null, error };
|
|
173
|
+
}
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Deletes a vector index and all its data
|
|
180
|
+
* This operation removes the index schema and all vectors stored in the index
|
|
181
|
+
*
|
|
182
|
+
* @param vectorBucketName - Name of the parent vector bucket
|
|
183
|
+
* @param indexName - Name of the index to delete
|
|
184
|
+
* @returns Promise with empty response on success or error
|
|
185
|
+
*
|
|
186
|
+
* @throws {StorageVectorsApiError} With code:
|
|
187
|
+
* - `S3VectorNotFoundException` if index or bucket doesn't exist (HTTP 404)
|
|
188
|
+
* - `InternalError` for server errors (HTTP 500)
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* // Delete an index and all its vectors
|
|
193
|
+
* const { error } = await client.deleteIndex('embeddings-prod', 'old-index')
|
|
194
|
+
* if (!error) {
|
|
195
|
+
* console.log('Index deleted successfully')
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
deleteIndex(vectorBucketName, indexName) {
|
|
200
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
try {
|
|
202
|
+
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/DeleteIndex`, { vectorBucketName, indexName }, { headers: this.headers });
|
|
203
|
+
return { data: data || {}, error: null };
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
if (this.shouldThrowOnError) {
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
if ((0, errors_1.isStorageVectorsError)(error)) {
|
|
210
|
+
return { data: null, error };
|
|
211
|
+
}
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.default = VectorIndexApi;
|
|
218
|
+
//# sourceMappingURL=VectorIndexApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VectorIndexApi.js","sourceRoot":"","sources":["../../../../src/lib/vectors/VectorIndexApi.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,qCAAgD;AAChD,mCAAqC;AACrC,uCAAwC;AAuBxC;;;GAGG;AACH,MAAqB,cAAc;IAMjC,YAAY,GAAW,EAAE,UAAqC,EAAE,EAAE,KAAa;QAFrE,uBAAkB,GAAG,KAAK,CAAA;QAGlC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QACjC,IAAI,CAAC,OAAO,mCAAQ,2BAAe,GAAK,OAAO,CAAE,CAAA;QACjD,IAAI,CAAC,KAAK,GAAG,IAAA,sBAAY,EAAC,KAAK,CAAC,CAAA;IAClC,CAAC;IAED;;;;;;;;;;;OAWG;IACI,YAAY;QACjB,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACG,WAAW,CAAC,OAA2B;;YAC3C,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,IAAA,YAAI,EAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,cAAc,EAAE,OAAO,EAAE;oBACtE,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAA;gBACF,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,KAAK,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ings":"AACA,eAAO,MAAM,eAAe;;;CAG3B,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_HEADERS = void 0;
|
|
4
|
+
const version_1 = require("../version");
|
|
5
|
+
exports.DEFAULT_HEADERS = {
|
|
6
|
+
'X-Client-Info': `storage-js/${version_1.version}`,
|
|
7
|
+
'Content-Type': 'application/json',
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/lib/vectors/constants.ts"],"names":[],"mappings":";;;AAAA,wCAAoC;AACvB,QAAA,eAAe,GAAG;IAC7B,eAAe,EAAE,cAAc,iBAAO,EAAE;IACxC,cAAc,EAAE,kBAAkB;CACnC,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Storage Vectors errors
|
|
3
|
+
*/
|
|
4
|
+
export declare class StorageVectorsError extends Error {
|
|
5
|
+
protected __isStorageVectorsError: boolean;
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Type guard to check if an error is a StorageVectorsError
|
|
10
|
+
* @param error - The error to check
|
|
11
|
+
* @returns True if the error is a StorageVectorsError
|
|
12
|
+
*/
|
|
13
|
+
export declare function isStorageVectorsError(error: unknown): error is StorageVectorsError;
|
|
14
|
+
/**
|
|
15
|
+
* API error returned from S3 Vectors service
|
|
16
|
+
* Includes HTTP status code and service-specific error code
|
|
17
|
+
*/
|
|
18
|
+
export declare class StorageVectorsApiError extends StorageVectorsError {
|
|
19
|
+
status: number;
|
|
20
|
+
statusCode: string;
|
|
21
|
+
constructor(message: string, status: number, statusCode: string);
|
|
22
|
+
toJSON(): {
|
|
23
|
+
name: string;
|
|
24
|
+
message: string;
|
|
25
|
+
status: number;
|
|
26
|
+
statusCode: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Unknown error that doesn't match expected error patterns
|
|
31
|
+
* Wraps the original error for debugging
|
|
32
|
+
*/
|
|
33
|
+
export declare class StorageVectorsUnknownError extends StorageVectorsError {
|
|
34
|
+
originalError: unknown;
|
|
35
|
+
constructor(message: string, originalError: unknown);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Error codes specific to S3 Vectors API
|
|
39
|
+
* Maps AWS service errors to application-friendly error codes
|
|
40
|
+
*/
|
|
41
|
+
export declare enum StorageVectorsErrorCode {
|
|
42
|
+
/** Internal server fault (HTTP 500) */
|
|
43
|
+
InternalError = "InternalError",
|
|
44
|
+
/** Resource already exists / conflict (HTTP 409) */
|
|
45
|
+
S3VectorConflictException = "S3VectorConflictException",
|
|
46
|
+
/** Resource not found (HTTP 404) */
|
|
47
|
+
S3VectorNotFoundException = "S3VectorNotFoundException",
|
|
48
|
+
/** Delete bucket while not empty (HTTP 400) */
|
|
49
|
+
S3VectorBucketNotEmpty = "S3VectorBucketNotEmpty",
|
|
50
|
+
/** Exceeds bucket quota/limit (HTTP 400) */
|
|
51
|
+
S3VectorMaxBucketsExceeded = "S3VectorMaxBucketsExceeded",
|
|
52
|
+
/** Exceeds index quota/limit (HTTP 400) */
|
|
53
|
+
S3VectorMaxIndexesExceeded = "S3VectorMaxIndexesExceeded"
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/lib/vectors/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAS,CAAC,uBAAuB,UAAO;gBAE5B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB,CAElF;AAED;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;gBAEN,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAO/D,MAAM;;;;;;CAQP;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,mBAAmB;IACjE,aAAa,EAAE,OAAO,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO;CAKpD;AAED;;;GAGG;AACH,oBAAY,uBAAuB;IACjC,uCAAuC;IACvC,aAAa,kBAAkB;IAC/B,oDAAoD;IACpD,yBAAyB,8BAA8B;IACvD,oCAAoC;IACpC,yBAAyB,8BAA8B;IACvD,+CAA+C;IAC/C,sBAAsB,2BAA2B;IACjD,4CAA4C;IAC5C,0BAA0B,+BAA+B;IACzD,2CAA2C;IAC3C,0BAA0B,+BAA+B;CAC1D"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StorageVectorsErrorCode = exports.StorageVectorsUnknownError = exports.StorageVectorsApiError = exports.StorageVectorsError = void 0;
|
|
4
|
+
exports.isStorageVectorsError = isStorageVectorsError;
|
|
5
|
+
/**
|
|
6
|
+
* Base error class for all Storage Vectors errors
|
|
7
|
+
*/
|
|
8
|
+
class StorageVectorsError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.__isStorageVectorsError = true;
|
|
12
|
+
this.name = 'StorageVectorsError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.StorageVectorsError = StorageVectorsError;
|
|
16
|
+
/**
|
|
17
|
+
* Type guard to check if an error is a StorageVectorsError
|
|
18
|
+
* @param error - The error to check
|
|
19
|
+
* @returns True if the error is a StorageVectorsError
|
|
20
|
+
*/
|
|
21
|
+
function isStorageVectorsError(error) {
|
|
22
|
+
return typeof error === 'object' && error !== null && '__isStorageVectorsError' in error;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* API error returned from S3 Vectors service
|
|
26
|
+
* Includes HTTP status code and service-specific error code
|
|
27
|
+
*/
|
|
28
|
+
class StorageVectorsApiError extends StorageVectorsError {
|
|
29
|
+
constructor(message, status, statusCode) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = 'StorageVectorsApiError';
|
|
32
|
+
this.status = status;
|
|
33
|
+
this.statusCode = statusCode;
|
|
34
|
+
}
|
|
35
|
+
toJSON() {
|
|
36
|
+
return {
|
|
37
|
+
name: this.name,
|
|
38
|
+
message: this.message,
|
|
39
|
+
status: this.status,
|
|
40
|
+
statusCode: this.statusCode,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.StorageVectorsApiError = StorageVectorsApiError;
|
|
45
|
+
/**
|
|
46
|
+
* Unknown error that doesn't match expected error patterns
|
|
47
|
+
* Wraps the original error for debugging
|
|
48
|
+
*/
|
|
49
|
+
class StorageVectorsUnknownError extends StorageVectorsError {
|
|
50
|
+
constructor(message, originalError) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.name = 'StorageVectorsUnknownError';
|
|
53
|
+
this.originalError = originalError;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.StorageVectorsUnknownError = StorageVectorsUnknownError;
|
|
57
|
+
/**
|
|
58
|
+
* Error codes specific to S3 Vectors API
|
|
59
|
+
* Maps AWS service errors to application-friendly error codes
|
|
60
|
+
*/
|
|
61
|
+
var StorageVectorsErrorCode;
|
|
62
|
+
(function (StorageVectorsErrorCode) {
|
|
63
|
+
/** Internal server fault (HTTP 500) */
|
|
64
|
+
StorageVectorsErrorCode["InternalError"] = "InternalError";
|
|
65
|
+
/** Resource already exists / conflict (HTTP 409) */
|
|
66
|
+
StorageVectorsErrorCode["S3VectorConflictException"] = "S3VectorConflictException";
|
|
67
|
+
/** Resource not found (HTTP 404) */
|
|
68
|
+
StorageVectorsErrorCode["S3VectorNotFoundException"] = "S3VectorNotFoundException";
|
|
69
|
+
/** Delete bucket while not empty (HTTP 400) */
|
|
70
|
+
StorageVectorsErrorCode["S3VectorBucketNotEmpty"] = "S3VectorBucketNotEmpty";
|
|
71
|
+
/** Exceeds bucket quota/limit (HTTP 400) */
|
|
72
|
+
StorageVectorsErrorCode["S3VectorMaxBucketsExceeded"] = "S3VectorMaxBucketsExceeded";
|
|
73
|
+
/** Exceeds index quota/limit (HTTP 400) */
|
|
74
|
+
StorageVectorsErrorCode["S3VectorMaxIndexesExceeded"] = "S3VectorMaxIndexesExceeded";
|
|
75
|
+
})(StorageVectorsErrorCode || (exports.StorageVectorsErrorCode = StorageVectorsErrorCode = {}));
|
|
76
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/lib/vectors/errors.ts"],"names":[],"mappings":";;;AAiBA,sDAEC;AAnBD;;GAEG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAG5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QAHN,4BAAuB,GAAG,IAAI,CAAA;QAItC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AAPD,kDAOC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,KAAc;IAClD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,yBAAyB,IAAI,KAAK,CAAA;AAC1F,CAAC;AAED;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,mBAAmB;IAI7D,YAAY,OAAe,EAAE,MAAc,EAAE,UAAkB;QAC7D,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAA;IACH,CAAC;CACF;AAnBD,wDAmBC;AAED;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,mBAAmB;IAGjE,YAAY,OAAe,EAAE,aAAsB;QACjD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;QACxC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;CACF;AARD,gEAQC;AAED;;;GAGG;AACH,IAAY,uBAaX;AAbD,WAAY,uBAAuB;IACjC,uCAAuC;IACvC,0DAA+B,CAAA;IAC/B,oDAAoD;IACpD,kFAAuD,CAAA;IACvD,oCAAoC;IACpC,kFAAuD,CAAA;IACvD,+CAA+C;IAC/C,4EAAiD,CAAA;IACjD,4CAA4C;IAC5C,oFAAyD,CAAA;IACzD,2CAA2C;IAC3C,oFAAyD,CAAA;AAC3D,CAAC,EAbW,uBAAuB,uCAAvB,uBAAuB,QAalC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { VectorFetchParameters } from './types';
|
|
2
|
+
export type Fetch = typeof fetch;
|
|
3
|
+
/**
|
|
4
|
+
* Options for fetch requests
|
|
5
|
+
* @property headers - Custom HTTP headers
|
|
6
|
+
* @property noResolveJson - If true, return raw Response instead of parsing JSON
|
|
7
|
+
*/
|
|
8
|
+
export interface FetchOptions {
|
|
9
|
+
headers?: {
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
};
|
|
12
|
+
noResolveJson?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* HTTP methods supported by the API
|
|
16
|
+
*/
|
|
17
|
+
export type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
18
|
+
/**
|
|
19
|
+
* Performs a GET request
|
|
20
|
+
* @param fetcher - Fetch function to use
|
|
21
|
+
* @param url - Request URL
|
|
22
|
+
* @param options - Custom fetch options
|
|
23
|
+
* @param parameters - Additional fetch parameters
|
|
24
|
+
* @returns Promise with parsed response
|
|
25
|
+
*/
|
|
26
|
+
export declare function get(fetcher: Fetch, url: string, options?: FetchOptions, parameters?: VectorFetchParameters): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Performs a POST request
|
|
29
|
+
* @param fetcher - Fetch function to use
|
|
30
|
+
* @param url - Request URL
|
|
31
|
+
* @param body - Request body to be JSON stringified
|
|
32
|
+
* @param options - Custom fetch options
|
|
33
|
+
* @param parameters - Additional fetch parameters
|
|
34
|
+
* @returns Promise with parsed response
|
|
35
|
+
*/
|
|
36
|
+
export declare function post(fetcher: Fetch, url: string, body: object, options?: FetchOptions, parameters?: VectorFetchParameters): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Performs a PUT request
|
|
39
|
+
* @param fetcher - Fetch function to use
|
|
40
|
+
* @param url - Request URL
|
|
41
|
+
* @param body - Request body to be JSON stringified
|
|
42
|
+
* @param options - Custom fetch options
|
|
43
|
+
* @param parameters - Additional fetch parameters
|
|
44
|
+
* @returns Promise with parsed response
|
|
45
|
+
*/
|
|
46
|
+
export declare function put(fetcher: Fetch, url: string, body: object, options?: FetchOptions, parameters?: VectorFetchParameters): Promise<any>;
|
|
47
|
+
/**
|
|
48
|
+
* Performs a DELETE request
|
|
49
|
+
* @param fetcher - Fetch function to use
|
|
50
|
+
* @param url - Request URL
|
|
51
|
+
* @param body - Request body to be JSON stringified
|
|
52
|
+
* @param options - Custom fetch options
|
|
53
|
+
* @param parameters - Additional fetch parameters
|
|
54
|
+
* @returns Promise with parsed response
|
|
55
|
+
*/
|
|
56
|
+
export declare function remove(fetcher: Fetch, url: string, body: object, options?: FetchOptions, parameters?: VectorFetchParameters): Promise<any>;
|
|
57
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/lib/vectors/fetch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAE/C,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAA;AAEhC;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KACtB,CAAA;IACD,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAA;AA4HjE;;;;;;;GAOG;AACH,wBAAsB,GAAG,CACvB,OAAO,EAAE,KAAK,EACd,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,YAAY,EACtB,UAAU,CAAC,EAAE,qBAAqB,GACjC,OAAO,CAAC,GAAG,CAAC,CAEd;AAED;;;;;;;;GAQG;AACH,wBAAsB,IAAI,CACxB,OAAO,EAAE,KAAK,EACd,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,YAAY,EACtB,UAAU,CAAC,EAAE,qBAAqB,GACjC,OAAO,CAAC,GAAG,CAAC,CAEd;AAED;;;;;;;;GAQG;AACH,wBAAsB,GAAG,CACvB,OAAO,EAAE,KAAK,EACd,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,YAAY,EACtB,UAAU,CAAC,EAAE,qBAAqB,GACjC,OAAO,CAAC,GAAG,CAAC,CAEd;AAED;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE,KAAK,EACd,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,YAAY,EACtB,UAAU,CAAC,EAAE,qBAAqB,GACjC,OAAO,CAAC,GAAG,CAAC,CAEd"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get = get;
|
|
4
|
+
exports.post = post;
|
|
5
|
+
exports.put = put;
|
|
6
|
+
exports.remove = remove;
|
|
7
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
const helpers_1 = require("./helpers");
|
|
10
|
+
/**
|
|
11
|
+
* Extracts error message from various error response formats
|
|
12
|
+
* @param err - Error object from API
|
|
13
|
+
* @returns Human-readable error message
|
|
14
|
+
*/
|
|
15
|
+
const _getErrorMessage = (err) => err.msg || err.message || err.error_description || err.error || JSON.stringify(err);
|
|
16
|
+
/**
|
|
17
|
+
* Handles fetch errors and converts them to StorageVectors error types
|
|
18
|
+
* @param error - The error caught from fetch
|
|
19
|
+
* @param reject - Promise rejection function
|
|
20
|
+
* @param options - Fetch options that may affect error handling
|
|
21
|
+
*/
|
|
22
|
+
const handleError = (error, reject, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
// Check if error is a Response-like object (has status and ok properties)
|
|
24
|
+
// This is more reliable than instanceof which can fail across realms
|
|
25
|
+
const isResponseLike = error &&
|
|
26
|
+
typeof error === 'object' &&
|
|
27
|
+
'status' in error &&
|
|
28
|
+
'ok' in error &&
|
|
29
|
+
typeof error.status === 'number';
|
|
30
|
+
if (isResponseLike && !(options === null || options === void 0 ? void 0 : options.noResolveJson)) {
|
|
31
|
+
const status = error.status || 500;
|
|
32
|
+
const responseError = error;
|
|
33
|
+
// Try to parse JSON body if available
|
|
34
|
+
if (typeof responseError.json === 'function') {
|
|
35
|
+
responseError
|
|
36
|
+
.json()
|
|
37
|
+
.then((err) => {
|
|
38
|
+
const statusCode = (err === null || err === void 0 ? void 0 : err.statusCode) || (err === null || err === void 0 ? void 0 : err.code) || status + '';
|
|
39
|
+
reject(new errors_1.StorageVectorsApiError(_getErrorMessage(err), status, statusCode));
|
|
40
|
+
})
|
|
41
|
+
.catch(() => {
|
|
42
|
+
// If JSON parsing fails, create an ApiError with the HTTP status code
|
|
43
|
+
const statusCode = status + '';
|
|
44
|
+
const message = responseError.statusText || `HTTP ${status} error`;
|
|
45
|
+
reject(new errors_1.StorageVectorsApiError(message, status, statusCode));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// No json() method available, create error from status
|
|
50
|
+
const statusCode = status + '';
|
|
51
|
+
const message = responseError.statusText || `HTTP ${status} error`;
|
|
52
|
+
reject(new errors_1.StorageVectorsApiError(message, status, statusCode));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
reject(new errors_1.StorageVectorsUnknownError(_getErrorMessage(error), error));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Builds request parameters for fetch calls
|
|
61
|
+
* @param method - HTTP method
|
|
62
|
+
* @param options - Custom fetch options
|
|
63
|
+
* @param parameters - Additional fetch parameters like AbortSignal
|
|
64
|
+
* @param body - Request body (will be JSON stringified if plain object)
|
|
65
|
+
* @returns Complete fetch request parameters
|
|
66
|
+
*/
|
|
67
|
+
const _getRequestParams = (method, options, parameters, body) => {
|
|
68
|
+
const params = { method, headers: (options === null || options === void 0 ? void 0 : options.headers) || {} };
|
|
69
|
+
if (method === 'GET' || !body) {
|
|
70
|
+
return params;
|
|
71
|
+
}
|
|
72
|
+
if ((0, helpers_1.isPlainObject)(body)) {
|
|
73
|
+
params.headers = Object.assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers);
|
|
74
|
+
params.body = JSON.stringify(body);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
params.body = body;
|
|
78
|
+
}
|
|
79
|
+
return Object.assign(Object.assign({}, params), parameters);
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Internal request handler that wraps fetch with error handling
|
|
83
|
+
* @param fetcher - Fetch function to use
|
|
84
|
+
* @param method - HTTP method
|
|
85
|
+
* @param url - Request URL
|
|
86
|
+
* @param options - Custom fetch options
|
|
87
|
+
* @param parameters - Additional fetch parameters
|
|
88
|
+
* @param body - Request body
|
|
89
|
+
* @returns Promise with parsed response or error
|
|
90
|
+
*/
|
|
91
|
+
function _handleRequest(fetcher, method, url, options, parameters, body) {
|
|
92
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
fetcher(url, _getRequestParams(method, options, parameters, body))
|
|
95
|
+
.then((result) => {
|
|
96
|
+
if (!result.ok)
|
|
97
|
+
throw result;
|
|
98
|
+
if (options === null || options === void 0 ? void 0 : options.noResolveJson)
|
|
99
|
+
return result;
|
|
100
|
+
// Handle empty responses (204, empty body)
|
|
101
|
+
const contentType = result.headers.get('content-type');
|
|
102
|
+
if (!contentType || !contentType.includes('application/json')) {
|
|
103
|
+
return {};
|
|
104
|
+
}
|
|
105
|
+
return result.json();
|
|
106
|
+
})
|
|
107
|
+
.then((data) => resolve(data))
|
|
108
|
+
.catch((error) => handleError(error, reject, options));
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Performs a GET request
|
|
114
|
+
* @param fetcher - Fetch function to use
|
|
115
|
+
* @param url - Request URL
|
|
116
|
+
* @param options - Custom fetch options
|
|
117
|
+
* @param parameters - Additional fetch parameters
|
|
118
|
+
* @returns Promise with parsed response
|
|
119
|
+
*/
|
|
120
|
+
function get(fetcher, url, options, parameters) {
|
|
121
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
return _handleRequest(fetcher, 'GET', url, options, parameters);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Performs a POST request
|
|
127
|
+
* @param fetcher - Fetch function to use
|
|
128
|
+
* @param url - Request URL
|
|
129
|
+
* @param body - Request body to be JSON stringified
|
|
130
|
+
* @param options - Custom fetch options
|
|
131
|
+
* @param parameters - Additional fetch parameters
|
|
132
|
+
* @returns Promise with parsed response
|
|
133
|
+
*/
|
|
134
|
+
function post(fetcher, url, body, options, parameters) {
|
|
135
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
return _handleRequest(fetcher, 'POST', url, options, parameters, body);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Performs a PUT request
|
|
141
|
+
* @param fetcher - Fetch function to use
|
|
142
|
+
* @param url - Request URL
|
|
143
|
+
* @param body - Request body to be JSON stringified
|
|
144
|
+
* @param options - Custom fetch options
|
|
145
|
+
* @param parameters - Additional fetch parameters
|
|
146
|
+
* @returns Promise with parsed response
|
|
147
|
+
*/
|
|
148
|
+
function put(fetcher, url, body, options, parameters) {
|
|
149
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
return _handleRequest(fetcher, 'PUT', url, options, parameters, body);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Performs a DELETE request
|
|
155
|
+
* @param fetcher - Fetch function to use
|
|
156
|
+
* @param url - Request URL
|
|
157
|
+
* @param body - Request body to be JSON stringified
|
|
158
|
+
* @param options - Custom fetch options
|
|
159
|
+
* @param parameters - Additional fetch parameters
|
|
160
|
+
* @returns Promise with parsed response
|
|
161
|
+
*/
|
|
162
|
+
function remove(fetcher, url, body, options, parameters) {
|
|
163
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
return _handleRequest(fetcher, 'DELETE', url, options, parameters, body);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@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