@stacksjs/storage 0.70.87 → 0.70.90

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/delete.js ADDED
@@ -0,0 +1,103 @@
1
+ import { italic, log } from "@stacksjs/cli";
2
+ import { err, handleError, ok } from "@stacksjs/error-handling";
3
+ import { join } from "@stacksjs/path";
4
+ import { isFolder } from "./folders";
5
+ import { fs } from "./fs";
6
+ import { glob } from "./glob";
7
+ export function deleteFolder(path) {
8
+ return new Promise((resolve, reject) => {
9
+ try {
10
+ if (isFolder(path)) {
11
+ fs.rmSync(path, { recursive: !0, force: !0 });
12
+ return resolve(ok(`Deleted ${path}`));
13
+ }
14
+ return resolve(ok(`Path ${path} was not a directory`));
15
+ } catch (error) {
16
+ return reject(err(error));
17
+ }
18
+ });
19
+ }
20
+ export async function isDirectoryEmpty(path) {
21
+ return new Promise((resolve, reject) => {
22
+ try {
23
+ if (fs.statSync(path).isDirectory()) {
24
+ if (fs.readdirSync(path).length === 0)
25
+ return resolve(ok(!0));
26
+ return resolve(ok(!1));
27
+ }
28
+ return resolve(ok(!1));
29
+ } catch (error) {
30
+ return reject(err(error));
31
+ }
32
+ });
33
+ }
34
+ export async function deleteEmptyFolder(path) {
35
+ return new Promise((resolve, reject) => {
36
+ try {
37
+ if (fs.statSync(path).isDirectory()) {
38
+ if (fs.readdirSync(path).length === 0) {
39
+ fs.rmSync(path, { recursive: !0, force: !0 });
40
+ return resolve(ok(`Deleted ${path}`));
41
+ }
42
+ return resolve(ok(`Path ${path} was not empty`));
43
+ }
44
+ return resolve(ok(`Path ${path} was not a directory`));
45
+ } catch (error) {
46
+ return reject(err(error));
47
+ }
48
+ });
49
+ }
50
+ export async function deleteEmptyFolders(dir) {
51
+ try {
52
+ if (!fs.existsSync(dir))
53
+ return ok(`Path ${dir} does not exist`);
54
+ const files = fs.readdirSync(dir);
55
+ for (const file of files) {
56
+ const p = join(dir, file);
57
+ if (isFolder(p))
58
+ if (fs.readdirSync(p).length === 0)
59
+ fs.rmSync(p, { recursive: !0, force: !0 });
60
+ else
61
+ await deleteEmptyFolders(p);
62
+ }
63
+ return ok(`Deleted empty folders located in ${dir}`);
64
+ } catch (error) {
65
+ return err(error);
66
+ }
67
+ }
68
+ export function deleteFile(path) {
69
+ return new Promise((resolve, reject) => {
70
+ try {
71
+ if (fs.statSync(path).isFile()) {
72
+ fs.rmSync(path, { recursive: !0, force: !0 });
73
+ return resolve(ok(`Deleted ${path}`));
74
+ }
75
+ return resolve(ok(`Path ${path} was not a file`));
76
+ } catch (error) {
77
+ return reject(err(error));
78
+ }
79
+ });
80
+ }
81
+ export async function deleteGlob(path) {
82
+ if (!path.includes("*"))
83
+ return err(handleError(`Path ${path} does not contain a glob`));
84
+ const directories = await glob([path], { onlyDirectories: !0 });
85
+ for (const directory of directories) {
86
+ const result = await deleteFolder(directory);
87
+ if (result.isErr) {
88
+ log.error(result.error);
89
+ return result;
90
+ }
91
+ log.info(`Deleted ${italic(directory)}`);
92
+ }
93
+ return ok(`Deleted ${directories.length} directories`);
94
+ }
95
+ export async function del(path) {
96
+ if (fs.existsSync(path) && fs.statSync(path).isFile())
97
+ return await deleteFile(path);
98
+ if (isFolder(path))
99
+ return await deleteFolder(path);
100
+ if (path.includes("*"))
101
+ return await deleteGlob(path);
102
+ return err(handleError(`Path ${path} cannot be deleted due to an unhandled condition. Please report this issue.`));
103
+ }
@@ -0,0 +1,94 @@
1
+ import { createS3Storage } from "../adapters/s3";
2
+ let _adapterPromise = null;
3
+ async function loadConfig() {
4
+ try {
5
+ const { filesystems } = await import("@stacksjs/config"), s3Config = filesystems.s3;
6
+ return createS3Storage(null, {
7
+ bucket: s3Config?.bucket || "stacks",
8
+ prefix: s3Config?.prefix || "stx",
9
+ region: s3Config?.region || "us-east-1"
10
+ });
11
+ } catch {
12
+ const { env } = await import("@stacksjs/env");
13
+ return createS3Storage(null, {
14
+ bucket: env.AWS_S3_BUCKET || "stacks",
15
+ prefix: env.AWS_S3_PREFIX || "stx",
16
+ region: env.AWS_REGION || "us-east-1"
17
+ });
18
+ }
19
+ }
20
+ async function getAdapter() {
21
+ if (!_adapterPromise)
22
+ _adapterPromise = loadConfig();
23
+ return _adapterPromise;
24
+ }
25
+ export async function getAwsStorage() {
26
+ return getAdapter();
27
+ }
28
+ export const aws = {
29
+ async write(path, contents) {
30
+ await (await getAdapter()).write(path, contents);
31
+ },
32
+ async deleteFile(path) {
33
+ await (await getAdapter()).deleteFile(path);
34
+ },
35
+ async createDirectory(path) {
36
+ await (await getAdapter()).createDirectory(path);
37
+ },
38
+ async moveFile(from, to) {
39
+ await (await getAdapter()).moveFile(from, to);
40
+ },
41
+ async copyFile(from, to) {
42
+ await (await getAdapter()).copyFile(from, to);
43
+ },
44
+ async stat(path) {
45
+ return await (await getAdapter()).stat(path);
46
+ },
47
+ list(path, options = { deep: !1 }) {
48
+ return async function* () {
49
+ yield* (await getAdapter()).list(path, options);
50
+ }();
51
+ },
52
+ async changeVisibility(path, visibility) {
53
+ await (await getAdapter()).changeVisibility(path, visibility);
54
+ },
55
+ async visibility(path) {
56
+ return await (await getAdapter()).visibility(path);
57
+ },
58
+ async fileExists(path) {
59
+ return await (await getAdapter()).fileExists(path);
60
+ },
61
+ async directoryExists(path) {
62
+ return await (await getAdapter()).directoryExists(path);
63
+ },
64
+ async publicUrl(path, options) {
65
+ return await (await getAdapter()).publicUrl(path, options);
66
+ },
67
+ async temporaryUrl(path, options) {
68
+ return await (await getAdapter()).temporaryUrl(path, options);
69
+ },
70
+ async checksum(path, options) {
71
+ return await (await getAdapter()).checksum(path, options);
72
+ },
73
+ async mimeType(path, options) {
74
+ return await (await getAdapter()).mimeType(path, options);
75
+ },
76
+ async lastModified(path) {
77
+ return await (await getAdapter()).lastModified(path);
78
+ },
79
+ async fileSize(path) {
80
+ return await (await getAdapter()).fileSize(path);
81
+ },
82
+ async read(path) {
83
+ return await (await getAdapter()).read(path);
84
+ },
85
+ async readToString(path) {
86
+ return await (await getAdapter()).readToString(path);
87
+ },
88
+ async readToBuffer(path) {
89
+ return await (await getAdapter()).readToBuffer(path);
90
+ },
91
+ async readToUint8Array(path) {
92
+ return await (await getAdapter()).readToUint8Array(path);
93
+ }
94
+ };
@@ -0,0 +1,88 @@
1
+ import { resolve } from "node:path";
2
+ import process from "node:process";
3
+ import { createBunStorage } from "../adapters/bun";
4
+ let _adapterPromise = null;
5
+ async function loadConfig() {
6
+ try {
7
+ const { filesystems } = await import("@stacksjs/config"), rootDirectory = resolve(filesystems.root || process.cwd());
8
+ return createBunStorage({ root: rootDirectory });
9
+ } catch {
10
+ const rootDirectory = resolve(process.cwd());
11
+ return createBunStorage({ root: rootDirectory });
12
+ }
13
+ }
14
+ async function getAdapter() {
15
+ if (!_adapterPromise)
16
+ _adapterPromise = loadConfig();
17
+ return _adapterPromise;
18
+ }
19
+ export async function getBunStorage() {
20
+ return getAdapter();
21
+ }
22
+ export const bun = {
23
+ async write(path, contents) {
24
+ await (await getAdapter()).write(path, contents);
25
+ },
26
+ async deleteFile(path) {
27
+ await (await getAdapter()).deleteFile(path);
28
+ },
29
+ async createDirectory(path) {
30
+ await (await getAdapter()).createDirectory(path);
31
+ },
32
+ async moveFile(from, to) {
33
+ await (await getAdapter()).moveFile(from, to);
34
+ },
35
+ async copyFile(from, to) {
36
+ await (await getAdapter()).copyFile(from, to);
37
+ },
38
+ async stat(path) {
39
+ return await (await getAdapter()).stat(path);
40
+ },
41
+ list(path, options = { deep: !1 }) {
42
+ return async function* () {
43
+ yield* (await getAdapter()).list(path, options);
44
+ }();
45
+ },
46
+ async changeVisibility(path, visibility) {
47
+ await (await getAdapter()).changeVisibility(path, visibility);
48
+ },
49
+ async visibility(path) {
50
+ return await (await getAdapter()).visibility(path);
51
+ },
52
+ async fileExists(path) {
53
+ return await (await getAdapter()).fileExists(path);
54
+ },
55
+ async directoryExists(path) {
56
+ return await (await getAdapter()).directoryExists(path);
57
+ },
58
+ async publicUrl(path, options) {
59
+ return await (await getAdapter()).publicUrl(path, options);
60
+ },
61
+ async temporaryUrl(path, options) {
62
+ return await (await getAdapter()).temporaryUrl(path, options);
63
+ },
64
+ async checksum(path, options) {
65
+ return await (await getAdapter()).checksum(path, options);
66
+ },
67
+ async mimeType(path, options) {
68
+ return await (await getAdapter()).mimeType(path, options);
69
+ },
70
+ async lastModified(path) {
71
+ return await (await getAdapter()).lastModified(path);
72
+ },
73
+ async fileSize(path) {
74
+ return await (await getAdapter()).fileSize(path);
75
+ },
76
+ async read(path) {
77
+ return await (await getAdapter()).read(path);
78
+ },
79
+ async readToString(path) {
80
+ return await (await getAdapter()).readToString(path);
81
+ },
82
+ async readToBuffer(path) {
83
+ return await (await getAdapter()).readToBuffer(path);
84
+ },
85
+ async readToUint8Array(path) {
86
+ return await (await getAdapter()).readToUint8Array(path);
87
+ }
88
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./aws";
2
+ export * from "./local";
3
+ export * from "./memory";
4
+ export * from "./bun";
@@ -0,0 +1,88 @@
1
+ import { resolve } from "node:path";
2
+ import process from "node:process";
3
+ import { createLocalStorage } from "../adapters/local";
4
+ let _adapterPromise = null;
5
+ async function loadConfig() {
6
+ try {
7
+ const { filesystems } = await import("@stacksjs/config"), rootDirectory = resolve(filesystems.root || process.cwd());
8
+ return createLocalStorage({ root: rootDirectory });
9
+ } catch {
10
+ const rootDirectory = resolve(process.cwd());
11
+ return createLocalStorage({ root: rootDirectory });
12
+ }
13
+ }
14
+ async function getAdapter() {
15
+ if (!_adapterPromise)
16
+ _adapterPromise = loadConfig();
17
+ return _adapterPromise;
18
+ }
19
+ export async function getLocalStorage() {
20
+ return getAdapter();
21
+ }
22
+ export const local = {
23
+ async write(path, contents) {
24
+ await (await getAdapter()).write(path, contents);
25
+ },
26
+ async deleteFile(path) {
27
+ await (await getAdapter()).deleteFile(path);
28
+ },
29
+ async createDirectory(path) {
30
+ await (await getAdapter()).createDirectory(path);
31
+ },
32
+ async moveFile(from, to) {
33
+ await (await getAdapter()).moveFile(from, to);
34
+ },
35
+ async copyFile(from, to) {
36
+ await (await getAdapter()).copyFile(from, to);
37
+ },
38
+ async stat(path) {
39
+ return await (await getAdapter()).stat(path);
40
+ },
41
+ list(path, options = { deep: !1 }) {
42
+ return async function* () {
43
+ yield* (await getAdapter()).list(path, options);
44
+ }();
45
+ },
46
+ async changeVisibility(path, visibility) {
47
+ await (await getAdapter()).changeVisibility(path, visibility);
48
+ },
49
+ async visibility(path) {
50
+ return await (await getAdapter()).visibility(path);
51
+ },
52
+ async fileExists(path) {
53
+ return await (await getAdapter()).fileExists(path);
54
+ },
55
+ async directoryExists(path) {
56
+ return await (await getAdapter()).directoryExists(path);
57
+ },
58
+ async publicUrl(path, options) {
59
+ return await (await getAdapter()).publicUrl(path, options);
60
+ },
61
+ async temporaryUrl(path, options) {
62
+ return await (await getAdapter()).temporaryUrl(path, options);
63
+ },
64
+ async checksum(path, options) {
65
+ return await (await getAdapter()).checksum(path, options);
66
+ },
67
+ async mimeType(path, options) {
68
+ return await (await getAdapter()).mimeType(path, options);
69
+ },
70
+ async lastModified(path) {
71
+ return await (await getAdapter()).lastModified(path);
72
+ },
73
+ async fileSize(path) {
74
+ return await (await getAdapter()).fileSize(path);
75
+ },
76
+ async read(path) {
77
+ return await (await getAdapter()).read(path);
78
+ },
79
+ async readToString(path) {
80
+ return await (await getAdapter()).readToString(path);
81
+ },
82
+ async readToBuffer(path) {
83
+ return await (await getAdapter()).readToBuffer(path);
84
+ },
85
+ async readToUint8Array(path) {
86
+ return await (await getAdapter()).readToUint8Array(path);
87
+ }
88
+ };
@@ -0,0 +1,67 @@
1
+ import { createMemoryStorage } from "../adapters/memory";
2
+ const adapter = createMemoryStorage();
3
+ export const memoryStorage = adapter, memory = {
4
+ async write(path, contents) {
5
+ await adapter.write(path, contents);
6
+ },
7
+ async deleteFile(path) {
8
+ await adapter.deleteFile(path);
9
+ },
10
+ async createDirectory(path) {
11
+ await adapter.createDirectory(path);
12
+ },
13
+ async moveFile(from, to) {
14
+ await adapter.moveFile(from, to);
15
+ },
16
+ async copyFile(from, to) {
17
+ await adapter.copyFile(from, to);
18
+ },
19
+ async stat(path) {
20
+ return await adapter.stat(path);
21
+ },
22
+ list(path, options = { deep: !1 }) {
23
+ return adapter.list(path, options);
24
+ },
25
+ async changeVisibility(path, visibility) {
26
+ await adapter.changeVisibility(path, visibility);
27
+ },
28
+ async visibility(path) {
29
+ return await adapter.visibility(path);
30
+ },
31
+ async fileExists(path) {
32
+ return await adapter.fileExists(path);
33
+ },
34
+ async directoryExists(path) {
35
+ return await adapter.directoryExists(path);
36
+ },
37
+ async publicUrl(path, options) {
38
+ return await adapter.publicUrl(path, options);
39
+ },
40
+ async temporaryUrl(path, options) {
41
+ return await adapter.temporaryUrl(path, options);
42
+ },
43
+ async checksum(path, options) {
44
+ return await adapter.checksum(path, options);
45
+ },
46
+ async mimeType(path, options) {
47
+ return await adapter.mimeType(path, options);
48
+ },
49
+ async lastModified(path) {
50
+ return await adapter.lastModified(path);
51
+ },
52
+ async fileSize(path) {
53
+ return await adapter.fileSize(path);
54
+ },
55
+ async read(path) {
56
+ return await adapter.read(path);
57
+ },
58
+ async readToString(path) {
59
+ return await adapter.readToString(path);
60
+ },
61
+ async readToBuffer(path) {
62
+ return await adapter.readToBuffer(path);
63
+ },
64
+ async readToUint8Array(path) {
65
+ return await adapter.readToUint8Array(path);
66
+ }
67
+ };
package/dist/facade.js ADDED
@@ -0,0 +1,226 @@
1
+ import { resolve } from "node:path";
2
+ import process from "node:process";
3
+ import { filesystems, app as appConfig } from "@stacksjs/config";
4
+ import { createLocalStorage } from "./adapters/local";
5
+ import { S3StorageAdapter } from "./adapters/s3";
6
+ import { parseDiskPath } from "./path-sanitize";
7
+ import { putUploadedFile } from "./put-file";
8
+ function buildConfig() {
9
+ const cwd = process.cwd(), rootDir = filesystems.root || cwd, s3Config = filesystems.s3, appUrl = appConfig?.url || "", config = {
10
+ default: filesystems.driver || "local",
11
+ disks: {
12
+ local: {
13
+ driver: "local",
14
+ root: resolve(rootDir, "storage/app"),
15
+ visibility: filesystems.defaultVisibility || "private"
16
+ },
17
+ public: {
18
+ driver: "local",
19
+ root: resolve(rootDir, "public"),
20
+ url: appUrl ? `${appUrl}/storage` : "/storage",
21
+ visibility: "public"
22
+ }
23
+ }
24
+ };
25
+ if (s3Config?.bucket)
26
+ config.disks.s3 = {
27
+ driver: "s3",
28
+ bucket: s3Config.bucket,
29
+ region: s3Config.region || "us-east-1",
30
+ prefix: s3Config.prefix,
31
+ endpoint: s3Config.endpoint,
32
+ url: filesystems.publicUrl?.domain,
33
+ usePathStyleEndpoint: !!s3Config.endpoint,
34
+ visibility: filesystems.defaultVisibility || "private",
35
+ credentials: s3Config.credentials ? { key: s3Config.credentials.accessKeyId, secret: s3Config.credentials.secretAccessKey } : void 0
36
+ };
37
+ return config;
38
+ }
39
+
40
+ class StorageManager {
41
+ _config = null;
42
+ disks = new Map;
43
+ customConfig = null;
44
+ get config() {
45
+ if (!this._config) {
46
+ const builtConfig = buildConfig();
47
+ this._config = this.customConfig ? {
48
+ default: this.customConfig.default || builtConfig.default,
49
+ disks: { ...builtConfig.disks, ...this.customConfig.disks }
50
+ } : builtConfig;
51
+ }
52
+ return this._config;
53
+ }
54
+ init(config) {
55
+ this.customConfig = config;
56
+ this._config = null;
57
+ this.disks.clear();
58
+ return this;
59
+ }
60
+ disk(name) {
61
+ const diskName = name || this.config.default;
62
+ if (this.disks.has(diskName))
63
+ return this.disks.get(diskName);
64
+ const diskConfig = this.config.disks[diskName];
65
+ if (!diskConfig) {
66
+ const available = Object.keys(this.config.disks).join(", ");
67
+ throw Error(`Disk [${diskName}] is not configured. Available: ${available}`);
68
+ }
69
+ const adapter = this.createAdapter(diskName, diskConfig);
70
+ this.disks.set(diskName, adapter);
71
+ return adapter;
72
+ }
73
+ createAdapter(name, config) {
74
+ switch (config.driver) {
75
+ case "local":
76
+ return this.createLocalAdapter(config);
77
+ case "s3":
78
+ return this.createS3Adapter(name, config);
79
+ default:
80
+ throw Error(`Unsupported driver: ${config.driver}`);
81
+ }
82
+ }
83
+ createLocalAdapter(config) {
84
+ return createLocalStorage({ root: config.root });
85
+ }
86
+ createS3Adapter(_name, config) {
87
+ return new S3StorageAdapter(null, {
88
+ bucket: config.bucket,
89
+ region: config.region,
90
+ prefix: config.prefix
91
+ });
92
+ }
93
+ async put(pathOrFile, contentsOrOpts) {
94
+ if (typeof pathOrFile === "string")
95
+ return this.disk().write(pathOrFile, contentsOrOpts);
96
+ return putUploadedFile(this, pathOrFile, contentsOrOpts ?? {});
97
+ }
98
+ async stat(path) {
99
+ return this.disk().stat(path);
100
+ }
101
+ async getStream(path, options) {
102
+ const adapter = this.disk();
103
+ if (typeof adapter.getStream !== "function")
104
+ throw Error(`[storage] disk '${this.config.default}' does not support getStream \u2014 adapter is missing the optional method`);
105
+ return adapter.getStream(path, options);
106
+ }
107
+ async putStream(path, stream, options) {
108
+ const adapter = this.disk();
109
+ if (typeof adapter.putStream !== "function")
110
+ throw Error(`[storage] disk '${this.config.default}' does not support putStream \u2014 adapter is missing the optional method`);
111
+ return adapter.putStream(path, stream, options);
112
+ }
113
+ async copyAcross(source, dest) {
114
+ const src = parseDiskPath(source), dst = parseDiskPath(dest);
115
+ if (src.disk === dst.disk) {
116
+ const adapter = this.disk(src.disk);
117
+ await adapter.copyFile(src.path, dst.path);
118
+ return adapter.stat(dst.path).then((entry) => ({
119
+ path: dst.path,
120
+ size: entry.size,
121
+ contentType: entry.mimeType,
122
+ lastModified: entry.lastModified
123
+ }));
124
+ }
125
+ const contents = await this.disk(src.disk).read(src.path);
126
+ return this.disk(dst.disk).write(dst.path, contents);
127
+ }
128
+ async moveAcross(source, dest) {
129
+ const src = parseDiskPath(source), result = await this.copyAcross(source, dest);
130
+ await this.disk(src.disk).deleteFile(src.path);
131
+ return result;
132
+ }
133
+ async get(path) {
134
+ return this.disk().readToString(path);
135
+ }
136
+ async exists(path) {
137
+ return this.disk().fileExists(path);
138
+ }
139
+ async missing(path) {
140
+ return !await this.exists(path);
141
+ }
142
+ async delete(path) {
143
+ return this.disk().deleteFile(path);
144
+ }
145
+ async copy(from, to) {
146
+ return this.disk().copyFile(from, to);
147
+ }
148
+ async move(from, to) {
149
+ return this.disk().moveFile(from, to);
150
+ }
151
+ async url(path) {
152
+ return this.disk().publicUrl(path);
153
+ }
154
+ async signedUrl(path, options) {
155
+ const adapter = this.disk();
156
+ if (typeof adapter.signedUrl !== "function")
157
+ throw Error(`[storage] disk '${this.config.default}' does not support signedUrl`);
158
+ return adapter.signedUrl(path, options);
159
+ }
160
+ async presignedUploadUrl(options) {
161
+ const adapter = this.disk();
162
+ if (typeof adapter.presignedUploadUrl !== "function")
163
+ throw Error(`[storage] disk '${this.config.default}' does not support presignedUploadUrl \u2014 only S3-style adapters do. Use \`Storage.put(file, opts)\` for local/proxied uploads.`);
164
+ return adapter.presignedUploadUrl(options);
165
+ }
166
+ async presignedUploadPolicy(options) {
167
+ const adapter = this.disk();
168
+ if (typeof adapter.presignedUploadPolicy !== "function")
169
+ throw Error(`[storage] disk '${this.config.default}' does not support presignedUploadPolicy \u2014 S3-only. Use \`presignedUploadUrl\` for the PUT-form, or \`Storage.put(file, opts)\` for server-proxied uploads.`);
170
+ return adapter.presignedUploadPolicy(options);
171
+ }
172
+ async size(path) {
173
+ return this.disk().fileSize(path);
174
+ }
175
+ async lastModified(path) {
176
+ return this.disk().lastModified(path);
177
+ }
178
+ async mimeType(path) {
179
+ return this.disk().mimeType(path);
180
+ }
181
+ async checksum(path, algorithm) {
182
+ return this.disk().checksum(path, { algorithm });
183
+ }
184
+ async makeDirectory(path) {
185
+ return this.disk().createDirectory(path);
186
+ }
187
+ async deleteDirectory(path) {
188
+ return this.disk().deleteDirectory(path);
189
+ }
190
+ files(path = "") {
191
+ return this.disk().list(path);
192
+ }
193
+ allFiles(path = "") {
194
+ return this.disk().list(path, { deep: !0 });
195
+ }
196
+ configure(name, config) {
197
+ const currentConfig = this.config;
198
+ currentConfig.disks[name] = config;
199
+ this.disks.delete(name);
200
+ return this;
201
+ }
202
+ setDefaultDisk(name) {
203
+ if (!this.config.disks[name])
204
+ throw Error(`Disk [${name}] is not configured`);
205
+ this.config.default = name;
206
+ return this;
207
+ }
208
+ getDiskConfig(name) {
209
+ return this.config.disks[name || this.config.default];
210
+ }
211
+ getConfiguredDisks() {
212
+ return Object.keys(this.config.disks);
213
+ }
214
+ getDefaultDisk() {
215
+ return this.config.default;
216
+ }
217
+ reset() {
218
+ this._config = null;
219
+ this.customConfig = null;
220
+ this.disks.clear();
221
+ return this;
222
+ }
223
+ }
224
+ export const Storage = new StorageManager;
225
+
226
+ export { StorageManager };