@nuvix/storage 0.1.0 → 1.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/README.md +125 -68
- package/dist/index.cjs +7375 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +469 -0
- package/dist/index.d.ts +38 -88
- package/dist/index.js +7360 -0
- package/dist/index.js.map +1 -0
- package/package.json +18 -23
- package/dist/index.cjs.js +0 -1270
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -1258
- package/dist/index.esm.js.map +0 -1
- package/dist/src/device/local.d.ts +0 -31
- package/dist/src/device/local.d.ts.map +0 -1
- package/dist/src/device/s3.d.ts +0 -89
- package/dist/src/device/s3.d.ts.map +0 -1
- package/dist/src/device/wasabi.d.ts +0 -24
- package/dist/src/device/wasabi.d.ts.map +0 -1
- package/dist/src/device.d.ts +0 -146
- package/dist/src/device.d.ts.map +0 -1
- package/dist/src/storage.d.ts +0 -56
- package/dist/src/storage.d.ts.map +0 -1
- package/dist/src/validator/file-ext.d.ts +0 -17
- package/dist/src/validator/file-ext.d.ts.map +0 -1
- package/dist/src/validator/file-name.d.ts +0 -31
- package/dist/src/validator/file-name.d.ts.map +0 -1
- package/dist/src/validator/file-size.d.ts +0 -29
- package/dist/src/validator/file-size.d.ts.map +0 -1
- package/dist/src/validator/file-type.d.ts +0 -35
- package/dist/src/validator/file-type.d.ts.map +0 -1
- package/dist/src/validator/file.d.ts +0 -30
- package/dist/src/validator/file.d.ts.map +0 -1
- package/dist/src/validator/upload.d.ts +0 -31
- package/dist/src/validator/upload.d.ts.map +0 -1
- package/dist/src/validator/validator.d.ts +0 -8
- package/dist/src/validator/validator.d.ts.map +0 -1
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
interface DeviceMetadata {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
declare abstract class Device {
|
|
5
|
+
/**
|
|
6
|
+
* Max chunk size while transferring file from one device to another
|
|
7
|
+
*/
|
|
8
|
+
protected transferChunkSize: number;
|
|
9
|
+
/**
|
|
10
|
+
* Sets the maximum number of keys returned to the response. By default, the action returns up to 1,000 key names.
|
|
11
|
+
*/
|
|
12
|
+
protected static readonly MAX_PAGE_SIZE: number;
|
|
13
|
+
/**
|
|
14
|
+
* Set Transfer Chunk Size
|
|
15
|
+
*/
|
|
16
|
+
setTransferChunkSize(chunkSize: number): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get Transfer Chunk Size
|
|
19
|
+
*/
|
|
20
|
+
getTransferChunkSize(): number;
|
|
21
|
+
/**
|
|
22
|
+
* Get Name.
|
|
23
|
+
*
|
|
24
|
+
* Get storage device name
|
|
25
|
+
*/
|
|
26
|
+
abstract getName(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Get Type.
|
|
29
|
+
*
|
|
30
|
+
* Get storage device type
|
|
31
|
+
*/
|
|
32
|
+
abstract getType(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Get Description.
|
|
35
|
+
*
|
|
36
|
+
* Get storage device description and purpose.
|
|
37
|
+
*/
|
|
38
|
+
abstract getDescription(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Get Root.
|
|
41
|
+
*
|
|
42
|
+
* Get storage device root path
|
|
43
|
+
*/
|
|
44
|
+
abstract getRoot(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Get Path.
|
|
47
|
+
*
|
|
48
|
+
* Each device hold a complex directory structure that is being build in this method.
|
|
49
|
+
*/
|
|
50
|
+
abstract getPath(filename: string, prefix?: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Upload.
|
|
53
|
+
*
|
|
54
|
+
* Upload a file to desired destination in the selected disk
|
|
55
|
+
* return number of chunks uploaded or 0 if it fails.
|
|
56
|
+
*/
|
|
57
|
+
abstract upload(source: string, path: string, chunk?: number, chunks?: number, metadata?: DeviceMetadata): Promise<number>;
|
|
58
|
+
/**
|
|
59
|
+
* Upload Data.
|
|
60
|
+
*
|
|
61
|
+
* Upload file contents to desired destination in the selected disk.
|
|
62
|
+
* return number of chunks uploaded or 0 if it fails.
|
|
63
|
+
*/
|
|
64
|
+
abstract uploadData(data: string | Buffer, path: string, contentType: string, chunk?: number, chunks?: number, metadata?: DeviceMetadata): Promise<number>;
|
|
65
|
+
/**
|
|
66
|
+
* Abort Chunked Upload
|
|
67
|
+
*/
|
|
68
|
+
abstract abort(path: string, extra?: string): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Read file by given path.
|
|
71
|
+
*/
|
|
72
|
+
abstract read(path: string, offset?: number, length?: number): Promise<Buffer>;
|
|
73
|
+
/**
|
|
74
|
+
* Transfer
|
|
75
|
+
* Transfer a file from current device to destination device.
|
|
76
|
+
*/
|
|
77
|
+
abstract transfer(path: string, destination: string, device: Device): Promise<boolean>;
|
|
78
|
+
/**
|
|
79
|
+
* Write file by given path.
|
|
80
|
+
*/
|
|
81
|
+
abstract write(path: string, data: string | Buffer, contentType: string): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Move file from given source to given path, return true on success and false on failure.
|
|
84
|
+
*/
|
|
85
|
+
move(source: string, target: string): Promise<boolean>;
|
|
86
|
+
/**
|
|
87
|
+
* Delete file in given path return true on success and false on failure.
|
|
88
|
+
*/
|
|
89
|
+
abstract delete(path: string, recursive?: boolean): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* Delete files in given path, path must be a directory. return true on success and false on failure.
|
|
92
|
+
*/
|
|
93
|
+
abstract deletePath(path: string): Promise<boolean>;
|
|
94
|
+
/**
|
|
95
|
+
* Check if file exists
|
|
96
|
+
*/
|
|
97
|
+
abstract exists(path: string): Promise<boolean>;
|
|
98
|
+
/**
|
|
99
|
+
* Returns given file path its size.
|
|
100
|
+
*/
|
|
101
|
+
abstract getFileSize(path: string): Promise<number>;
|
|
102
|
+
/**
|
|
103
|
+
* Returns given file path its mime type.
|
|
104
|
+
*/
|
|
105
|
+
abstract getFileMimeType(path: string): Promise<string>;
|
|
106
|
+
/**
|
|
107
|
+
* Returns given file path its MD5 hash value.
|
|
108
|
+
*/
|
|
109
|
+
abstract getFileHash(path: string): Promise<string>;
|
|
110
|
+
/**
|
|
111
|
+
* Create a directory at the specified path.
|
|
112
|
+
*
|
|
113
|
+
* Returns true on success or if the directory already exists and false on error
|
|
114
|
+
*/
|
|
115
|
+
abstract createDirectory(path: string): Promise<boolean>;
|
|
116
|
+
/**
|
|
117
|
+
* Get directory size in bytes.
|
|
118
|
+
*
|
|
119
|
+
* Return -1 on error
|
|
120
|
+
*/
|
|
121
|
+
abstract getDirectorySize(path: string): Promise<number>;
|
|
122
|
+
/**
|
|
123
|
+
* Get Partition Free Space.
|
|
124
|
+
*
|
|
125
|
+
* Returns available space on filesystem or disk partition
|
|
126
|
+
*/
|
|
127
|
+
abstract getPartitionFreeSpace(): Promise<number>;
|
|
128
|
+
/**
|
|
129
|
+
* Get Partition Total Space.
|
|
130
|
+
*
|
|
131
|
+
* Returns the total size of a filesystem or disk partition
|
|
132
|
+
*/
|
|
133
|
+
abstract getPartitionTotalSpace(): Promise<number>;
|
|
134
|
+
/**
|
|
135
|
+
* Get all files and directories inside a directory.
|
|
136
|
+
*/
|
|
137
|
+
abstract getFiles(dir: string, max?: number, continuationToken?: string): Promise<any[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Get the absolute path by resolving strings like ../, .., //, /\ and so on.
|
|
140
|
+
*
|
|
141
|
+
* Works like the realpath function but works on files that does not exist
|
|
142
|
+
*/
|
|
143
|
+
getAbsolutePath(path: string): string;
|
|
144
|
+
protected getMimeType(filePath: string): Promise<string>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
declare class Storage {
|
|
148
|
+
/**
|
|
149
|
+
* Supported devices
|
|
150
|
+
*/
|
|
151
|
+
static readonly DEVICE_LOCAL = "local";
|
|
152
|
+
static readonly DEVICE_S3 = "s3";
|
|
153
|
+
static readonly DEVICE_WASABI = "wasabi";
|
|
154
|
+
static readonly DEVICE_MINIO = "minio";
|
|
155
|
+
/**
|
|
156
|
+
* Devices.
|
|
157
|
+
*
|
|
158
|
+
* List of all available storage devices
|
|
159
|
+
*/
|
|
160
|
+
private static devices;
|
|
161
|
+
/**
|
|
162
|
+
* Set Device.
|
|
163
|
+
*
|
|
164
|
+
* Add device by name
|
|
165
|
+
*
|
|
166
|
+
* @param name
|
|
167
|
+
* @param device
|
|
168
|
+
* @throws Error
|
|
169
|
+
*/
|
|
170
|
+
static setDevice(name: string, device: Device): void;
|
|
171
|
+
/**
|
|
172
|
+
* Get Device.
|
|
173
|
+
*
|
|
174
|
+
* Get device by name
|
|
175
|
+
*
|
|
176
|
+
* @param name
|
|
177
|
+
* @returns Device
|
|
178
|
+
* @throws Error
|
|
179
|
+
*/
|
|
180
|
+
static getDevice(name: string): Device;
|
|
181
|
+
/**
|
|
182
|
+
* Exists.
|
|
183
|
+
*
|
|
184
|
+
* Checks if given storage name is registered or not
|
|
185
|
+
*
|
|
186
|
+
* @param name
|
|
187
|
+
* @returns boolean
|
|
188
|
+
*/
|
|
189
|
+
static exists(name: string): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Human readable data size format from bytes input.
|
|
192
|
+
*
|
|
193
|
+
* Based on: https://stackoverflow.com/a/38659168/2299554
|
|
194
|
+
*
|
|
195
|
+
* @param bytes
|
|
196
|
+
* @param decimals
|
|
197
|
+
* @param system
|
|
198
|
+
* @returns string
|
|
199
|
+
*/
|
|
200
|
+
static human(bytes: number, decimals?: number, system?: "binary" | "metric"): string;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
declare abstract class Validator {
|
|
204
|
+
static TYPE_STRING: string;
|
|
205
|
+
static TYPE_ARRAY: string;
|
|
206
|
+
static TYPE_INTEGER: string;
|
|
207
|
+
static TYPE_BOOLEAN: string;
|
|
208
|
+
abstract isValid(value: any): boolean | Promise<boolean>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare class File extends Validator {
|
|
212
|
+
getDescription(): string;
|
|
213
|
+
/**
|
|
214
|
+
* NOT MUCH RIGHT NOW.
|
|
215
|
+
*
|
|
216
|
+
* TODO think what to do here, currently only used for parameter to be present in SDKs
|
|
217
|
+
*
|
|
218
|
+
* @param name
|
|
219
|
+
* @return boolean
|
|
220
|
+
*/
|
|
221
|
+
isValid(name: any): boolean;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
declare class FileExt extends Validator {
|
|
225
|
+
static readonly TYPE_JPEG = "jpeg";
|
|
226
|
+
static readonly TYPE_JPG = "jpg";
|
|
227
|
+
static readonly TYPE_GIF = "gif";
|
|
228
|
+
static readonly TYPE_PNG = "png";
|
|
229
|
+
static readonly TYPE_GZIP = "gz";
|
|
230
|
+
static readonly TYPE_ZIP = "zip";
|
|
231
|
+
private allowed;
|
|
232
|
+
constructor(allowed: string[]);
|
|
233
|
+
getDescription(): string;
|
|
234
|
+
isValid(filename: string): boolean;
|
|
235
|
+
private getFileExtension;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
declare class FileName extends Validator {
|
|
239
|
+
/**
|
|
240
|
+
* Get Description
|
|
241
|
+
*/
|
|
242
|
+
getDescription(): string;
|
|
243
|
+
/**
|
|
244
|
+
* The file name can only contain "a-z", "A-Z", "0-9" and "." and not empty.
|
|
245
|
+
*
|
|
246
|
+
* @param name - The filename to validate
|
|
247
|
+
* @returns boolean indicating if the filename is valid
|
|
248
|
+
*/
|
|
249
|
+
isValid(name: any): boolean;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
declare class FileSize extends Validator {
|
|
253
|
+
private max;
|
|
254
|
+
/**
|
|
255
|
+
* Max size in bytes
|
|
256
|
+
*/
|
|
257
|
+
constructor(max: number);
|
|
258
|
+
/**
|
|
259
|
+
* Get Description
|
|
260
|
+
*/
|
|
261
|
+
getDescription(): string;
|
|
262
|
+
/**
|
|
263
|
+
* Finds whether a file size is smaller than required limit.
|
|
264
|
+
*/
|
|
265
|
+
isValid(fileSize: any): boolean;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
declare class FileType extends Validator {
|
|
269
|
+
/**
|
|
270
|
+
* File Types Constants.
|
|
271
|
+
*/
|
|
272
|
+
static readonly FILE_TYPE_JPEG = "jpeg";
|
|
273
|
+
static readonly FILE_TYPE_GIF = "gif";
|
|
274
|
+
static readonly FILE_TYPE_PNG = "png";
|
|
275
|
+
static readonly FILE_TYPE_GZIP = "gz";
|
|
276
|
+
/**
|
|
277
|
+
* File Type Binaries.
|
|
278
|
+
*/
|
|
279
|
+
private readonly types;
|
|
280
|
+
private readonly allowed;
|
|
281
|
+
constructor(allowed: string[]);
|
|
282
|
+
/**
|
|
283
|
+
* Get Description
|
|
284
|
+
*/
|
|
285
|
+
getDescription(): string;
|
|
286
|
+
/**
|
|
287
|
+
* Is Valid.
|
|
288
|
+
*
|
|
289
|
+
* Binary check to finds whether a file is of valid type
|
|
290
|
+
*/
|
|
291
|
+
isValid(path: string): Promise<boolean>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
declare class Upload extends Validator {
|
|
295
|
+
/**
|
|
296
|
+
* Get Description
|
|
297
|
+
*/
|
|
298
|
+
getDescription(): string;
|
|
299
|
+
/**
|
|
300
|
+
* Check if a file is a valid upload file
|
|
301
|
+
*
|
|
302
|
+
* @param path - The file path to validate
|
|
303
|
+
* @returns Promise that resolves to true if valid upload file, false otherwise
|
|
304
|
+
*/
|
|
305
|
+
isValid(path: unknown): Promise<boolean>;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
declare class Local extends Device {
|
|
309
|
+
protected root: string;
|
|
310
|
+
protected readonly MAX_PAGE_SIZE = 1000;
|
|
311
|
+
constructor(root?: string);
|
|
312
|
+
getName(): string;
|
|
313
|
+
getType(): string;
|
|
314
|
+
getDescription(): string;
|
|
315
|
+
getRoot(): string;
|
|
316
|
+
getPath(filename: string, prefix?: string): string;
|
|
317
|
+
upload(source: string, filePath: string, chunk?: number, chunks?: number, metadata?: Record<string, any>): Promise<number>;
|
|
318
|
+
uploadData(data: string | Buffer, filePath: string, contentType: string, chunk?: number, chunks?: number, metadata?: Record<string, any>): Promise<number>;
|
|
319
|
+
private joinChunks;
|
|
320
|
+
transfer(filePath: string, destination: string, device: Device): Promise<boolean>;
|
|
321
|
+
abort(filePath: string, extra?: string): Promise<boolean>;
|
|
322
|
+
read(filePath: string, offset?: number, length?: number): Promise<Buffer>;
|
|
323
|
+
write(filePath: string, data: string | Buffer, contentType?: string): Promise<boolean>;
|
|
324
|
+
move(source: string, target: string): Promise<boolean>;
|
|
325
|
+
delete(filePath: string, recursive?: boolean): Promise<boolean>;
|
|
326
|
+
deletePath(filePath: string): Promise<boolean>;
|
|
327
|
+
exists(filePath: string): Promise<boolean>;
|
|
328
|
+
getFileSize(filePath: string): Promise<number>;
|
|
329
|
+
getFileMimeType(filePath: string): Promise<string>;
|
|
330
|
+
getFileHash(filePath: string): Promise<string>;
|
|
331
|
+
createDirectory(dirPath: string): Promise<boolean>;
|
|
332
|
+
getDirectorySize(dirPath: string): Promise<number>;
|
|
333
|
+
getPartitionFreeSpace(): Promise<number>;
|
|
334
|
+
getPartitionTotalSpace(): Promise<number>;
|
|
335
|
+
getFiles(dir: string, max?: number, continuationToken?: string): Promise<string[]>;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
declare class S3 extends Device {
|
|
339
|
+
static readonly METHOD_GET = "GET";
|
|
340
|
+
static readonly METHOD_POST = "POST";
|
|
341
|
+
static readonly METHOD_PUT = "PUT";
|
|
342
|
+
static readonly METHOD_PATCH = "PATCH";
|
|
343
|
+
static readonly METHOD_DELETE = "DELETE";
|
|
344
|
+
static readonly METHOD_HEAD = "HEAD";
|
|
345
|
+
static readonly METHOD_OPTIONS = "OPTIONS";
|
|
346
|
+
static readonly METHOD_CONNECT = "CONNECT";
|
|
347
|
+
static readonly METHOD_TRACE = "TRACE";
|
|
348
|
+
static readonly US_EAST_1 = "us-east-1";
|
|
349
|
+
static readonly US_EAST_2 = "us-east-2";
|
|
350
|
+
static readonly US_WEST_1 = "us-west-1";
|
|
351
|
+
static readonly US_WEST_2 = "us-west-2";
|
|
352
|
+
static readonly AF_SOUTH_1 = "af-south-1";
|
|
353
|
+
static readonly AP_EAST_1 = "ap-east-1";
|
|
354
|
+
static readonly AP_SOUTH_1 = "ap-south-1";
|
|
355
|
+
static readonly AP_NORTHEAST_3 = "ap-northeast-3";
|
|
356
|
+
static readonly AP_NORTHEAST_2 = "ap-northeast-2";
|
|
357
|
+
static readonly AP_NORTHEAST_1 = "ap-northeast-1";
|
|
358
|
+
static readonly AP_SOUTHEAST_1 = "ap-southeast-1";
|
|
359
|
+
static readonly AP_SOUTHEAST_2 = "ap-southeast-2";
|
|
360
|
+
static readonly CA_CENTRAL_1 = "ca-central-1";
|
|
361
|
+
static readonly EU_CENTRAL_1 = "eu-central-1";
|
|
362
|
+
static readonly EU_WEST_1 = "eu-west-1";
|
|
363
|
+
static readonly EU_SOUTH_1 = "eu-south-1";
|
|
364
|
+
static readonly EU_WEST_2 = "eu-west-2";
|
|
365
|
+
static readonly EU_WEST_3 = "eu-west-3";
|
|
366
|
+
static readonly EU_NORTH_1 = "eu-north-1";
|
|
367
|
+
static readonly SA_EAST_1 = "eu-north-1";
|
|
368
|
+
static readonly CN_NORTH_1 = "cn-north-1";
|
|
369
|
+
static readonly CN_NORTH_4 = "cn-north-4";
|
|
370
|
+
static readonly CN_NORTHWEST_1 = "cn-northwest-1";
|
|
371
|
+
static readonly ME_SOUTH_1 = "me-south-1";
|
|
372
|
+
static readonly US_GOV_EAST_1 = "us-gov-east-1";
|
|
373
|
+
static readonly US_GOV_WEST_1 = "us-gov-west-1";
|
|
374
|
+
static readonly ACL_PRIVATE = "private";
|
|
375
|
+
static readonly ACL_PUBLIC_READ = "public-read";
|
|
376
|
+
static readonly ACL_PUBLIC_READ_WRITE = "public-read-write";
|
|
377
|
+
static readonly ACL_AUTHENTICATED_READ = "authenticated-read";
|
|
378
|
+
protected static readonly MAX_PAGE_SIZE = 1000;
|
|
379
|
+
protected static retryAttempts: number;
|
|
380
|
+
protected static retryDelay: number;
|
|
381
|
+
protected accessKey: string;
|
|
382
|
+
protected secretKey: string;
|
|
383
|
+
protected bucket: string;
|
|
384
|
+
protected region: string;
|
|
385
|
+
protected acl: string;
|
|
386
|
+
protected root: string;
|
|
387
|
+
protected headers: Record<string, string>;
|
|
388
|
+
protected amzHeaders: Record<string, string>;
|
|
389
|
+
constructor(root: string, accessKey: string, secretKey: string, bucket: string, region?: string, acl?: string, endpointUrl?: string);
|
|
390
|
+
getName(): string;
|
|
391
|
+
getType(): string;
|
|
392
|
+
getDescription(): string;
|
|
393
|
+
getRoot(): string;
|
|
394
|
+
getPath(filename: string, prefix?: string): string;
|
|
395
|
+
getPartitionTotalSpace(): Promise<number>;
|
|
396
|
+
static setRetryAttempts(attempts: number): void;
|
|
397
|
+
static setRetryDelay(delay: number): void;
|
|
398
|
+
upload(source: string | Buffer, path: string, chunk?: number, chunks?: number, metadata?: Record<string, any>): Promise<number>;
|
|
399
|
+
uploadData(data: Buffer, path: string, contentType: string, chunk?: number, chunks?: number, metadata?: Record<string, any>): Promise<number>;
|
|
400
|
+
transfer(path: string, destination: string, device: Device): Promise<boolean>;
|
|
401
|
+
protected createMultipartUpload(path: string, contentType: string): Promise<string>;
|
|
402
|
+
protected uploadPart(data: Buffer, path: string, contentType: string, chunk: number, uploadId: string): Promise<string>;
|
|
403
|
+
protected completeMultipartUpload(path: string, uploadId: string, parts: Record<number, string>): Promise<boolean>;
|
|
404
|
+
abort(path: string, extra?: string): Promise<boolean>;
|
|
405
|
+
read(path: string, offset?: number, length?: number): Promise<Buffer>;
|
|
406
|
+
write(path: string, data: Buffer, contentType?: string): Promise<boolean>;
|
|
407
|
+
delete(path: string, recursive?: boolean): Promise<boolean>;
|
|
408
|
+
protected listObjects(prefix?: string, maxKeys?: number, continuationToken?: string): Promise<any>;
|
|
409
|
+
deletePath(path: string): Promise<boolean>;
|
|
410
|
+
exists(path: string): Promise<boolean>;
|
|
411
|
+
getFileSize(path: string): Promise<number>;
|
|
412
|
+
getFileMimeType(path: string): Promise<string>;
|
|
413
|
+
getFileHash(path: string): Promise<string>;
|
|
414
|
+
createDirectory(path: string): Promise<boolean>;
|
|
415
|
+
getDirectorySize(path: string): Promise<number>;
|
|
416
|
+
getPartitionFreeSpace(): Promise<number>;
|
|
417
|
+
getFiles(dir: string, max?: number, continuationToken?: string): Promise<any>;
|
|
418
|
+
private getInfo;
|
|
419
|
+
protected getSignatureV4(method: string, uri: string, parameters?: Record<string, string>): string;
|
|
420
|
+
protected call(method: string, uri: string, data?: string | Buffer, parameters?: Record<string, string>, decode?: boolean): Promise<{
|
|
421
|
+
body: any;
|
|
422
|
+
buffer: ArrayBuffer;
|
|
423
|
+
headers: Record<string, string>;
|
|
424
|
+
code: number;
|
|
425
|
+
}>;
|
|
426
|
+
protected md5(data: string | Buffer): Buffer;
|
|
427
|
+
protected sha256(data: string | Buffer): string;
|
|
428
|
+
protected hmacSha256(data: string | Buffer, key: string | Buffer, encoding?: "hex" | "binary"): string | Buffer;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
declare class Wasabi extends S3 {
|
|
432
|
+
/**
|
|
433
|
+
* Regions constants
|
|
434
|
+
*/
|
|
435
|
+
static readonly US_WEST_1 = "us-west-1";
|
|
436
|
+
static readonly AP_NORTHEAST_1 = "ap-northeast-1";
|
|
437
|
+
static readonly AP_NORTHEAST_2 = "ap-northeast-2";
|
|
438
|
+
static readonly EU_CENTRAL_1 = "eu-central-1";
|
|
439
|
+
static readonly EU_CENTRAL_2 = "eu-central-2";
|
|
440
|
+
static readonly EU_WEST_1 = "eu-west-1";
|
|
441
|
+
static readonly EU_WEST_2 = "eu-west-2";
|
|
442
|
+
static readonly US_CENTRAL_1 = "us-central-1";
|
|
443
|
+
static readonly US_EAST_1 = "us-east-1";
|
|
444
|
+
static readonly US_EAST_2 = "us-east-2";
|
|
445
|
+
/**
|
|
446
|
+
* Wasabi Constructor
|
|
447
|
+
*/
|
|
448
|
+
constructor(root: string, accessKey: string, secretKey: string, bucket: string, region?: string, acl?: string);
|
|
449
|
+
getName(): string;
|
|
450
|
+
getDescription(): string;
|
|
451
|
+
getType(): string;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
declare class MinIO extends S3 {
|
|
455
|
+
/**
|
|
456
|
+
* MinIO Constructor
|
|
457
|
+
*/
|
|
458
|
+
constructor(root: string, accessKey: string, secretKey: string, bucket: string, endpoint?: string, acl?: string, useSSL?: boolean);
|
|
459
|
+
private endpointUrl;
|
|
460
|
+
getName(): string;
|
|
461
|
+
getDescription(): string;
|
|
462
|
+
getType(): string;
|
|
463
|
+
/**
|
|
464
|
+
* Override the call method to use the custom endpoint
|
|
465
|
+
*/
|
|
466
|
+
protected call(method: string, uri: string, data?: string | Buffer, parameters?: Record<string, string>, decode?: boolean): Promise<any>;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export { Device, type DeviceMetadata, File, FileExt, FileName, FileSize, FileType, Local, MinIO, S3, Storage, Upload, Wasabi };
|
package/dist/index.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ declare abstract class Device {
|
|
|
61
61
|
* Upload file contents to desired destination in the selected disk.
|
|
62
62
|
* return number of chunks uploaded or 0 if it fails.
|
|
63
63
|
*/
|
|
64
|
-
abstract uploadData(data: string, path: string, contentType: string, chunk?: number, chunks?: number, metadata?: DeviceMetadata): Promise<number>;
|
|
64
|
+
abstract uploadData(data: string | Buffer, path: string, contentType: string, chunk?: number, chunks?: number, metadata?: DeviceMetadata): Promise<number>;
|
|
65
65
|
/**
|
|
66
66
|
* Abort Chunked Upload
|
|
67
67
|
*/
|
|
@@ -69,7 +69,7 @@ declare abstract class Device {
|
|
|
69
69
|
/**
|
|
70
70
|
* Read file by given path.
|
|
71
71
|
*/
|
|
72
|
-
abstract read(path: string, offset?: number, length?: number): Promise<
|
|
72
|
+
abstract read(path: string, offset?: number, length?: number): Promise<Buffer>;
|
|
73
73
|
/**
|
|
74
74
|
* Transfer
|
|
75
75
|
* Transfer a file from current device to destination device.
|
|
@@ -78,7 +78,7 @@ declare abstract class Device {
|
|
|
78
78
|
/**
|
|
79
79
|
* Write file by given path.
|
|
80
80
|
*/
|
|
81
|
-
abstract write(path: string, data: string, contentType: string): Promise<boolean>;
|
|
81
|
+
abstract write(path: string, data: string | Buffer, contentType: string): Promise<boolean>;
|
|
82
82
|
/**
|
|
83
83
|
* Move file from given source to given path, return true on success and false on failure.
|
|
84
84
|
*/
|
|
@@ -151,6 +151,7 @@ declare class Storage {
|
|
|
151
151
|
static readonly DEVICE_LOCAL = "local";
|
|
152
152
|
static readonly DEVICE_S3 = "s3";
|
|
153
153
|
static readonly DEVICE_WASABI = "wasabi";
|
|
154
|
+
static readonly DEVICE_MINIO = "minio";
|
|
154
155
|
/**
|
|
155
156
|
* Devices.
|
|
156
157
|
*
|
|
@@ -196,7 +197,7 @@ declare class Storage {
|
|
|
196
197
|
* @param system
|
|
197
198
|
* @returns string
|
|
198
199
|
*/
|
|
199
|
-
static human(bytes: number, decimals?: number, system?:
|
|
200
|
+
static human(bytes: number, decimals?: number, system?: "binary" | "metric"): string;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
declare abstract class Validator {
|
|
@@ -218,22 +219,6 @@ declare class File extends Validator {
|
|
|
218
219
|
* @return boolean
|
|
219
220
|
*/
|
|
220
221
|
isValid(name: any): boolean;
|
|
221
|
-
/**
|
|
222
|
-
* Is array
|
|
223
|
-
*
|
|
224
|
-
* Function will return true if object is array.
|
|
225
|
-
*
|
|
226
|
-
* @return boolean
|
|
227
|
-
*/
|
|
228
|
-
isArray(): boolean;
|
|
229
|
-
/**
|
|
230
|
-
* Get Type
|
|
231
|
-
*
|
|
232
|
-
* Returns validator type.
|
|
233
|
-
*
|
|
234
|
-
* @return string
|
|
235
|
-
*/
|
|
236
|
-
getType(): string;
|
|
237
222
|
}
|
|
238
223
|
|
|
239
224
|
declare class FileExt extends Validator {
|
|
@@ -247,8 +232,6 @@ declare class FileExt extends Validator {
|
|
|
247
232
|
constructor(allowed: string[]);
|
|
248
233
|
getDescription(): string;
|
|
249
234
|
isValid(filename: string): boolean;
|
|
250
|
-
isArray(): boolean;
|
|
251
|
-
getType(): string;
|
|
252
235
|
private getFileExtension;
|
|
253
236
|
}
|
|
254
237
|
|
|
@@ -264,22 +247,6 @@ declare class FileName extends Validator {
|
|
|
264
247
|
* @returns boolean indicating if the filename is valid
|
|
265
248
|
*/
|
|
266
249
|
isValid(name: any): boolean;
|
|
267
|
-
/**
|
|
268
|
-
* Is array
|
|
269
|
-
*
|
|
270
|
-
* Function will return true if object is array.
|
|
271
|
-
*
|
|
272
|
-
* @returns boolean
|
|
273
|
-
*/
|
|
274
|
-
isArray(): boolean;
|
|
275
|
-
/**
|
|
276
|
-
* Get Type
|
|
277
|
-
*
|
|
278
|
-
* Returns validator type.
|
|
279
|
-
*
|
|
280
|
-
* @returns string
|
|
281
|
-
*/
|
|
282
|
-
getType(): string;
|
|
283
250
|
}
|
|
284
251
|
|
|
285
252
|
declare class FileSize extends Validator {
|
|
@@ -296,18 +263,6 @@ declare class FileSize extends Validator {
|
|
|
296
263
|
* Finds whether a file size is smaller than required limit.
|
|
297
264
|
*/
|
|
298
265
|
isValid(fileSize: any): boolean;
|
|
299
|
-
/**
|
|
300
|
-
* Is array
|
|
301
|
-
*
|
|
302
|
-
* Function will return true if object is array.
|
|
303
|
-
*/
|
|
304
|
-
isArray(): boolean;
|
|
305
|
-
/**
|
|
306
|
-
* Get Type
|
|
307
|
-
*
|
|
308
|
-
* Returns validator type.
|
|
309
|
-
*/
|
|
310
|
-
getType(): string;
|
|
311
266
|
}
|
|
312
267
|
|
|
313
268
|
declare class FileType extends Validator {
|
|
@@ -334,14 +289,6 @@ declare class FileType extends Validator {
|
|
|
334
289
|
* Binary check to finds whether a file is of valid type
|
|
335
290
|
*/
|
|
336
291
|
isValid(path: string): Promise<boolean>;
|
|
337
|
-
/**
|
|
338
|
-
* Is array
|
|
339
|
-
*/
|
|
340
|
-
isArray(): boolean;
|
|
341
|
-
/**
|
|
342
|
-
* Get Type
|
|
343
|
-
*/
|
|
344
|
-
getType(): string;
|
|
345
292
|
}
|
|
346
293
|
|
|
347
294
|
declare class Upload extends Validator {
|
|
@@ -356,22 +303,6 @@ declare class Upload extends Validator {
|
|
|
356
303
|
* @returns Promise that resolves to true if valid upload file, false otherwise
|
|
357
304
|
*/
|
|
358
305
|
isValid(path: unknown): Promise<boolean>;
|
|
359
|
-
/**
|
|
360
|
-
* Is array
|
|
361
|
-
*
|
|
362
|
-
* Function will return true if object is array.
|
|
363
|
-
*
|
|
364
|
-
* @returns false - this validator doesn't handle arrays
|
|
365
|
-
*/
|
|
366
|
-
isArray(): boolean;
|
|
367
|
-
/**
|
|
368
|
-
* Get Type
|
|
369
|
-
*
|
|
370
|
-
* Returns validator type.
|
|
371
|
-
*
|
|
372
|
-
* @returns The validator type
|
|
373
|
-
*/
|
|
374
|
-
getType(): string;
|
|
375
306
|
}
|
|
376
307
|
|
|
377
308
|
declare class Local extends Device {
|
|
@@ -384,12 +315,12 @@ declare class Local extends Device {
|
|
|
384
315
|
getRoot(): string;
|
|
385
316
|
getPath(filename: string, prefix?: string): string;
|
|
386
317
|
upload(source: string, filePath: string, chunk?: number, chunks?: number, metadata?: Record<string, any>): Promise<number>;
|
|
387
|
-
uploadData(data: string, filePath: string, contentType: string, chunk?: number, chunks?: number, metadata?: Record<string, any>): Promise<number>;
|
|
318
|
+
uploadData(data: string | Buffer, filePath: string, contentType: string, chunk?: number, chunks?: number, metadata?: Record<string, any>): Promise<number>;
|
|
388
319
|
private joinChunks;
|
|
389
320
|
transfer(filePath: string, destination: string, device: Device): Promise<boolean>;
|
|
390
321
|
abort(filePath: string, extra?: string): Promise<boolean>;
|
|
391
|
-
read(filePath: string, offset?: number, length?: number): Promise<
|
|
392
|
-
write(filePath: string, data: string, contentType?: string): Promise<boolean>;
|
|
322
|
+
read(filePath: string, offset?: number, length?: number): Promise<Buffer>;
|
|
323
|
+
write(filePath: string, data: string | Buffer, contentType?: string): Promise<boolean>;
|
|
393
324
|
move(source: string, target: string): Promise<boolean>;
|
|
394
325
|
delete(filePath: string, recursive?: boolean): Promise<boolean>;
|
|
395
326
|
deletePath(filePath: string): Promise<boolean>;
|
|
@@ -465,14 +396,14 @@ declare class S3 extends Device {
|
|
|
465
396
|
static setRetryAttempts(attempts: number): void;
|
|
466
397
|
static setRetryDelay(delay: number): void;
|
|
467
398
|
upload(source: string | Buffer, path: string, chunk?: number, chunks?: number, metadata?: Record<string, any>): Promise<number>;
|
|
468
|
-
uploadData(data:
|
|
399
|
+
uploadData(data: Buffer, path: string, contentType: string, chunk?: number, chunks?: number, metadata?: Record<string, any>): Promise<number>;
|
|
469
400
|
transfer(path: string, destination: string, device: Device): Promise<boolean>;
|
|
470
401
|
protected createMultipartUpload(path: string, contentType: string): Promise<string>;
|
|
471
|
-
protected uploadPart(data:
|
|
402
|
+
protected uploadPart(data: Buffer, path: string, contentType: string, chunk: number, uploadId: string): Promise<string>;
|
|
472
403
|
protected completeMultipartUpload(path: string, uploadId: string, parts: Record<number, string>): Promise<boolean>;
|
|
473
404
|
abort(path: string, extra?: string): Promise<boolean>;
|
|
474
|
-
read(path: string, offset?: number, length?: number): Promise<
|
|
475
|
-
write(path: string, data:
|
|
405
|
+
read(path: string, offset?: number, length?: number): Promise<Buffer>;
|
|
406
|
+
write(path: string, data: Buffer, contentType?: string): Promise<boolean>;
|
|
476
407
|
delete(path: string, recursive?: boolean): Promise<boolean>;
|
|
477
408
|
protected listObjects(prefix?: string, maxKeys?: number, continuationToken?: string): Promise<any>;
|
|
478
409
|
deletePath(path: string): Promise<boolean>;
|
|
@@ -485,11 +416,16 @@ declare class S3 extends Device {
|
|
|
485
416
|
getPartitionFreeSpace(): Promise<number>;
|
|
486
417
|
getFiles(dir: string, max?: number, continuationToken?: string): Promise<any>;
|
|
487
418
|
private getInfo;
|
|
488
|
-
|
|
489
|
-
protected call(method: string, uri: string, data?: string, parameters?: Record<string, string>, decode?: boolean): Promise<
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
419
|
+
protected getSignatureV4(method: string, uri: string, parameters?: Record<string, string>): string;
|
|
420
|
+
protected call(method: string, uri: string, data?: string | Buffer, parameters?: Record<string, string>, decode?: boolean): Promise<{
|
|
421
|
+
body: any;
|
|
422
|
+
buffer: ArrayBuffer;
|
|
423
|
+
headers: Record<string, string>;
|
|
424
|
+
code: number;
|
|
425
|
+
}>;
|
|
426
|
+
protected md5(data: string | Buffer): Buffer;
|
|
427
|
+
protected sha256(data: string | Buffer): string;
|
|
428
|
+
protected hmacSha256(data: string | Buffer, key: string | Buffer, encoding?: "hex" | "binary"): string | Buffer;
|
|
493
429
|
}
|
|
494
430
|
|
|
495
431
|
declare class Wasabi extends S3 {
|
|
@@ -515,5 +451,19 @@ declare class Wasabi extends S3 {
|
|
|
515
451
|
getType(): string;
|
|
516
452
|
}
|
|
517
453
|
|
|
518
|
-
|
|
519
|
-
|
|
454
|
+
declare class MinIO extends S3 {
|
|
455
|
+
/**
|
|
456
|
+
* MinIO Constructor
|
|
457
|
+
*/
|
|
458
|
+
constructor(root: string, accessKey: string, secretKey: string, bucket: string, endpoint?: string, acl?: string, useSSL?: boolean);
|
|
459
|
+
private endpointUrl;
|
|
460
|
+
getName(): string;
|
|
461
|
+
getDescription(): string;
|
|
462
|
+
getType(): string;
|
|
463
|
+
/**
|
|
464
|
+
* Override the call method to use the custom endpoint
|
|
465
|
+
*/
|
|
466
|
+
protected call(method: string, uri: string, data?: string | Buffer, parameters?: Record<string, string>, decode?: boolean): Promise<any>;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export { Device, type DeviceMetadata, File, FileExt, FileName, FileSize, FileType, Local, MinIO, S3, Storage, Upload, Wasabi };
|