@flystorage/file-storage 0.0.9 → 0.1.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 +19 -0
- package/README.md +11 -16
- package/dist/cjs/file-storage.js +6 -0
- package/dist/cjs/path-prefixer.js +8 -4
- package/dist/esm/file-storage.js +6 -0
- package/dist/esm/path-prefixer.js +8 -4
- package/dist/types/file-storage.d.ts +4 -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,6 +1,6 @@
|
|
|
1
|
-
<img src="https://
|
|
1
|
+
<img src="https://raw.githubusercontent.com/duna-oss/flystorage/main/flystorage.svg" width="50px" height="50px" />
|
|
2
2
|
|
|
3
|
-
# Flystorage
|
|
3
|
+
# Flystorage
|
|
4
4
|
Flystorage is a file storage abstraction for NodeJS and TypeScript. It is an 80/20 solution
|
|
5
5
|
that is built around a set of goals:
|
|
6
6
|
|
|
@@ -39,18 +39,14 @@ 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)
|
|
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/file-storage)
|
|
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)
|
|
46
48
|
|
|
47
49
|
### Planned
|
|
48
|
-
|
|
49
|
-
#### Prio 1
|
|
50
|
-
- [ ] Failure decorator (stage errors for tests)
|
|
51
|
-
- [ ] Google Cloud Storage
|
|
52
|
-
|
|
53
|
-
### Prio 2
|
|
54
50
|
- [ ] FTP (using `basic-ftp`)
|
|
55
51
|
- [ ] SFTP (?)
|
|
56
52
|
|
|
@@ -72,7 +68,7 @@ npm i -S @flystorage/local-fs
|
|
|
72
68
|
import {resolve} from 'node:path';
|
|
73
69
|
import {createReadStream} from 'node:fs';
|
|
74
70
|
import {FileStorage, Visibility} from '@flystorage/file-storage';
|
|
75
|
-
import {
|
|
71
|
+
import {LocalStorageAdapter} from '@flystorage/local-fs';
|
|
76
72
|
|
|
77
73
|
/**
|
|
78
74
|
* SETUP
|
|
@@ -122,6 +118,5 @@ await storage.deleteDirectory('some-directory');
|
|
|
122
118
|
|
|
123
119
|
## Author
|
|
124
120
|
Flystorage is built by the maintainer of [Flysystem](https://flysystem.thephpleague.com), a
|
|
125
|
-
filesystem abstraction for PHP. This brings along
|
|
126
|
-
a decade of
|
|
127
|
-
and weighing trade-offs to make a usable API.
|
|
121
|
+
filesystem abstraction for PHP. This brings along over
|
|
122
|
+
a decade of filesystem abstraction experience.
|
package/dist/cjs/file-storage.js
CHANGED
|
@@ -149,7 +149,13 @@ class FileStorage {
|
|
|
149
149
|
throw errors.UnableToCopyFile.because(errors.errorToMessage(error), { cause: error, context: { from, to } });
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* @deprecated use changeVisibility instead
|
|
154
|
+
*/
|
|
152
155
|
async setVisibility(path, visibility) {
|
|
156
|
+
return this.changeVisibility(path, visibility);
|
|
157
|
+
}
|
|
158
|
+
async changeVisibility(path, visibility) {
|
|
153
159
|
try {
|
|
154
160
|
return await this.adapter.changeVisibility(this.pathNormalizer.normalizePath(path), visibility);
|
|
155
161
|
}
|
|
@@ -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);
|
package/dist/esm/file-storage.js
CHANGED
|
@@ -142,7 +142,13 @@ export class FileStorage {
|
|
|
142
142
|
throw errors.UnableToCopyFile.because(errors.errorToMessage(error), { cause: error, context: { from, to } });
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated use changeVisibility instead
|
|
147
|
+
*/
|
|
145
148
|
async setVisibility(path, visibility) {
|
|
149
|
+
return this.changeVisibility(path, visibility);
|
|
150
|
+
}
|
|
151
|
+
async changeVisibility(path, visibility) {
|
|
146
152
|
try {
|
|
147
153
|
return await this.adapter.changeVisibility(this.pathNormalizer.normalizePath(path), visibility);
|
|
148
154
|
}
|
|
@@ -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);
|
|
@@ -118,7 +118,11 @@ export declare class FileStorage {
|
|
|
118
118
|
stat(path: string): Promise<StatEntry>;
|
|
119
119
|
moveFile(from: string, to: string, options?: MoveFileOptions): Promise<void>;
|
|
120
120
|
copyFile(from: string, to: string, options?: CopyFileOptions): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated use changeVisibility instead
|
|
123
|
+
*/
|
|
121
124
|
setVisibility(path: string, visibility: string): Promise<void>;
|
|
125
|
+
changeVisibility(path: string, visibility: string): Promise<void>;
|
|
122
126
|
visibility(path: string): Promise<string>;
|
|
123
127
|
fileExists(path: string): Promise<boolean>;
|
|
124
128
|
list(path: string, { deep }?: ListOptions): DirectoryListing;
|
|
@@ -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