@contractspec/lib.files 1.57.0 → 1.58.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.
- package/dist/contracts/index.d.ts +1080 -1086
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +575 -854
- package/dist/docs/files.docblock.d.ts +2 -1
- package/dist/docs/files.docblock.d.ts.map +1 -0
- package/dist/docs/files.docblock.js +17 -22
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +66 -1
- package/dist/entities/index.d.ts +134 -139
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js +228 -257
- package/dist/events.d.ts +357 -363
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +217 -400
- package/dist/files.capability.d.ts +2 -7
- package/dist/files.capability.d.ts.map +1 -1
- package/dist/files.capability.js +29 -25
- package/dist/files.feature.d.ts +1 -6
- package/dist/files.feature.d.ts.map +1 -1
- package/dist/files.feature.js +50 -131
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1411 -8
- package/dist/node/contracts/index.js +576 -0
- package/dist/node/docs/files.docblock.js +65 -0
- package/dist/node/docs/index.js +65 -0
- package/dist/node/entities/index.js +235 -0
- package/dist/node/events.js +219 -0
- package/dist/node/files.capability.js +28 -0
- package/dist/node/files.feature.js +51 -0
- package/dist/node/index.js +1410 -0
- package/dist/node/storage/index.js +268 -0
- package/dist/storage/index.d.ts +163 -166
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +266 -266
- package/package.json +104 -30
- package/dist/contracts/index.js.map +0 -1
- package/dist/docs/files.docblock.js.map +0 -1
- package/dist/entities/index.js.map +0 -1
- package/dist/events.js.map +0 -1
- package/dist/files.capability.js.map +0 -1
- package/dist/files.feature.js.map +0 -1
- package/dist/storage/index.js.map +0 -1
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// src/storage/index.ts
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import * as crypto from "node:crypto";
|
|
5
|
+
|
|
6
|
+
class LocalStorageAdapter {
|
|
7
|
+
provider = "LOCAL";
|
|
8
|
+
basePath;
|
|
9
|
+
baseUrl;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.basePath = options.basePath;
|
|
12
|
+
this.baseUrl = options.baseUrl;
|
|
13
|
+
}
|
|
14
|
+
async upload(options) {
|
|
15
|
+
const fullPath = path.join(this.basePath, options.path);
|
|
16
|
+
const dir = path.dirname(fullPath);
|
|
17
|
+
await fs.mkdir(dir, { recursive: true });
|
|
18
|
+
const content = typeof options.content === "string" ? Buffer.from(options.content, "base64") : options.content;
|
|
19
|
+
await fs.writeFile(fullPath, content);
|
|
20
|
+
const checksum = crypto.createHash("sha256").update(content).digest("hex");
|
|
21
|
+
return {
|
|
22
|
+
path: options.path,
|
|
23
|
+
size: content.length,
|
|
24
|
+
mimeType: options.mimeType,
|
|
25
|
+
checksum,
|
|
26
|
+
metadata: options.metadata
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async download(filePath) {
|
|
30
|
+
const fullPath = path.join(this.basePath, filePath);
|
|
31
|
+
return fs.readFile(fullPath);
|
|
32
|
+
}
|
|
33
|
+
async delete(filePath) {
|
|
34
|
+
const fullPath = path.join(this.basePath, filePath);
|
|
35
|
+
await fs.unlink(fullPath);
|
|
36
|
+
}
|
|
37
|
+
async exists(filePath) {
|
|
38
|
+
const fullPath = path.join(this.basePath, filePath);
|
|
39
|
+
try {
|
|
40
|
+
await fs.access(fullPath);
|
|
41
|
+
return true;
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async getMetadata(filePath) {
|
|
47
|
+
const fullPath = path.join(this.basePath, filePath);
|
|
48
|
+
try {
|
|
49
|
+
const stat2 = await fs.stat(fullPath);
|
|
50
|
+
return {
|
|
51
|
+
path: filePath,
|
|
52
|
+
size: stat2.size,
|
|
53
|
+
mimeType: "application/octet-stream"
|
|
54
|
+
};
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async list(options) {
|
|
60
|
+
const dir = options?.prefix ? path.join(this.basePath, options.prefix) : this.basePath;
|
|
61
|
+
try {
|
|
62
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
63
|
+
const files = [];
|
|
64
|
+
for (const entry of entries) {
|
|
65
|
+
if (entry.isFile()) {
|
|
66
|
+
const filePath = options?.prefix ? path.join(options.prefix, entry.name) : entry.name;
|
|
67
|
+
const stat2 = await fs.stat(path.join(dir, entry.name));
|
|
68
|
+
files.push({
|
|
69
|
+
path: filePath,
|
|
70
|
+
size: stat2.size,
|
|
71
|
+
mimeType: "application/octet-stream"
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const limit = options?.limit || files.length;
|
|
76
|
+
return {
|
|
77
|
+
files: files.slice(0, limit),
|
|
78
|
+
hasMore: files.length > limit
|
|
79
|
+
};
|
|
80
|
+
} catch {
|
|
81
|
+
return { files: [], hasMore: false };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async createPresignedUpload(options) {
|
|
85
|
+
const expiresIn = options.expiresIn || 3600;
|
|
86
|
+
const expiresAt = new Date(Date.now() + expiresIn * 1000);
|
|
87
|
+
return {
|
|
88
|
+
url: this.baseUrl ? `${this.baseUrl}/upload?path=${encodeURIComponent(options.path)}` : `/upload?path=${encodeURIComponent(options.path)}`,
|
|
89
|
+
fields: {
|
|
90
|
+
path: options.path,
|
|
91
|
+
mimeType: options.mimeType
|
|
92
|
+
},
|
|
93
|
+
expiresAt
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async createPresignedDownload(options) {
|
|
97
|
+
const expiresIn = options.expiresIn || 3600;
|
|
98
|
+
const expiresAt = new Date(Date.now() + expiresIn * 1000);
|
|
99
|
+
return {
|
|
100
|
+
url: this.baseUrl ? `${this.baseUrl}/download/${options.path}` : `/download/${options.path}`,
|
|
101
|
+
expiresAt
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
getPublicUrl(filePath) {
|
|
105
|
+
if (!this.baseUrl)
|
|
106
|
+
return null;
|
|
107
|
+
return `${this.baseUrl}/${filePath}`;
|
|
108
|
+
}
|
|
109
|
+
async copy(sourcePath, destinationPath) {
|
|
110
|
+
const sourceFullPath = path.join(this.basePath, sourcePath);
|
|
111
|
+
const destFullPath = path.join(this.basePath, destinationPath);
|
|
112
|
+
const destDir = path.dirname(destFullPath);
|
|
113
|
+
await fs.mkdir(destDir, { recursive: true });
|
|
114
|
+
await fs.copyFile(sourceFullPath, destFullPath);
|
|
115
|
+
const stat2 = await fs.stat(destFullPath);
|
|
116
|
+
return {
|
|
117
|
+
path: destinationPath,
|
|
118
|
+
size: stat2.size,
|
|
119
|
+
mimeType: "application/octet-stream"
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
class S3StorageAdapter {
|
|
125
|
+
provider = "S3";
|
|
126
|
+
config;
|
|
127
|
+
constructor(options) {
|
|
128
|
+
this.config = options;
|
|
129
|
+
}
|
|
130
|
+
async upload(_options) {
|
|
131
|
+
throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the upload method.");
|
|
132
|
+
}
|
|
133
|
+
async download(_filePath) {
|
|
134
|
+
throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the download method.");
|
|
135
|
+
}
|
|
136
|
+
async delete(_filePath) {
|
|
137
|
+
throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the delete method.");
|
|
138
|
+
}
|
|
139
|
+
async exists(_filePath) {
|
|
140
|
+
throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the exists method.");
|
|
141
|
+
}
|
|
142
|
+
async getMetadata(_filePath) {
|
|
143
|
+
throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the getMetadata method.");
|
|
144
|
+
}
|
|
145
|
+
async list(_options) {
|
|
146
|
+
throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the list method.");
|
|
147
|
+
}
|
|
148
|
+
async createPresignedUpload(_options) {
|
|
149
|
+
throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the createPresignedUpload method.");
|
|
150
|
+
}
|
|
151
|
+
async createPresignedDownload(_options) {
|
|
152
|
+
throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the createPresignedDownload method.");
|
|
153
|
+
}
|
|
154
|
+
getPublicUrl(filePath) {
|
|
155
|
+
const { bucket, region, endpoint } = this.config;
|
|
156
|
+
if (endpoint) {
|
|
157
|
+
return `${endpoint}/${bucket}/${filePath}`;
|
|
158
|
+
}
|
|
159
|
+
return `https://${bucket}.s3.${region}.amazonaws.com/${filePath}`;
|
|
160
|
+
}
|
|
161
|
+
async copy(_sourcePath, _destinationPath) {
|
|
162
|
+
throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the copy method.");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
class InMemoryStorageAdapter {
|
|
167
|
+
provider = "LOCAL";
|
|
168
|
+
files = new Map;
|
|
169
|
+
async upload(options) {
|
|
170
|
+
const content = typeof options.content === "string" ? Buffer.from(options.content, "base64") : options.content;
|
|
171
|
+
const checksum = crypto.createHash("sha256").update(content).digest("hex");
|
|
172
|
+
const metadata = {
|
|
173
|
+
path: options.path,
|
|
174
|
+
size: content.length,
|
|
175
|
+
mimeType: options.mimeType,
|
|
176
|
+
checksum,
|
|
177
|
+
metadata: options.metadata
|
|
178
|
+
};
|
|
179
|
+
this.files.set(options.path, { content, metadata });
|
|
180
|
+
return metadata;
|
|
181
|
+
}
|
|
182
|
+
async download(filePath) {
|
|
183
|
+
const file = this.files.get(filePath);
|
|
184
|
+
if (!file) {
|
|
185
|
+
throw new Error(`File not found: ${filePath}`);
|
|
186
|
+
}
|
|
187
|
+
return file.content;
|
|
188
|
+
}
|
|
189
|
+
async delete(filePath) {
|
|
190
|
+
this.files.delete(filePath);
|
|
191
|
+
}
|
|
192
|
+
async exists(filePath) {
|
|
193
|
+
return this.files.has(filePath);
|
|
194
|
+
}
|
|
195
|
+
async getMetadata(filePath) {
|
|
196
|
+
const file = this.files.get(filePath);
|
|
197
|
+
return file?.metadata || null;
|
|
198
|
+
}
|
|
199
|
+
async list(options) {
|
|
200
|
+
const prefix = options?.prefix || "";
|
|
201
|
+
const files = [];
|
|
202
|
+
for (const [path2, file] of this.files) {
|
|
203
|
+
if (path2.startsWith(prefix)) {
|
|
204
|
+
files.push(file.metadata);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const limit = options?.limit || files.length;
|
|
208
|
+
return {
|
|
209
|
+
files: files.slice(0, limit),
|
|
210
|
+
hasMore: files.length > limit
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
async createPresignedUpload(options) {
|
|
214
|
+
const expiresAt = new Date(Date.now() + (options.expiresIn || 3600) * 1000);
|
|
215
|
+
return {
|
|
216
|
+
url: `/upload?path=${encodeURIComponent(options.path)}`,
|
|
217
|
+
fields: { path: options.path },
|
|
218
|
+
expiresAt
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
async createPresignedDownload(options) {
|
|
222
|
+
const expiresAt = new Date(Date.now() + (options.expiresIn || 3600) * 1000);
|
|
223
|
+
return {
|
|
224
|
+
url: `/download/${options.path}`,
|
|
225
|
+
expiresAt
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
getPublicUrl(filePath) {
|
|
229
|
+
return `/files/${filePath}`;
|
|
230
|
+
}
|
|
231
|
+
async copy(sourcePath, destinationPath) {
|
|
232
|
+
const source = this.files.get(sourcePath);
|
|
233
|
+
if (!source) {
|
|
234
|
+
throw new Error(`Source file not found: ${sourcePath}`);
|
|
235
|
+
}
|
|
236
|
+
const metadata = {
|
|
237
|
+
...source.metadata,
|
|
238
|
+
path: destinationPath
|
|
239
|
+
};
|
|
240
|
+
this.files.set(destinationPath, { content: source.content, metadata });
|
|
241
|
+
return metadata;
|
|
242
|
+
}
|
|
243
|
+
clear() {
|
|
244
|
+
this.files.clear();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function createStorageAdapter(config) {
|
|
248
|
+
switch (config.provider) {
|
|
249
|
+
case "LOCAL":
|
|
250
|
+
if (!config.local) {
|
|
251
|
+
throw new Error("Local storage configuration required");
|
|
252
|
+
}
|
|
253
|
+
return new LocalStorageAdapter(config.local);
|
|
254
|
+
case "S3":
|
|
255
|
+
if (!config.s3) {
|
|
256
|
+
throw new Error("S3 storage configuration required");
|
|
257
|
+
}
|
|
258
|
+
return new S3StorageAdapter(config.s3);
|
|
259
|
+
default:
|
|
260
|
+
throw new Error(`Unsupported storage provider: ${config.provider}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
export {
|
|
264
|
+
createStorageAdapter,
|
|
265
|
+
S3StorageAdapter,
|
|
266
|
+
LocalStorageAdapter,
|
|
267
|
+
InMemoryStorageAdapter
|
|
268
|
+
};
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,151 +1,150 @@
|
|
|
1
|
-
//#region src/storage/index.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* File storage adapters for different backends.
|
|
4
3
|
*/
|
|
5
|
-
type StorageProvider = 'LOCAL' | 'S3' | 'GCS' | 'AZURE' | 'CLOUDFLARE';
|
|
6
|
-
interface StorageFile {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
export type StorageProvider = 'LOCAL' | 'S3' | 'GCS' | 'AZURE' | 'CLOUDFLARE';
|
|
5
|
+
export interface StorageFile {
|
|
6
|
+
path: string;
|
|
7
|
+
size: number;
|
|
8
|
+
mimeType: string;
|
|
9
|
+
checksum?: string;
|
|
10
|
+
etag?: string;
|
|
11
|
+
metadata?: Record<string, string>;
|
|
13
12
|
}
|
|
14
|
-
interface UploadOptions {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
export interface UploadOptions {
|
|
14
|
+
/** Target path in storage */
|
|
15
|
+
path: string;
|
|
16
|
+
/** File content */
|
|
17
|
+
content: Buffer | string;
|
|
18
|
+
/** MIME type */
|
|
19
|
+
mimeType: string;
|
|
20
|
+
/** Additional metadata */
|
|
21
|
+
metadata?: Record<string, string>;
|
|
22
|
+
/** Whether file should be publicly accessible */
|
|
23
|
+
isPublic?: boolean;
|
|
25
24
|
}
|
|
26
|
-
interface PresignedUploadOptions {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
export interface PresignedUploadOptions {
|
|
26
|
+
/** Target path in storage */
|
|
27
|
+
path: string;
|
|
28
|
+
/** MIME type */
|
|
29
|
+
mimeType: string;
|
|
30
|
+
/** File size in bytes */
|
|
31
|
+
size: number;
|
|
32
|
+
/** Expiration time in seconds */
|
|
33
|
+
expiresIn?: number;
|
|
34
|
+
/** Additional conditions */
|
|
35
|
+
conditions?: Record<string, unknown>[];
|
|
37
36
|
}
|
|
38
|
-
interface PresignedDownloadOptions {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
export interface PresignedDownloadOptions {
|
|
38
|
+
/** File path in storage */
|
|
39
|
+
path: string;
|
|
40
|
+
/** Expiration time in seconds */
|
|
41
|
+
expiresIn?: number;
|
|
42
|
+
/** Response content disposition */
|
|
43
|
+
contentDisposition?: string;
|
|
45
44
|
}
|
|
46
|
-
interface PresignedUrl {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
export interface PresignedUrl {
|
|
46
|
+
url: string;
|
|
47
|
+
fields?: Record<string, string>;
|
|
48
|
+
expiresAt: Date;
|
|
50
49
|
}
|
|
51
|
-
interface ListOptions {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
export interface ListOptions {
|
|
51
|
+
/** Path prefix */
|
|
52
|
+
prefix?: string;
|
|
53
|
+
/** Maximum results */
|
|
54
|
+
limit?: number;
|
|
55
|
+
/** Continuation token */
|
|
56
|
+
cursor?: string;
|
|
58
57
|
}
|
|
59
|
-
interface ListResult {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
export interface ListResult {
|
|
59
|
+
files: StorageFile[];
|
|
60
|
+
cursor?: string;
|
|
61
|
+
hasMore: boolean;
|
|
63
62
|
}
|
|
64
|
-
interface StorageAdapter {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
63
|
+
export interface StorageAdapter {
|
|
64
|
+
/** Storage provider type */
|
|
65
|
+
readonly provider: StorageProvider;
|
|
66
|
+
/**
|
|
67
|
+
* Upload a file to storage.
|
|
68
|
+
*/
|
|
69
|
+
upload(options: UploadOptions): Promise<StorageFile>;
|
|
70
|
+
/**
|
|
71
|
+
* Download a file from storage.
|
|
72
|
+
*/
|
|
73
|
+
download(path: string): Promise<Buffer>;
|
|
74
|
+
/**
|
|
75
|
+
* Delete a file from storage.
|
|
76
|
+
*/
|
|
77
|
+
delete(path: string): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Check if a file exists.
|
|
80
|
+
*/
|
|
81
|
+
exists(path: string): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Get file metadata.
|
|
84
|
+
*/
|
|
85
|
+
getMetadata(path: string): Promise<StorageFile | null>;
|
|
86
|
+
/**
|
|
87
|
+
* List files in a directory.
|
|
88
|
+
*/
|
|
89
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Generate a presigned URL for uploading.
|
|
92
|
+
*/
|
|
93
|
+
createPresignedUpload(options: PresignedUploadOptions): Promise<PresignedUrl>;
|
|
94
|
+
/**
|
|
95
|
+
* Generate a presigned URL for downloading.
|
|
96
|
+
*/
|
|
97
|
+
createPresignedDownload(options: PresignedDownloadOptions): Promise<PresignedUrl>;
|
|
98
|
+
/**
|
|
99
|
+
* Get public URL for a file (if applicable).
|
|
100
|
+
*/
|
|
101
|
+
getPublicUrl(path: string): string | null;
|
|
102
|
+
/**
|
|
103
|
+
* Copy a file within storage.
|
|
104
|
+
*/
|
|
105
|
+
copy(sourcePath: string, destinationPath: string): Promise<StorageFile>;
|
|
107
106
|
}
|
|
108
|
-
interface LocalStorageOptions {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
export interface LocalStorageOptions {
|
|
108
|
+
/** Base directory for file storage */
|
|
109
|
+
basePath: string;
|
|
110
|
+
/** Base URL for serving files (optional) */
|
|
111
|
+
baseUrl?: string;
|
|
113
112
|
}
|
|
114
113
|
/**
|
|
115
114
|
* Local filesystem storage adapter.
|
|
116
115
|
* For development and testing purposes.
|
|
117
116
|
*/
|
|
118
|
-
declare class LocalStorageAdapter implements StorageAdapter {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
export declare class LocalStorageAdapter implements StorageAdapter {
|
|
118
|
+
readonly provider: StorageProvider;
|
|
119
|
+
private basePath;
|
|
120
|
+
private baseUrl?;
|
|
121
|
+
constructor(options: LocalStorageOptions);
|
|
122
|
+
upload(options: UploadOptions): Promise<StorageFile>;
|
|
123
|
+
download(filePath: string): Promise<Buffer>;
|
|
124
|
+
delete(filePath: string): Promise<void>;
|
|
125
|
+
exists(filePath: string): Promise<boolean>;
|
|
126
|
+
getMetadata(filePath: string): Promise<StorageFile | null>;
|
|
127
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
128
|
+
createPresignedUpload(options: PresignedUploadOptions): Promise<PresignedUrl>;
|
|
129
|
+
createPresignedDownload(options: PresignedDownloadOptions): Promise<PresignedUrl>;
|
|
130
|
+
getPublicUrl(filePath: string): string | null;
|
|
131
|
+
copy(sourcePath: string, destinationPath: string): Promise<StorageFile>;
|
|
133
132
|
}
|
|
134
|
-
interface S3StorageOptions {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
133
|
+
export interface S3StorageOptions {
|
|
134
|
+
/** S3 bucket name */
|
|
135
|
+
bucket: string;
|
|
136
|
+
/** AWS region */
|
|
137
|
+
region: string;
|
|
138
|
+
/** AWS access key ID */
|
|
139
|
+
accessKeyId?: string;
|
|
140
|
+
/** AWS secret access key */
|
|
141
|
+
secretAccessKey?: string;
|
|
142
|
+
/** Endpoint URL (for S3-compatible services) */
|
|
143
|
+
endpoint?: string;
|
|
144
|
+
/** Force path style (for S3-compatible services) */
|
|
145
|
+
forcePathStyle?: boolean;
|
|
146
|
+
/** Default ACL for uploads */
|
|
147
|
+
defaultAcl?: 'private' | 'public-read';
|
|
149
148
|
}
|
|
150
149
|
/**
|
|
151
150
|
* S3 storage adapter interface.
|
|
@@ -154,48 +153,46 @@ interface S3StorageOptions {
|
|
|
154
153
|
* This is a placeholder that defines the interface.
|
|
155
154
|
* Actual implementation would require @aws-sdk/client-s3 dependency.
|
|
156
155
|
*/
|
|
157
|
-
declare class S3StorageAdapter implements StorageAdapter {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
156
|
+
export declare class S3StorageAdapter implements StorageAdapter {
|
|
157
|
+
readonly provider: StorageProvider;
|
|
158
|
+
private config;
|
|
159
|
+
constructor(options: S3StorageOptions);
|
|
160
|
+
upload(_options: UploadOptions): Promise<StorageFile>;
|
|
161
|
+
download(_filePath: string): Promise<Buffer>;
|
|
162
|
+
delete(_filePath: string): Promise<void>;
|
|
163
|
+
exists(_filePath: string): Promise<boolean>;
|
|
164
|
+
getMetadata(_filePath: string): Promise<StorageFile | null>;
|
|
165
|
+
list(_options?: ListOptions): Promise<ListResult>;
|
|
166
|
+
createPresignedUpload(_options: PresignedUploadOptions): Promise<PresignedUrl>;
|
|
167
|
+
createPresignedDownload(_options: PresignedDownloadOptions): Promise<PresignedUrl>;
|
|
168
|
+
getPublicUrl(filePath: string): string | null;
|
|
169
|
+
copy(_sourcePath: string, _destinationPath: string): Promise<StorageFile>;
|
|
171
170
|
}
|
|
172
171
|
/**
|
|
173
172
|
* In-memory storage adapter for testing.
|
|
174
173
|
*/
|
|
175
|
-
declare class InMemoryStorageAdapter implements StorageAdapter {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
174
|
+
export declare class InMemoryStorageAdapter implements StorageAdapter {
|
|
175
|
+
readonly provider: StorageProvider;
|
|
176
|
+
private files;
|
|
177
|
+
upload(options: UploadOptions): Promise<StorageFile>;
|
|
178
|
+
download(filePath: string): Promise<Buffer>;
|
|
179
|
+
delete(filePath: string): Promise<void>;
|
|
180
|
+
exists(filePath: string): Promise<boolean>;
|
|
181
|
+
getMetadata(filePath: string): Promise<StorageFile | null>;
|
|
182
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
183
|
+
createPresignedUpload(options: PresignedUploadOptions): Promise<PresignedUrl>;
|
|
184
|
+
createPresignedDownload(options: PresignedDownloadOptions): Promise<PresignedUrl>;
|
|
185
|
+
getPublicUrl(filePath: string): string | null;
|
|
186
|
+
copy(sourcePath: string, destinationPath: string): Promise<StorageFile>;
|
|
187
|
+
clear(): void;
|
|
189
188
|
}
|
|
190
|
-
interface StorageConfig {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
export interface StorageConfig {
|
|
190
|
+
provider: StorageProvider;
|
|
191
|
+
local?: LocalStorageOptions;
|
|
192
|
+
s3?: S3StorageOptions;
|
|
194
193
|
}
|
|
195
194
|
/**
|
|
196
195
|
* Create a storage adapter based on configuration.
|
|
197
196
|
*/
|
|
198
|
-
declare function createStorageAdapter(config: StorageConfig): StorageAdapter;
|
|
199
|
-
//#endregion
|
|
200
|
-
export { InMemoryStorageAdapter, ListOptions, ListResult, LocalStorageAdapter, LocalStorageOptions, PresignedDownloadOptions, PresignedUploadOptions, PresignedUrl, S3StorageAdapter, S3StorageOptions, StorageAdapter, StorageConfig, StorageFile, StorageProvider, UploadOptions, createStorageAdapter };
|
|
197
|
+
export declare function createStorageAdapter(config: StorageConfig): StorageAdapter;
|
|
201
198
|
//# sourceMappingURL=index.d.ts.map
|