@maestro-js/file-storage 1.0.0-alpha.1 → 1.0.0-alpha.11
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/index.d.ts +14 -8
- package/dist/index.js +15 -7
- package/package.json +8 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Iso } from 'iso-fns2';
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
3
|
import { ReadableStream } from 'node:stream/web';
|
|
4
|
-
import { File } from 'node:buffer';
|
|
5
4
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
6
5
|
|
|
7
6
|
interface Driver<TemporaryUrlParams> {
|
|
@@ -31,8 +30,9 @@ interface Driver<TemporaryUrlParams> {
|
|
|
31
30
|
removeDirectory(directory: string): Promise<void>;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
declare function createLocalDriver<TemporaryUrlParams>({ pathPrefix, buildTemporaryUrlsUsing }: {
|
|
33
|
+
declare function createLocalDriver<TemporaryUrlParams>({ pathPrefix, urlPrefix, buildTemporaryUrlsUsing }: {
|
|
35
34
|
pathPrefix?: string;
|
|
35
|
+
urlPrefix?: string;
|
|
36
36
|
buildTemporaryUrlsUsing?(path: string, expiration: Iso.Instant, params?: TemporaryUrlParams): string | Promise<string>;
|
|
37
37
|
}): Driver<TemporaryUrlParams>;
|
|
38
38
|
|
|
@@ -43,6 +43,12 @@ declare function createS3Driver({ client, bucket, prefix, url: baseUrl }: {
|
|
|
43
43
|
url?: string;
|
|
44
44
|
}): Driver<void>;
|
|
45
45
|
|
|
46
|
+
interface FileInput {
|
|
47
|
+
name: string;
|
|
48
|
+
type: string;
|
|
49
|
+
stream(): ReadableStream | globalThis.ReadableStream;
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
declare function create(config: FileStorage.Provider.FileStorageServiceConfig): FileStorage.FileStorageService;
|
|
47
53
|
type KeysWithFallback = keyof FileStorage.Provider.Keys extends never ? {
|
|
48
54
|
default: unknown;
|
|
@@ -69,8 +75,8 @@ declare function provider(key: FileStorage.Provider.Key): {
|
|
|
69
75
|
append: (path: string, contents: string | Buffer | Readable | ReadableStream) => Promise<void>;
|
|
70
76
|
copy: (source: string, destination: string) => Promise<void>;
|
|
71
77
|
move: (source: string, destination: string) => Promise<void>;
|
|
72
|
-
putFileAs: (dir: string, file:
|
|
73
|
-
putFile: (dir: string, file:
|
|
78
|
+
putFileAs: (dir: string, file: FileInput, filename: string) => Promise<string>;
|
|
79
|
+
putFile: (dir: string, file: FileInput) => Promise<string>;
|
|
74
80
|
remove: (...paths: string[]) => Promise<void>;
|
|
75
81
|
files: (directory: string) => Promise<string[]>;
|
|
76
82
|
allFiles: (directory: string) => Promise<string[]>;
|
|
@@ -106,8 +112,8 @@ declare const FileStorage: {
|
|
|
106
112
|
append: (path: string, contents: string | Buffer | Readable | ReadableStream) => Promise<void>;
|
|
107
113
|
copy: (source: string, destination: string) => Promise<void>;
|
|
108
114
|
move: (source: string, destination: string) => Promise<void>;
|
|
109
|
-
putFileAs: (dir: string, file:
|
|
110
|
-
putFile: (dir: string, file:
|
|
115
|
+
putFileAs: (dir: string, file: FileInput, filename: string) => Promise<string>;
|
|
116
|
+
putFile: (dir: string, file: FileInput) => Promise<string>;
|
|
111
117
|
remove: (...paths: string[]) => Promise<void>;
|
|
112
118
|
files: (directory: string) => Promise<string[]>;
|
|
113
119
|
allFiles: (directory: string) => Promise<string[]>;
|
|
@@ -144,8 +150,8 @@ declare namespace FileStorage {
|
|
|
144
150
|
append(path: string, contents: string | Buffer | Readable | ReadableStream): Promise<void>;
|
|
145
151
|
copy(source: string, destination: string): Promise<void>;
|
|
146
152
|
move(source: string, destination: string): Promise<void>;
|
|
147
|
-
putFileAs(dir: string, file:
|
|
148
|
-
putFile(dir: string, file:
|
|
153
|
+
putFileAs(dir: string, file: FileInput, filename: string): Promise<string>;
|
|
154
|
+
putFile(dir: string, file: FileInput): Promise<string>;
|
|
149
155
|
remove(...paths: string[]): Promise<void>;
|
|
150
156
|
files(directory: string): Promise<string[]>;
|
|
151
157
|
allFiles(directory: string): Promise<string[]>;
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,6 @@ import "stream";
|
|
|
9
9
|
import "stream/web";
|
|
10
10
|
|
|
11
11
|
// src/index.ts
|
|
12
|
-
import "buffer";
|
|
13
12
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
14
13
|
import mimeTypes from "mime-types";
|
|
15
14
|
|
|
@@ -73,6 +72,7 @@ import stream from "stream";
|
|
|
73
72
|
import { lookup } from "mime-types";
|
|
74
73
|
function createLocalDriver({
|
|
75
74
|
pathPrefix = "storage",
|
|
75
|
+
urlPrefix = "/files",
|
|
76
76
|
buildTemporaryUrlsUsing
|
|
77
77
|
}) {
|
|
78
78
|
return {
|
|
@@ -88,7 +88,7 @@ function createLocalDriver({
|
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
90
|
url(path) {
|
|
91
|
-
return
|
|
91
|
+
return `${urlPrefix}/${path}`;
|
|
92
92
|
},
|
|
93
93
|
async temporaryUrl(path, expiration, params) {
|
|
94
94
|
if (buildTemporaryUrlsUsing) {
|
|
@@ -115,24 +115,32 @@ function createLocalDriver({
|
|
|
115
115
|
return nodePath.resolve(nodePath.join(pathPrefix, path));
|
|
116
116
|
},
|
|
117
117
|
async put(path, contents) {
|
|
118
|
-
|
|
118
|
+
const fullPath = nodePath.join(pathPrefix, path);
|
|
119
|
+
await fs.mkdir(nodePath.dirname(fullPath), { recursive: true });
|
|
120
|
+
await fs.writeFile(fullPath, contents);
|
|
119
121
|
},
|
|
120
122
|
async prepend(path, contents) {
|
|
121
123
|
await prepend(nodePath.join(pathPrefix, path), contents);
|
|
122
124
|
},
|
|
123
125
|
async append(path, contents) {
|
|
126
|
+
const fullPath = nodePath.join(pathPrefix, path);
|
|
127
|
+
await fs.mkdir(nodePath.dirname(fullPath), { recursive: true });
|
|
124
128
|
if (Buffer.isBuffer(contents) || typeof contents == "string") {
|
|
125
|
-
await fs.appendFile(
|
|
129
|
+
await fs.appendFile(fullPath, contents);
|
|
126
130
|
} else {
|
|
127
|
-
const writeStream2 = createWriteStream(
|
|
131
|
+
const writeStream2 = createWriteStream(fullPath, { flags: "a" });
|
|
128
132
|
await promiseStream.pipeline(contents, writeStream2);
|
|
129
133
|
}
|
|
130
134
|
},
|
|
131
135
|
async copy(source, destination) {
|
|
132
|
-
|
|
136
|
+
const destPath = nodePath.join(pathPrefix, destination);
|
|
137
|
+
await fs.mkdir(nodePath.dirname(destPath), { recursive: true });
|
|
138
|
+
await fs.copyFile(nodePath.join(pathPrefix, source), destPath);
|
|
133
139
|
},
|
|
134
140
|
async move(source, destination) {
|
|
135
|
-
|
|
141
|
+
const destPath = nodePath.join(pathPrefix, destination);
|
|
142
|
+
await fs.mkdir(nodePath.dirname(destPath), { recursive: true });
|
|
143
|
+
await fs.rename(nodePath.join(pathPrefix, source), destPath);
|
|
136
144
|
},
|
|
137
145
|
async remove(...paths) {
|
|
138
146
|
await Promise.all(paths.map((p) => fs.rm(nodePath.join(pathPrefix, p))));
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"default": "./dist/index.js"
|
|
8
8
|
}
|
|
9
9
|
},
|
|
10
|
-
"version": "1.0.0-alpha.
|
|
10
|
+
"version": "1.0.0-alpha.11",
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "restricted"
|
|
13
13
|
},
|
|
@@ -15,14 +15,17 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@aws-sdk/client-s3": "^3.750.0",
|
|
19
|
-
"@aws-sdk/s3-request-presigner": "^3.750.0",
|
|
20
18
|
"iso-fns2": "npm:iso-fns@2.0.0-alpha.26",
|
|
21
19
|
"mime-types": "^2.1.35",
|
|
22
|
-
"@maestro-js/service-registry": "1.0.0-alpha.
|
|
23
|
-
|
|
20
|
+
"@maestro-js/service-registry": "1.0.0-alpha.11"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@aws-sdk/client-s3": "^3.750.0",
|
|
24
|
+
"@aws-sdk/s3-request-presigner": "^3.750.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
27
|
+
"@aws-sdk/client-s3": "^3.750.0",
|
|
28
|
+
"@aws-sdk/s3-request-presigner": "^3.750.0",
|
|
26
29
|
"@types/node": "^22.19.11",
|
|
27
30
|
"@types/mime-types": "^2.1.4"
|
|
28
31
|
},
|