@devbro/neko-storage 0.1.3 → 0.1.5

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.
Files changed (42) hide show
  1. package/README.md +104 -7
  2. package/dist/Storage.d.mts +14 -13
  3. package/dist/Storage.mjs +30 -8
  4. package/dist/Storage.mjs.map +1 -1
  5. package/dist/StorageProviderFactory.d.mts +15 -0
  6. package/dist/StorageProviderFactory.mjs +19 -0
  7. package/dist/StorageProviderFactory.mjs.map +1 -0
  8. package/dist/StorageProviderInterface.d.mts +18 -0
  9. package/dist/StorageProviderInterface.mjs +1 -0
  10. package/dist/StorageProviderInterface.mjs.map +1 -0
  11. package/dist/index.d.mts +11 -4
  12. package/dist/index.js +609 -221
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.mjs +8 -3
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/{AWSS3Storage.d.mts → providers/AWSS3StorageProvider.d.mts} +7 -7
  17. package/dist/providers/AWSS3StorageProvider.mjs +108 -0
  18. package/dist/providers/AWSS3StorageProvider.mjs.map +1 -0
  19. package/dist/providers/AzureBlobStorageProvider.d.mts +23 -0
  20. package/dist/providers/AzureBlobStorageProvider.mjs +116 -0
  21. package/dist/providers/AzureBlobStorageProvider.mjs.map +1 -0
  22. package/dist/providers/FTPStorageProvider.d.mts +22 -0
  23. package/dist/providers/FTPStorageProvider.mjs +124 -0
  24. package/dist/providers/FTPStorageProvider.mjs.map +1 -0
  25. package/dist/providers/GCPStorageProvider.d.mts +22 -0
  26. package/dist/providers/GCPStorageProvider.mjs +82 -0
  27. package/dist/providers/GCPStorageProvider.mjs.map +1 -0
  28. package/dist/{LocalStorage.d.mts → providers/LocalStorageProvider.d.mts} +7 -6
  29. package/dist/providers/LocalStorageProvider.mjs +84 -0
  30. package/dist/providers/LocalStorageProvider.mjs.map +1 -0
  31. package/dist/providers/SFTPStorageProvider.d.mts +22 -0
  32. package/dist/providers/SFTPStorageProvider.mjs +124 -0
  33. package/dist/providers/SFTPStorageProvider.mjs.map +1 -0
  34. package/dist/types.d.mts +32 -6
  35. package/package.json +10 -6
  36. package/dist/AWSS3Storage.mjs +0 -154
  37. package/dist/AWSS3Storage.mjs.map +0 -1
  38. package/dist/LocalStorage.mjs +0 -129
  39. package/dist/LocalStorage.mjs.map +0 -1
  40. package/dist/StorageFactory.d.mts +0 -13
  41. package/dist/StorageFactory.mjs +0 -24
  42. package/dist/StorageFactory.mjs.map +0 -1
