@qrvey/object-storage 2.0.3-beta → 2.0.4-1170
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 +1 -1
- package/dist/cjs/index-v2.js +1699 -0
- package/dist/cjs/index-v2.js.map +1 -0
- package/dist/cjs/index.js +163 -1051
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/chunk-66BQA4WX.mjs +96 -0
- package/dist/esm/chunk-66BQA4WX.mjs.map +1 -0
- package/dist/esm/index-v2.d.mts +417 -0
- package/dist/esm/index-v2.mjs +1582 -0
- package/dist/esm/index-v2.mjs.map +1 -0
- package/dist/esm/index.d.mts +19 -45
- package/dist/esm/index.mjs +158 -1088
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index-v2.d.ts +417 -0
- package/dist/types/index.d.ts +19 -45
- package/package.json +23 -11
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { AwsCredentialIdentity } from '@aws-sdk/types';
|
|
3
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
4
|
+
import { BlobServiceClient } from '@azure/storage-blob';
|
|
5
|
+
|
|
6
|
+
interface StorageErrorOptions {
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
retryable: boolean;
|
|
10
|
+
provider?: string;
|
|
11
|
+
requestId?: string;
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
}
|
|
14
|
+
type SubclassOptions = Omit<StorageErrorOptions, 'code' | 'retryable'> & {
|
|
15
|
+
code?: string;
|
|
16
|
+
retryable?: boolean;
|
|
17
|
+
};
|
|
18
|
+
declare class StorageError extends Error {
|
|
19
|
+
readonly code: string;
|
|
20
|
+
readonly retryable: boolean;
|
|
21
|
+
readonly provider?: string;
|
|
22
|
+
readonly requestId?: string;
|
|
23
|
+
readonly cause?: unknown;
|
|
24
|
+
constructor(options: StorageErrorOptions);
|
|
25
|
+
}
|
|
26
|
+
interface ThrottledErrorOptions extends SubclassOptions {
|
|
27
|
+
retryAfterMs?: number;
|
|
28
|
+
}
|
|
29
|
+
declare class ThrottledError extends StorageError {
|
|
30
|
+
readonly retryAfterMs?: number;
|
|
31
|
+
constructor(options: ThrottledErrorOptions);
|
|
32
|
+
}
|
|
33
|
+
declare class NotFoundError extends StorageError {
|
|
34
|
+
constructor(options: SubclassOptions);
|
|
35
|
+
}
|
|
36
|
+
declare class AuthError extends StorageError {
|
|
37
|
+
constructor(options: SubclassOptions);
|
|
38
|
+
}
|
|
39
|
+
declare class ValidationError extends StorageError {
|
|
40
|
+
constructor(options: SubclassOptions);
|
|
41
|
+
}
|
|
42
|
+
declare class ConfigurationError extends StorageError {
|
|
43
|
+
constructor(options: SubclassOptions);
|
|
44
|
+
}
|
|
45
|
+
declare class NetworkError extends StorageError {
|
|
46
|
+
constructor(options: SubclassOptions);
|
|
47
|
+
}
|
|
48
|
+
declare class IntegrityError extends StorageError {
|
|
49
|
+
constructor(options: SubclassOptions);
|
|
50
|
+
}
|
|
51
|
+
declare class MultipartSessionError extends StorageError {
|
|
52
|
+
constructor(options: SubclassOptions);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface ObjectSummary {
|
|
56
|
+
key: string;
|
|
57
|
+
size?: number;
|
|
58
|
+
etag?: string;
|
|
59
|
+
lastModified?: Date;
|
|
60
|
+
}
|
|
61
|
+
interface ListOptions {
|
|
62
|
+
prefix?: string;
|
|
63
|
+
limit?: number;
|
|
64
|
+
continuationToken?: string;
|
|
65
|
+
}
|
|
66
|
+
interface ListResult {
|
|
67
|
+
items: ObjectSummary[];
|
|
68
|
+
nextToken?: string;
|
|
69
|
+
}
|
|
70
|
+
interface IterateOptions {
|
|
71
|
+
prefix?: string;
|
|
72
|
+
pageSize?: number;
|
|
73
|
+
}
|
|
74
|
+
interface GetObjectOptions {
|
|
75
|
+
range?: string;
|
|
76
|
+
versionId?: string;
|
|
77
|
+
}
|
|
78
|
+
interface GetObjectResult {
|
|
79
|
+
body: Readable;
|
|
80
|
+
contentLength?: number;
|
|
81
|
+
contentType?: string;
|
|
82
|
+
contentEncoding?: string;
|
|
83
|
+
contentDisposition?: string;
|
|
84
|
+
contentLanguage?: string;
|
|
85
|
+
cacheControl?: string;
|
|
86
|
+
etag?: string;
|
|
87
|
+
lastModified?: Date;
|
|
88
|
+
metadata?: Record<string, string>;
|
|
89
|
+
}
|
|
90
|
+
interface ObjectProperties {
|
|
91
|
+
contentLength?: number;
|
|
92
|
+
contentType?: string;
|
|
93
|
+
etag?: string;
|
|
94
|
+
lastModified?: Date;
|
|
95
|
+
metadata?: Record<string, string>;
|
|
96
|
+
}
|
|
97
|
+
type UploadBody = Buffer | Uint8Array | string | Readable;
|
|
98
|
+
interface UploadOptions {
|
|
99
|
+
contentType?: string;
|
|
100
|
+
contentEncoding?: string;
|
|
101
|
+
cacheControl?: string;
|
|
102
|
+
contentDisposition?: string;
|
|
103
|
+
metadata?: Record<string, string>;
|
|
104
|
+
partSizeBytes?: number;
|
|
105
|
+
queueSize?: number;
|
|
106
|
+
}
|
|
107
|
+
interface UploadResult {
|
|
108
|
+
key: string;
|
|
109
|
+
etag?: string;
|
|
110
|
+
versionId?: string;
|
|
111
|
+
}
|
|
112
|
+
interface WriteStreamResult {
|
|
113
|
+
stream: NodeJS.WritableStream;
|
|
114
|
+
done: Promise<UploadResult>;
|
|
115
|
+
abort: () => Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
interface DeleteManyResult {
|
|
118
|
+
key: string;
|
|
119
|
+
deleted: boolean;
|
|
120
|
+
error?: string;
|
|
121
|
+
}
|
|
122
|
+
interface HeadBucketResult {
|
|
123
|
+
exists: boolean;
|
|
124
|
+
metadata?: Record<string, string>;
|
|
125
|
+
}
|
|
126
|
+
interface PresignOptions {
|
|
127
|
+
expiresInSeconds?: number;
|
|
128
|
+
contentType?: string;
|
|
129
|
+
}
|
|
130
|
+
interface PresignedUpload {
|
|
131
|
+
key: string;
|
|
132
|
+
url: string;
|
|
133
|
+
}
|
|
134
|
+
interface MultipartPart {
|
|
135
|
+
partNumber: number;
|
|
136
|
+
etag: string;
|
|
137
|
+
}
|
|
138
|
+
interface MultipartPartSummary extends MultipartPart {
|
|
139
|
+
size?: number;
|
|
140
|
+
lastModified?: Date;
|
|
141
|
+
}
|
|
142
|
+
interface MultipartUploadSummary {
|
|
143
|
+
key: string;
|
|
144
|
+
uploadId: string;
|
|
145
|
+
initiatedAt?: Date;
|
|
146
|
+
}
|
|
147
|
+
interface MultipartClient {
|
|
148
|
+
create(key: string, options?: UploadOptions): Promise<{
|
|
149
|
+
uploadId: string;
|
|
150
|
+
}>;
|
|
151
|
+
uploadPart(key: string, uploadId: string, partNumber: number, body: UploadBody, contentLengthBytes?: number): Promise<MultipartPart>;
|
|
152
|
+
getPartUploadUrl(key: string, uploadId: string, partNumber: number, options?: PresignOptions): Promise<string>;
|
|
153
|
+
complete(key: string, uploadId: string, parts: MultipartPart[]): Promise<UploadResult>;
|
|
154
|
+
abort(key: string, uploadId: string): Promise<void>;
|
|
155
|
+
listParts(key: string, uploadId: string): Promise<MultipartPartSummary[]>;
|
|
156
|
+
listUploads(prefix?: string): Promise<MultipartUploadSummary[]>;
|
|
157
|
+
}
|
|
158
|
+
interface ObjectStorageClient {
|
|
159
|
+
readonly bucketName: string;
|
|
160
|
+
readonly multipart: MultipartClient;
|
|
161
|
+
getObject(key: string, options?: GetObjectOptions): Promise<GetObjectResult>;
|
|
162
|
+
getObjectProperties(key: string): Promise<ObjectProperties>;
|
|
163
|
+
upload(key: string, body: UploadBody, options?: UploadOptions): Promise<UploadResult>;
|
|
164
|
+
createWriteStream(key: string, options?: UploadOptions): WriteStreamResult;
|
|
165
|
+
delete(key: string): Promise<void>;
|
|
166
|
+
deleteMany(keys: string[]): Promise<DeleteManyResult[]>;
|
|
167
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
168
|
+
listAll(options?: IterateOptions): Promise<ObjectSummary[]>;
|
|
169
|
+
iterate(options?: IterateOptions): AsyncIterable<ObjectSummary>;
|
|
170
|
+
headBucket(): Promise<HeadBucketResult>;
|
|
171
|
+
getDownloadUrl(key: string, options?: PresignOptions): Promise<string>;
|
|
172
|
+
getUploadUrl(key: string, options?: PresignOptions): Promise<PresignedUpload>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
interface HttpOptions {
|
|
176
|
+
connectionTimeoutMs?: number;
|
|
177
|
+
requestTimeoutMs?: number;
|
|
178
|
+
maxSockets?: number;
|
|
179
|
+
}
|
|
180
|
+
interface BaseStorageOptions {
|
|
181
|
+
provider: string;
|
|
182
|
+
endpoint?: string;
|
|
183
|
+
http?: HttpOptions;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Open registry of provider option types, augmented by each provider via
|
|
187
|
+
* declaration merging so new providers never require editing core:
|
|
188
|
+
*
|
|
189
|
+
* declare module '../../core/config' {
|
|
190
|
+
* interface ProviderOptionsRegistry {
|
|
191
|
+
* 'aws_s3': AwsS3StorageOptions;
|
|
192
|
+
* }
|
|
193
|
+
* }
|
|
194
|
+
*/
|
|
195
|
+
interface ProviderOptionsRegistry {
|
|
196
|
+
}
|
|
197
|
+
type ObjectStorageOptions = ProviderOptionsRegistry[keyof ProviderOptionsRegistry];
|
|
198
|
+
|
|
199
|
+
declare function resolveOptionsFromEnv(env?: NodeJS.ProcessEnv): ObjectStorageOptions;
|
|
200
|
+
declare function resolveObjectStorageOptions(options?: ObjectStorageOptions, env?: NodeJS.ProcessEnv): ObjectStorageOptions;
|
|
201
|
+
|
|
202
|
+
interface RetryPolicy {
|
|
203
|
+
numOfAttempts?: number;
|
|
204
|
+
startingDelayMs?: number;
|
|
205
|
+
maxDelayMs?: number;
|
|
206
|
+
retry?: (error: unknown, attempt: number) => boolean;
|
|
207
|
+
}
|
|
208
|
+
declare function isRetryableError(error: unknown): boolean;
|
|
209
|
+
declare function withRetry<T>(fn: () => Promise<T>, policy?: RetryPolicy): Promise<T>;
|
|
210
|
+
|
|
211
|
+
interface LimiterOptions {
|
|
212
|
+
max: number;
|
|
213
|
+
adaptive?: boolean;
|
|
214
|
+
minMax?: number;
|
|
215
|
+
growthThreshold?: number;
|
|
216
|
+
}
|
|
217
|
+
interface Limiter {
|
|
218
|
+
run<T>(fn: () => Promise<T>): Promise<T>;
|
|
219
|
+
readonly inFlight: number;
|
|
220
|
+
readonly pending: number;
|
|
221
|
+
readonly currentMax: number;
|
|
222
|
+
}
|
|
223
|
+
declare function createLimiter(options: LimiterOptions): Limiter;
|
|
224
|
+
|
|
225
|
+
declare function chunk<T>(items: readonly T[], size: number): T[][];
|
|
226
|
+
declare function mapBatched<T, R>(items: readonly T[], batchSize: number, limiter: Limiter, fn: (batch: T[], index: number) => Promise<R>): Promise<R[]>;
|
|
227
|
+
|
|
228
|
+
interface ByteRange {
|
|
229
|
+
start?: number;
|
|
230
|
+
end?: number;
|
|
231
|
+
suffixLength?: number;
|
|
232
|
+
}
|
|
233
|
+
declare function parseRange(input: string): ByteRange;
|
|
234
|
+
declare function toRangeHeader(range: ByteRange): string;
|
|
235
|
+
|
|
236
|
+
declare const AWS_S3_PROVIDER_ID: "aws_s3";
|
|
237
|
+
type AwsS3Auth = {
|
|
238
|
+
kind: 'default';
|
|
239
|
+
} | {
|
|
240
|
+
kind: 'static';
|
|
241
|
+
credentials: AwsCredentialIdentity;
|
|
242
|
+
} | {
|
|
243
|
+
kind: 'assumeRole';
|
|
244
|
+
roleArn: string;
|
|
245
|
+
externalId?: string;
|
|
246
|
+
} | {
|
|
247
|
+
kind: 'webIdentity';
|
|
248
|
+
roleArn: string;
|
|
249
|
+
tokenFile?: string;
|
|
250
|
+
};
|
|
251
|
+
interface AwsS3StorageOptions extends BaseStorageOptions {
|
|
252
|
+
provider: typeof AWS_S3_PROVIDER_ID;
|
|
253
|
+
region: string;
|
|
254
|
+
auth?: AwsS3Auth;
|
|
255
|
+
}
|
|
256
|
+
declare module '../../core/config' {
|
|
257
|
+
interface ProviderOptionsRegistry {
|
|
258
|
+
aws_s3: AwsS3StorageOptions;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
declare function isAwsS3StorageOptions(options: BaseStorageOptions): options is AwsS3StorageOptions;
|
|
262
|
+
declare function getDefaultAwsS3OptionsFromEnv(env?: NodeJS.ProcessEnv): AwsS3StorageOptions;
|
|
263
|
+
|
|
264
|
+
declare function getAwsS3Client(options: AwsS3StorageOptions): S3Client;
|
|
265
|
+
declare function clearAwsS3ClientCache(): void;
|
|
266
|
+
|
|
267
|
+
declare function mapAwsError(error: unknown): StorageError;
|
|
268
|
+
|
|
269
|
+
interface AwsS3ProviderConfig {
|
|
270
|
+
bucketName: string;
|
|
271
|
+
options?: AwsS3StorageOptions;
|
|
272
|
+
retry?: RetryPolicy;
|
|
273
|
+
limiter?: Limiter;
|
|
274
|
+
}
|
|
275
|
+
declare class AwsS3Provider implements ObjectStorageClient {
|
|
276
|
+
readonly bucketName: string;
|
|
277
|
+
readonly multipart: MultipartClient;
|
|
278
|
+
private readonly client;
|
|
279
|
+
private readonly retryPolicy;
|
|
280
|
+
private readonly limiter;
|
|
281
|
+
constructor(config: AwsS3ProviderConfig);
|
|
282
|
+
private send;
|
|
283
|
+
getObject(key: string, options?: GetObjectOptions): Promise<GetObjectResult>;
|
|
284
|
+
getObjectProperties(key: string): Promise<ObjectProperties>;
|
|
285
|
+
upload(key: string, body: UploadBody, options?: UploadOptions): Promise<UploadResult>;
|
|
286
|
+
private uploadStream;
|
|
287
|
+
createWriteStream(key: string, options?: UploadOptions): WriteStreamResult;
|
|
288
|
+
delete(key: string): Promise<void>;
|
|
289
|
+
deleteMany(keys: string[]): Promise<DeleteManyResult[]>;
|
|
290
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
291
|
+
iterate(options?: IterateOptions): AsyncIterable<ObjectSummary>;
|
|
292
|
+
listAll(options?: IterateOptions): Promise<ObjectSummary[]>;
|
|
293
|
+
headBucket(): Promise<HeadBucketResult>;
|
|
294
|
+
getDownloadUrl(key: string, options?: PresignOptions): Promise<string>;
|
|
295
|
+
getUploadUrl(key: string, options?: PresignOptions): Promise<PresignedUpload>;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
declare const AZURE_BLOB_PROVIDER_ID: "azure_blob_storage";
|
|
299
|
+
type AzureBlobAuth = {
|
|
300
|
+
kind: 'connectionString';
|
|
301
|
+
connectionString: string;
|
|
302
|
+
} | {
|
|
303
|
+
kind: 'accountKey';
|
|
304
|
+
accountName: string;
|
|
305
|
+
accountKey: string;
|
|
306
|
+
} | {
|
|
307
|
+
kind: 'sas';
|
|
308
|
+
accountName: string;
|
|
309
|
+
sasToken: string;
|
|
310
|
+
} | {
|
|
311
|
+
kind: 'workloadIdentity';
|
|
312
|
+
accountName: string;
|
|
313
|
+
};
|
|
314
|
+
interface AzureBlobStorageOptions extends BaseStorageOptions {
|
|
315
|
+
provider: typeof AZURE_BLOB_PROVIDER_ID;
|
|
316
|
+
auth: AzureBlobAuth;
|
|
317
|
+
}
|
|
318
|
+
declare module '../../core/config' {
|
|
319
|
+
interface ProviderOptionsRegistry {
|
|
320
|
+
azure_blob_storage: AzureBlobStorageOptions;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
declare function isAzureBlobStorageOptions(options: BaseStorageOptions): options is AzureBlobStorageOptions;
|
|
324
|
+
declare function getDefaultAzureBlobOptionsFromEnv(env?: NodeJS.ProcessEnv): AzureBlobStorageOptions;
|
|
325
|
+
|
|
326
|
+
declare function getAzureBlobServiceClient(options: AzureBlobStorageOptions): BlobServiceClient;
|
|
327
|
+
declare function clearAzureBlobClientCache(): void;
|
|
328
|
+
|
|
329
|
+
declare function mapAzureError(error: unknown): StorageError;
|
|
330
|
+
|
|
331
|
+
interface MultipartBlockRecord {
|
|
332
|
+
blockId: string;
|
|
333
|
+
partNumber: number;
|
|
334
|
+
}
|
|
335
|
+
interface MultipartSession {
|
|
336
|
+
uploadId: string;
|
|
337
|
+
blobName: string;
|
|
338
|
+
containerName: string;
|
|
339
|
+
blocks: MultipartBlockRecord[];
|
|
340
|
+
createdAt: number;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Azure has no native multipart upload sessions (S3 UploadId semantics).
|
|
344
|
+
* This store tracks which staged blocks belong to which logical upload so
|
|
345
|
+
* concurrent uploads to the same blob name cannot corrupt each other.
|
|
346
|
+
* Default in-memory implementation is single-process only — multi-pod
|
|
347
|
+
* deployments doing distributed multipart must inject a shared store (Redis).
|
|
348
|
+
*/
|
|
349
|
+
interface MultipartSessionStore {
|
|
350
|
+
create(session: MultipartSession): Promise<void>;
|
|
351
|
+
get(uploadId: string): Promise<MultipartSession | undefined>;
|
|
352
|
+
appendBlock(uploadId: string, block: MultipartBlockRecord): Promise<void>;
|
|
353
|
+
delete(uploadId: string): Promise<void>;
|
|
354
|
+
list(containerName: string, blobNamePrefix?: string): Promise<MultipartSession[]>;
|
|
355
|
+
}
|
|
356
|
+
declare class InMemoryMultipartSessionStore implements MultipartSessionStore {
|
|
357
|
+
private readonly ttlMs;
|
|
358
|
+
private readonly sessions;
|
|
359
|
+
constructor(ttlMs?: number);
|
|
360
|
+
create(session: MultipartSession): Promise<void>;
|
|
361
|
+
get(uploadId: string): Promise<MultipartSession | undefined>;
|
|
362
|
+
appendBlock(uploadId: string, block: MultipartBlockRecord): Promise<void>;
|
|
363
|
+
delete(uploadId: string): Promise<void>;
|
|
364
|
+
list(containerName: string, blobNamePrefix?: string): Promise<MultipartSession[]>;
|
|
365
|
+
private isExpired;
|
|
366
|
+
private evictExpired;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
interface AzureBlobStorageProviderConfig {
|
|
370
|
+
bucketName: string;
|
|
371
|
+
options?: AzureBlobStorageOptions;
|
|
372
|
+
retry?: RetryPolicy;
|
|
373
|
+
limiter?: Limiter;
|
|
374
|
+
multipartStore?: MultipartSessionStore;
|
|
375
|
+
}
|
|
376
|
+
declare class AzureBlobStorageProvider implements ObjectStorageClient {
|
|
377
|
+
readonly bucketName: string;
|
|
378
|
+
readonly multipart: MultipartClient;
|
|
379
|
+
private readonly serviceClient;
|
|
380
|
+
private readonly container;
|
|
381
|
+
private readonly retryPolicy;
|
|
382
|
+
private readonly limiter;
|
|
383
|
+
constructor(config: AzureBlobStorageProviderConfig);
|
|
384
|
+
private send;
|
|
385
|
+
private block;
|
|
386
|
+
getObject(key: string, options?: GetObjectOptions): Promise<GetObjectResult>;
|
|
387
|
+
private resolveRange;
|
|
388
|
+
getObjectProperties(key: string): Promise<ObjectProperties>;
|
|
389
|
+
upload(key: string, body: UploadBody, options?: UploadOptions): Promise<UploadResult>;
|
|
390
|
+
createWriteStream(key: string, options?: UploadOptions): WriteStreamResult;
|
|
391
|
+
delete(key: string): Promise<void>;
|
|
392
|
+
deleteMany(keys: string[]): Promise<DeleteManyResult[]>;
|
|
393
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
394
|
+
iterate(options?: IterateOptions): AsyncIterable<ObjectSummary>;
|
|
395
|
+
listAll(options?: IterateOptions): Promise<ObjectSummary[]>;
|
|
396
|
+
headBucket(): Promise<HeadBucketResult>;
|
|
397
|
+
getDownloadUrl(key: string, options?: PresignOptions): Promise<string>;
|
|
398
|
+
getUploadUrl(key: string, options?: PresignOptions): Promise<PresignedUpload>;
|
|
399
|
+
private generateSasUrl;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Returns a cached `ObjectStorageClient` for a bucket. The concrete provider
|
|
404
|
+
* (AWS S3 or Azure Blob) is resolved from `options` or the environment — callers
|
|
405
|
+
* (services, `@repo` wrappers) never pick a provider or manage caching.
|
|
406
|
+
*/
|
|
407
|
+
declare function getObjectStorageClient(bucket: string, options?: ObjectStorageOptions): ObjectStorageClient;
|
|
408
|
+
/** Test/teardown helper. */
|
|
409
|
+
declare function clearObjectStorageClientCache(): void;
|
|
410
|
+
|
|
411
|
+
declare const OBJECT_STORAGE_PROVIDERS: Readonly<{
|
|
412
|
+
readonly AWS_S3: "aws_s3";
|
|
413
|
+
readonly AZURE_BLOB_STORAGE: "azure_blob_storage";
|
|
414
|
+
}>;
|
|
415
|
+
type ObjectStorageProvider = (typeof OBJECT_STORAGE_PROVIDERS)[keyof typeof OBJECT_STORAGE_PROVIDERS];
|
|
416
|
+
|
|
417
|
+
export { AWS_S3_PROVIDER_ID, AZURE_BLOB_PROVIDER_ID, AuthError, AwsS3Auth, AwsS3Provider, AwsS3ProviderConfig, AwsS3StorageOptions, AzureBlobAuth, AzureBlobStorageOptions, AzureBlobStorageProvider, AzureBlobStorageProviderConfig, BaseStorageOptions, ByteRange, ConfigurationError, DeleteManyResult, GetObjectOptions, GetObjectResult, HeadBucketResult, HttpOptions, InMemoryMultipartSessionStore, IntegrityError, IterateOptions, Limiter, LimiterOptions, ListOptions, ListResult, MultipartBlockRecord, MultipartClient, MultipartPart, MultipartPartSummary, MultipartSession, MultipartSessionError, MultipartSessionStore, MultipartUploadSummary, NetworkError, NotFoundError, OBJECT_STORAGE_PROVIDERS, ObjectProperties, ObjectStorageClient, ObjectStorageOptions, ObjectStorageProvider, ObjectSummary, PresignOptions, PresignedUpload, ProviderOptionsRegistry, RetryPolicy, StorageError, StorageErrorOptions, ThrottledError, ThrottledErrorOptions, UploadBody, UploadOptions, UploadResult, ValidationError, WriteStreamResult, chunk, clearAwsS3ClientCache, clearAzureBlobClientCache, clearObjectStorageClientCache, createLimiter, getAwsS3Client, getAzureBlobServiceClient, getDefaultAwsS3OptionsFromEnv, getDefaultAzureBlobOptionsFromEnv, getObjectStorageClient, isAwsS3StorageOptions, isAzureBlobStorageOptions, isRetryableError, mapAwsError, mapAzureError, mapBatched, parseRange, resolveObjectStorageOptions, resolveOptionsFromEnv, toRangeHeader, withRetry };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -41,7 +41,6 @@ type GetObjectResponse = {
|
|
|
41
41
|
contentDisposition?: string;
|
|
42
42
|
contentLanguage?: string;
|
|
43
43
|
body?: Readable;
|
|
44
|
-
content?: Readable;
|
|
45
44
|
};
|
|
46
45
|
|
|
47
46
|
type GetUploadUrlResponse = {
|
|
@@ -58,16 +57,9 @@ type CreateUploadWriteStreamResponse = {
|
|
|
58
57
|
type HeadBucketResponse = HeadBucketCommandOutput | ContainerGetPropertiesResponse;
|
|
59
58
|
|
|
60
59
|
type ObjectStorageOptions = {
|
|
61
|
-
region
|
|
62
|
-
credentials
|
|
63
|
-
provider
|
|
64
|
-
connectionString?: string;
|
|
65
|
-
host?: string;
|
|
66
|
-
port?: string | number;
|
|
67
|
-
user?: string;
|
|
68
|
-
password?: string;
|
|
69
|
-
privateKey?: string | Buffer;
|
|
70
|
-
secure?: boolean;
|
|
60
|
+
region: string;
|
|
61
|
+
credentials: AwsCredentialIdentity;
|
|
62
|
+
provider: string;
|
|
71
63
|
};
|
|
72
64
|
|
|
73
65
|
type ListPartsMultipartUploadResponse = {
|
|
@@ -141,57 +133,49 @@ declare class ObjectStorageService {
|
|
|
141
133
|
*
|
|
142
134
|
* @param {ListRequestOptions} options - The options to apply to the list operation.
|
|
143
135
|
* @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.
|
|
144
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
145
136
|
* @return {Promise<ListResponse>} A promise that resolves to the list of objects.
|
|
146
137
|
*/
|
|
147
|
-
static list(options: ListRequestOptions, bucketName?: string
|
|
138
|
+
static list(options: ListRequestOptions, bucketName?: string): Promise<ListResponse>;
|
|
148
139
|
/**
|
|
149
140
|
* Retrieves a list of all objects from the object storage service.
|
|
150
141
|
*
|
|
151
142
|
* @param {ListRequestOptions} options - The options to apply to the list operation.
|
|
152
143
|
* @param {string} [bucketName] - The name of the bucket to list objects from. If not provided, the default bucket name will be used.
|
|
153
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
154
144
|
* @return {Promise<ListResponse>} A promise that resolves to the list of all objects.
|
|
155
145
|
*/
|
|
156
|
-
static listAll(options: ListRequestOptions, bucketName?: string
|
|
146
|
+
static listAll(options: ListRequestOptions, bucketName?: string): Promise<ListResponse>;
|
|
157
147
|
/**
|
|
158
148
|
* Retrieves an object from the object storage service.
|
|
159
149
|
*
|
|
160
150
|
* @param {string} key - The key of the object to retrieve.
|
|
161
151
|
* @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.
|
|
162
|
-
* @param {IGetObjectOptions} [options] - The options to apply to the get operation.
|
|
163
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
164
152
|
* @return {Promise<GetObjectResponse>} A promise that resolves to the retrieved object.
|
|
165
153
|
*/
|
|
166
|
-
static getObject(key: string, bucketName?: string, options?: IGetObjectOptions
|
|
154
|
+
static getObject(key: string, bucketName?: string, options?: IGetObjectOptions): Promise<GetObjectResponse>;
|
|
167
155
|
/**
|
|
168
156
|
* Retrieves an object info (without file content) from the object storage service.
|
|
169
157
|
* @param key - The key of the object to retrieve.
|
|
170
|
-
* @param bucketName - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.
|
|
171
|
-
* @param objectStorageOptions - The options for the object storage service.
|
|
172
158
|
* @returns A promise that resolves to the info of the file.
|
|
173
159
|
*/
|
|
174
|
-
static getHeadObject(key: string, bucketName?: string
|
|
160
|
+
static getHeadObject(key: string, bucketName?: string): Promise<GetObjectResponse>;
|
|
175
161
|
/**
|
|
176
162
|
* Retrieves a signed URL for the specified object in the object storage service.
|
|
177
163
|
*
|
|
178
164
|
* @param {string} key - The key of the object for which to generate the signed URL.
|
|
179
165
|
* @param {number} expiresInMinutes - The number of minutes until the signed URL expires.
|
|
180
166
|
* @param {string} [bucketName] - The name of the bucket where the object is stored. If not provided, the default bucket name will be used.
|
|
181
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
182
167
|
* @return {Promise<string>} A promise that resolves to the generated signed URL.
|
|
183
168
|
*/
|
|
184
|
-
static getDownloadUrl(key: string, expiresInMinutes: number, bucketName?: string
|
|
169
|
+
static getDownloadUrl(key: string, expiresInMinutes: number, bucketName?: string): Promise<string>;
|
|
185
170
|
/**
|
|
186
171
|
* Retrieves an upload URL for the specified object in the object storage service.
|
|
187
172
|
*
|
|
188
173
|
* @param {string} key - The key of the object for which to generate the upload URL.
|
|
189
174
|
* @param {number} expiresInMinutes - The number of minutes until the upload URL expires.
|
|
190
175
|
* @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.
|
|
191
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
192
176
|
* @return {Promise<string>} A promise that resolves to the generated upload URL.
|
|
193
177
|
*/
|
|
194
|
-
static getUploadUrl(key: string, expiresInMinutes: number, bucketName?: string
|
|
178
|
+
static getUploadUrl(key: string, expiresInMinutes: number, bucketName?: string): Promise<GetUploadUrlResponse>;
|
|
195
179
|
/**
|
|
196
180
|
* Uploads a file to the object storage service.
|
|
197
181
|
*
|
|
@@ -199,30 +183,27 @@ declare class ObjectStorageService {
|
|
|
199
183
|
* @param {FileContent} body - The content of the file to upload.
|
|
200
184
|
* @param {Object} [metadata] - Optional metadata to associate with the object.
|
|
201
185
|
* @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.
|
|
202
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
203
186
|
* @return {Promise<UploadResponse>} A promise that resolves to the response of the upload operation.
|
|
204
187
|
*/
|
|
205
188
|
static upload(key: string, body: FileContent, metadata?: {
|
|
206
189
|
[key: string]: string;
|
|
207
|
-
}, bucketName?: string
|
|
190
|
+
}, bucketName?: string): Promise<UploadResponse>;
|
|
208
191
|
/**
|
|
209
192
|
* Creates an upload write stream for the specified key in the object storage service.
|
|
210
193
|
*
|
|
211
194
|
* @param {string} key - The key of the object to create the upload write stream for.
|
|
212
195
|
* @param {string} [bucketName] - The name of the bucket where the object will be stored. If not provided, the default bucket name will be used.
|
|
213
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
214
196
|
* @return {Promise<CreateUploadWriteStreamResponse>} A promise that resolves to the response of the upload operation.
|
|
215
197
|
*/
|
|
216
|
-
static createUploadWriteStream(key: string, bucketName?: string
|
|
198
|
+
static createUploadWriteStream(key: string, bucketName?: string): Promise<CreateUploadWriteStreamResponse>;
|
|
217
199
|
/**
|
|
218
200
|
* Deletes an object or multiple objects from the object storage service.
|
|
219
201
|
*
|
|
220
202
|
* @param {string | string[]} key - The key or array of keys of the objects to delete.
|
|
221
203
|
* @param {string} [bucketName] - The name of the bucket where the objects are stored. If not provided, the default bucket name will be used.
|
|
222
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
223
204
|
* @return {Promise<{ key: string; deleted: boolean; error?: string }[] | boolean>} A promise that resolves to an array of objects containing the key, deleted status, and an optional error message for each object deleted, or a boolean value indicating the success of the deletion.
|
|
224
205
|
*/
|
|
225
|
-
static delete(key: string | string[], bucketName?: string
|
|
206
|
+
static delete(key: string | string[], bucketName?: string): Promise<{
|
|
226
207
|
key: string;
|
|
227
208
|
deleted: boolean;
|
|
228
209
|
error?: string;
|
|
@@ -231,37 +212,33 @@ declare class ObjectStorageService {
|
|
|
231
212
|
* Retrieves the head bucket from the object storage service.
|
|
232
213
|
*
|
|
233
214
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
234
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
235
215
|
* @return {Promise<HeadBucketResponse>} A promise that resolves to the head bucket response.
|
|
236
216
|
*/
|
|
237
|
-
static getHeadBucket(bucketName?: string
|
|
217
|
+
static getHeadBucket(bucketName?: string): Promise<HeadBucketResponse>;
|
|
238
218
|
/**
|
|
239
219
|
* Generates a unique upload ID for a multipart upload.
|
|
240
220
|
*
|
|
241
221
|
* @param {string} key - The key of the object to upload.
|
|
242
222
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
243
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
244
223
|
* @return {Promise<string>} A promise that resolves to the generated upload ID.
|
|
245
224
|
*/
|
|
246
|
-
static generateUploadIdMultipart(key: string, bucketName?: string
|
|
225
|
+
static generateUploadIdMultipart(key: string, bucketName?: string): Promise<string>;
|
|
247
226
|
/**
|
|
248
227
|
* Retrieves a list of multipart uploads for a specified key in the object storage service.
|
|
249
228
|
*
|
|
250
229
|
* @param {string} key - The key of the object to retrieve uploads for.
|
|
251
230
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
252
231
|
* @param {string} [uploadId] - The upload ID to filter the results by.
|
|
253
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
254
232
|
* @return {Promise<ListPartsMultipartUploadResponse>} A promise that resolves to the list of multipart uploads for the specified key.
|
|
255
233
|
*/
|
|
256
|
-
static listMultipartUploadsForKey(key: string, bucketName?: string, uploadId?: string
|
|
234
|
+
static listMultipartUploadsForKey(key: string, bucketName?: string, uploadId?: string): Promise<ListPartsMultipartUploadResponse>;
|
|
257
235
|
/**
|
|
258
236
|
* Retrieves a list of all multipart uploads for a specified bucket in the object storage service.
|
|
259
237
|
*
|
|
260
238
|
* @param {string} [bucketName] - The name of the bucket. If not provided, the default bucket name will be used.
|
|
261
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
262
239
|
* @return {Promise<ListMultipartUploadsResponse>} A promise that resolves to the list of multipart uploads for the specified bucket.
|
|
263
240
|
*/
|
|
264
|
-
static listMultipartUploadsForBucket(bucketName?: string
|
|
241
|
+
static listMultipartUploadsForBucket(bucketName?: string): Promise<ListMultipartUploadsResponse>;
|
|
265
242
|
/**
|
|
266
243
|
* Uploads a multipart file to the specified bucket in the object storage service.
|
|
267
244
|
*
|
|
@@ -270,30 +247,27 @@ declare class ObjectStorageService {
|
|
|
270
247
|
* @param {number} partNumber - The number of the part being uploaded.
|
|
271
248
|
* @param {string} [uploadId] - The ID of the multipart upload.
|
|
272
249
|
* @param {string} [bucketName] - The name of the bucket to upload the file to. If not provided, the default bucket name will be used.
|
|
273
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
274
250
|
* @return {Promise<string>} A Promise that resolves to the base64 encoded block ID of the uploaded part.
|
|
275
251
|
*/
|
|
276
|
-
static uploadMultipart(key: string, file: FileContent, partNumber: number, uploadId?: string, bucketName?: string
|
|
252
|
+
static uploadMultipart(key: string, file: FileContent, partNumber: number, uploadId?: string, bucketName?: string): Promise<string>;
|
|
277
253
|
/**
|
|
278
254
|
* Completes a multipart upload for the specified object in the object storage service.
|
|
279
255
|
*
|
|
280
256
|
* @param {string} key - The key of the object to complete the multipart upload for.
|
|
281
257
|
* @param {string} uploadId - The ID of the multipart upload to complete.
|
|
282
258
|
* @param {string} [bucketName] - The name of the bucket to complete the multipart upload in. If not provided, the default bucket name will be used.
|
|
283
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
284
259
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is completed.
|
|
285
260
|
*/
|
|
286
|
-
static completeMultipartUpload(key: string, uploadId: string, bucketName?: string
|
|
261
|
+
static completeMultipartUpload(key: string, uploadId: string, bucketName?: string): Promise<void>;
|
|
287
262
|
/**
|
|
288
263
|
* Aborts a multipart upload for the specified object in the object storage service.
|
|
289
264
|
*
|
|
290
265
|
* @param {string} key - The key of the object to abort the multipart upload for.
|
|
291
266
|
* @param {string} uploadId - The ID of the multipart upload to abort.
|
|
292
267
|
* @param {string} [bucketName] - The name of the bucket to abort the multipart upload in. If not provided, the default bucket name will be used.
|
|
293
|
-
* @param {ObjectStorageOptions} [objectStorageOptions] - The options for the object storage service.
|
|
294
268
|
* @return {Promise<void>} A Promise that resolves when the multipart upload is aborted.
|
|
295
269
|
*/
|
|
296
|
-
static abortMultipartUpload(key: string, uploadId: string, bucketName?: string
|
|
270
|
+
static abortMultipartUpload(key: string, uploadId: string, bucketName?: string): Promise<void>;
|
|
297
271
|
/**
|
|
298
272
|
* Retrieves a presigned URL for a specific part of a multipart upload.
|
|
299
273
|
*
|