@nuvix/storage 1.0.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.
Files changed (38) hide show
  1. package/dist/index.cjs +7375 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +469 -0
  4. package/dist/index.d.ts +1 -2
  5. package/dist/index.js +7360 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +12 -18
  8. package/dist/index.cjs.js +0 -1296
  9. package/dist/index.cjs.js.map +0 -1
  10. package/dist/index.d.ts.map +0 -1
  11. package/dist/index.esm.js +0 -1283
  12. package/dist/index.esm.js.map +0 -1
  13. package/dist/src/device/local.d.ts +0 -31
  14. package/dist/src/device/local.d.ts.map +0 -1
  15. package/dist/src/device/minio.d.ts +0 -16
  16. package/dist/src/device/minio.d.ts.map +0 -1
  17. package/dist/src/device/s3.d.ts +0 -94
  18. package/dist/src/device/s3.d.ts.map +0 -1
  19. package/dist/src/device/wasabi.d.ts +0 -24
  20. package/dist/src/device/wasabi.d.ts.map +0 -1
  21. package/dist/src/device.d.ts +0 -146
  22. package/dist/src/device.d.ts.map +0 -1
  23. package/dist/src/storage.d.ts +0 -57
  24. package/dist/src/storage.d.ts.map +0 -1
  25. package/dist/src/validator/file-ext.d.ts +0 -15
  26. package/dist/src/validator/file-ext.d.ts.map +0 -1
  27. package/dist/src/validator/file-name.d.ts +0 -15
  28. package/dist/src/validator/file-name.d.ts.map +0 -1
  29. package/dist/src/validator/file-size.d.ts +0 -17
  30. package/dist/src/validator/file-size.d.ts.map +0 -1
  31. package/dist/src/validator/file-type.d.ts +0 -27
  32. package/dist/src/validator/file-type.d.ts.map +0 -1
  33. package/dist/src/validator/file.d.ts +0 -14
  34. package/dist/src/validator/file.d.ts.map +0 -1
  35. package/dist/src/validator/upload.d.ts +0 -15
  36. package/dist/src/validator/upload.d.ts.map +0 -1
  37. package/dist/src/validator/validator.d.ts +0 -8
  38. package/dist/src/validator/validator.d.ts.map +0 -1
@@ -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
@@ -466,5 +466,4 @@ declare class MinIO extends S3 {
466
466
  protected call(method: string, uri: string, data?: string | Buffer, parameters?: Record<string, string>, decode?: boolean): Promise<any>;
467
467
  }
468
468
 
469
- export { Device, File, FileExt, FileName, FileSize, FileType, Local, MinIO, S3, Storage, Upload, Wasabi };
470
- export type { DeviceMetadata };
469
+ export { Device, type DeviceMetadata, File, FileExt, FileName, FileSize, FileType, Local, MinIO, S3, Storage, Upload, Wasabi };