@devbro/neko-storage 0.1.0

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.
@@ -0,0 +1,23 @@
1
+ import { StorageConfig, Metadata } from './types.mjs';
2
+ import { Storage } from './Storage.mjs';
3
+ import { ReadStream } from 'fs';
4
+ import Stream from 'stream';
5
+ import '@aws-sdk/client-s3';
6
+
7
+ declare class AWSS3Storage extends Storage {
8
+ protected config: StorageConfig;
9
+ private s3;
10
+ constructor(config: StorageConfig);
11
+ static canHandle(config: StorageConfig): boolean;
12
+ exists(path: string): Promise<boolean>;
13
+ put(path: string, content: string | object | Stream | Buffer): Promise<boolean>;
14
+ getJson(path: string): Promise<object>;
15
+ getString(path: string): Promise<string>;
16
+ delete(path: string): Promise<boolean>;
17
+ private streamToString;
18
+ getBuffer(path: string): Promise<Buffer>;
19
+ getStream(path: string): Promise<ReadStream>;
20
+ metadata(path: string): Promise<Metadata>;
21
+ }
22
+
23
+ export { AWSS3Storage };
@@ -0,0 +1,23 @@
1
+ import { StorageConfig, Metadata } from './types.js';
2
+ import { Storage } from './Storage.js';
3
+ import { ReadStream } from 'fs';
4
+ import Stream from 'stream';
5
+ import '@aws-sdk/client-s3';
6
+
7
+ declare class AWSS3Storage extends Storage {
8
+ protected config: StorageConfig;
9
+ private s3;
10
+ constructor(config: StorageConfig);
11
+ static canHandle(config: StorageConfig): boolean;
12
+ exists(path: string): Promise<boolean>;
13
+ put(path: string, content: string | object | Stream | Buffer): Promise<boolean>;
14
+ getJson(path: string): Promise<object>;
15
+ getString(path: string): Promise<string>;
16
+ delete(path: string): Promise<boolean>;
17
+ private streamToString;
18
+ getBuffer(path: string): Promise<Buffer>;
19
+ getStream(path: string): Promise<ReadStream>;
20
+ metadata(path: string): Promise<Metadata>;
21
+ }
22
+
23
+ export { AWSS3Storage };
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
52
+ var AWSS3Storage_exports = {};
53
+ __export(AWSS3Storage_exports, {
54
+ AWSS3Storage: () => AWSS3Storage
55
+ });
56
+ module.exports = __toCommonJS(AWSS3Storage_exports);
57
+ var import_Storage = require("./Storage");
58
+ var import_client_s3 = require("@aws-sdk/client-s3");
59
+ var import_stream = __toESM(require("stream"));
60
+ const _AWSS3Storage = class _AWSS3Storage extends import_Storage.Storage {
61
+ constructor(config) {
62
+ var _a;
63
+ super(config);
64
+ __publicField(this, "config");
65
+ __publicField(this, "s3");
66
+ this.config = config;
67
+ if (!_AWSS3Storage.canHandle(config)) {
68
+ throw new Error(`storage engine cannot handle this config.`);
69
+ }
70
+ this.s3 = new import_client_s3.S3Client(((_a = this.config) == null ? void 0 : _a.s3Config) || {});
71
+ }
72
+ static canHandle(config) {
73
+ return config.engine === "s3";
74
+ }
75
+ exists(path) {
76
+ return __async(this, null, function* () {
77
+ var _a;
78
+ try {
79
+ yield this.s3.send(new import_client_s3.HeadObjectCommand({
80
+ Bucket: (_a = this.config) == null ? void 0 : _a.bucket,
81
+ Key: path
82
+ }));
83
+ return true;
84
+ } catch (error) {
85
+ if (error.name === "NotFound") {
86
+ return false;
87
+ }
88
+ throw error;
89
+ }
90
+ });
91
+ }
92
+ put(path, content) {
93
+ return __async(this, null, function* () {
94
+ let body;
95
+ if (typeof content === "string" || content instanceof Buffer) {
96
+ body = content;
97
+ } else if (typeof content === "object" && !(content instanceof import_stream.default)) {
98
+ body = JSON.stringify(content);
99
+ } else if (content instanceof import_stream.default) {
100
+ body = content;
101
+ } else {
102
+ throw new Error("Unsupported content type");
103
+ }
104
+ yield this.s3.send(new import_client_s3.PutObjectCommand({
105
+ Bucket: this.config.bucket,
106
+ Key: path,
107
+ Body: body
108
+ }));
109
+ return true;
110
+ });
111
+ }
112
+ getJson(path) {
113
+ return __async(this, null, function* () {
114
+ const data = yield this.s3.send(new import_client_s3.GetObjectCommand({
115
+ Bucket: this.config.bucket,
116
+ Key: path
117
+ }));
118
+ const body = yield this.streamToString(data.Body);
119
+ return JSON.parse(body);
120
+ });
121
+ }
122
+ getString(path) {
123
+ return __async(this, null, function* () {
124
+ const data = yield this.s3.send(new import_client_s3.GetObjectCommand({
125
+ Bucket: this.config.bucket,
126
+ Key: path
127
+ }));
128
+ return yield this.streamToString(data.Body);
129
+ });
130
+ }
131
+ delete(path) {
132
+ return __async(this, null, function* () {
133
+ yield this.s3.send(new import_client_s3.DeleteObjectCommand({
134
+ Bucket: this.config.bucket,
135
+ Key: path
136
+ }));
137
+ return true;
138
+ });
139
+ }
140
+ streamToString(stream) {
141
+ return __async(this, null, function* () {
142
+ return new Promise((resolve, reject) => {
143
+ const chunks = [];
144
+ stream.on("data", (chunk) => chunks.push(chunk));
145
+ stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")));
146
+ stream.on("error", reject);
147
+ });
148
+ });
149
+ }
150
+ getBuffer(path) {
151
+ return __async(this, null, function* () {
152
+ const data = yield this.s3.send(new import_client_s3.GetObjectCommand({
153
+ Bucket: this.config.bucket,
154
+ Key: path
155
+ }));
156
+ const chunks = [];
157
+ const stream = data.Body;
158
+ return new Promise((resolve, reject) => {
159
+ stream.on("data", (chunk) => chunks.push(chunk));
160
+ stream.on("end", () => resolve(Buffer.concat(chunks)));
161
+ stream.on("error", reject);
162
+ });
163
+ });
164
+ }
165
+ getStream(path) {
166
+ return __async(this, null, function* () {
167
+ const data = yield this.s3.send(new import_client_s3.GetObjectCommand({
168
+ Bucket: this.config.bucket,
169
+ Key: path
170
+ }));
171
+ return data.Body;
172
+ });
173
+ }
174
+ metadata(path) {
175
+ return __async(this, null, function* () {
176
+ const metadata = yield this.s3.send(new import_client_s3.HeadObjectCommand({
177
+ Bucket: this.config.bucket,
178
+ Key: path
179
+ }));
180
+ return {
181
+ size: metadata.ContentLength || 0,
182
+ mimeType: metadata.ContentType || "unknown",
183
+ lastModifiedDate: (metadata.LastModified || /* @__PURE__ */ new Date(0)).toISOString()
184
+ };
185
+ });
186
+ }
187
+ };
188
+ __name(_AWSS3Storage, "AWSS3Storage");
189
+ let AWSS3Storage = _AWSS3Storage;
190
+ // Annotate the CommonJS export names for ESM import in node:
191
+ 0 && (module.exports = {
192
+ AWSS3Storage
193
+ });
194
+ //# sourceMappingURL=AWSS3Storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/AWSS3Storage.ts"],"sourcesContent":["import { Metadata, StorageConfig } from './types';\nimport { Storage } from './Storage';\nimport {\n S3Client,\n HeadObjectCommand,\n PutObjectCommand,\n GetObjectCommand,\n DeleteObjectCommand,\n HeadObjectOutput,\n} from '@aws-sdk/client-s3';\nimport { ReadStream } from 'fs';\nimport Stream, { Readable } from 'stream';\n\nexport class AWSS3Storage extends Storage {\n private s3: S3Client;\n\n constructor(protected config: StorageConfig) {\n super(config);\n\n if (!AWSS3Storage.canHandle(config)) {\n throw new Error(`storage engine cannot handle this config.`);\n }\n\n this.s3 = new S3Client(this.config?.s3Config || {});\n }\n\n static canHandle(config: StorageConfig): boolean {\n return config.engine === 's3';\n }\n\n async exists(path: string): Promise<boolean> {\n try {\n await this.s3.send(new HeadObjectCommand({ Bucket: this.config?.bucket, Key: path }));\n return true;\n } catch (error: any) {\n if (error.name === 'NotFound') {\n return false;\n }\n throw error;\n }\n }\n\n async put(path: string, content: string | object | Stream | Buffer): Promise<boolean> {\n let body: any;\n if (typeof content === 'string' || content instanceof Buffer) {\n body = content;\n } else if (typeof content === 'object' && !(content instanceof Stream)) {\n body = JSON.stringify(content);\n } else if (content instanceof Stream) {\n body = content;\n } else {\n throw new Error('Unsupported content type');\n }\n\n await this.s3.send(\n new PutObjectCommand({\n Bucket: this.config.bucket,\n Key: path,\n Body: body,\n })\n );\n\n return true;\n }\n\n async getJson(path: string): Promise<object> {\n const data = await this.s3.send(\n new GetObjectCommand({ Bucket: this.config.bucket, Key: path })\n );\n const body = await this.streamToString(data.Body as Stream);\n return JSON.parse(body);\n }\n\n async getString(path: string): Promise<string> {\n const data = await this.s3.send(\n new GetObjectCommand({ Bucket: this.config.bucket, Key: path })\n );\n return await this.streamToString(data.Body as Stream);\n }\n\n async delete(path: string): Promise<boolean> {\n await this.s3.send(new DeleteObjectCommand({ Bucket: this.config.bucket, Key: path }));\n return true;\n }\n\n private async streamToString(stream: Stream): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Uint8Array[] = [];\n stream.on('data', (chunk) => chunks.push(chunk));\n stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));\n stream.on('error', reject);\n });\n }\n\n async getBuffer(path: string): Promise<Buffer> {\n const data = await this.s3.send(\n new GetObjectCommand({ Bucket: this.config.bucket, Key: path })\n );\n const chunks: Uint8Array[] = [];\n const stream = data.Body as Readable;\n\n return new Promise((resolve, reject) => {\n stream.on('data', (chunk) => chunks.push(chunk));\n stream.on('end', () => resolve(Buffer.concat(chunks)));\n stream.on('error', reject);\n });\n }\n\n async getStream(path: string): Promise<ReadStream> {\n const data = await this.s3.send(\n new GetObjectCommand({ Bucket: this.config.bucket, Key: path })\n );\n return data.Body as unknown as ReadStream;\n }\n\n async metadata(path: string): Promise<Metadata> {\n const metadata = await this.s3.send(\n new HeadObjectCommand({ Bucket: this.config.bucket, Key: path })\n );\n return {\n size: metadata.ContentLength || 0,\n mimeType: metadata.ContentType || 'unknown',\n lastModifiedDate: (metadata.LastModified || new Date(0)).toISOString(),\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;;;;AAAA,qBAAwB;AACxB,uBAOO;AAEP,oBAAiC;AAE1B,MAAMA,gBAAN,MAAMA,sBAAqBC,uBAAAA;EAGhC,YAAsBC,QAAuB;AAf/C;AAgBI,UAAMA,MAAAA;;AAHAC;AAGAD,SADcA,SAAAA;AAGpB,QAAI,CAACF,cAAaI,UAAUF,MAAAA,GAAS;AACnC,YAAM,IAAIG,MAAM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SAASrC,MAAiC;;AAC9C,YAAMqC,WAAW,MAAM,KAAK5C,GAAGQ,KAC7B,IAAIC,mCAAkB;QAAEC,QAAQ,KAAKX,OAAOY;QAAQC,KAAKL;MAAK,CAAA,CAAA;AAEhE,aAAO;QACLsC,MAAMD,SAASE,iBAAiB;QAChCC,UAAUH,SAASI,eAAe;QAClCC,mBAAmBL,SAASM,gBAAgB,oBAAIC,KAAK,CAAA,GAAIC,YAAW;MACtE;IACF;;AACF;AAhHkCtD;AAA3B,IAAMD,eAAN;","names":["AWSS3Storage","Storage","config","s3","canHandle","Error","S3Client","s3Config","engine","exists","path","send","HeadObjectCommand","Bucket","bucket","Key","error","name","put","content","body","Buffer","Stream","JSON","stringify","PutObjectCommand","Body","getJson","data","GetObjectCommand","streamToString","parse","getString","delete","DeleteObjectCommand","stream","Promise","resolve","reject","chunks","on","chunk","push","concat","toString","getBuffer","getStream","metadata","size","ContentLength","mimeType","ContentType","lastModifiedDate","LastModified","Date","toISOString"]}
@@ -0,0 +1,161 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ var __async = (__this, __arguments, generator) => {
6
+ return new Promise((resolve, reject) => {
7
+ var fulfilled = (value) => {
8
+ try {
9
+ step(generator.next(value));
10
+ } catch (e) {
11
+ reject(e);
12
+ }
13
+ };
14
+ var rejected = (value) => {
15
+ try {
16
+ step(generator.throw(value));
17
+ } catch (e) {
18
+ reject(e);
19
+ }
20
+ };
21
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
22
+ step((generator = generator.apply(__this, __arguments)).next());
23
+ });
24
+ };
25
+ import { Storage } from "./Storage";
26
+ import { S3Client, HeadObjectCommand, PutObjectCommand, GetObjectCommand, DeleteObjectCommand } from "@aws-sdk/client-s3";
27
+ import Stream from "stream";
28
+ const _AWSS3Storage = class _AWSS3Storage extends Storage {
29
+ constructor(config) {
30
+ var _a;
31
+ super(config);
32
+ __publicField(this, "config");
33
+ __publicField(this, "s3");
34
+ this.config = config;
35
+ if (!_AWSS3Storage.canHandle(config)) {
36
+ throw new Error(`storage engine cannot handle this config.`);
37
+ }
38
+ this.s3 = new S3Client(((_a = this.config) == null ? void 0 : _a.s3Config) || {});
39
+ }
40
+ static canHandle(config) {
41
+ return config.engine === "s3";
42
+ }
43
+ exists(path) {
44
+ return __async(this, null, function* () {
45
+ var _a;
46
+ try {
47
+ yield this.s3.send(new HeadObjectCommand({
48
+ Bucket: (_a = this.config) == null ? void 0 : _a.bucket,
49
+ Key: path
50
+ }));
51
+ return true;
52
+ } catch (error) {
53
+ if (error.name === "NotFound") {
54
+ return false;
55
+ }
56
+ throw error;
57
+ }
58
+ });
59
+ }
60
+ put(path, content) {
61
+ return __async(this, null, function* () {
62
+ let body;
63
+ if (typeof content === "string" || content instanceof Buffer) {
64
+ body = content;
65
+ } else if (typeof content === "object" && !(content instanceof Stream)) {
66
+ body = JSON.stringify(content);
67
+ } else if (content instanceof Stream) {
68
+ body = content;
69
+ } else {
70
+ throw new Error("Unsupported content type");
71
+ }
72
+ yield this.s3.send(new PutObjectCommand({
73
+ Bucket: this.config.bucket,
74
+ Key: path,
75
+ Body: body
76
+ }));
77
+ return true;
78
+ });
79
+ }
80
+ getJson(path) {
81
+ return __async(this, null, function* () {
82
+ const data = yield this.s3.send(new GetObjectCommand({
83
+ Bucket: this.config.bucket,
84
+ Key: path
85
+ }));
86
+ const body = yield this.streamToString(data.Body);
87
+ return JSON.parse(body);
88
+ });
89
+ }
90
+ getString(path) {
91
+ return __async(this, null, function* () {
92
+ const data = yield this.s3.send(new GetObjectCommand({
93
+ Bucket: this.config.bucket,
94
+ Key: path
95
+ }));
96
+ return yield this.streamToString(data.Body);
97
+ });
98
+ }
99
+ delete(path) {
100
+ return __async(this, null, function* () {
101
+ yield this.s3.send(new DeleteObjectCommand({
102
+ Bucket: this.config.bucket,
103
+ Key: path
104
+ }));
105
+ return true;
106
+ });
107
+ }
108
+ streamToString(stream) {
109
+ return __async(this, null, function* () {
110
+ return new Promise((resolve, reject) => {
111
+ const chunks = [];
112
+ stream.on("data", (chunk) => chunks.push(chunk));
113
+ stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")));
114
+ stream.on("error", reject);
115
+ });
116
+ });
117
+ }
118
+ getBuffer(path) {
119
+ return __async(this, null, function* () {
120
+ const data = yield this.s3.send(new GetObjectCommand({
121
+ Bucket: this.config.bucket,
122
+ Key: path
123
+ }));
124
+ const chunks = [];
125
+ const stream = data.Body;
126
+ return new Promise((resolve, reject) => {
127
+ stream.on("data", (chunk) => chunks.push(chunk));
128
+ stream.on("end", () => resolve(Buffer.concat(chunks)));
129
+ stream.on("error", reject);
130
+ });
131
+ });
132
+ }
133
+ getStream(path) {
134
+ return __async(this, null, function* () {
135
+ const data = yield this.s3.send(new GetObjectCommand({
136
+ Bucket: this.config.bucket,
137
+ Key: path
138
+ }));
139
+ return data.Body;
140
+ });
141
+ }
142
+ metadata(path) {
143
+ return __async(this, null, function* () {
144
+ const metadata = yield this.s3.send(new HeadObjectCommand({
145
+ Bucket: this.config.bucket,
146
+ Key: path
147
+ }));
148
+ return {
149
+ size: metadata.ContentLength || 0,
150
+ mimeType: metadata.ContentType || "unknown",
151
+ lastModifiedDate: (metadata.LastModified || /* @__PURE__ */ new Date(0)).toISOString()
152
+ };
153
+ });
154
+ }
155
+ };
156
+ __name(_AWSS3Storage, "AWSS3Storage");
157
+ let AWSS3Storage = _AWSS3Storage;
158
+ export {
159
+ AWSS3Storage
160
+ };
161
+ //# sourceMappingURL=AWSS3Storage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/AWSS3Storage.ts"],"sourcesContent":["import { Metadata, StorageConfig } from './types';\nimport { Storage } from './Storage';\nimport {\n S3Client,\n HeadObjectCommand,\n PutObjectCommand,\n GetObjectCommand,\n DeleteObjectCommand,\n HeadObjectOutput,\n} from '@aws-sdk/client-s3';\nimport { ReadStream } from 'fs';\nimport Stream, { Readable } from 'stream';\n\nexport class AWSS3Storage extends Storage {\n private s3: S3Client;\n\n constructor(protected config: StorageConfig) {\n super(config);\n\n if (!AWSS3Storage.canHandle(config)) {\n throw new Error(`storage engine cannot handle this config.`);\n }\n\n this.s3 = new S3Client(this.config?.s3Config || {});\n }\n\n static canHandle(config: StorageConfig): boolean {\n return config.engine === 's3';\n }\n\n async exists(path: string): Promise<boolean> {\n try {\n await this.s3.send(new HeadObjectCommand({ Bucket: this.config?.bucket, Key: path }));\n return true;\n } catch (error: any) {\n if (error.name === 'NotFound') {\n return false;\n }\n throw error;\n }\n }\n\n async put(path: string, content: string | object | Stream | Buffer): Promise<boolean> {\n let body: any;\n if (typeof content === 'string' || content instanceof Buffer) {\n body = content;\n } else if (typeof content === 'object' && !(content instanceof Stream)) {\n body = JSON.stringify(content);\n } else if (content instanceof Stream) {\n body = content;\n } else {\n throw new Error('Unsupported content type');\n }\n\n await this.s3.send(\n new PutObjectCommand({\n Bucket: this.config.bucket,\n Key: path,\n Body: body,\n })\n );\n\n return true;\n }\n\n async getJson(path: string): Promise<object> {\n const data = await this.s3.send(\n new GetObjectCommand({ Bucket: this.config.bucket, Key: path })\n );\n const body = await this.streamToString(data.Body as Stream);\n return JSON.parse(body);\n }\n\n async getString(path: string): Promise<string> {\n const data = await this.s3.send(\n new GetObjectCommand({ Bucket: this.config.bucket, Key: path })\n );\n return await this.streamToString(data.Body as Stream);\n }\n\n async delete(path: string): Promise<boolean> {\n await this.s3.send(new DeleteObjectCommand({ Bucket: this.config.bucket, Key: path }));\n return true;\n }\n\n private async streamToString(stream: Stream): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Uint8Array[] = [];\n stream.on('data', (chunk) => chunks.push(chunk));\n stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));\n stream.on('error', reject);\n });\n }\n\n async getBuffer(path: string): Promise<Buffer> {\n const data = await this.s3.send(\n new GetObjectCommand({ Bucket: this.config.bucket, Key: path })\n );\n const chunks: Uint8Array[] = [];\n const stream = data.Body as Readable;\n\n return new Promise((resolve, reject) => {\n stream.on('data', (chunk) => chunks.push(chunk));\n stream.on('end', () => resolve(Buffer.concat(chunks)));\n stream.on('error', reject);\n });\n }\n\n async getStream(path: string): Promise<ReadStream> {\n const data = await this.s3.send(\n new GetObjectCommand({ Bucket: this.config.bucket, Key: path })\n );\n return data.Body as unknown as ReadStream;\n }\n\n async metadata(path: string): Promise<Metadata> {\n const metadata = await this.s3.send(\n new HeadObjectCommand({ Bucket: this.config.bucket, Key: path })\n );\n return {\n size: metadata.ContentLength || 0,\n mimeType: metadata.ContentType || 'unknown',\n lastModifiedDate: (metadata.LastModified || new Date(0)).toISOString(),\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,SAASA,eAAe;AACxB,SACEC,UACAC,mBACAC,kBACAC,kBACAC,2BAEK;AAEP,OAAOC,YAA0B;AAE1B,MAAMC,gBAAN,MAAMA,sBAAqBP,QAAAA;EAGhC,YAAsBQ,QAAuB;AAf/C;AAgBI,UAAMA,MAAAA;;AAHAC;AAGAD,SADcA,SAAAA;AAGpB,QAAI,CAACD,cAAaG,UAAUF,MAAAA,GAAS;AACnC,YAAM,IAAIG,MAAM,2CAA2C;IAC7D;AAEA,SAAKF,KAAK,IAAIR,WAAS,UAAKO,WAAL,mBAAaI,aAAY,CAAC,CAAA;EACnD;EAEA,OAAOF,UAAUF,QAAgC;AAC/C,WAAOA,OAAOK,WAAW;EAC3B;EAEMC,OAAOC,MAAgC;;AA7B/C;AA8BI,UAAI;AACF,cAAM,KAAKN,GAAGO,KAAK,IAAId,kBAAkB;UAAEe,SAAQ,UAAKT,WAAL,mBAAaU;UAAQC,KAAKJ;QAAK,CAAA,CAAA;AAClF,eA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ommand","PutObjectCommand","GetObjectCommand","DeleteObjectCommand","Stream","AWSS3Storage","config","s3","canHandle","Error","s3Config","engine","exists","path","send","Bucket","bucket","Key","error","name","put","content","body","Buffer","JSON","stringify","Body","getJson","data","streamToString","parse","getString","delete","stream","Promise","resolve","reject","chunks","on","chunk","push","concat","toString","getBuffer","getStream","metadata","size","ContentLength","mimeType","ContentType","lastModifiedDate","LastModified","Date","toISOString"]}
@@ -0,0 +1,21 @@
1
+ import Stream from 'stream';
2
+ import { ReadStream } from 'fs';
3
+ import { StorageConfig, Metadata } from './types.mjs';
4
+ import { Storage } from './Storage.mjs';
5
+ import '@aws-sdk/client-s3';
6
+
7
+ declare class LocalStorage extends Storage {
8
+ constructor(config: StorageConfig);
9
+ metadata(path: string): Promise<Metadata>;
10
+ static canHandle(config: StorageConfig): boolean;
11
+ getFullPath(filePath: string): string;
12
+ exists(path: string): Promise<boolean>;
13
+ put(path: string, content: string | object | Stream | Buffer): Promise<boolean>;
14
+ getJson(path: string): Promise<object>;
15
+ getString(path: string, encoding?: BufferEncoding): Promise<string>;
16
+ getBuffer(path: string): Promise<Buffer>;
17
+ getStream(path: string): Promise<ReadStream>;
18
+ delete(path: string): Promise<boolean>;
19
+ }
20
+
21
+ export { LocalStorage };
@@ -0,0 +1,21 @@
1
+ import Stream from 'stream';
2
+ import { ReadStream } from 'fs';
3
+ import { StorageConfig, Metadata } from './types.js';
4
+ import { Storage } from './Storage.js';
5
+ import '@aws-sdk/client-s3';
6
+
7
+ declare class LocalStorage extends Storage {
8
+ constructor(config: StorageConfig);
9
+ metadata(path: string): Promise<Metadata>;
10
+ static canHandle(config: StorageConfig): boolean;
11
+ getFullPath(filePath: string): string;
12
+ exists(path: string): Promise<boolean>;
13
+ put(path: string, content: string | object | Stream | Buffer): Promise<boolean>;
14
+ getJson(path: string): Promise<object>;
15
+ getString(path: string, encoding?: BufferEncoding): Promise<string>;
16
+ getBuffer(path: string): Promise<Buffer>;
17
+ getStream(path: string): Promise<ReadStream>;
18
+ delete(path: string): Promise<boolean>;
19
+ }
20
+
21
+ export { LocalStorage };
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
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
+ var LocalStorage_exports = {};
51
+ __export(LocalStorage_exports, {
52
+ LocalStorage: () => LocalStorage
53
+ });
54
+ module.exports = __toCommonJS(LocalStorage_exports);
55
+ var import_stream = __toESM(require("stream"));
56
+ var fs = __toESM(require("fs/promises"));
57
+ var import_fs = require("fs");
58
+ var path = __toESM(require("path"));
59
+ var mime = __toESM(require("mime-types"));
60
+ var import_Storage = require("./Storage");
61
+ const _LocalStorage = class _LocalStorage extends import_Storage.Storage {
62
+ constructor(config) {
63
+ super(config);
64
+ if (!_LocalStorage.canHandle(config)) {
65
+ throw new Error(`storage engine cannot handle this config.`);
66
+ }
67
+ fs.mkdir(this.config.basePath, {
68
+ recursive: true
69
+ }).catch((error) => {
70
+ throw error;
71
+ });
72
+ }
73
+ metadata(path2) {
74
+ return __async(this, null, function* () {
75
+ const fullPath = this.getFullPath(path2);
76
+ const stats = yield fs.stat(fullPath);
77
+ return {
78
+ size: stats.size,
79
+ mimeType: mime.lookup(fullPath) || "unknown",
80
+ lastModifiedDate: stats.mtime.toISOString()
81
+ };
82
+ });
83
+ }
84
+ static canHandle(config) {
85
+ if (config.engine === "local") {
86
+ return true;
87
+ }
88
+ return false;
89
+ }
90
+ getFullPath(filePath) {
91
+ return path.join(this.config.basePath, filePath);
92
+ }
93
+ exists(path2) {
94
+ return __async(this, null, function* () {
95
+ try {
96
+ yield fs.access(this.getFullPath(path2));
97
+ return true;
98
+ } catch (e) {
99
+ return false;
100
+ }
101
+ });
102
+ }
103
+ put(path2, content) {
104
+ return __async(this, null, function* () {
105
+ const fullPath = this.getFullPath(path2);
106
+ if (typeof content === "string" || content instanceof Buffer) {
107
+ yield fs.writeFile(fullPath, content);
108
+ } else if (typeof content === "object" && !(content instanceof import_stream.default)) {
109
+ yield fs.writeFile(fullPath, JSON.stringify(content, null, 2));
110
+ } else if (typeof content === "object" && content instanceof import_stream.default) {
111
+ const writeStream = (0, import_fs.createWriteStream)(fullPath);
112
+ yield new Promise((resolve, reject) => {
113
+ content.pipe(writeStream);
114
+ content.on("end", resolve);
115
+ content.on("error", reject);
116
+ });
117
+ } else {
118
+ throw new Error("Unsupported content type");
119
+ }
120
+ return true;
121
+ });
122
+ }
123
+ getJson(path2) {
124
+ return __async(this, null, function* () {
125
+ const fullPath = this.getFullPath(path2);
126
+ const content = yield fs.readFile(fullPath, "utf-8");
127
+ return JSON.parse(content);
128
+ });
129
+ }
130
+ getString(path2, encoding = "utf-8") {
131
+ return __async(this, null, function* () {
132
+ const fullPath = this.getFullPath(path2);
133
+ return yield fs.readFile(fullPath, encoding);
134
+ });
135
+ }
136
+ getBuffer(path2) {
137
+ return __async(this, null, function* () {
138
+ const fullPath = this.getFullPath(path2);
139
+ return yield fs.readFile(fullPath);
140
+ });
141
+ }
142
+ getStream(path2) {
143
+ return __async(this, null, function* () {
144
+ const fullPath = this.getFullPath(path2);
145
+ return (0, import_fs.createReadStream)(fullPath);
146
+ });
147
+ }
148
+ delete(path2) {
149
+ return __async(this, null, function* () {
150
+ const fullPath = this.getFullPath(path2);
151
+ yield fs.unlink(fullPath);
152
+ return true;
153
+ });
154
+ }
155
+ };
156
+ __name(_LocalStorage, "LocalStorage");
157
+ let LocalStorage = _LocalStorage;
158
+ // Annotate the CommonJS export names for ESM import in node:
159
+ 0 && (module.exports = {
160
+ LocalStorage
161
+ });
162
+ //# sourceMappingURL=LocalStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/LocalStorage.ts"],"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';\nimport { Storage } from './Storage';\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(path: string, content: string | object | Stream | Buffer): Promise<boolean> {\n const fullPath = this.getFullPath(path);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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B,KAAKC,UAAUL,SAAS,MAAM,CAAA,CAAA;MAC7D,WAAW,OAAOA,YAAY,YAAYA,mBAAmBG,cAAAA,SAAQ;AACnE,cAAMG,kBAAcC,6BAAkBxB,QAAAA;AACtC,cAAM,IAAIyB,QAAQ,CAACC,SAASC,WAAAA;AACzBV,kBAAmBW,KAAKL,WAAAA;AACxBN,kBAAmBY,GAAG,OAAOH,OAAAA;AAC7BT,kBAAmBY,GAAG,SAASF,MAAAA;QAClC,CAAA;MACF,OAAO;AACL,cAAM,IAAIpC,MAAM,0BAAA;MAClB;AAEA,aAAO;IACT;;EAEMuC,QAAQ/B,OAA+B;;AAC3C,YAAMC,WAAW,KAAKC,YAAYF,KAAAA;AAClC,YAAMkB,UAAU,MAAMzB,GAAGuC,SAAS/B,UAAU,OAAA;AAC5C,aAAOqB,KAAKW,MAAMf,OAAAA;IACpB;;EAEMgB,UAAUlC,OAAcmC,WAA2B,SAA0B;;AACjF,YAAMlC,WAAW,KAAKC,YAAYF,KAAAA;AAClC,aAAO,MAAMP,GAAGuC,SAAS/B,UAAUkC,QAAAA;IACrC;;EAEMC,UAAUpC,OAA+B;;AAC7C,YAAMC,WAAW,KAAKC,YAAYF,KAAAA;AAClC,aAAO,MAAMP,GAAGuC,SAAS/B,QAAAA;IAC3B;;EAEMoC,UAAUrC,OAAmC;;AACjD,YAAMC,WAAW,KAAKC,YAAYF,KAAAA;AAClC,iBAAOsC,4BAAiBrC,QAAAA;IAC1B;;EAEMsC,OAAOvC,OAAgC;;AAC3C,YAAMC,WAAW,KAAKC,YAAYF,KAAAA;AAClC,YAAMP,GAAG+C,OAAOvC,QAAAA;AAChB,aAAO;IACT;;AACF;AA1FkCZ;AAA3B,IAAMD,eAAN;","names":["LocalStorage","Storage","config","canHandle","Error","fs","mkdir","basePath","recursive","catch","error","metadata","path","fullPath","getFullPath","stats","stat","size","mimeType","mime","lookup","lastModifiedDate","mtime","toISOString","engine","filePath","join","exists","access","put","content","Buffer","writeFile","Stream","JSON","stringify","writeStream","createWriteStream","Promise","resolve","reject","pipe","on","getJson","readFile","parse","getString","encoding","getBuffer","getStream","createReadStream","delete","unlink"]}
@@ -0,0 +1,129 @@
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";
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, {
36
+ recursive: true
37
+ }).catch((error) => {
38
+ throw error;
39
+ });
40
+ }
41
+ metadata(path2) {
42
+ return __async(this, null, function* () {
43
+ const fullPath = this.getFullPath(path2);
44
+ const stats = yield fs.stat(fullPath);
45
+ return {
46
+ size: stats.size,
47
+ mimeType: mime.lookup(fullPath) || "unknown",
48
+ lastModifiedDate: stats.mtime.toISOString()
49
+ };
50
+ });
51
+ }
52
+ static canHandle(config) {
53
+ if (config.engine === "local") {
54
+ return true;
55
+ }
56
+ return false;
57
+ }
58
+ getFullPath(filePath) {
59
+ return path.join(this.config.basePath, filePath);
60
+ }
61
+ exists(path2) {
62
+ return __async(this, null, function* () {
63
+ try {
64
+ yield fs.access(this.getFullPath(path2));
65
+ return true;
66
+ } catch (e) {
67
+ return false;
68
+ }
69
+ });
70
+ }
71
+ put(path2, content) {
72
+ return __async(this, null, function* () {
73
+ const fullPath = this.getFullPath(path2);
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
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/LocalStorage.ts"],"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';\nimport { Storage } from './Storage';\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(path: string, content: string | object | Stream | Buffer): Promise<boolean> {\n const fullPath = this.getFullPath(path);\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,OAAOA,YAAY;AACnB,YAAYC,QAAQ;AACpB,SAASC,mBAAmBC,wBAAoC;AAChE,YAAYC,UAAU;AACtB,YAAYC,UAAU;AAEtB,SAASC,eAAe;AAEjB,MAAMC,gBAAN,MAAMA,sBAAqBD,QAAAA;EAChC,YAAYE,QAAuB;AACjC,UAAMA,MAAAA;AAEN,QAAI,CAACD,cAAaE,UAAUD,MAAAA,GAAS;AACnC,YAAM,IAAIE,MAAM,2CAA2C;IAC7D;AAEAT,OAAGU,MAAM,KAAKH,OAAOI,UAAU;MAAEC,WAAW;IAAK,CAAA,EAAGC,MAAM,CAACC,UAAAA;AACzD,YAAMA;IACR,CAAA;EACF;EAEMC,SAASZ,OAAiC;;AAC9C,YAAMa,WAAW,KAAKC,YAAYd,KAAAA;AAClC,YAAMe,QAAQ,MAAMlB,GAAGmB,KAAKH,QAAAA;AAC5B,aAAO;QACLI,MAAMF,MAAME;QACZC,UAAUjB,KAAKkB,OAAON,QAAAA,KAAa;QACnCO,kBAAkBL,MAAMM,MAAMC,YAAW;MAC3C;IACF;;EAEA,OAAOjB,UAAUD,QAAuB;AACtC,QAAIA,OAAOmB,WAAW,SAAS;AAC7B,aAAO;IACT;AACA,WAAO;EACT;EAEAT,YAAYU,UAAkB;AAC5B,WAAOxB,KAAKyB,KAAK,KAAKrB,OAAOI,UAAUgB,QAAAA;EACzC;EAEME,OAAO1B,OAAgC;;AAC3C,UAAI;AACF,cAAMH,GAAG8B,OAAO,KAAKb,YAAYd,KAAAA,CAAAA;AACjC,eAAO;MACT,SAAQ;AACN,eAAO;MACT;IACF;;EAEM4B,IA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AMH,GAAGmD,OAAOnC,QAAAA;AAChB,aAAO;IACT;;AACF;AA1FkCX;AAA3B,IAAMC,eAAN;","names":["Stream","fs","createWriteStream","createReadStream","path","mime","Storage","LocalStorage","config","canHandle","Error","mkdir","basePath","recursive","catch","error","metadata","fullPath","getFullPath","stats","stat","size","mimeType","lookup","lastModifiedDate","mtime","toISOString","engine","filePath","join","exists","access","put","content","Buffer","writeFile","JSON","stringify","writeStream","Promise","resolve","reject","pipe","on","getJson","readFile","parse","getString","encoding","getBuffer","getStream","delete","unlink"]}
@@ -0,0 +1,20 @@
1
+ import { ReadStream } from 'fs';
2
+ import { Stream } from 'stream';
3
+ import { StorageConfig, Metadata } from './types.mjs';
4
+ import '@aws-sdk/client-s3';
5
+
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>;
18
+ }
19
+
20
+ export { Storage };
@@ -0,0 +1,20 @@
1
+ import { ReadStream } from 'fs';
2
+ import { Stream } from 'stream';
3
+ import { StorageConfig, Metadata } from './types.js';
4
+ import '@aws-sdk/client-s3';
5
+
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>;
18
+ }
19
+
20
+ export { Storage };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ var Storage_exports = {};
23
+ __export(Storage_exports, {
24
+ Storage: () => Storage
25
+ });
26
+ module.exports = __toCommonJS(Storage_exports);
27
+ const _Storage = class _Storage {
28
+ constructor(config) {
29
+ __publicField(this, "config");
30
+ this.config = config;
31
+ }
32
+ static canHandle(config) {
33
+ throw new Error("Method not implemented.");
34
+ }
35
+ };
36
+ __name(_Storage, "Storage");
37
+ let Storage = _Storage;
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ Storage
41
+ });
42
+ //# sourceMappingURL=Storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Storage.ts"],"sourcesContent":["import { ReadStream } from 'fs';\nimport { Stream } from 'stream';\nimport { Metadata } from './types';\nimport { StorageConfig } from './types';\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":";;;;;;;;;;;;;;;;;;;;;AAKA;;;;;AAAO,MAAeA,WAAf,MAAeA,SAAAA;EACpB,YAAsBC,QAAuB;;SAAvBA,SAAAA;EAAwB;EAE9C,OAAOC,UAAUD,QAAgC;AAC/C,UAAM,IAAIE,MAAM,yBAAA;EAClB;AAUF;AAfsBH;AAAf,IAAeA,UAAf;","names":["Storage","config","canHandle","Error"]}
@@ -0,0 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ const _Storage = class _Storage {
6
+ constructor(config) {
7
+ __publicField(this, "config");
8
+ this.config = config;
9
+ }
10
+ static canHandle(config) {
11
+ throw new Error("Method not implemented.");
12
+ }
13
+ };
14
+ __name(_Storage, "Storage");
15
+ let Storage = _Storage;
16
+ export {
17
+ Storage
18
+ };
19
+ //# sourceMappingURL=Storage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Storage.ts"],"sourcesContent":["import { ReadStream } from 'fs';\nimport { Stream } from 'stream';\nimport { Metadata } from './types';\nimport { StorageConfig } from './types';\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,MAAeA,WAAf,MAAeA,SAAAA;EACpB,YAAsBC,QAAuB;;SAAvBA,SAAAA;EAAwB;EAE9C,OAAOC,UAAUD,QAAgC;AAC/C,UAAM,IAAIE,MAAM,yBAAA;EAClB;AAUF;AAfsBH;AAAf,IAAeA,UAAf;","names":["Storage","config","canHandle","Error"]}
@@ -0,0 +1,13 @@
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 };
@@ -0,0 +1,13 @@
1
+ import { Storage } from './Storage.js';
2
+ import { StorageConfig } from './types.js';
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 };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ var StorageFactory_exports = {};
23
+ __export(StorageFactory_exports, {
24
+ StorageFactory: () => StorageFactory
25
+ });
26
+ module.exports = __toCommonJS(StorageFactory_exports);
27
+ var import_AWSS3Storage = require("./AWSS3Storage");
28
+ var import_LocalStorage = require("./LocalStorage");
29
+ const _StorageFactory = class _StorageFactory {
30
+ registerStorageEngine(engine) {
31
+ _StorageFactory.storageEngines.push(engine);
32
+ }
33
+ static create(config) {
34
+ for (const engine of _StorageFactory.storageEngines) {
35
+ if (engine.canHandle(config)) {
36
+ return new engine(config);
37
+ }
38
+ }
39
+ throw new Error("No matchin storage engine found");
40
+ }
41
+ };
42
+ __name(_StorageFactory, "StorageFactory");
43
+ __publicField(_StorageFactory, "storageEngines", [
44
+ import_LocalStorage.LocalStorage,
45
+ import_AWSS3Storage.AWSS3Storage
46
+ ]);
47
+ let StorageFactory = _StorageFactory;
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ StorageFactory
51
+ });
52
+ //# sourceMappingURL=StorageFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/StorageFactory.ts"],"sourcesContent":["import { AWSS3Storage } from './AWSS3Storage';\nimport { LocalStorage } from './LocalStorage';\nimport { Storage } from './Storage';\nimport { StorageConfig } from './types';\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;;;;;AAAA,0BAA6B;AAC7B,0BAA6B;AAItB,MAAMA,kBAAN,MAAMA,gBAAAA;EAGXC,sBAAsBC,QAAwB;AAC5CF,oBAAeG,eAAeC,KAAKF,MAAAA;EACrC;EAEA,OAAcG,OAAOC,QAAgC;AACnD,eAAWJ,UAAUF,gBAAeG,gBAAgB;AAClD,UAAID,OAAOK,UAAUD,MAAAA,GAAS;AAE5B,eAAO,IAAIJ,OAAOI,MAAAA;MACpB;IACF;AACA,UAAM,IAAIE,MAAM,iCAAA;EAClB;AACF;AAhBaR;AACX,cADWA,iBACGG,kBAAqC;EAACM;EAAcC;;AAD7D,IAAMV,iBAAN;","names":["StorageFactory","registerStorageEngine","engine","storageEngines","push","create","config","canHandle","Error","LocalStorage","AWSS3Storage"]}
@@ -0,0 +1,29 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ import { AWSS3Storage } from "./AWSS3Storage";
6
+ import { LocalStorage } from "./LocalStorage";
7
+ const _StorageFactory = class _StorageFactory {
8
+ registerStorageEngine(engine) {
9
+ _StorageFactory.storageEngines.push(engine);
10
+ }
11
+ static create(config) {
12
+ for (const engine of _StorageFactory.storageEngines) {
13
+ if (engine.canHandle(config)) {
14
+ return new engine(config);
15
+ }
16
+ }
17
+ throw new Error("No matchin storage engine found");
18
+ }
19
+ };
20
+ __name(_StorageFactory, "StorageFactory");
21
+ __publicField(_StorageFactory, "storageEngines", [
22
+ LocalStorage,
23
+ AWSS3Storage
24
+ ]);
25
+ let StorageFactory = _StorageFactory;
26
+ export {
27
+ StorageFactory
28
+ };
29
+ //# sourceMappingURL=StorageFactory.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/StorageFactory.ts"],"sourcesContent":["import { AWSS3Storage } from './AWSS3Storage';\nimport { LocalStorage } from './LocalStorage';\nimport { Storage } from './Storage';\nimport { StorageConfig } from './types';\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,SAASA,oBAAoB;AAC7B,SAASC,oBAAoB;AAItB,MAAMC,kBAAN,MAAMA,gBAAAA;EAGXC,sBAAsBC,QAAwB;AAC5CF,oBAAeG,eAAeC,KAAKF,MAAAA;EACrC;EAEA,OAAcG,OAAOC,QAAgC;AACnD,eAAWJ,UAAUF,gBAAeG,gBAAgB;AAClD,UAAID,OAAOK,UAAUD,MAAAA,GAAS;AAE5B,eAAO,IAAIJ,OAAOI,MAAAA;MACpB;IACF;AACA,UAAM,IAAIE,MAAM,iCAAA;EAClB;AACF;AAhBaR;AACX,cADWA,iBACGG,kBAAqC;EAACJ;EAAcD;;AAD7D,IAAME,iBAAN;","names":["AWSS3Storage","LocalStorage","StorageFactory","registerStorageEngine","engine","storageEngines","push","create","config","canHandle","Error"]}
@@ -0,0 +1,8 @@
1
+ export { Metadata, StorageConfig } from './types.mjs';
2
+ export { Storage } from './Storage.mjs';
3
+ export { AWSS3Storage } from './AWSS3Storage.mjs';
4
+ export { LocalStorage } from './LocalStorage.mjs';
5
+ export { StorageFactory } from './StorageFactory.mjs';
6
+ import '@aws-sdk/client-s3';
7
+ import 'fs';
8
+ import 'stream';
@@ -0,0 +1,8 @@
1
+ export { Metadata, StorageConfig } from './types.js';
2
+ export { Storage } from './Storage.js';
3
+ export { AWSS3Storage } from './AWSS3Storage.js';
4
+ export { LocalStorage } from './LocalStorage.js';
5
+ export { StorageFactory } from './StorageFactory.js';
6
+ import '@aws-sdk/client-s3';
7
+ import 'fs';
8
+ import 'stream';
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var index_exports = {};
17
+ module.exports = __toCommonJS(index_exports);
18
+ __reExport(index_exports, require("./types"), module.exports);
19
+ __reExport(index_exports, require("./Storage"), module.exports);
20
+ __reExport(index_exports, require("./AWSS3Storage"), module.exports);
21
+ __reExport(index_exports, require("./LocalStorage"), module.exports);
22
+ __reExport(index_exports, require("./StorageFactory"), module.exports);
23
+ // Annotate the CommonJS export names for ESM import in node:
24
+ 0 && (module.exports = {
25
+ ...require("./types"),
26
+ ...require("./Storage"),
27
+ ...require("./AWSS3Storage"),
28
+ ...require("./LocalStorage"),
29
+ ...require("./StorageFactory")
30
+ });
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './types';\nexport * from './Storage';\nexport * from './AWSS3Storage';\nexport * from './LocalStorage';\nexport * from './StorageFactory';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;;0BAAc,oBAAd;AACA,0BAAc,sBADd;AAEA,0BAAc,2BAFd;AAGA,0BAAc,2BAHd;AAIA,0BAAc,6BAJd;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./types";
2
+ export * from "./Storage";
3
+ export * from "./AWSS3Storage";
4
+ export * from "./LocalStorage";
5
+ export * from "./StorageFactory";
6
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './types';\nexport * from './Storage';\nexport * from './AWSS3Storage';\nexport * from './LocalStorage';\nexport * from './StorageFactory';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,15 @@
1
+ import { S3ClientConfig } from '@aws-sdk/client-s3';
2
+
3
+ type Metadata = {
4
+ size: number;
5
+ mimeType: string;
6
+ lastModifiedDate: string;
7
+ };
8
+ type StorageConfig = {
9
+ engine: string;
10
+ basePath: string;
11
+ bucket?: string;
12
+ s3Config?: S3ClientConfig;
13
+ };
14
+
15
+ export type { Metadata, StorageConfig };
@@ -0,0 +1,15 @@
1
+ import { S3ClientConfig } from '@aws-sdk/client-s3';
2
+
3
+ type Metadata = {
4
+ size: number;
5
+ mimeType: string;
6
+ lastModifiedDate: string;
7
+ };
8
+ type StorageConfig = {
9
+ engine: string;
10
+ basePath: string;
11
+ bucket?: string;
12
+ s3Config?: S3ClientConfig;
13
+ };
14
+
15
+ export type { Metadata, StorageConfig };
package/dist/types.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
17
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import { S3ClientConfig } from '@aws-sdk/client-s3';\n\nexport type Metadata = {\n size: number;\n mimeType: string;\n lastModifiedDate: string;\n};\n\nexport type StorageConfig = {\n engine: string;\n basePath: string;\n bucket?: string;\n s3Config?: S3ClientConfig;\n};\n"],"mappings":";;;;;;;;;;;;;;AAQA;;","names":[]}
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@devbro/neko-storage",
3
+ "version": "0.1.0",
4
+ "description": "abstracted file storage implementation",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.mjs",
15
+ "require": "./dist/index.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "tsup",
20
+ "test": "jest",
21
+ "format": "eslint . --fix --ext ts,tsx --report-unused-disable-directives --max-warnings 0 ",
22
+ "prepare": "husky",
23
+ "prettier": "prettier --write .",
24
+ "clean": "rm -rf dist"
25
+ },
26
+ "author": "Farzad Meow Khalafi",
27
+ "license": "MIT",
28
+ "devDependencies": {
29
+ "@types/jest": "^29.5.12",
30
+ "@types/node": "^22.14.1",
31
+ "@typescript-eslint/eslint-plugin": "^7.1.1",
32
+ "@typescript-eslint/parser": "^7.1.1",
33
+ "eslint": "8.57.0",
34
+ "husky": "^9.1.7",
35
+ "jest": "^29.7.0",
36
+ "pinst": "^3.0.0",
37
+ "prettier": "^3.5.3",
38
+ "ts-jest": "^29.1.2",
39
+ "ts-node": "^10.9.2",
40
+ "tsup": "^8.0.2",
41
+ "typescript": "^5.3.3",
42
+ "@types/mime-types": "^2.1.4"
43
+ },
44
+ "dependencies": {
45
+ "@aws-sdk/client-s3": "^3.817.0",
46
+ "mime-types": "^3.0.1"
47
+ },
48
+ "directories": {
49
+ "doc": "docs",
50
+ "test": "tests"
51
+ },
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+ssh://git@github.com/devbro1/pashmak.git"
55
+ },
56
+ "keywords": [
57
+ "@devbro/neko-storage",
58
+ "devbro",
59
+ "neko-storage",
60
+ "file storage",
61
+ "file management"
62
+ ],
63
+ "bugs": {
64
+ "url": "https://github.com/devbro1/pashmak/issues"
65
+ },
66
+ "homepage": "https://devbro1.github.io/pashmak/",
67
+ "tags": {
68
+ "needsCompile": true,
69
+ "canPublishToNpm": true
70
+ }
71
+ }