@@ -1,129 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- var __async = (__this, __arguments, generator) => {
4
- return new Promise((resolve, reject) => {
5
- var fulfilled = (value) => {
6
- try {
7
- step(generator.next(value));
8
- } catch (e) {
9
- reject(e);
10
- }
11
- };
12
- var rejected = (value) => {
13
- try {
14
- step(generator.throw(value));
15
- } catch (e) {
16
- reject(e);
17
- }
18
- };
19
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
20
- step((generator = generator.apply(__this, __arguments)).next());
21
- });
22
- };
23
- import Stream from "stream";
24
- import * as fs from "fs/promises";
25
- import { createWriteStream, createReadStream } from "fs";
26
- import * as path from "path";
27
- import * as mime from "mime-types";
28
- import { Storage } from "./Storage.mjs";
29
- const _LocalStorage = class _LocalStorage extends Storage {
30
- constructor(config) {
31
- super(config);
32
- if (!_LocalStorage.canHandle(config)) {
33
- throw new Error(`storage engine cannot handle this config.`);
34
- }
35
- fs.mkdir(this.config.basePath, { recursive: true }).catch((error) => {
36
- throw error;
37
- });
38
- }
39
- metadata(path2) {
40
- return __async(this, null, function* () {
41
- const fullPath = this.getFullPath(path2);
42
- const stats = yield fs.stat(fullPath);
43
- return {
44
- size: stats.size,
45
- mimeType: mime.lookup(fullPath) || "unknown",
46
- lastModifiedDate: stats.mtime.toISOString()
47
- };
48
- });
49
- }
50
- static canHandle(config) {
51
- if (config.engine === "local") {
52
- return true;
53
- }
54
- return false;
55
- }
56
- getFullPath(filePath) {
57
- return path.join(this.config.basePath, filePath);
58
- }
59
- exists(path2) {
60
- return __async(this, null, function* () {
61
- try {
62
- yield fs.access(this.getFullPath(path2));
63
- return true;
64
- } catch (e) {
65
- return false;
66
- }
67
- });
68
- }
69
- put(filepath, content) {
70
- return __async(this, null, function* () {
71
- const fullPath = this.getFullPath(filepath);
72
- const dir = path.dirname(fullPath);
73
- yield fs.mkdir(dir, { recursive: true });
74
- if (typeof content === "string" || content instanceof Buffer) {
75
- yield fs.writeFile(fullPath, content);
76
- } else if (typeof content === "object" && !(content instanceof Stream)) {
77
- yield fs.writeFile(fullPath, JSON.stringify(content, null, 2));
78
- } else if (typeof content === "object" && content instanceof Stream) {
79
- const writeStream = createWriteStream(fullPath);
80
- yield new Promise((resolve, reject) => {
81
- content.pipe(writeStream);
82
- content.on("end", resolve);
83
- content.on("error", reject);
84
- });
85
- } else {
86
- throw new Error("Unsupported content type");
87
- }
88
- return true;
89
- });
90
- }
91
- getJson(path2) {
92
- return __async(this, null, function* () {
93
- const fullPath = this.getFullPath(path2);
94
- const content = yield fs.readFile(fullPath, "utf-8");
95
- return JSON.parse(content);
96
- });
97
- }
98
- getString(path2, encoding = "utf-8") {
99
- return __async(this, null, function* () {
100
- const fullPath = this.getFullPath(path2);
101
- return yield fs.readFile(fullPath, encoding);
102
- });
103
- }
104
- getBuffer(path2) {
105
- return __async(this, null, function* () {
106
- const fullPath = this.getFullPath(path2);
107
- return yield fs.readFile(fullPath);
108
- });
109
- }
110
- getStream(path2) {
111
- return __async(this, null, function* () {
112
- const fullPath = this.getFullPath(path2);
113
- return createReadStream(fullPath);
114
- });
115
- }
116
- delete(path2) {
117
- return __async(this, null, function* () {
118
- const fullPath = this.getFullPath(path2);
119
- yield fs.unlink(fullPath);
120
- return true;
121
- });
122
- }
123
- };
124
- __name(_LocalStorage, "LocalStorage");
125
- let LocalStorage = _LocalStorage;
126
- export {
127
- LocalStorage
128
- };
129
- //# sourceMappingURL=LocalStorage.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/LocalStorage.mts"],"sourcesContent":["import Stream from 'stream';\nimport * as fs from 'fs/promises';\nimport { createWriteStream, createReadStream, ReadStream } from 'fs';\nimport * as path from 'path';\nimport * as mime from 'mime-types';\nimport { Metadata, StorageConfig } from './types.mjs';\nimport { Storage } from './Storage.mjs';\n\nexport class LocalStorage extends Storage {\n constructor(config: StorageConfig) {\n super(config);\n\n if (!LocalStorage.canHandle(config)) {\n throw new Error(`storage engine cannot handle this config.`);\n }\n // Ensure the base folder exists\n fs.mkdir(this.config.basePath, { recursive: true }).catch((error) => {\n throw error;\n });\n }\n\n async metadata(path: string): Promise<Metadata> {\n const fullPath = this.getFullPath(path);\n const stats = await fs.stat(fullPath);\n return {\n size: stats.size,\n mimeType: mime.lookup(fullPath) || 'unknown',\n lastModifiedDate: stats.mtime.toISOString(),\n };\n }\n\n static canHandle(config: StorageConfig) {\n if (config.engine === 'local') {\n return true;\n }\n return false;\n }\n\n getFullPath(filePath: string) {\n return path.join(this.config.basePath, filePath);\n }\n\n async exists(path: string): Promise<boolean> {\n try {\n await fs.access(this.getFullPath(path));\n return true;\n } catch {\n return false;\n }\n }\n\n async put(filepath: string, content: string | object | Stream | Buffer): Promise<boolean> {\n const fullPath = this.getFullPath(filepath);\n\n const dir = path.dirname(fullPath);\n await fs.mkdir(dir, { recursive: true });\n\n if (typeof content === 'string' || content instanceof Buffer) {\n await fs.writeFile(fullPath, content);\n } else if (typeof content === 'object' && !(content instanceof Stream)) {\n await fs.writeFile(fullPath, JSON.stringify(content, null, 2));\n } else if (typeof content === 'object' && content instanceof Stream) {\n const writeStream = createWriteStream(fullPath);\n await new Promise((resolve, reject) => {\n (content as Stream).pipe(writeStream);\n (content as Stream).on('end', resolve);\n (content as Stream).on('error', reject);\n });\n } else {\n throw new Error('Unsupported content type');\n }\n\n return true;\n }\n\n async getJson(path: string): Promise<object> {\n const fullPath = this.getFullPath(path);\n const content = await fs.readFile(fullPath, 'utf-8');\n return JSON.parse(content);\n }\n\n async getString(path: string, encoding: BufferEncoding = 'utf-8'): Promise<string> {\n const fullPath = this.getFullPath(path);\n return await fs.readFile(fullPath, encoding);\n }\n\n async getBuffer(path: string): Promise<Buffer> {\n const fullPath = this.getFullPath(path);\n return await fs.readFile(fullPath);\n }\n\n async getStream(path: string): Promise<ReadStream> {\n const fullPath = this.getFullPath(path);\n return createReadStream(fullPath);\n }\n\n async delete(path: string): Promise<boolean> {\n const fullPath = this.getFullPath(path);\n await fs.unlink(fullPath);\n return true;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,YAAY;AACnB,YAAY,QAAQ;AACpB,SAAS,mBAAmB,wBAAoC;AAChE,YAAY,UAAU;AACtB,YAAY,UAAU;AAEtB,SAAS,eAAe;AAEjB,MAAM,gBAAN,MAAM,sBAAqB,QAAQ;AAAA,EACxC,YAAY,QAAuB;AACjC,UAAM,MAAM;AAEZ,QAAI,CAAC,cAAa,UAAU,MAAM,GAAG;AACnC,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC7D;AAEA,OAAG,MAAM,KAAK,OAAO,UAAU,EAAE,WAAW,KAAK,CAAC,EAAE,MAAM,CAAC,UAAU;AACnE,YAAM;AAAA,IACR,CAAC;AAAA,EACH;AAAA,EAEM,SAASA,OAAiC;AAAA;AAC9C,YAAM,WAAW,KAAK,YAAYA,KAAI;AACtC,YAAM,QAAQ,MAAM,GAAG,KAAK,QAAQ;AACpC,aAAO;AAAA,QACL,MAAM,MAAM;AAAA,QACZ,UAAU,KAAK,OAAO,QAAQ,KAAK;AAAA,QACnC,kBAAkB,MAAM,MAAM,YAAY;AAAA,MAC5C;AAAA,IACF;AAAA;AAAA,EAEA,OAAO,UAAU,QAAuB;AACtC,QAAI,OAAO,WAAW,SAAS;AAC7B,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,UAAkB;AAC5B,WAAO,KAAK,KAAK,KAA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AAAA,EAEM,UAAUA,OAA+B;AAAA;AAC7C,YAAM,WAAW,KAAK,YAAYA,KAAI;AACtC,aAAO,MAAM,GAAG,SAAS,QAAQ;AAAA,IACnC;AAAA;AAAA,EAEM,UAAUA,OAAmC;AAAA;AACjD,YAAM,WAAW,KAAK,YAAYA,KAAI;AACtC,aAAO,iBAAiB,QAAQ;AAAA,IAClC;AAAA;AAAA,EAEM,OAAOA,OAAgC;AAAA;AAC3C,YAAM,WAAW,KAAK,YAAYA,KAAI;AACtC,YAAM,GAAG,OAAO,QAAQ;AACxB,aAAO;AAAA,IACT;AAAA;AACF;AA7F0C;AAAnC,IAAM,eAAN;","names":["path"]}
@@ -1,13 +0,0 @@
1
- import { Storage } from './Storage.mjs';
2
- import { StorageConfig } from './types.mjs';
3
- import 'fs';
4
- import 'stream';
5
- import '@aws-sdk/client-s3';
6
-
7
- declare class StorageFactory {
8
- static storageEngines: (typeof Storage)[];
9
- registerStorageEngine(engine: typeof Storage): void;
10
- static create(config: StorageConfig): Storage;
11
- }
12
-
13
- export { StorageFactory };
@@ -1,24 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { AWSS3Storage } from "./AWSS3Storage.mjs";
4
- import { LocalStorage } from "./LocalStorage.mjs";
5
- const _StorageFactory = class _StorageFactory {
6
- registerStorageEngine(engine) {
7
- _StorageFactory.storageEngines.push(engine);
8
- }
9
- static create(config) {
10
- for (const engine of _StorageFactory.storageEngines) {
11
- if (engine.canHandle(config)) {
12
- return new engine(config);
13
- }
14
- }
15
- throw new Error("No matchin storage engine found");
16
- }
17
- };
18
- __name(_StorageFactory, "StorageFactory");
19
- _StorageFactory.storageEngines = [LocalStorage, AWSS3Storage];
20
- let StorageFactory = _StorageFactory;
21
- export {
22
- StorageFactory
23
- };
24
- //# sourceMappingURL=StorageFactory.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/StorageFactory.mts"],"sourcesContent":["import { AWSS3Storage } from './AWSS3Storage.mjs';\nimport { LocalStorage } from './LocalStorage.mjs';\nimport { Storage } from './Storage.mjs';\nimport { StorageConfig } from './types.mjs';\n\nexport class StorageFactory {\n public static storageEngines: (typeof Storage)[] = [LocalStorage, AWSS3Storage];\n\n registerStorageEngine(engine: typeof Storage) {\n StorageFactory.storageEngines.push(engine);\n }\n\n public static create(config: StorageConfig): Storage {\n for (const engine of StorageFactory.storageEngines) {\n if (engine.canHandle(config)) {\n // @ts-ignore\n return new engine(config);\n }\n }\n throw new Error('No matchin storage engine found');\n }\n}\n"],"mappings":";;AAAA,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAItB,MAAM,kBAAN,MAAM,gBAAe;AAAA,EAG1B,sBAAsB,QAAwB;AAC5C,oBAAe,eAAe,KAAK,MAAM;AAAA,EAC3C;AAAA,EAEA,OAAc,OAAO,QAAgC;AACnD,eAAW,UAAU,gBAAe,gBAAgB;AAClD,UAAI,OAAO,UAAU,MAAM,GAAG;AAE5B,eAAO,IAAI,OAAO,MAAM;AAAA,MAC1B;AAAA,IACF;AACA,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACF;AAhB4B;AAAf,gBACG,iBAAqC,CAAC,cAAc,YAAY;AADzE,IAAM,iBAAN;","names":[]}