@flystorage/file-storage 0.0.1 → 0.0.3
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/dist/cjs/errors.js +17 -2
- package/dist/cjs/file-storage.js +24 -0
- package/dist/esm/errors.js +17 -2
- package/dist/esm/file-storage.js +24 -0
- package/dist/types/errors.d.ts +22 -1
- package/dist/types/file-storage.d.ts +10 -0
- package/package.json +1 -1
package/dist/cjs/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnableToListDirectory = exports.UnableToCheckDirectoryExistence = exports.UnableToCheckFileExistence = exports.UnableToDeleteFile = exports.UnableToDeleteDirectory = exports.UnableToCreateDirectory = exports.UnableToGetStat = exports.UnableToGetTemporaryUrl = exports.UnableToGetPublicUrl = exports.UnableToGetVisibility = exports.UnableToSetVisibility = exports.UnableToReadFile = exports.UnableToWriteFile = exports.UnableToGetChecksum = exports.ChecksumIsNotAvailable = exports.FlystorageError = exports.errorToMessage = void 0;
|
|
3
|
+
exports.UnableToListDirectory = exports.UnableToCheckDirectoryExistence = exports.UnableToCheckFileExistence = exports.UnableToDeleteFile = exports.UnableToDeleteDirectory = exports.UnableToCreateDirectory = exports.UnableToGetStat = exports.UnableToGetTemporaryUrl = exports.UnableToGetPublicUrl = exports.UnableToGetVisibility = exports.UnableToSetVisibility = exports.UnableToReadFile = exports.UnableToWriteFile = exports.UnableToGetFileSize = exports.UnableToGetLastModified = exports.UnableToGetMimeType = exports.UnableToGetChecksum = exports.ChecksumIsNotAvailable = exports.FlystorageError = exports.errorToMessage = void 0;
|
|
4
4
|
function errorToMessage(error) {
|
|
5
5
|
return error instanceof Error ? error.message : String(error);
|
|
6
6
|
}
|
|
@@ -32,9 +32,24 @@ class ChecksumIsNotAvailable extends FlystorageError {
|
|
|
32
32
|
exports.ChecksumIsNotAvailable = ChecksumIsNotAvailable;
|
|
33
33
|
class UnableToGetChecksum extends FlystorageError {
|
|
34
34
|
code = 'flystorage.unable_to_get_checksum';
|
|
35
|
-
static because = (reason, { context = {}, cause = undefined }) => new
|
|
35
|
+
static because = (reason, { context = {}, cause = undefined }) => new UnableToGetChecksum(`Unable to write the file. Reason: ${reason}`, context, cause);
|
|
36
36
|
}
|
|
37
37
|
exports.UnableToGetChecksum = UnableToGetChecksum;
|
|
38
|
+
class UnableToGetMimeType extends FlystorageError {
|
|
39
|
+
code = 'flystorage.unable_to_get_mimetype';
|
|
40
|
+
static because = (reason, { context = {}, cause = undefined }) => new UnableToGetMimeType(`Unable to get mime-type. Reason: ${reason}`, context, cause);
|
|
41
|
+
}
|
|
42
|
+
exports.UnableToGetMimeType = UnableToGetMimeType;
|
|
43
|
+
class UnableToGetLastModified extends FlystorageError {
|
|
44
|
+
code = 'flystorage.unable_to_get_last_modified';
|
|
45
|
+
static because = (reason, { context = {}, cause = undefined }) => new UnableToGetLastModified(`Unable to get last modified. Reason: ${reason}`, context, cause);
|
|
46
|
+
}
|
|
47
|
+
exports.UnableToGetLastModified = UnableToGetLastModified;
|
|
48
|
+
class UnableToGetFileSize extends FlystorageError {
|
|
49
|
+
code = 'flystorage.unable_to_get_file_size';
|
|
50
|
+
static because = (reason, { context = {}, cause = undefined }) => new UnableToGetFileSize(`Unable to get file size. Reason: ${reason}`, context, cause);
|
|
51
|
+
}
|
|
52
|
+
exports.UnableToGetFileSize = UnableToGetFileSize;
|
|
38
53
|
class UnableToWriteFile extends FlystorageError {
|
|
39
54
|
code = 'flystorage.unable_to_write_file';
|
|
40
55
|
static because = (reason, { context = {}, cause = undefined }) => new UnableToWriteFile(`Unable to write the file. Reason: ${reason}`, context, cause);
|
package/dist/cjs/file-storage.js
CHANGED
|
@@ -177,6 +177,30 @@ class FileStorage {
|
|
|
177
177
|
throw errors.UnableToGetChecksum.because(errors.errorToMessage(error), { cause: error, context: { path, options } });
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
+
async mimeType(path, options = {}) {
|
|
181
|
+
try {
|
|
182
|
+
return await this.adapter.mimeType(this.pathNormalizer.normalizePath(path), options);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
throw errors.UnableToGetMimeType.because(errors.errorToMessage(error), { cause: error, context: { path, options } });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async lastModified(path) {
|
|
189
|
+
try {
|
|
190
|
+
return await this.adapter.lastModified(this.pathNormalizer.normalizePath(path));
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
throw errors.UnableToGetLastModified.because(errors.errorToMessage(error), { cause: error, context: { path } });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async fileSize(path) {
|
|
197
|
+
try {
|
|
198
|
+
return await this.adapter.fileSize(this.pathNormalizer.normalizePath(path));
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
throw errors.UnableToGetFileSize.because(errors.errorToMessage(error), { cause: error, context: { path } });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
180
204
|
async calculateChecksum(path, options) {
|
|
181
205
|
try {
|
|
182
206
|
return await (0, checksum_from_stream_js_1.checksumFromStream)(await this.read(path), options);
|
package/dist/esm/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnableToListDirectory = exports.UnableToCheckDirectoryExistence = exports.UnableToCheckFileExistence = exports.UnableToDeleteFile = exports.UnableToDeleteDirectory = exports.UnableToCreateDirectory = exports.UnableToGetStat = exports.UnableToGetTemporaryUrl = exports.UnableToGetPublicUrl = exports.UnableToGetVisibility = exports.UnableToSetVisibility = exports.UnableToReadFile = exports.UnableToWriteFile = exports.UnableToGetChecksum = exports.ChecksumIsNotAvailable = exports.FlystorageError = exports.errorToMessage = void 0;
|
|
3
|
+
exports.UnableToListDirectory = exports.UnableToCheckDirectoryExistence = exports.UnableToCheckFileExistence = exports.UnableToDeleteFile = exports.UnableToDeleteDirectory = exports.UnableToCreateDirectory = exports.UnableToGetStat = exports.UnableToGetTemporaryUrl = exports.UnableToGetPublicUrl = exports.UnableToGetVisibility = exports.UnableToSetVisibility = exports.UnableToReadFile = exports.UnableToWriteFile = exports.UnableToGetFileSize = exports.UnableToGetLastModified = exports.UnableToGetMimeType = exports.UnableToGetChecksum = exports.ChecksumIsNotAvailable = exports.FlystorageError = exports.errorToMessage = void 0;
|
|
4
4
|
function errorToMessage(error) {
|
|
5
5
|
return error instanceof Error ? error.message : String(error);
|
|
6
6
|
}
|
|
@@ -32,9 +32,24 @@ class ChecksumIsNotAvailable extends FlystorageError {
|
|
|
32
32
|
exports.ChecksumIsNotAvailable = ChecksumIsNotAvailable;
|
|
33
33
|
class UnableToGetChecksum extends FlystorageError {
|
|
34
34
|
code = 'flystorage.unable_to_get_checksum';
|
|
35
|
-
static because = (reason, { context = {}, cause = undefined }) => new
|
|
35
|
+
static because = (reason, { context = {}, cause = undefined }) => new UnableToGetChecksum(`Unable to write the file. Reason: ${reason}`, context, cause);
|
|
36
36
|
}
|
|
37
37
|
exports.UnableToGetChecksum = UnableToGetChecksum;
|
|
38
|
+
class UnableToGetMimeType extends FlystorageError {
|
|
39
|
+
code = 'flystorage.unable_to_get_mimetype';
|
|
40
|
+
static because = (reason, { context = {}, cause = undefined }) => new UnableToGetMimeType(`Unable to get mime-type. Reason: ${reason}`, context, cause);
|
|
41
|
+
}
|
|
42
|
+
exports.UnableToGetMimeType = UnableToGetMimeType;
|
|
43
|
+
class UnableToGetLastModified extends FlystorageError {
|
|
44
|
+
code = 'flystorage.unable_to_get_last_modified';
|
|
45
|
+
static because = (reason, { context = {}, cause = undefined }) => new UnableToGetLastModified(`Unable to get last modified. Reason: ${reason}`, context, cause);
|
|
46
|
+
}
|
|
47
|
+
exports.UnableToGetLastModified = UnableToGetLastModified;
|
|
48
|
+
class UnableToGetFileSize extends FlystorageError {
|
|
49
|
+
code = 'flystorage.unable_to_get_file_size';
|
|
50
|
+
static because = (reason, { context = {}, cause = undefined }) => new UnableToGetFileSize(`Unable to get file size. Reason: ${reason}`, context, cause);
|
|
51
|
+
}
|
|
52
|
+
exports.UnableToGetFileSize = UnableToGetFileSize;
|
|
38
53
|
class UnableToWriteFile extends FlystorageError {
|
|
39
54
|
code = 'flystorage.unable_to_write_file';
|
|
40
55
|
static because = (reason, { context = {}, cause = undefined }) => new UnableToWriteFile(`Unable to write the file. Reason: ${reason}`, context, cause);
|
package/dist/esm/file-storage.js
CHANGED
|
@@ -177,6 +177,30 @@ class FileStorage {
|
|
|
177
177
|
throw errors.UnableToGetChecksum.because(errors.errorToMessage(error), { cause: error, context: { path, options } });
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
+
async mimeType(path, options = {}) {
|
|
181
|
+
try {
|
|
182
|
+
return await this.adapter.mimeType(this.pathNormalizer.normalizePath(path), options);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
throw errors.UnableToGetMimeType.because(errors.errorToMessage(error), { cause: error, context: { path, options } });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async lastModified(path) {
|
|
189
|
+
try {
|
|
190
|
+
return await this.adapter.lastModified(this.pathNormalizer.normalizePath(path));
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
throw errors.UnableToGetLastModified.because(errors.errorToMessage(error), { cause: error, context: { path } });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async fileSize(path) {
|
|
197
|
+
try {
|
|
198
|
+
return await this.adapter.fileSize(this.pathNormalizer.normalizePath(path));
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
throw errors.UnableToGetFileSize.because(errors.errorToMessage(error), { cause: error, context: { path } });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
180
204
|
async calculateChecksum(path, options) {
|
|
181
205
|
try {
|
|
182
206
|
return await (0, checksum_from_stream_js_1.checksumFromStream)(await this.read(path), options);
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -29,7 +29,28 @@ export declare class UnableToGetChecksum extends FlystorageError {
|
|
|
29
29
|
static because: (reason: string, { context, cause }: {
|
|
30
30
|
context?: ErrorContext | undefined;
|
|
31
31
|
cause?: unknown;
|
|
32
|
-
}) =>
|
|
32
|
+
}) => UnableToGetChecksum;
|
|
33
|
+
}
|
|
34
|
+
export declare class UnableToGetMimeType extends FlystorageError {
|
|
35
|
+
readonly code = "flystorage.unable_to_get_mimetype";
|
|
36
|
+
static because: (reason: string, { context, cause }: {
|
|
37
|
+
context?: ErrorContext | undefined;
|
|
38
|
+
cause?: unknown;
|
|
39
|
+
}) => UnableToGetMimeType;
|
|
40
|
+
}
|
|
41
|
+
export declare class UnableToGetLastModified extends FlystorageError {
|
|
42
|
+
readonly code = "flystorage.unable_to_get_last_modified";
|
|
43
|
+
static because: (reason: string, { context, cause }: {
|
|
44
|
+
context?: ErrorContext | undefined;
|
|
45
|
+
cause?: unknown;
|
|
46
|
+
}) => UnableToGetLastModified;
|
|
47
|
+
}
|
|
48
|
+
export declare class UnableToGetFileSize extends FlystorageError {
|
|
49
|
+
readonly code = "flystorage.unable_to_get_file_size";
|
|
50
|
+
static because: (reason: string, { context, cause }: {
|
|
51
|
+
context?: ErrorContext | undefined;
|
|
52
|
+
cause?: unknown;
|
|
53
|
+
}) => UnableToGetFileSize;
|
|
33
54
|
}
|
|
34
55
|
export declare class UnableToWriteFile extends FlystorageError {
|
|
35
56
|
readonly code = "flystorage.unable_to_write_file";
|
|
@@ -41,6 +41,9 @@ export interface StorageAdapter {
|
|
|
41
41
|
publicUrl(path: string, options: PublicUrlOptions): Promise<string>;
|
|
42
42
|
temporaryUrl(path: string, options: TemporaryUrlOptions): Promise<string>;
|
|
43
43
|
checksum(path: string, options: ChecksumOptions): Promise<string>;
|
|
44
|
+
mimeType(path: string, options: MimeTypeOptions): Promise<string>;
|
|
45
|
+
lastModified(path: string): Promise<number>;
|
|
46
|
+
fileSize(path: string): Promise<number>;
|
|
44
47
|
}
|
|
45
48
|
export interface DirectoryListing extends AsyncIterable<StatEntry> {
|
|
46
49
|
toArray(sorted?: boolean): Promise<StatEntry[]>;
|
|
@@ -49,6 +52,10 @@ export type FileContents = Iterable<any> | AsyncIterable<any> | NodeJS.ReadableS
|
|
|
49
52
|
export type MiscellaneousOptions = {
|
|
50
53
|
[option: string]: any;
|
|
51
54
|
};
|
|
55
|
+
export type MimeTypeOptions = MiscellaneousOptions & {
|
|
56
|
+
disallowFallback?: boolean;
|
|
57
|
+
fallbackMethod?: 'contents' | 'path';
|
|
58
|
+
};
|
|
52
59
|
export type VisibilityOptions = {
|
|
53
60
|
visibility?: string;
|
|
54
61
|
directoryVisibility?: string;
|
|
@@ -94,6 +101,9 @@ export declare class FileStorage {
|
|
|
94
101
|
publicUrl(path: string, options?: PublicUrlOptions): Promise<string>;
|
|
95
102
|
temporaryUrl(path: string, options: TemporaryUrlOptions): Promise<string>;
|
|
96
103
|
checksum(path: string, options?: ChecksumOptions): Promise<string>;
|
|
104
|
+
mimeType(path: string, options?: MimeTypeOptions): Promise<string>;
|
|
105
|
+
lastModified(path: string): Promise<number>;
|
|
106
|
+
fileSize(path: string): Promise<number>;
|
|
97
107
|
private calculateChecksum;
|
|
98
108
|
}
|
|
99
109
|
export type TimestampMs = number;
|