@devbro/neko-storage 0.1.2 → 0.1.4

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.
@@ -1,20 +1,20 @@
1
1
  import { ReadStream } from 'fs';
2
2
  import { Stream } from 'stream';
3
- import { StorageConfig, Metadata } from './types.mjs';
3
+ import { Metadata } from './types.mjs';
4
+ import { StorageProviderInterface } from './StorageProviderInterface.mjs';
4
5
  import '@aws-sdk/client-s3';
5
6
 
6
- declare abstract class Storage {
7
- protected config: StorageConfig;
8
- constructor(config: StorageConfig);
9
- static canHandle(config: StorageConfig): boolean;
10
- abstract exists(path: string): Promise<boolean>;
11
- abstract put(path: string, content: string | object | Stream | Buffer): Promise<boolean>;
12
- abstract getJson(path: string): Promise<object>;
13
- abstract getString(path: string): Promise<string>;
14
- abstract getBuffer(path: string): Promise<Buffer>;
15
- abstract getStream(path: string): Promise<ReadStream>;
16
- abstract delete(path: string): Promise<boolean>;
17
- abstract metadata(path: string): Promise<Metadata>;
7
+ declare class Storage {
8
+ protected provider: StorageProviderInterface;
9
+ constructor(provider: StorageProviderInterface);
10
+ exists(path: string): Promise<boolean>;
11
+ put(path: string, content: string | object | Stream | Buffer): Promise<boolean>;
12
+ getJson(path: string): Promise<object>;
13
+ getString(path: string): Promise<string>;
14
+ getBuffer(path: string): Promise<Buffer>;
15
+ getStream(path: string): Promise<ReadStream>;
16
+ delete(path: string): Promise<boolean>;
17
+ metadata(path: string): Promise<Metadata>;
18
18
  }
19
19
 
20
20
  export { Storage };
package/dist/Storage.mjs CHANGED
@@ -1,15 +1,37 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- const _Storage = class _Storage {
4
- constructor(config) {
5
- this.config = config;
3
+ class Storage {
4
+ constructor(provider) {
5
+ this.provider = provider;
6
6
  }
7
- static canHandle(config) {
8
- throw new Error("Method not implemented.");
7
+ static {
8
+ __name(this, "Storage");
9
9
  }
10
- };
11
- __name(_Storage, "Storage");
12
- let Storage = _Storage;
10
+ exists(path) {
11
+ return this.provider.exists(path);
12
+ }
13
+ put(path, content) {
14
+ return this.provider.put(path, content);
15
+ }
16
+ getJson(path) {
17
+ return this.provider.getJson(path);
18
+ }
19
+ getString(path) {
20
+ return this.provider.getString(path);
21
+ }
22
+ getBuffer(path) {
23
+ return this.provider.getBuffer(path);
24
+ }
25
+ getStream(path) {
26
+ return this.provider.getStream(path);
27
+ }
28
+ delete(path) {
29
+ return this.provider.delete(path);
30
+ }
31
+ metadata(path) {
32
+ return this.provider.metadata(path);
33
+ }
34
+ }
13
35
  export {
14
36
  Storage
15
37
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Storage.mts"],"sourcesContent":["import { ReadStream } from 'fs';\nimport { Stream } from 'stream';\nimport { Metadata } from './types.mjs';\nimport { StorageConfig } from './types.mjs';\n\nexport abstract class Storage {\n constructor(protected config: StorageConfig) {}\n\n static canHandle(config: StorageConfig): boolean {\n throw new Error('Method not implemented.');\n }\n\n abstract exists(path: string): Promise<boolean>;\n abstract put(path: string, content: string | object | Stream | Buffer): Promise<boolean>;\n abstract getJson(path: string): Promise<object>;\n abstract getString(path: string): Promise<string>;\n abstract getBuffer(path: string): Promise<Buffer>;\n abstract getStream(path: string): Promise<ReadStream>;\n abstract delete(path: string): Promise<boolean>;\n abstract metadata(path: string): Promise<Metadata>;\n}\n"],"mappings":";;AAKO,MAAe,WAAf,MAAe,SAAQ;AAAA,EAC5B,YAAsB,QAAuB;AAAvB;AAAA,EAAwB;AAAA,EAE9C,OAAO,UAAU,QAAgC;AAC/C,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAUF;AAf8B;AAAvB,IAAe,UAAf;","names":[]}
1
+ {"version":3,"sources":["../src/Storage.mts"],"sourcesContent":["import { ReadStream } from 'fs';\nimport { Stream } from 'stream';\nimport { Metadata } from './types.mjs';\nimport { StorageConfig } from './types.mjs';\nimport { StorageProviderInterface } from './StorageProviderInterface.mjs';\n\nexport class Storage {\n constructor(protected provider: StorageProviderInterface) {}\n\n exists(path: string): Promise<boolean> {\n return this.provider.exists(path);\n }\n \n put(path: string, content: string | object | Stream | Buffer): Promise<boolean> {\n return this.provider.put(path, content);\n }\n \n getJson(path: string): Promise<object> {\n return this.provider.getJson(path);\n }\n \n getString(path: string): Promise<string> {\n return this.provider.getString(path);\n }\n \n getBuffer(path: string): Promise<Buffer> {\n return this.provider.getBuffer(path);\n }\n \n getStream(path: string): Promise<ReadStream> {\n return this.provider.getStream(path);\n }\n \n delete(path: string): Promise<boolean> {\n return this.provider.delete(path);\n }\n \n metadata(path: string): Promise<Metadata> {\n return this.provider.metadata(path);\n }\n}\n"],"mappings":";;AAMO,MAAM,QAAQ;AAAA,EACnB,YAAsB,UAAoC;AAApC;AAAA,EAAqC;AAAA,EAP7D,OAMqB;AAAA;AAAA;AAAA,EAGnB,OAAO,MAAgC;AACrC,WAAO,KAAK,SAAS,OAAO,IAAI;AAAA,EAClC;AAAA,EAEA,IAAI,MAAc,SAA8D;AAC9E,WAAO,KAAK,SAAS,IAAI,MAAM,OAAO;AAAA,EACxC;AAAA,EAEA,QAAQ,MAA+B;AACrC,WAAO,KAAK,SAAS,QAAQ,IAAI;AAAA,EACnC;AAAA,EAEA,UAAU,MAA+B;AACvC,WAAO,KAAK,SAAS,UAAU,IAAI;AAAA,EACrC;AAAA,EAEA,UAAU,MAA+B;AACvC,WAAO,KAAK,SAAS,UAAU,IAAI;AAAA,EACrC;AAAA,EAEA,UAAU,MAAmC;AAC3C,WAAO,KAAK,SAAS,UAAU,IAAI;AAAA,EACrC;AAAA,EAEA,OAAO,MAAgC;AACrC,WAAO,KAAK,SAAS,OAAO,IAAI;AAAA,EAClC;AAAA,EAEA,SAAS,MAAiC;AACxC,WAAO,KAAK,SAAS,SAAS,IAAI;AAAA,EACpC;AACF;","names":[]}
@@ -0,0 +1,14 @@
1
+ import { FlexibleFactory } from '@devbro/neko-helper';
2
+ import { StorageProviderInterface } from './StorageProviderInterface.mjs';
3
+ import 'fs';
4
+ import 'stream';
5
+ import './types.mjs';
6
+ import '@aws-sdk/client-s3';
7
+
8
+ declare class StorageProviderFactory {
9
+ static instance: FlexibleFactory<StorageProviderInterface>;
10
+ static register(key: string, factory: (...args: any[]) => StorageProviderInterface): void;
11
+ static create<T>(key: string, ...args: any[]): StorageProviderInterface;
12
+ }
13
+
14
+ export { StorageProviderFactory };
@@ -0,0 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { FlexibleFactory } from "@devbro/neko-helper";
4
+ class StorageProviderFactory {
5
+ static {
6
+ __name(this, "StorageProviderFactory");
7
+ }
8
+ static instance = new FlexibleFactory();
9
+ static register(key, factory) {
10
+ StorageProviderFactory.instance.register(key, factory);
11
+ }
12
+ static create(key, ...args) {
13
+ return StorageProviderFactory.instance.create(key, ...args);
14
+ }
15
+ }
16
+ export {
17
+ StorageProviderFactory
18
+ };
19
+ //# sourceMappingURL=StorageProviderFactory.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/StorageProviderFactory.mts"],"sourcesContent":["import { Storage } from './Storage.mjs';\nimport { FlexibleFactory } from '@devbro/neko-helper';\nimport { StorageProviderInterface } from './StorageProviderInterface.mjs';\n\nexport class StorageProviderFactory {\n static instance: FlexibleFactory<StorageProviderInterface> = new FlexibleFactory<StorageProviderInterface>();\n\n static register(key: string, factory: (...args: any[]) => StorageProviderInterface): void {\n StorageProviderFactory.instance.register(key, factory);\n }\n\n static create<T>(key: string, ...args: any[]): StorageProviderInterface {\n return StorageProviderFactory.instance.create(key, ...args);\n }\n}\n"],"mappings":";;AACA,SAAS,uBAAuB;AAGzB,MAAM,uBAAuB;AAAA,EAJpC,OAIoC;AAAA;AAAA;AAAA,EAClC,OAAO,WAAsD,IAAI,gBAA0C;AAAA,EAE3G,OAAO,SAAS,KAAa,SAA6D;AACxF,2BAAuB,SAAS,SAAS,KAAK,OAAO;AAAA,EACvD;AAAA,EAEA,OAAO,OAAU,QAAgB,MAAuC;AACtE,WAAO,uBAAuB,SAAS,OAAO,KAAK,GAAG,IAAI;AAAA,EAC5D;AACF;","names":[]}
@@ -0,0 +1,17 @@
1
+ import { ReadStream } from 'fs';
2
+ import { Stream } from 'stream';
3
+ import { Metadata } from './types.mjs';
4
+ import '@aws-sdk/client-s3';
5
+
6
+ interface StorageProviderInterface {
7
+ exists(path: string): Promise<boolean>;
8
+ put(path: string, content: string | object | Stream | Buffer): Promise<boolean>;
9
+ getJson(path: string): Promise<object>;
10
+ getString(path: string): Promise<string>;
11
+ getBuffer(path: string): Promise<Buffer>;
12
+ getStream(path: string): Promise<ReadStream>;
13
+ delete(path: string): Promise<boolean>;
14
+ metadata(path: string): Promise<Metadata>;
15
+ }
16
+
17
+ export type { StorageProviderInterface };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=StorageProviderInterface.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/index.d.mts CHANGED
@@ -1,8 +1,10 @@
1
1
  export { Metadata, StorageConfig } from './types.mjs';
2
2
  export { Storage } from './Storage.mjs';
3
- export { AWSS3Storage } from './AWSS3Storage.mjs';
4
- export { LocalStorage } from './LocalStorage.mjs';
5
- export { StorageFactory } from './StorageFactory.mjs';
3
+ export { AWSS3StorageProvider } from './providers/AWSS3StorageProvider.mjs';
4
+ export { LocalStorageProvider } from './providers/LocalStorageProvider.mjs';
5
+ export { StorageProviderFactory } from './StorageProviderFactory.mjs';
6
+ export { StorageProviderInterface } from './StorageProviderInterface.mjs';
6
7
  import '@aws-sdk/client-s3';
7
8
  import 'fs';
8
9
  import 'stream';
10
+ import '@devbro/neko-helper';
package/dist/index.js CHANGED
@@ -27,296 +27,248 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  mod
28
28
  ));
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __async = (__this, __arguments, generator) => {
31
- return new Promise((resolve, reject) => {
32
- var fulfilled = (value) => {
33
- try {
34
- step(generator.next(value));
35
- } catch (e) {
36
- reject(e);
37
- }
38
- };
39
- var rejected = (value) => {
40
- try {
41
- step(generator.throw(value));
42
- } catch (e) {
43
- reject(e);
44
- }
45
- };
46
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
47
- step((generator = generator.apply(__this, __arguments)).next());
48
- });
49
- };
50
30
 
51
31
  // src/index.ts
52
32
  var index_exports = {};
53
33
  __export(index_exports, {
54
- AWSS3Storage: () => AWSS3Storage,
55
- LocalStorage: () => LocalStorage,
34
+ AWSS3StorageProvider: () => AWSS3StorageProvider,
35
+ LocalStorageProvider: () => LocalStorageProvider,
56
36
  Storage: () => Storage,
57
- StorageFactory: () => StorageFactory
37
+ StorageProviderFactory: () => StorageProviderFactory
58
38
  });
59
39
  module.exports = __toCommonJS(index_exports);
60
40
 
61
41
  // src/Storage.mts
62
- var _Storage = class _Storage {
63
- constructor(config) {
64
- this.config = config;
42
+ var Storage = class {
43
+ constructor(provider) {
44
+ this.provider = provider;
45
+ }
46
+ static {
47
+ __name(this, "Storage");
48
+ }
49
+ exists(path2) {
50
+ return this.provider.exists(path2);
51
+ }
52
+ put(path2, content) {
53
+ return this.provider.put(path2, content);
54
+ }
55
+ getJson(path2) {
56
+ return this.provider.getJson(path2);
65
57
  }
66
- static canHandle(config) {
67
- throw new Error("Method not implemented.");
58
+ getString(path2) {
59
+ return this.provider.getString(path2);
60
+ }
61
+ getBuffer(path2) {
62
+ return this.provider.getBuffer(path2);
63
+ }
64
+ getStream(path2) {
65
+ return this.provider.getStream(path2);
66
+ }
67
+ delete(path2) {
68
+ return this.provider.delete(path2);
69
+ }
70
+ metadata(path2) {
71
+ return this.provider.metadata(path2);
68
72
  }
69
73
  };
70
- __name(_Storage, "Storage");
71
- var Storage = _Storage;
72
74
 
73
- // src/AWSS3Storage.mts
75
+ // src/providers/AWSS3StorageProvider.mts
74
76
  var import_client_s3 = require("@aws-sdk/client-s3");
75
77
  var import_stream = __toESM(require("stream"), 1);
76
- var _AWSS3Storage = class _AWSS3Storage extends Storage {
78
+ var AWSS3StorageProvider = class {
77
79
  constructor(config) {
78
- var _a;
79
- super(config);
80
80
  this.config = config;
81
- if (!_AWSS3Storage.canHandle(config)) {
82
- throw new Error(`storage engine cannot handle this config.`);
83
- }
84
- this.s3 = new import_client_s3.S3Client(((_a = this.config) == null ? void 0 : _a.s3Config) || {});
81
+ this.s3 = new import_client_s3.S3Client(this.config?.s3Config || {});
85
82
  }
86
- static canHandle(config) {
87
- return config.engine === "s3";
83
+ static {
84
+ __name(this, "AWSS3StorageProvider");
88
85
  }
89
- exists(path2) {
90
- return __async(this, null, function* () {
91
- var _a;
92
- try {
93
- yield this.s3.send(new import_client_s3.HeadObjectCommand({ Bucket: (_a = this.config) == null ? void 0 : _a.bucket, Key: path2 }));
94
- return true;
95
- } catch (error) {
96
- if (error.name === "NotFound") {
97
- return false;
98
- }
99
- throw error;
86
+ s3;
87
+ async exists(path2) {
88
+ try {
89
+ await this.s3.send(new import_client_s3.HeadObjectCommand({ Bucket: this.config?.bucket, Key: path2 }));
90
+ return true;
91
+ } catch (error) {
92
+ if (error.name === "NotFound") {
93
+ return false;
100
94
  }
101
- });
95
+ throw error;
96
+ }
102
97
  }
103
- put(path2, content) {
104
- return __async(this, null, function* () {
105
- let body;
106
- if (typeof content === "string" || content instanceof Buffer) {
107
- body = content;
108
- } else if (typeof content === "object" && !(content instanceof import_stream.default)) {
109
- body = JSON.stringify(content);
110
- } else if (content instanceof import_stream.default) {
111
- body = content;
112
- } else {
113
- throw new Error("Unsupported content type");
114
- }
115
- yield this.s3.send(
116
- new import_client_s3.PutObjectCommand({
117
- Bucket: this.config.bucket,
118
- Key: path2,
119
- Body: body
120
- })
121
- );
122
- return true;
123
- });
98
+ async put(path2, content) {
99
+ let body;
100
+ if (typeof content === "string" || content instanceof Buffer) {
101
+ body = content;
102
+ } else if (typeof content === "object" && !(content instanceof import_stream.default)) {
103
+ body = JSON.stringify(content);
104
+ } else if (content instanceof import_stream.default) {
105
+ body = content;
106
+ } else {
107
+ throw new Error("Unsupported content type");
108
+ }
109
+ await this.s3.send(
110
+ new import_client_s3.PutObjectCommand({
111
+ Bucket: this.config.bucket,
112
+ Key: path2,
113
+ Body: body
114
+ })
115
+ );
116
+ return true;
124
117
  }
125
- getJson(path2) {
126
- return __async(this, null, function* () {
127
- const data = yield this.s3.send(
128
- new import_client_s3.GetObjectCommand({ Bucket: this.config.bucket, Key: path2 })
129
- );
130
- const body = yield this.streamToString(data.Body);
131
- return JSON.parse(body);
132
- });
118
+ async getJson(path2) {
119
+ const data = await this.s3.send(
120
+ new import_client_s3.GetObjectCommand({ Bucket: this.config.bucket, Key: path2 })
121
+ );
122
+ const body = await this.streamToString(data.Body);
123
+ return JSON.parse(body);
133
124
  }
134
- getString(path2) {
135
- return __async(this, null, function* () {
136
- const data = yield this.s3.send(
137
- new import_client_s3.GetObjectCommand({ Bucket: this.config.bucket, Key: path2 })
138
- );
139
- return yield this.streamToString(data.Body);
140
- });
125
+ async getString(path2) {
126
+ const data = await this.s3.send(
127
+ new import_client_s3.GetObjectCommand({ Bucket: this.config.bucket, Key: path2 })
128
+ );
129
+ return await this.streamToString(data.Body);
141
130
  }
142
- delete(path2) {
143
- return __async(this, null, function* () {
144
- yield this.s3.send(new import_client_s3.DeleteObjectCommand({ Bucket: this.config.bucket, Key: path2 }));
145
- return true;
146
- });
131
+ async delete(path2) {
132
+ await this.s3.send(new import_client_s3.DeleteObjectCommand({ Bucket: this.config.bucket, Key: path2 }));
133
+ return true;
147
134
  }
148
- streamToString(stream) {
149
- return __async(this, null, function* () {
150
- return new Promise((resolve, reject) => {
151
- const chunks = [];
152
- stream.on("data", (chunk) => chunks.push(chunk));
153
- stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")));
154
- stream.on("error", reject);
155
- });
156
- });
157
- }
158
- getBuffer(path2) {
159
- return __async(this, null, function* () {
160
- const data = yield this.s3.send(
161
- new import_client_s3.GetObjectCommand({ Bucket: this.config.bucket, Key: path2 })
162
- );
135
+ async streamToString(stream) {
136
+ return new Promise((resolve, reject) => {
163
137
  const chunks = [];
164
- const stream = data.Body;
165
- return new Promise((resolve, reject) => {
166
- stream.on("data", (chunk) => chunks.push(chunk));
167
- stream.on("end", () => resolve(Buffer.concat(chunks)));
168
- stream.on("error", reject);
169
- });
138
+ stream.on("data", (chunk) => chunks.push(chunk));
139
+ stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")));
140
+ stream.on("error", reject);
170
141
  });
171
142
  }
172
- getStream(path2) {
173
- return __async(this, null, function* () {
174
- const data = yield this.s3.send(
175
- new import_client_s3.GetObjectCommand({ Bucket: this.config.bucket, Key: path2 })
176
- );
177
- return data.Body;
143
+ async getBuffer(path2) {
144
+ const data = await this.s3.send(
145
+ new import_client_s3.GetObjectCommand({ Bucket: this.config.bucket, Key: path2 })
146
+ );
147
+ const chunks = [];
148
+ const stream = data.Body;
149
+ return new Promise((resolve, reject) => {
150
+ stream.on("data", (chunk) => chunks.push(chunk));
151
+ stream.on("end", () => resolve(Buffer.concat(chunks)));
152
+ stream.on("error", reject);
178
153
  });
179
154
  }
180
- metadata(path2) {
181
- return __async(this, null, function* () {
182
- const metadata = yield this.s3.send(
183
- new import_client_s3.HeadObjectCommand({ Bucket: this.config.bucket, Key: path2 })
184
- );
185
- return {
186
- size: metadata.ContentLength || 0,
187
- mimeType: metadata.ContentType || "unknown",
188
- lastModifiedDate: (metadata.LastModified || /* @__PURE__ */ new Date(0)).toISOString()
189
- };
190
- });
155
+ async getStream(path2) {
156
+ const data = await this.s3.send(
157
+ new import_client_s3.GetObjectCommand({ Bucket: this.config.bucket, Key: path2 })
158
+ );
159
+ return data.Body;
160
+ }
161
+ async metadata(path2) {
162
+ const metadata = await this.s3.send(
163
+ new import_client_s3.HeadObjectCommand({ Bucket: this.config.bucket, Key: path2 })
164
+ );
165
+ return {
166
+ size: metadata.ContentLength || 0,
167
+ mimeType: metadata.ContentType || "unknown",
168
+ lastModifiedDate: (metadata.LastModified || /* @__PURE__ */ new Date(0)).toISOString()
169
+ };
191
170
  }
192
171
  };
193
- __name(_AWSS3Storage, "AWSS3Storage");
194
- var AWSS3Storage = _AWSS3Storage;
195
172
 
196
- // src/LocalStorage.mts
173
+ // src/providers/LocalStorageProvider.mts
197
174
  var import_stream2 = __toESM(require("stream"), 1);
198
175
  var fs = __toESM(require("fs/promises"), 1);
199
176
  var import_fs = require("fs");
200
177
  var path = __toESM(require("path"), 1);
201
178
  var mime = __toESM(require("mime-types"), 1);
202
- var _LocalStorage = class _LocalStorage extends Storage {
179
+ var LocalStorageProvider = class {
203
180
  constructor(config) {
204
- super(config);
205
- if (!_LocalStorage.canHandle(config)) {
206
- throw new Error(`storage engine cannot handle this config.`);
207
- }
181
+ this.config = config;
208
182
  fs.mkdir(this.config.basePath, { recursive: true }).catch((error) => {
209
183
  throw error;
210
184
  });
211
185
  }
212
- metadata(path2) {
213
- return __async(this, null, function* () {
214
- const fullPath = this.getFullPath(path2);
215
- const stats = yield fs.stat(fullPath);
216
- return {
217
- size: stats.size,
218
- mimeType: mime.lookup(fullPath) || "unknown",
219
- lastModifiedDate: stats.mtime.toISOString()
220
- };
221
- });
186
+ static {
187
+ __name(this, "LocalStorageProvider");
222
188
  }
223
- static canHandle(config) {
224
- if (config.engine === "local") {
225
- return true;
226
- }
227
- return false;
189
+ async metadata(path2) {
190
+ const fullPath = this.getFullPath(path2);
191
+ const stats = await fs.stat(fullPath);
192
+ return {
193
+ size: stats.size,
194
+ mimeType: mime.lookup(fullPath) || "unknown",
195
+ lastModifiedDate: stats.mtime.toISOString()
196
+ };
228
197
  }
229
198
  getFullPath(filePath) {
230
199
  return path.join(this.config.basePath, filePath);
231
200
  }
232
- exists(path2) {
233
- return __async(this, null, function* () {
234
- try {
235
- yield fs.access(this.getFullPath(path2));
236
- return true;
237
- } catch (e) {
238
- return false;
239
- }
240
- });
241
- }
242
- put(path2, content) {
243
- return __async(this, null, function* () {
244
- const fullPath = this.getFullPath(path2);
245
- if (typeof content === "string" || content instanceof Buffer) {
246
- yield fs.writeFile(fullPath, content);
247
- } else if (typeof content === "object" && !(content instanceof import_stream2.default)) {
248
- yield fs.writeFile(fullPath, JSON.stringify(content, null, 2));
249
- } else if (typeof content === "object" && content instanceof import_stream2.default) {
250
- const writeStream = (0, import_fs.createWriteStream)(fullPath);
251
- yield new Promise((resolve, reject) => {
252
- content.pipe(writeStream);
253
- content.on("end", resolve);
254
- content.on("error", reject);
255
- });
256
- } else {
257
- throw new Error("Unsupported content type");
258
- }
201
+ async exists(path2) {
202
+ try {
203
+ await fs.access(this.getFullPath(path2));
259
204
  return true;
260
- });
205
+ } catch {
206
+ return false;
207
+ }
261
208
  }
262
- getJson(path2) {
263
- return __async(this, null, function* () {
264
- const fullPath = this.getFullPath(path2);
265
- const content = yield fs.readFile(fullPath, "utf-8");
266
- return JSON.parse(content);
267
- });
209
+ async put(filepath, content) {
210
+ const fullPath = this.getFullPath(filepath);
211
+ const dir = path.dirname(fullPath);
212
+ await fs.mkdir(dir, { recursive: true });
213
+ if (typeof content === "string" || content instanceof Buffer) {
214
+ await fs.writeFile(fullPath, content);
215
+ } else if (typeof content === "object" && !(content instanceof import_stream2.default)) {
216
+ await fs.writeFile(fullPath, JSON.stringify(content, null, 2));
217
+ } else if (typeof content === "object" && content instanceof import_stream2.default) {
218
+ const writeStream = (0, import_fs.createWriteStream)(fullPath);
219
+ await new Promise((resolve, reject) => {
220
+ content.pipe(writeStream);
221
+ content.on("end", resolve);
222
+ content.on("error", reject);
223
+ });
224
+ } else {
225
+ throw new Error("Unsupported content type");
226
+ }
227
+ return true;
268
228
  }
269
- getString(path2, encoding = "utf-8") {
270
- return __async(this, null, function* () {
271
- const fullPath = this.getFullPath(path2);
272
- return yield fs.readFile(fullPath, encoding);
273
- });
229
+ async getJson(path2) {
230
+ const fullPath = this.getFullPath(path2);
231
+ const content = await fs.readFile(fullPath, "utf-8");
232
+ return JSON.parse(content);
274
233
  }
275
- getBuffer(path2) {
276
- return __async(this, null, function* () {
277
- const fullPath = this.getFullPath(path2);
278
- return yield fs.readFile(fullPath);
279
- });
234
+ async getString(path2, encoding = "utf-8") {
235
+ const fullPath = this.getFullPath(path2);
236
+ return await fs.readFile(fullPath, encoding);
280
237
  }
281
- getStream(path2) {
282
- return __async(this, null, function* () {
283
- const fullPath = this.getFullPath(path2);
284
- return (0, import_fs.createReadStream)(fullPath);
285
- });
238
+ async getBuffer(path2) {
239
+ const fullPath = this.getFullPath(path2);
240
+ return await fs.readFile(fullPath);
286
241
  }
287
- delete(path2) {
288
- return __async(this, null, function* () {
289
- const fullPath = this.getFullPath(path2);
290
- yield fs.unlink(fullPath);
291
- return true;
292
- });
242
+ async getStream(path2) {
243
+ const fullPath = this.getFullPath(path2);
244
+ return (0, import_fs.createReadStream)(fullPath);
245
+ }
246
+ async delete(path2) {
247
+ const fullPath = this.getFullPath(path2);
248
+ await fs.unlink(fullPath);
249
+ return true;
293
250
  }
294
251
  };
295
- __name(_LocalStorage, "LocalStorage");
296
- var LocalStorage = _LocalStorage;
297
252
 
298
- // src/StorageFactory.mts
299
- var _StorageFactory = class _StorageFactory {
300
- registerStorageEngine(engine) {
301
- _StorageFactory.storageEngines.push(engine);
302
- }
303
- static create(config) {
304
- for (const engine of _StorageFactory.storageEngines) {
305
- if (engine.canHandle(config)) {
306
- return new engine(config);
307
- }
308
- }
309
- throw new Error("No matchin storage engine found");
253
+ // src/StorageProviderFactory.mts
254
+ var import_neko_helper = require("@devbro/neko-helper");
255
+ var StorageProviderFactory = class _StorageProviderFactory {
256
+ static {
257
+ __name(this, "StorageProviderFactory");
258
+ }
259
+ static instance = new import_neko_helper.FlexibleFactory();
260
+ static register(key, factory) {
261
+ _StorageProviderFactory.instance.register(key, factory);
262
+ }
263
+ static create(key, ...args) {
264
+ return _StorageProviderFactory.instance.create(key, ...args);
310
265
  }
311
266
  };
312
- __name(_StorageFactory, "StorageFactory");
313
- _StorageFactory.storageEngines = [LocalStorage, AWSS3Storage];
314
- var StorageFactory = _StorageFactory;
315
267
  // Annotate the CommonJS export names for ESM import in node:
316
268
  0 && (module.exports = {
317
- AWSS3Storage,
318
- LocalStorage,
269
+ AWSS3StorageProvider,
270
+ LocalStorageProvider,
319
271
  Storage,
320
- StorageFactory
272
+ StorageProviderFactory
321
273
  });
322
274
  //# sourceMappingURL=index.js.map