@cubis/vfsclient 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +315 -0
- package/dist/index.cjs +1577 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +649 -0
- package/dist/index.d.ts +649 -0
- package/dist/index.js +1560 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache entry and adapter interfaces for isomorphic VFS caching.
|
|
3
|
+
*/
|
|
4
|
+
interface VFSCacheEntry {
|
|
5
|
+
data: Uint8Array;
|
|
6
|
+
contentType?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
size: number;
|
|
9
|
+
hash?: string;
|
|
10
|
+
createdAt: number;
|
|
11
|
+
expiresAt?: number;
|
|
12
|
+
}
|
|
13
|
+
interface VFSCacheAdapter {
|
|
14
|
+
get(key: string): Promise<VFSCacheEntry | null> | VFSCacheEntry | null;
|
|
15
|
+
set(key: string, entry: VFSCacheEntry, ttlSeconds?: number): Promise<void> | void;
|
|
16
|
+
delete(key: string): Promise<boolean> | boolean;
|
|
17
|
+
clear(): Promise<void> | void;
|
|
18
|
+
has(key: string): Promise<boolean> | boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* VFS Server models and response structures.
|
|
23
|
+
*/
|
|
24
|
+
interface AttachmentResponse {
|
|
25
|
+
id: string;
|
|
26
|
+
bucket_id: string;
|
|
27
|
+
file_id: string;
|
|
28
|
+
file_hash?: string;
|
|
29
|
+
extension: string;
|
|
30
|
+
name: string;
|
|
31
|
+
size: number;
|
|
32
|
+
type: string;
|
|
33
|
+
metadata?: Record<string, unknown>;
|
|
34
|
+
user_details?: Record<string, unknown>;
|
|
35
|
+
store?: 'local' | 's3' | 'r2' | 'vfs' | 'edge' | string;
|
|
36
|
+
is_stat_synced?: boolean;
|
|
37
|
+
created_at: string;
|
|
38
|
+
url: string;
|
|
39
|
+
key: string;
|
|
40
|
+
cdn_url?: string;
|
|
41
|
+
}
|
|
42
|
+
interface ObjectManifestResponse {
|
|
43
|
+
id: string;
|
|
44
|
+
bucket_id: string;
|
|
45
|
+
file_id: string;
|
|
46
|
+
file_hash?: string;
|
|
47
|
+
extension: string;
|
|
48
|
+
name: string;
|
|
49
|
+
size: number;
|
|
50
|
+
type: string;
|
|
51
|
+
metadata?: Record<string, unknown>;
|
|
52
|
+
created_at: string;
|
|
53
|
+
url: string;
|
|
54
|
+
key: string;
|
|
55
|
+
cdn_url?: string;
|
|
56
|
+
}
|
|
57
|
+
interface PreflightRequest {
|
|
58
|
+
bucket_id: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
size?: number;
|
|
61
|
+
content_type?: string;
|
|
62
|
+
file_hash?: string;
|
|
63
|
+
}
|
|
64
|
+
interface PreflightResponse {
|
|
65
|
+
upload_protocol?: 'edge-chunks-v1' | string;
|
|
66
|
+
allowed: boolean;
|
|
67
|
+
reason?: string;
|
|
68
|
+
bucket_id: string;
|
|
69
|
+
name?: string;
|
|
70
|
+
size: number;
|
|
71
|
+
content_type?: string;
|
|
72
|
+
file_hash?: string;
|
|
73
|
+
max_upload_bytes: number;
|
|
74
|
+
remaining_bytes?: number;
|
|
75
|
+
remaining_files?: number;
|
|
76
|
+
duplicate?: AttachmentResponse;
|
|
77
|
+
upload_token?: string;
|
|
78
|
+
expires_in?: number;
|
|
79
|
+
}
|
|
80
|
+
interface SessionView {
|
|
81
|
+
id: string;
|
|
82
|
+
name: string;
|
|
83
|
+
state: 'receiving' | 'paused' | 'queued' | 'finalizing' | 'complete' | 'error';
|
|
84
|
+
file_hash?: string;
|
|
85
|
+
offset: number;
|
|
86
|
+
size: number;
|
|
87
|
+
chunk_size: number;
|
|
88
|
+
error?: string;
|
|
89
|
+
attempts: number;
|
|
90
|
+
}
|
|
91
|
+
interface BucketStat {
|
|
92
|
+
id?: string;
|
|
93
|
+
bucket_id: string;
|
|
94
|
+
total_size: number;
|
|
95
|
+
total_file: number;
|
|
96
|
+
total_files?: number;
|
|
97
|
+
total_dir?: number;
|
|
98
|
+
total_read?: number;
|
|
99
|
+
total_write?: number;
|
|
100
|
+
owner_id?: string;
|
|
101
|
+
max_size_bytes: number;
|
|
102
|
+
max_files: number;
|
|
103
|
+
lifecycle_enabled: boolean;
|
|
104
|
+
default_ttl_seconds: number;
|
|
105
|
+
created_at?: string;
|
|
106
|
+
updated_at?: string;
|
|
107
|
+
}
|
|
108
|
+
interface BucketStatSummary {
|
|
109
|
+
total_buckets: number;
|
|
110
|
+
total_files: number;
|
|
111
|
+
total_size: number;
|
|
112
|
+
}
|
|
113
|
+
interface BucketMetricsByDate {
|
|
114
|
+
date: string;
|
|
115
|
+
total_size: number;
|
|
116
|
+
total_files: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Problem details (RFC 7807) and SDK error definitions.
|
|
121
|
+
*/
|
|
122
|
+
interface ProblemDetails {
|
|
123
|
+
type?: string;
|
|
124
|
+
title?: string;
|
|
125
|
+
status?: number;
|
|
126
|
+
detail?: string;
|
|
127
|
+
instance?: string;
|
|
128
|
+
extensions?: {
|
|
129
|
+
trace_id?: string;
|
|
130
|
+
[key: string]: unknown;
|
|
131
|
+
};
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
}
|
|
134
|
+
declare class VFSError extends Error {
|
|
135
|
+
readonly status: number;
|
|
136
|
+
readonly code?: string;
|
|
137
|
+
readonly problem?: ProblemDetails;
|
|
138
|
+
readonly headers?: Headers;
|
|
139
|
+
constructor(message: string, options?: {
|
|
140
|
+
status?: number;
|
|
141
|
+
code?: string;
|
|
142
|
+
problem?: ProblemDetails;
|
|
143
|
+
headers?: Headers;
|
|
144
|
+
cause?: unknown;
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
* Helper to check if error is a specific HTTP status code.
|
|
148
|
+
*/
|
|
149
|
+
is(status: number): boolean;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
type SupportedBinaryInput = Blob | File | Uint8Array | ArrayBuffer | ReadableStream<Uint8Array> | NodeJS.ReadableStream | string;
|
|
153
|
+
interface VFSClientOptions {
|
|
154
|
+
/**
|
|
155
|
+
* Base URL of the VFS Server (e.g. "http://localhost:5002" or "https://vfs.company.com").
|
|
156
|
+
*/
|
|
157
|
+
endpoint: string;
|
|
158
|
+
/**
|
|
159
|
+
* API Key for authentication (sent via `x-api-key` header).
|
|
160
|
+
*/
|
|
161
|
+
apiKey?: string;
|
|
162
|
+
/**
|
|
163
|
+
* HMAC/Hashed API Key for authentication (sent via `x-api-hash` header).
|
|
164
|
+
*/
|
|
165
|
+
apiHash?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Default bucket ID to use if not specified in method calls (defaults to 'default').
|
|
168
|
+
*/
|
|
169
|
+
defaultBucket?: string;
|
|
170
|
+
/**
|
|
171
|
+
* Request timeout in milliseconds (default: 30,000ms = 30s).
|
|
172
|
+
*/
|
|
173
|
+
timeout?: number;
|
|
174
|
+
/**
|
|
175
|
+
* Caching configuration:
|
|
176
|
+
* - `true`: automatically uses Browser Cache API in browser or FileSystem / Memory cache in Node.js
|
|
177
|
+
* - `false` or `undefined`: caching disabled
|
|
178
|
+
* - `VFSCacheAdapter`: custom cache adapter instance
|
|
179
|
+
*/
|
|
180
|
+
cache?: boolean | VFSCacheAdapter;
|
|
181
|
+
/**
|
|
182
|
+
* Optional custom fetch implementation (defaults to globalThis.fetch).
|
|
183
|
+
*/
|
|
184
|
+
fetch?: typeof fetch;
|
|
185
|
+
/**
|
|
186
|
+
* Enable debug logging or provide custom logger.
|
|
187
|
+
*/
|
|
188
|
+
debug?: boolean | ((message: string, ...args: unknown[]) => void);
|
|
189
|
+
/**
|
|
190
|
+
* Retry configuration for transient HTTP errors (network failures, 502, 503, 504).
|
|
191
|
+
*/
|
|
192
|
+
retry?: {
|
|
193
|
+
maxRetries?: number;
|
|
194
|
+
retryDelay?: number;
|
|
195
|
+
retryOnStatus?: number[];
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
interface UploadProgress {
|
|
199
|
+
loaded: number;
|
|
200
|
+
total: number;
|
|
201
|
+
percent: number;
|
|
202
|
+
phase: 'hashing' | 'preflight' | 'uploading' | 'chunks' | 'finalizing' | 'complete';
|
|
203
|
+
}
|
|
204
|
+
interface UploadInput {
|
|
205
|
+
/**
|
|
206
|
+
* File data: Blob, File, Uint8Array, Buffer, ReadableStream, or local file path in Node.js.
|
|
207
|
+
*/
|
|
208
|
+
file: SupportedBinaryInput;
|
|
209
|
+
/**
|
|
210
|
+
* Target bucket ID (defaults to client's defaultBucket, or 'default').
|
|
211
|
+
*/
|
|
212
|
+
bucketId?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Original file name (required if input is stream/buffer without name).
|
|
215
|
+
*/
|
|
216
|
+
name?: string;
|
|
217
|
+
/**
|
|
218
|
+
* MIME content type (e.g. "image/png", "application/pdf").
|
|
219
|
+
*/
|
|
220
|
+
contentType?: string;
|
|
221
|
+
/**
|
|
222
|
+
* Pre-calculated SHA-256 hash. If not provided, will be computed automatically for preflight.
|
|
223
|
+
*/
|
|
224
|
+
fileHash?: string;
|
|
225
|
+
/**
|
|
226
|
+
* Custom metadata attached to the file in MongoDB.
|
|
227
|
+
*/
|
|
228
|
+
metadata?: Record<string, unknown>;
|
|
229
|
+
/**
|
|
230
|
+
* Whether to run preflight check before uploading bytes (default: true).
|
|
231
|
+
* Preflight checks quota, file size limits, and checks for deduplication.
|
|
232
|
+
*/
|
|
233
|
+
preflight?: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* If true, forces chunked session upload (or when preflight indicates edge-chunks-v1).
|
|
236
|
+
*/
|
|
237
|
+
resumable?: boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Chunk size in bytes for chunked uploads (default: 1,048,576 = 1 MiB).
|
|
240
|
+
*/
|
|
241
|
+
chunkSize?: number;
|
|
242
|
+
/**
|
|
243
|
+
* Session ID to resume an interrupted chunked upload.
|
|
244
|
+
*/
|
|
245
|
+
resumeId?: string;
|
|
246
|
+
/**
|
|
247
|
+
* Progress callback for upload updates.
|
|
248
|
+
*/
|
|
249
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
250
|
+
/**
|
|
251
|
+
* Optional AbortSignal for cancellation.
|
|
252
|
+
*/
|
|
253
|
+
signal?: AbortSignal;
|
|
254
|
+
}
|
|
255
|
+
interface UploadMultipleInput {
|
|
256
|
+
/**
|
|
257
|
+
* List of files to upload.
|
|
258
|
+
*/
|
|
259
|
+
files: UploadInput[];
|
|
260
|
+
/**
|
|
261
|
+
* Target bucket ID for all files unless overridden per file.
|
|
262
|
+
*/
|
|
263
|
+
bucketId?: string;
|
|
264
|
+
/**
|
|
265
|
+
* Maximum concurrent uploads (default: 3).
|
|
266
|
+
*/
|
|
267
|
+
concurrency?: number;
|
|
268
|
+
/**
|
|
269
|
+
* Overall progress callback for the batch.
|
|
270
|
+
*/
|
|
271
|
+
onProgress?: (progress: {
|
|
272
|
+
totalFiles: number;
|
|
273
|
+
completedFiles: number;
|
|
274
|
+
failedFiles: number;
|
|
275
|
+
overallPercent: number;
|
|
276
|
+
currentFile?: string;
|
|
277
|
+
}) => void;
|
|
278
|
+
/**
|
|
279
|
+
* Callback on each file success.
|
|
280
|
+
*/
|
|
281
|
+
onFileSuccess?: (file: UploadInput, response: AttachmentResponse) => void;
|
|
282
|
+
/**
|
|
283
|
+
* Callback on file failure.
|
|
284
|
+
*/
|
|
285
|
+
onFileError?: (file: UploadInput, error: Error) => void;
|
|
286
|
+
/**
|
|
287
|
+
* AbortSignal for cancelling entire batch.
|
|
288
|
+
*/
|
|
289
|
+
signal?: AbortSignal;
|
|
290
|
+
}
|
|
291
|
+
interface ImgProxyOptions {
|
|
292
|
+
width?: number;
|
|
293
|
+
height?: number;
|
|
294
|
+
resizingType?: 'fit' | 'fill' | 'auto';
|
|
295
|
+
format?: 'png' | 'jpeg' | 'webp' | 'avif';
|
|
296
|
+
quality?: number;
|
|
297
|
+
}
|
|
298
|
+
interface GetFileOptions {
|
|
299
|
+
/**
|
|
300
|
+
* Desired response format:
|
|
301
|
+
* - 'blob': Returns Blob (default in browser)
|
|
302
|
+
* - 'arrayBuffer': Returns ArrayBuffer
|
|
303
|
+
* - 'stream': Returns ReadableStream<Uint8Array>
|
|
304
|
+
* - 'text': Returns string text
|
|
305
|
+
* - 'json': Returns parsed JSON
|
|
306
|
+
*/
|
|
307
|
+
responseType?: 'blob' | 'arrayBuffer' | 'stream' | 'text' | 'json';
|
|
308
|
+
/**
|
|
309
|
+
* Set Content-Disposition to attachment to force file download.
|
|
310
|
+
*/
|
|
311
|
+
download?: boolean;
|
|
312
|
+
/**
|
|
313
|
+
* Whether to check and write to client cache (default: true if client cache enabled).
|
|
314
|
+
*/
|
|
315
|
+
useCache?: boolean;
|
|
316
|
+
/**
|
|
317
|
+
* Optional imgproxy image transformation options.
|
|
318
|
+
*/
|
|
319
|
+
imgproxy?: ImgProxyOptions;
|
|
320
|
+
/**
|
|
321
|
+
* Optional AbortSignal for cancelling download.
|
|
322
|
+
*/
|
|
323
|
+
signal?: AbortSignal;
|
|
324
|
+
}
|
|
325
|
+
interface GetUrlOptions {
|
|
326
|
+
/**
|
|
327
|
+
* Set download=true query param.
|
|
328
|
+
*/
|
|
329
|
+
download?: boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Optional imgproxy transformation query params.
|
|
332
|
+
*/
|
|
333
|
+
imgproxy?: ImgProxyOptions;
|
|
334
|
+
}
|
|
335
|
+
interface ListFilesOptions {
|
|
336
|
+
/**
|
|
337
|
+
* Target bucket ID (defaults to defaultBucket).
|
|
338
|
+
*/
|
|
339
|
+
bucketId?: string;
|
|
340
|
+
/**
|
|
341
|
+
* Optional AbortSignal.
|
|
342
|
+
*/
|
|
343
|
+
signal?: AbortSignal;
|
|
344
|
+
}
|
|
345
|
+
interface BucketStatsListResponse {
|
|
346
|
+
items: BucketStat[];
|
|
347
|
+
total?: number;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
interface RequestOptions {
|
|
351
|
+
headers?: Record<string, string>;
|
|
352
|
+
params?: Record<string, string | number | boolean | undefined | null>;
|
|
353
|
+
body?: BodyInit | null;
|
|
354
|
+
timeout?: number;
|
|
355
|
+
signal?: AbortSignal;
|
|
356
|
+
skipAuth?: boolean;
|
|
357
|
+
}
|
|
358
|
+
interface HttpResponse<T = unknown> {
|
|
359
|
+
data: T;
|
|
360
|
+
status: number;
|
|
361
|
+
statusText: string;
|
|
362
|
+
headers: Headers;
|
|
363
|
+
totalCount?: number;
|
|
364
|
+
}
|
|
365
|
+
declare class HttpClient {
|
|
366
|
+
private readonly endpoint;
|
|
367
|
+
private readonly apiKey?;
|
|
368
|
+
private readonly apiHash?;
|
|
369
|
+
private readonly defaultTimeout;
|
|
370
|
+
private readonly fetchImpl;
|
|
371
|
+
private readonly debug?;
|
|
372
|
+
private readonly maxRetries;
|
|
373
|
+
private readonly retryDelay;
|
|
374
|
+
private readonly retryOnStatus;
|
|
375
|
+
constructor(options: VFSClientOptions);
|
|
376
|
+
getEndpoint(): string;
|
|
377
|
+
getApiKey(): string | undefined;
|
|
378
|
+
getApiHash(): string | undefined;
|
|
379
|
+
private buildUrl;
|
|
380
|
+
private buildHeaders;
|
|
381
|
+
request<T = unknown>(method: string, path: string, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
382
|
+
get<T = unknown>(path: string, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
383
|
+
post<T = unknown>(path: string, body?: BodyInit | null, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
384
|
+
put<T = unknown>(path: string, body?: BodyInit | null, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
385
|
+
delete<T = unknown>(path: string, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
386
|
+
/**
|
|
387
|
+
* Fetches raw Response object directly (useful for streaming file downloads).
|
|
388
|
+
*/
|
|
389
|
+
fetchRaw(path: string, options?: RequestOptions): Promise<Response>;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
interface QueueItem {
|
|
393
|
+
id: string;
|
|
394
|
+
input: UploadInput;
|
|
395
|
+
status: 'pending' | 'uploading' | 'completed' | 'failed' | 'cancelled';
|
|
396
|
+
progress: number;
|
|
397
|
+
response?: AttachmentResponse;
|
|
398
|
+
error?: Error;
|
|
399
|
+
}
|
|
400
|
+
interface QueueProgress {
|
|
401
|
+
totalFiles: number;
|
|
402
|
+
completedFiles: number;
|
|
403
|
+
failedFiles: number;
|
|
404
|
+
overallPercent: number;
|
|
405
|
+
currentFile?: string;
|
|
406
|
+
}
|
|
407
|
+
type QueueListener = (progress: QueueProgress, item?: QueueItem) => void;
|
|
408
|
+
declare class BackgroundUploadQueue {
|
|
409
|
+
private readonly http;
|
|
410
|
+
private readonly defaultBucket;
|
|
411
|
+
private concurrency;
|
|
412
|
+
private items;
|
|
413
|
+
private activeCount;
|
|
414
|
+
private isPaused;
|
|
415
|
+
private abortController;
|
|
416
|
+
private listeners;
|
|
417
|
+
private onFileSuccessCb?;
|
|
418
|
+
private onFileErrorCb?;
|
|
419
|
+
private onCompletePromiseResolve?;
|
|
420
|
+
private onCompletePromiseReject?;
|
|
421
|
+
constructor(http: HttpClient, options?: {
|
|
422
|
+
defaultBucket?: string;
|
|
423
|
+
concurrency?: number;
|
|
424
|
+
});
|
|
425
|
+
onProgress(listener: QueueListener): () => void;
|
|
426
|
+
onFileSuccess(cb: (file: UploadInput, response: AttachmentResponse) => void): this;
|
|
427
|
+
onFileError(cb: (file: UploadInput, error: Error) => void): this;
|
|
428
|
+
add(input: UploadInput): string;
|
|
429
|
+
addAll(inputs: UploadInput[]): string[];
|
|
430
|
+
pause(): void;
|
|
431
|
+
resume(): void;
|
|
432
|
+
cancel(): void;
|
|
433
|
+
clear(): void;
|
|
434
|
+
getItems(): ReadonlyArray<QueueItem>;
|
|
435
|
+
getProgress(): QueueProgress;
|
|
436
|
+
private notifyProgress;
|
|
437
|
+
private processQueue;
|
|
438
|
+
private uploadItem;
|
|
439
|
+
private checkCompletion;
|
|
440
|
+
/**
|
|
441
|
+
* Returns a promise that resolves when all items currently in the queue have completed.
|
|
442
|
+
*/
|
|
443
|
+
wait(): Promise<AttachmentResponse[]>;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Uploads multiple files with concurrency control and progress tracking.
|
|
447
|
+
*/
|
|
448
|
+
declare function uploadMultipleFiles(http: HttpClient, input: UploadMultipleInput, defaultBucket?: string): Promise<AttachmentResponse[]>;
|
|
449
|
+
|
|
450
|
+
declare class VFSClient {
|
|
451
|
+
readonly http: HttpClient;
|
|
452
|
+
readonly defaultBucket: string;
|
|
453
|
+
readonly cache?: VFSCacheAdapter;
|
|
454
|
+
constructor(options: VFSClientOptions);
|
|
455
|
+
/**
|
|
456
|
+
* Upload a single file to VFS.
|
|
457
|
+
* Proactively checks preflight quota and deduplication: if identical file content exists,
|
|
458
|
+
* skips transfer and returns the existing file immediately.
|
|
459
|
+
*/
|
|
460
|
+
upload(input: UploadInput): Promise<AttachmentResponse>;
|
|
461
|
+
/**
|
|
462
|
+
* Upload multiple files with concurrency control, progress reporting, and stream/chunk support.
|
|
463
|
+
*/
|
|
464
|
+
uploadMultiple(input: UploadMultipleInput): Promise<AttachmentResponse[]>;
|
|
465
|
+
/**
|
|
466
|
+
* Creates a background upload queue manager for continuous uploads with pause/resume and events.
|
|
467
|
+
*/
|
|
468
|
+
createBackgroundQueue(options?: {
|
|
469
|
+
concurrency?: number;
|
|
470
|
+
bucketId?: string;
|
|
471
|
+
}): BackgroundUploadQueue;
|
|
472
|
+
/**
|
|
473
|
+
* Retrieves a file from VFS with multi-tier caching (Browser CacheStorage / Server Filesystem).
|
|
474
|
+
*/
|
|
475
|
+
getFile(bucketId: string, fileId: string, options?: GetFileOptions): Promise<Blob | ArrayBuffer | ReadableStream<Uint8Array> | string | unknown>;
|
|
476
|
+
/**
|
|
477
|
+
* Retrieves a file directly by its SHA-256 hash (/h/:hash).
|
|
478
|
+
* Hash-addressed content is immutable and cached indefinitely.
|
|
479
|
+
*/
|
|
480
|
+
getFileByHash(hash: string, options?: GetFileOptions): Promise<Blob | ArrayBuffer | ReadableStream<Uint8Array> | string | unknown>;
|
|
481
|
+
/**
|
|
482
|
+
* Gets metadata manifest of an uploaded file as a JSON object without downloading the file data.
|
|
483
|
+
*/
|
|
484
|
+
getFileMetadata(bucketId: string, fileId: string, signal?: AbortSignal): Promise<ObjectManifestResponse>;
|
|
485
|
+
/**
|
|
486
|
+
* Gets metadata manifest of a file by its SHA-256 hash.
|
|
487
|
+
*/
|
|
488
|
+
getFileMetadataByHash(hash: string, signal?: AbortSignal): Promise<ObjectManifestResponse>;
|
|
489
|
+
/**
|
|
490
|
+
* Generates public/access URL for a file, supporting imgproxy transformations and download triggers.
|
|
491
|
+
*/
|
|
492
|
+
getFileUrl(bucketId: string, fileId: string, options?: GetUrlOptions): string;
|
|
493
|
+
/**
|
|
494
|
+
* Generates public URL for a file addressed by its SHA-256 hash.
|
|
495
|
+
*/
|
|
496
|
+
getFileUrlByHash(hash: string): string;
|
|
497
|
+
/**
|
|
498
|
+
* Deletes a file by bucket ID and file ID, invalidating any cached copies.
|
|
499
|
+
*/
|
|
500
|
+
deleteFile(bucketId: string, fileId: string, signal?: AbortSignal): Promise<void>;
|
|
501
|
+
/**
|
|
502
|
+
* Deletes a file record by catalog ID.
|
|
503
|
+
*/
|
|
504
|
+
deleteFileById(id: string, signal?: AbortSignal): Promise<void>;
|
|
505
|
+
/**
|
|
506
|
+
* Deletes all files within a specified bucket.
|
|
507
|
+
*/
|
|
508
|
+
deleteAllInBucket(bucketId: string, signal?: AbortSignal): Promise<void>;
|
|
509
|
+
/**
|
|
510
|
+
* Lists stored objects in a bucket.
|
|
511
|
+
*/
|
|
512
|
+
listFiles(options?: ListFilesOptions): Promise<AttachmentResponse[]>;
|
|
513
|
+
/**
|
|
514
|
+
* Gets real-time statistics for a bucket (total files, storage usage, read/write counts, quota limits).
|
|
515
|
+
*/
|
|
516
|
+
getBucketStats(bucketId?: string, signal?: AbortSignal): Promise<BucketStat>;
|
|
517
|
+
/**
|
|
518
|
+
* Gets a list of all bucket statistics.
|
|
519
|
+
*/
|
|
520
|
+
getAllBucketStats(params?: {
|
|
521
|
+
page?: number;
|
|
522
|
+
limit?: number;
|
|
523
|
+
}, signal?: AbortSignal): Promise<BucketStatsListResponse>;
|
|
524
|
+
/**
|
|
525
|
+
* Gets overall system summary of bucket statistics (total buckets, total files, total storage size).
|
|
526
|
+
*/
|
|
527
|
+
getBucketSummary(signal?: AbortSignal): Promise<BucketStatSummary>;
|
|
528
|
+
/**
|
|
529
|
+
* Gets date-based usage growth metrics for a bucket.
|
|
530
|
+
*/
|
|
531
|
+
getBucketMetrics(bucketId?: string, signal?: AbortSignal): Promise<BucketMetricsByDate[]>;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
interface MemoryCacheOptions {
|
|
535
|
+
/**
|
|
536
|
+
* Maximum number of items in cache (default: 200).
|
|
537
|
+
*/
|
|
538
|
+
maxItems?: number;
|
|
539
|
+
/**
|
|
540
|
+
* Default TTL in seconds (default: 3600 = 1 hour, 0 for indefinite).
|
|
541
|
+
*/
|
|
542
|
+
defaultTTL?: number;
|
|
543
|
+
}
|
|
544
|
+
declare class MemoryCacheAdapter implements VFSCacheAdapter {
|
|
545
|
+
private readonly store;
|
|
546
|
+
private readonly maxItems;
|
|
547
|
+
private readonly defaultTTL;
|
|
548
|
+
constructor(options?: MemoryCacheOptions);
|
|
549
|
+
private isExpired;
|
|
550
|
+
get(key: string): VFSCacheEntry | null;
|
|
551
|
+
set(key: string, entry: VFSCacheEntry, ttlSeconds?: number): void;
|
|
552
|
+
delete(key: string): boolean;
|
|
553
|
+
clear(): void;
|
|
554
|
+
has(key: string): boolean;
|
|
555
|
+
size(): number;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
interface BrowserCacheOptions {
|
|
559
|
+
cacheName?: string;
|
|
560
|
+
defaultTTL?: number;
|
|
561
|
+
}
|
|
562
|
+
declare class BrowserCacheAdapter implements VFSCacheAdapter {
|
|
563
|
+
private readonly cacheName;
|
|
564
|
+
private readonly defaultTTL;
|
|
565
|
+
private readonly fallback;
|
|
566
|
+
constructor(options?: BrowserCacheOptions);
|
|
567
|
+
private isAvailable;
|
|
568
|
+
private urlForKey;
|
|
569
|
+
get(key: string): Promise<VFSCacheEntry | null>;
|
|
570
|
+
set(key: string, entry: VFSCacheEntry, ttlSeconds?: number): Promise<void>;
|
|
571
|
+
delete(key: string): Promise<boolean>;
|
|
572
|
+
clear(): Promise<void>;
|
|
573
|
+
has(key: string): Promise<boolean>;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
interface FileSystemCacheOptions {
|
|
577
|
+
/**
|
|
578
|
+
* Directory to store cached files (default: "./.vfs-cache").
|
|
579
|
+
*/
|
|
580
|
+
cacheDir?: string;
|
|
581
|
+
/**
|
|
582
|
+
* Default TTL in seconds (default: 3600 = 1 hour).
|
|
583
|
+
*/
|
|
584
|
+
defaultTTL?: number;
|
|
585
|
+
}
|
|
586
|
+
declare class FileSystemCacheAdapter implements VFSCacheAdapter {
|
|
587
|
+
private readonly cacheDir;
|
|
588
|
+
private readonly defaultTTL;
|
|
589
|
+
private readonly fallback;
|
|
590
|
+
private isNodeEnv;
|
|
591
|
+
constructor(options?: FileSystemCacheOptions);
|
|
592
|
+
private sanitizeKey;
|
|
593
|
+
private getFs;
|
|
594
|
+
private ensureDir;
|
|
595
|
+
get(key: string): Promise<VFSCacheEntry | null>;
|
|
596
|
+
set(key: string, entry: VFSCacheEntry, ttlSeconds?: number): Promise<void>;
|
|
597
|
+
delete(key: string): Promise<boolean>;
|
|
598
|
+
clear(): Promise<void>;
|
|
599
|
+
has(key: string): Promise<boolean>;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Creates the most suitable cache adapter for the current runtime environment.
|
|
604
|
+
* - In Browser: Uses BrowserCacheAdapter (CacheStorage / IndexedDB / Memory fallback)
|
|
605
|
+
* - In Node.js / Bun: Uses FileSystemCacheAdapter (or MemoryCacheAdapter if directory unwritable)
|
|
606
|
+
* - Otherwise: Uses MemoryCacheAdapter
|
|
607
|
+
*/
|
|
608
|
+
declare function createDefaultCache(): VFSCacheAdapter;
|
|
609
|
+
|
|
610
|
+
declare function uploadSingleFile(http: HttpClient, input: UploadInput, defaultBucket?: string): Promise<AttachmentResponse>;
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Uploads a file using the VFS Resumable Chunked Session Upload Protocol.
|
|
614
|
+
* Ideal for large files, unstable connections, and edge-distributed storage.
|
|
615
|
+
*/
|
|
616
|
+
declare function uploadSessionFile(http: HttpClient, input: UploadInput, defaultBucket?: string): Promise<AttachmentResponse>;
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Checks metadata with VFS Server preflight endpoint before uploading data.
|
|
620
|
+
* Detects quota violations, file size exceedance, and duplicate hits.
|
|
621
|
+
*/
|
|
622
|
+
declare function executePreflight(http: HttpClient, req: PreflightRequest, signal?: AbortSignal): Promise<PreflightResponse>;
|
|
623
|
+
|
|
624
|
+
interface NormalizedFileInput {
|
|
625
|
+
bytes: Uint8Array;
|
|
626
|
+
name: string;
|
|
627
|
+
size: number;
|
|
628
|
+
contentType: string;
|
|
629
|
+
hash: string;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Detects basic mime type from file name extension.
|
|
633
|
+
*/
|
|
634
|
+
declare function guessContentType(filename: string): string;
|
|
635
|
+
/**
|
|
636
|
+
* Normalizes any supported input into an in-memory Uint8Array with metadata and SHA-256 hash.
|
|
637
|
+
*/
|
|
638
|
+
declare function normalizeUploadInput(input: UploadInput): Promise<NormalizedFileInput>;
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Calculates SHA-256 hex digest of an ArrayBuffer or Uint8Array.
|
|
642
|
+
*/
|
|
643
|
+
declare function calculateSHA256(data: ArrayBuffer | Uint8Array | string): Promise<string>;
|
|
644
|
+
/**
|
|
645
|
+
* Calculates SHA-256 of a Blob or File.
|
|
646
|
+
*/
|
|
647
|
+
declare function calculateBlobSHA256(blob: Blob): Promise<string>;
|
|
648
|
+
|
|
649
|
+
export { type AttachmentResponse, BackgroundUploadQueue, BrowserCacheAdapter, type BrowserCacheOptions, type BucketMetricsByDate, type BucketStat, type BucketStatSummary, type BucketStatsListResponse, FileSystemCacheAdapter, type FileSystemCacheOptions, type GetFileOptions, type GetUrlOptions, HttpClient, type ImgProxyOptions, type ListFilesOptions, MemoryCacheAdapter, type MemoryCacheOptions, type ObjectManifestResponse, type PreflightRequest, type PreflightResponse, type ProblemDetails, type QueueItem, type QueueListener, type QueueProgress, type SessionView, type SupportedBinaryInput, type UploadInput, type UploadMultipleInput, type UploadProgress, type VFSCacheAdapter, type VFSCacheEntry, VFSClient, type VFSClientOptions, VFSError, calculateBlobSHA256, calculateSHA256, createDefaultCache, executePreflight, guessContentType, normalizeUploadInput, uploadMultipleFiles, uploadSessionFile, uploadSingleFile };
|