@flystorage/file-storage 0.1.0 → 0.1.2
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 +19 -0
- package/README.md +8 -8
- package/dist/cjs/path-prefixer.js +8 -4
- package/dist/esm/path-prefixer.js +8 -4
- package/dist/types/errors.d.ts +21 -21
- package/dist/types/file-storage.d.ts +1 -0
- package/dist/types/path-prefixer.d.ts +5 -1
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2023-2024 Frank de Jonge
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is furnished
|
|
8
|
+
to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<img src="https://
|
|
1
|
+
<img src="https://raw.githubusercontent.com/duna-oss/flystorage/main/flystorage.svg" width="50px" height="50px" />
|
|
2
2
|
|
|
3
3
|
# Flystorage
|
|
4
4
|
Flystorage is a file storage abstraction for NodeJS and TypeScript. It is an 80/20 solution
|
|
@@ -39,12 +39,12 @@ to, simply because they cannot be abstracted over in a reasonable manner.
|
|
|
39
39
|
## Implementations / Adapters
|
|
40
40
|
|
|
41
41
|
### Implemented
|
|
42
|
-
- [x] Local Filesystem
|
|
43
|
-
- [x] AWS S3 (using the V3 SDK)
|
|
44
|
-
- [x] Azure Blob Storage
|
|
45
|
-
- [x] Test implementation (in-memory)
|
|
46
|
-
- [x] Google Cloud Storage
|
|
47
|
-
- [x] Chaos adapter decorator
|
|
42
|
+
- [x] [Local Filesystem](https://www.npmjs.com/package/@flystorage/local-fs)
|
|
43
|
+
- [x] [AWS S3 (using the V3 SDK)](https://www.npmjs.com/package/@flystorage/aws-s3)
|
|
44
|
+
- [x] [Azure Blob Storage](https://www.npmjs.com/package/@flystorage/azure-storage-blob)
|
|
45
|
+
- [x] [Test implementation (in-memory)](https://www.npmjs.com/package/@flystorage/in-memory)
|
|
46
|
+
- [x] [Google Cloud Storage](https://www.npmjs.com/package/@flystorage/google-cloud-storage)
|
|
47
|
+
- [x] [Chaos adapter decorator](https://www.npmjs.com/package/@flystorage/chaos)
|
|
48
48
|
|
|
49
49
|
### Planned
|
|
50
50
|
- [ ] FTP (using `basic-ftp`)
|
|
@@ -75,7 +75,7 @@ import {LocalStorageAdapter} from '@flystorage/local-fs';
|
|
|
75
75
|
**/
|
|
76
76
|
|
|
77
77
|
const rootDirectory = resolve(process.cwd(), 'my-files');
|
|
78
|
-
const storage = new FileStorage(new
|
|
78
|
+
const storage = new FileStorage(new LocalStorageAdapter(rootDirectory));
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* USAGE
|
|
@@ -3,17 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PathPrefixer = void 0;
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
5
|
class PathPrefixer {
|
|
6
|
+
separator;
|
|
7
|
+
joinFunc;
|
|
6
8
|
prefix = '';
|
|
7
|
-
constructor(prefix = '') {
|
|
9
|
+
constructor(prefix = '', separator = '/', joinFunc = node_path_1.join) {
|
|
10
|
+
this.separator = separator;
|
|
11
|
+
this.joinFunc = joinFunc;
|
|
8
12
|
if (prefix.length > 0) {
|
|
9
|
-
this.prefix =
|
|
13
|
+
this.prefix = this.joinFunc(prefix, this.separator);
|
|
10
14
|
}
|
|
11
15
|
}
|
|
12
16
|
prefixFilePath(path) {
|
|
13
|
-
return this.prefix.length > 0 ?
|
|
17
|
+
return this.prefix.length > 0 ? this.joinFunc(this.prefix, path) : path;
|
|
14
18
|
}
|
|
15
19
|
prefixDirectoryPath(path) {
|
|
16
|
-
return this.prefix.length > 0 ?
|
|
20
|
+
return this.prefix.length > 0 ? this.joinFunc(this.prefix, path, '/') : this.joinFunc(path, '/');
|
|
17
21
|
}
|
|
18
22
|
stripFilePath(path) {
|
|
19
23
|
return path.substring(this.prefix.length);
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
export class PathPrefixer {
|
|
3
|
+
separator;
|
|
4
|
+
joinFunc;
|
|
3
5
|
prefix = '';
|
|
4
|
-
constructor(prefix = '') {
|
|
6
|
+
constructor(prefix = '', separator = '/', joinFunc = join) {
|
|
7
|
+
this.separator = separator;
|
|
8
|
+
this.joinFunc = joinFunc;
|
|
5
9
|
if (prefix.length > 0) {
|
|
6
|
-
this.prefix =
|
|
10
|
+
this.prefix = this.joinFunc(prefix, this.separator);
|
|
7
11
|
}
|
|
8
12
|
}
|
|
9
13
|
prefixFilePath(path) {
|
|
10
|
-
return this.prefix.length > 0 ?
|
|
14
|
+
return this.prefix.length > 0 ? this.joinFunc(this.prefix, path) : path;
|
|
11
15
|
}
|
|
12
16
|
prefixDirectoryPath(path) {
|
|
13
|
-
return this.prefix.length > 0 ?
|
|
17
|
+
return this.prefix.length > 0 ? this.joinFunc(this.prefix, path, '/') : this.joinFunc(path, '/');
|
|
14
18
|
}
|
|
15
19
|
stripFilePath(path) {
|
|
16
20
|
return path.substring(this.prefix.length);
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -20,144 +20,144 @@ export declare class ChecksumIsNotAvailable extends FlystorageError {
|
|
|
20
20
|
readonly code = "flystorage.checksum_not_supported";
|
|
21
21
|
constructor(message: string, algo: string, context?: ErrorContext, cause?: unknown);
|
|
22
22
|
static checksumNotSupported: (algo: string, { context, cause }?: {
|
|
23
|
-
context?: ErrorContext
|
|
23
|
+
context?: ErrorContext;
|
|
24
24
|
cause?: unknown;
|
|
25
25
|
}) => ChecksumIsNotAvailable;
|
|
26
26
|
}
|
|
27
27
|
export declare class UnableToGetChecksum extends FlystorageError {
|
|
28
28
|
readonly code = "flystorage.unable_to_get_checksum";
|
|
29
29
|
static because: (reason: string, { context, cause }: {
|
|
30
|
-
context?: ErrorContext
|
|
30
|
+
context?: ErrorContext;
|
|
31
31
|
cause?: unknown;
|
|
32
32
|
}) => UnableToGetChecksum;
|
|
33
33
|
}
|
|
34
34
|
export declare class UnableToGetMimeType extends FlystorageError {
|
|
35
35
|
readonly code = "flystorage.unable_to_get_mimetype";
|
|
36
36
|
static because: (reason: string, { context, cause }: {
|
|
37
|
-
context?: ErrorContext
|
|
37
|
+
context?: ErrorContext;
|
|
38
38
|
cause?: unknown;
|
|
39
39
|
}) => UnableToGetMimeType;
|
|
40
40
|
}
|
|
41
41
|
export declare class UnableToGetLastModified extends FlystorageError {
|
|
42
42
|
readonly code = "flystorage.unable_to_get_last_modified";
|
|
43
43
|
static because: (reason: string, { context, cause }: {
|
|
44
|
-
context?: ErrorContext
|
|
44
|
+
context?: ErrorContext;
|
|
45
45
|
cause?: unknown;
|
|
46
46
|
}) => UnableToGetLastModified;
|
|
47
47
|
}
|
|
48
48
|
export declare class UnableToGetFileSize extends FlystorageError {
|
|
49
49
|
readonly code = "flystorage.unable_to_get_file_size";
|
|
50
50
|
static because: (reason: string, { context, cause }: {
|
|
51
|
-
context?: ErrorContext
|
|
51
|
+
context?: ErrorContext;
|
|
52
52
|
cause?: unknown;
|
|
53
53
|
}) => UnableToGetFileSize;
|
|
54
54
|
}
|
|
55
55
|
export declare class UnableToWriteFile extends FlystorageError {
|
|
56
56
|
readonly code = "flystorage.unable_to_write_file";
|
|
57
57
|
static because: (reason: string, { context, cause }: {
|
|
58
|
-
context?: ErrorContext
|
|
58
|
+
context?: ErrorContext;
|
|
59
59
|
cause?: unknown;
|
|
60
60
|
}) => UnableToWriteFile;
|
|
61
61
|
}
|
|
62
62
|
export declare class UnableToReadFile extends FlystorageError {
|
|
63
63
|
readonly code = "flystorage.unable_to_read_file";
|
|
64
64
|
static because: (reason: string, { context, cause }: {
|
|
65
|
-
context?: ErrorContext
|
|
65
|
+
context?: ErrorContext;
|
|
66
66
|
cause?: unknown;
|
|
67
67
|
}) => UnableToReadFile;
|
|
68
68
|
}
|
|
69
69
|
export declare class UnableToSetVisibility extends FlystorageError {
|
|
70
70
|
readonly code = "flystorage.unable_to_set_visibility";
|
|
71
71
|
static because: (reason: string, { context, cause }: {
|
|
72
|
-
context?: ErrorContext
|
|
72
|
+
context?: ErrorContext;
|
|
73
73
|
cause?: unknown;
|
|
74
74
|
}) => UnableToSetVisibility;
|
|
75
75
|
}
|
|
76
76
|
export declare class UnableToGetVisibility extends FlystorageError {
|
|
77
77
|
readonly code = "flystorage.unable_to_get_visibility";
|
|
78
78
|
static because: (reason: string, { context, cause }: {
|
|
79
|
-
context?: ErrorContext
|
|
79
|
+
context?: ErrorContext;
|
|
80
80
|
cause?: unknown;
|
|
81
81
|
}) => UnableToGetVisibility;
|
|
82
82
|
}
|
|
83
83
|
export declare class UnableToGetPublicUrl extends FlystorageError {
|
|
84
84
|
readonly code = "flystorage.unable_to_get_public_url";
|
|
85
85
|
static because: (reason: string, { context, cause }: {
|
|
86
|
-
context?: ErrorContext
|
|
86
|
+
context?: ErrorContext;
|
|
87
87
|
cause?: unknown;
|
|
88
88
|
}) => UnableToGetPublicUrl;
|
|
89
89
|
}
|
|
90
90
|
export declare class UnableToGetTemporaryUrl extends FlystorageError {
|
|
91
91
|
readonly code = "flystorage.unable_to_get_temporary_url";
|
|
92
92
|
static because: (reason: string, { context, cause }: {
|
|
93
|
-
context?: ErrorContext
|
|
93
|
+
context?: ErrorContext;
|
|
94
94
|
cause?: unknown;
|
|
95
95
|
}) => UnableToGetTemporaryUrl;
|
|
96
96
|
}
|
|
97
97
|
export declare class UnableToCopyFile extends FlystorageError {
|
|
98
98
|
readonly code = "flystorage.unable_to_copy_file";
|
|
99
99
|
static because: (reason: string, { context, cause }: {
|
|
100
|
-
context?: ErrorContext
|
|
100
|
+
context?: ErrorContext;
|
|
101
101
|
cause?: unknown;
|
|
102
102
|
}) => UnableToCopyFile;
|
|
103
103
|
}
|
|
104
104
|
export declare class UnableToMoveFile extends FlystorageError {
|
|
105
105
|
readonly code = "flystorage.unable_to_move_file";
|
|
106
106
|
static because: (reason: string, { context, cause }: {
|
|
107
|
-
context?: ErrorContext
|
|
107
|
+
context?: ErrorContext;
|
|
108
108
|
cause?: unknown;
|
|
109
109
|
}) => UnableToMoveFile;
|
|
110
110
|
}
|
|
111
111
|
export declare class UnableToGetStat extends FlystorageError {
|
|
112
112
|
readonly code = "flystorage.unable_to_get_stat";
|
|
113
113
|
static because: (reason: string, { context, cause }: {
|
|
114
|
-
context?: ErrorContext
|
|
114
|
+
context?: ErrorContext;
|
|
115
115
|
cause?: unknown;
|
|
116
116
|
}) => UnableToGetStat;
|
|
117
117
|
static noFileStatResolved: ({ context, cause }: {
|
|
118
|
-
context?: ErrorContext
|
|
118
|
+
context?: ErrorContext;
|
|
119
119
|
cause?: unknown;
|
|
120
120
|
}) => UnableToGetStat;
|
|
121
121
|
}
|
|
122
122
|
export declare class UnableToCreateDirectory extends FlystorageError {
|
|
123
123
|
readonly code = "flystorage.unable_to_create_directory";
|
|
124
124
|
static because: (reason: string, { context, cause }: {
|
|
125
|
-
context?: ErrorContext
|
|
125
|
+
context?: ErrorContext;
|
|
126
126
|
cause?: unknown;
|
|
127
127
|
}) => UnableToCreateDirectory;
|
|
128
128
|
}
|
|
129
129
|
export declare class UnableToDeleteDirectory extends FlystorageError {
|
|
130
130
|
readonly code = "flystorage.unable_to_delete_directory";
|
|
131
131
|
static because: (reason: string, { context, cause }: {
|
|
132
|
-
context?: ErrorContext
|
|
132
|
+
context?: ErrorContext;
|
|
133
133
|
cause?: unknown;
|
|
134
134
|
}) => UnableToDeleteDirectory;
|
|
135
135
|
}
|
|
136
136
|
export declare class UnableToDeleteFile extends FlystorageError {
|
|
137
137
|
readonly code = "flystorage.unable_to_delete_file";
|
|
138
138
|
static because: (reason: string, { context, cause }: {
|
|
139
|
-
context?: ErrorContext
|
|
139
|
+
context?: ErrorContext;
|
|
140
140
|
cause?: unknown;
|
|
141
141
|
}) => UnableToDeleteFile;
|
|
142
142
|
}
|
|
143
143
|
export declare class UnableToCheckFileExistence extends FlystorageError {
|
|
144
144
|
readonly code = "flystorage.unable_to_check_file_existence";
|
|
145
145
|
static because: (reason: string, { context, cause }: {
|
|
146
|
-
context?: ErrorContext
|
|
146
|
+
context?: ErrorContext;
|
|
147
147
|
cause?: unknown;
|
|
148
148
|
}) => UnableToCheckFileExistence;
|
|
149
149
|
}
|
|
150
150
|
export declare class UnableToCheckDirectoryExistence extends FlystorageError {
|
|
151
151
|
readonly code = "flystorage.unable_to_check_directory_existence";
|
|
152
152
|
static because: (reason: string, { context, cause }: {
|
|
153
|
-
context?: ErrorContext
|
|
153
|
+
context?: ErrorContext;
|
|
154
154
|
cause?: unknown;
|
|
155
155
|
}) => UnableToCheckDirectoryExistence;
|
|
156
156
|
}
|
|
157
157
|
export declare class UnableToListDirectory extends FlystorageError {
|
|
158
158
|
readonly code = "flystorage.unable_to_list_directory_contents";
|
|
159
159
|
static because: (reason: string, { context, cause }: {
|
|
160
|
-
context?: ErrorContext
|
|
160
|
+
context?: ErrorContext;
|
|
161
161
|
cause?: unknown;
|
|
162
162
|
}) => UnableToListDirectory;
|
|
163
163
|
}
|
|
@@ -72,6 +72,7 @@ export type VisibilityOptions = {
|
|
|
72
72
|
export type WriteOptions = VisibilityOptions & MiscellaneousOptions & {
|
|
73
73
|
mimeType?: string;
|
|
74
74
|
size?: number;
|
|
75
|
+
cacheControl?: string;
|
|
75
76
|
};
|
|
76
77
|
export type CreateDirectoryOptions = MiscellaneousOptions & Pick<VisibilityOptions, 'directoryVisibility'> & {};
|
|
77
78
|
export type PublicUrlOptions = MiscellaneousOptions & {};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { join } from 'node:path';
|
|
1
3
|
export declare class PathPrefixer {
|
|
4
|
+
private readonly separator;
|
|
5
|
+
private readonly joinFunc;
|
|
2
6
|
private readonly prefix;
|
|
3
|
-
constructor(prefix?: string);
|
|
7
|
+
constructor(prefix?: string, separator?: string, joinFunc?: typeof join);
|
|
4
8
|
prefixFilePath(path: string): string;
|
|
5
9
|
prefixDirectoryPath(path: string): string;
|
|
6
10
|
stripFilePath(path: string): string;
|
package/package.json
CHANGED