@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.
Files changed (44) hide show
  1. package/dist/contracts/index.d.ts +1080 -1086
  2. package/dist/contracts/index.d.ts.map +1 -1
  3. package/dist/contracts/index.js +575 -854
  4. package/dist/docs/files.docblock.d.ts +2 -1
  5. package/dist/docs/files.docblock.d.ts.map +1 -0
  6. package/dist/docs/files.docblock.js +17 -22
  7. package/dist/docs/index.d.ts +2 -1
  8. package/dist/docs/index.d.ts.map +1 -0
  9. package/dist/docs/index.js +66 -1
  10. package/dist/entities/index.d.ts +134 -139
  11. package/dist/entities/index.d.ts.map +1 -1
  12. package/dist/entities/index.js +228 -257
  13. package/dist/events.d.ts +357 -363
  14. package/dist/events.d.ts.map +1 -1
  15. package/dist/events.js +217 -400
  16. package/dist/files.capability.d.ts +2 -7
  17. package/dist/files.capability.d.ts.map +1 -1
  18. package/dist/files.capability.js +29 -25
  19. package/dist/files.feature.d.ts +1 -6
  20. package/dist/files.feature.d.ts.map +1 -1
  21. package/dist/files.feature.js +50 -131
  22. package/dist/index.d.ts +7 -6
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +1411 -8
  25. package/dist/node/contracts/index.js +576 -0
  26. package/dist/node/docs/files.docblock.js +65 -0
  27. package/dist/node/docs/index.js +65 -0
  28. package/dist/node/entities/index.js +235 -0
  29. package/dist/node/events.js +219 -0
  30. package/dist/node/files.capability.js +28 -0
  31. package/dist/node/files.feature.js +51 -0
  32. package/dist/node/index.js +1410 -0
  33. package/dist/node/storage/index.js +268 -0
  34. package/dist/storage/index.d.ts +163 -166
  35. package/dist/storage/index.d.ts.map +1 -1
  36. package/dist/storage/index.js +266 -266
  37. package/package.json +104 -30
  38. package/dist/contracts/index.js.map +0 -1
  39. package/dist/docs/files.docblock.js.map +0 -1
  40. package/dist/entities/index.js.map +0 -1
  41. package/dist/events.js.map +0 -1
  42. package/dist/files.capability.js.map +0 -1
  43. package/dist/files.feature.js.map +0 -1
  44. package/dist/storage/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/storage/index.ts"],"mappings":";;AAMA;;KAAY,eAAA;AAAA,UAEK,WAAA;EACf,IAAA;EACA,IAAA;EACA,QAAA;EACA,QAAA;EACA,IAAA;EACA,QAAA,GAAW,MAAA;AAAA;AAAA,UAGI,aAAA;EALf;EAOA,IAAA;EALA;EAOA,OAAA,EAAS,MAAA;EAPQ;EASjB,QAAA;EANe;EAQf,QAAA,GAAW,MAAA;;EAEX,QAAA;AAAA;AAAA,UAGe,sBAAA;EATN;EAWT,IAAA;EAPA;EASA,QAAA;EAPA;EASA,IAAA;EATQ;EAWR,SAAA;EARqC;EAUrC,UAAA,GAAa,MAAA;AAAA;AAAA,UAGE,wBAAA;EATf;EAWA,IAAA;EAPA;EASA,SAAA;EAPa;EASb,kBAAA;AAAA;AAAA,UAGe,YAAA;EACf,GAAA;EACA,MAAA,GAAS,MAAA;EACT,SAAA,EAAW,IAAA;AAAA;AAAA,UAGI,WAAA;EATf;EAWA,MAAA;EAXkB;EAalB,KAAA;EAV2B;EAY3B,MAAA;AAAA;AAAA,UAGe,UAAA;EACf,KAAA,EAAO,WAAA;EACP,MAAA;EACA,OAAA;AAAA;AAAA,UAKe,cAAA;EApBA;EAAA,SAsBN,QAAA,EAAU,eAAA;EAnBO;;;EAwB1B,MAAA,CAAO,OAAA,EAAS,aAAA,GAAgB,OAAA,CAAQ,WAAA;EApBxC;;;EAyBA,QAAA,CAAS,IAAA,WAAe,OAAA,CAAQ,MAAA;EApBjB;;;EAyBf,MAAA,CAAO,IAAA,WAAe,OAAA;EAxBtB;;;EA6BA,MAAA,CAAO,IAAA,WAAe,OAAA;EA3Bf;;AAKT;EA2BE,WAAA,CAAY,IAAA,WAAe,OAAA,CAAQ,WAAA;;;;EAKnC,IAAA,CAAK,OAAA,GAAU,WAAA,GAAc,OAA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vB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc,CAiB1E"}
@@ -1,269 +1,269 @@
1
- import * as fs from "node:fs/promises";
2
- import * as path from "node:path";
3
- import * as crypto from "node:crypto";
1
+ // @bun
2
+ // src/storage/index.ts
3
+ import * as fs from "fs/promises";
4
+ import * as path from "path";
5
+ import * as crypto from "crypto";
4
6
 
5
- //#region src/storage/index.ts
6
- /**
7
- * Local filesystem storage adapter.
8
- * For development and testing purposes.
9
- */
10
- var LocalStorageAdapter = class {
11
- provider = "LOCAL";
12
- basePath;
13
- baseUrl;
14
- constructor(options) {
15
- this.basePath = options.basePath;
16
- this.baseUrl = options.baseUrl;
17
- }
18
- async upload(options) {
19
- const fullPath = path.join(this.basePath, options.path);
20
- const dir = path.dirname(fullPath);
21
- await fs.mkdir(dir, { recursive: true });
22
- const content = typeof options.content === "string" ? Buffer.from(options.content, "base64") : options.content;
23
- await fs.writeFile(fullPath, content);
24
- const checksum = crypto.createHash("sha256").update(content).digest("hex");
25
- return {
26
- path: options.path,
27
- size: content.length,
28
- mimeType: options.mimeType,
29
- checksum,
30
- metadata: options.metadata
31
- };
32
- }
33
- async download(filePath) {
34
- const fullPath = path.join(this.basePath, filePath);
35
- return fs.readFile(fullPath);
36
- }
37
- async delete(filePath) {
38
- const fullPath = path.join(this.basePath, filePath);
39
- await fs.unlink(fullPath);
40
- }
41
- async exists(filePath) {
42
- const fullPath = path.join(this.basePath, filePath);
43
- try {
44
- await fs.access(fullPath);
45
- return true;
46
- } catch {
47
- return false;
48
- }
49
- }
50
- async getMetadata(filePath) {
51
- const fullPath = path.join(this.basePath, filePath);
52
- try {
53
- return {
54
- path: filePath,
55
- size: (await fs.stat(fullPath)).size,
56
- mimeType: "application/octet-stream"
57
- };
58
- } catch {
59
- return null;
60
- }
61
- }
62
- async list(options) {
63
- const dir = options?.prefix ? path.join(this.basePath, options.prefix) : this.basePath;
64
- try {
65
- const entries = await fs.readdir(dir, { withFileTypes: true });
66
- const files = [];
67
- for (const entry of entries) if (entry.isFile()) {
68
- const filePath = options?.prefix ? path.join(options.prefix, entry.name) : entry.name;
69
- const stat = await fs.stat(path.join(dir, entry.name));
70
- files.push({
71
- path: filePath,
72
- size: stat.size,
73
- mimeType: "application/octet-stream"
74
- });
75
- }
76
- const limit = options?.limit || files.length;
77
- return {
78
- files: files.slice(0, limit),
79
- hasMore: files.length > limit
80
- };
81
- } catch {
82
- return {
83
- files: [],
84
- hasMore: false
85
- };
86
- }
87
- }
88
- async createPresignedUpload(options) {
89
- const expiresIn = options.expiresIn || 3600;
90
- const expiresAt = new Date(Date.now() + expiresIn * 1e3);
91
- return {
92
- url: this.baseUrl ? `${this.baseUrl}/upload?path=${encodeURIComponent(options.path)}` : `/upload?path=${encodeURIComponent(options.path)}`,
93
- fields: {
94
- path: options.path,
95
- mimeType: options.mimeType
96
- },
97
- expiresAt
98
- };
99
- }
100
- async createPresignedDownload(options) {
101
- const expiresIn = options.expiresIn || 3600;
102
- const expiresAt = new Date(Date.now() + expiresIn * 1e3);
103
- return {
104
- url: this.baseUrl ? `${this.baseUrl}/download/${options.path}` : `/download/${options.path}`,
105
- expiresAt
106
- };
107
- }
108
- getPublicUrl(filePath) {
109
- if (!this.baseUrl) return null;
110
- return `${this.baseUrl}/${filePath}`;
111
- }
112
- async copy(sourcePath, destinationPath) {
113
- const sourceFullPath = path.join(this.basePath, sourcePath);
114
- const destFullPath = path.join(this.basePath, destinationPath);
115
- const destDir = path.dirname(destFullPath);
116
- await fs.mkdir(destDir, { recursive: true });
117
- await fs.copyFile(sourceFullPath, destFullPath);
118
- return {
119
- path: destinationPath,
120
- size: (await fs.stat(destFullPath)).size,
121
- mimeType: "application/octet-stream"
122
- };
123
- }
124
- };
125
- /**
126
- * S3 storage adapter interface.
127
- * Implementation would use AWS SDK or compatible client.
128
- *
129
- * This is a placeholder that defines the interface.
130
- * Actual implementation would require @aws-sdk/client-s3 dependency.
131
- */
132
- var S3StorageAdapter = class {
133
- provider = "S3";
134
- config;
135
- constructor(options) {
136
- this.config = options;
137
- }
138
- async upload(_options) {
139
- throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the upload method.");
140
- }
141
- async download(_filePath) {
142
- throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the download method.");
143
- }
144
- async delete(_filePath) {
145
- throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the delete method.");
146
- }
147
- async exists(_filePath) {
148
- throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the exists method.");
149
- }
150
- async getMetadata(_filePath) {
151
- throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the getMetadata method.");
152
- }
153
- async list(_options) {
154
- throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the list method.");
155
- }
156
- async createPresignedUpload(_options) {
157
- throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the createPresignedUpload method.");
158
- }
159
- async createPresignedDownload(_options) {
160
- throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the createPresignedDownload method.");
161
- }
162
- getPublicUrl(filePath) {
163
- const { bucket, region, endpoint } = this.config;
164
- if (endpoint) return `${endpoint}/${bucket}/${filePath}`;
165
- return `https://${bucket}.s3.${region}.amazonaws.com/${filePath}`;
166
- }
167
- async copy(_sourcePath, _destinationPath) {
168
- throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the copy method.");
169
- }
170
- };
171
- /**
172
- * In-memory storage adapter for testing.
173
- */
174
- var InMemoryStorageAdapter = class {
175
- provider = "LOCAL";
176
- files = /* @__PURE__ */ new Map();
177
- async upload(options) {
178
- const content = typeof options.content === "string" ? Buffer.from(options.content, "base64") : options.content;
179
- const checksum = crypto.createHash("sha256").update(content).digest("hex");
180
- const metadata = {
181
- path: options.path,
182
- size: content.length,
183
- mimeType: options.mimeType,
184
- checksum,
185
- metadata: options.metadata
186
- };
187
- this.files.set(options.path, {
188
- content,
189
- metadata
190
- });
191
- return metadata;
192
- }
193
- async download(filePath) {
194
- const file = this.files.get(filePath);
195
- if (!file) throw new Error(`File not found: ${filePath}`);
196
- return file.content;
197
- }
198
- async delete(filePath) {
199
- this.files.delete(filePath);
200
- }
201
- async exists(filePath) {
202
- return this.files.has(filePath);
203
- }
204
- async getMetadata(filePath) {
205
- return this.files.get(filePath)?.metadata || null;
206
- }
207
- async list(options) {
208
- const prefix = options?.prefix || "";
209
- const files = [];
210
- for (const [path, file] of this.files) if (path.startsWith(prefix)) files.push(file.metadata);
211
- const limit = options?.limit || files.length;
212
- return {
213
- files: files.slice(0, limit),
214
- hasMore: files.length > limit
215
- };
216
- }
217
- async createPresignedUpload(options) {
218
- const expiresAt = new Date(Date.now() + (options.expiresIn || 3600) * 1e3);
219
- return {
220
- url: `/upload?path=${encodeURIComponent(options.path)}`,
221
- fields: { path: options.path },
222
- expiresAt
223
- };
224
- }
225
- async createPresignedDownload(options) {
226
- const expiresAt = new Date(Date.now() + (options.expiresIn || 3600) * 1e3);
227
- return {
228
- url: `/download/${options.path}`,
229
- expiresAt
230
- };
231
- }
232
- getPublicUrl(filePath) {
233
- return `/files/${filePath}`;
234
- }
235
- async copy(sourcePath, destinationPath) {
236
- const source = this.files.get(sourcePath);
237
- if (!source) throw new Error(`Source file not found: ${sourcePath}`);
238
- const metadata = {
239
- ...source.metadata,
240
- path: destinationPath
241
- };
242
- this.files.set(destinationPath, {
243
- content: source.content,
244
- metadata
245
- });
246
- return metadata;
247
- }
248
- clear() {
249
- this.files.clear();
250
- }
251
- };
252
- /**
253
- * Create a storage adapter based on configuration.
254
- */
255
- function createStorageAdapter(config) {
256
- switch (config.provider) {
257
- case "LOCAL":
258
- if (!config.local) throw new Error("Local storage configuration required");
259
- return new LocalStorageAdapter(config.local);
260
- case "S3":
261
- if (!config.s3) throw new Error("S3 storage configuration required");
262
- return new S3StorageAdapter(config.s3);
263
- default: throw new Error(`Unsupported storage provider: ${config.provider}`);
264
- }
7
+ class LocalStorageAdapter {
8
+ provider = "LOCAL";
9
+ basePath;
10
+ baseUrl;
11
+ constructor(options) {
12
+ this.basePath = options.basePath;
13
+ this.baseUrl = options.baseUrl;
14
+ }
15
+ async upload(options) {
16
+ const fullPath = path.join(this.basePath, options.path);
17
+ const dir = path.dirname(fullPath);
18
+ await fs.mkdir(dir, { recursive: true });
19
+ const content = typeof options.content === "string" ? Buffer.from(options.content, "base64") : options.content;
20
+ await fs.writeFile(fullPath, content);
21
+ const checksum = crypto.createHash("sha256").update(content).digest("hex");
22
+ return {
23
+ path: options.path,
24
+ size: content.length,
25
+ mimeType: options.mimeType,
26
+ checksum,
27
+ metadata: options.metadata
28
+ };
29
+ }
30
+ async download(filePath) {
31
+ const fullPath = path.join(this.basePath, filePath);
32
+ return fs.readFile(fullPath);
33
+ }
34
+ async delete(filePath) {
35
+ const fullPath = path.join(this.basePath, filePath);
36
+ await fs.unlink(fullPath);
37
+ }
38
+ async exists(filePath) {
39
+ const fullPath = path.join(this.basePath, filePath);
40
+ try {
41
+ await fs.access(fullPath);
42
+ return true;
43
+ } catch {
44
+ return false;
45
+ }
46
+ }
47
+ async getMetadata(filePath) {
48
+ const fullPath = path.join(this.basePath, filePath);
49
+ try {
50
+ const stat2 = await fs.stat(fullPath);
51
+ return {
52
+ path: filePath,
53
+ size: stat2.size,
54
+ mimeType: "application/octet-stream"
55
+ };
56
+ } catch {
57
+ return null;
58
+ }
59
+ }
60
+ async list(options) {
61
+ const dir = options?.prefix ? path.join(this.basePath, options.prefix) : this.basePath;
62
+ try {
63
+ const entries = await fs.readdir(dir, { withFileTypes: true });
64
+ const files = [];
65
+ for (const entry of entries) {
66
+ if (entry.isFile()) {
67
+ const filePath = options?.prefix ? path.join(options.prefix, entry.name) : entry.name;
68
+ const stat2 = await fs.stat(path.join(dir, entry.name));
69
+ files.push({
70
+ path: filePath,
71
+ size: stat2.size,
72
+ mimeType: "application/octet-stream"
73
+ });
74
+ }
75
+ }
76
+ const limit = options?.limit || files.length;
77
+ return {
78
+ files: files.slice(0, limit),
79
+ hasMore: files.length > limit
80
+ };
81
+ } catch {
82
+ return { files: [], hasMore: false };
83
+ }
84
+ }
85
+ async createPresignedUpload(options) {
86
+ const expiresIn = options.expiresIn || 3600;
87
+ const expiresAt = new Date(Date.now() + expiresIn * 1000);
88
+ return {
89
+ url: this.baseUrl ? `${this.baseUrl}/upload?path=${encodeURIComponent(options.path)}` : `/upload?path=${encodeURIComponent(options.path)}`,
90
+ fields: {
91
+ path: options.path,
92
+ mimeType: options.mimeType
93
+ },
94
+ expiresAt
95
+ };
96
+ }
97
+ async createPresignedDownload(options) {
98
+ const expiresIn = options.expiresIn || 3600;
99
+ const expiresAt = new Date(Date.now() + expiresIn * 1000);
100
+ return {
101
+ url: this.baseUrl ? `${this.baseUrl}/download/${options.path}` : `/download/${options.path}`,
102
+ expiresAt
103
+ };
104
+ }
105
+ getPublicUrl(filePath) {
106
+ if (!this.baseUrl)
107
+ return null;
108
+ return `${this.baseUrl}/${filePath}`;
109
+ }
110
+ async copy(sourcePath, destinationPath) {
111
+ const sourceFullPath = path.join(this.basePath, sourcePath);
112
+ const destFullPath = path.join(this.basePath, destinationPath);
113
+ const destDir = path.dirname(destFullPath);
114
+ await fs.mkdir(destDir, { recursive: true });
115
+ await fs.copyFile(sourceFullPath, destFullPath);
116
+ const stat2 = await fs.stat(destFullPath);
117
+ return {
118
+ path: destinationPath,
119
+ size: stat2.size,
120
+ mimeType: "application/octet-stream"
121
+ };
122
+ }
123
+ }
124
+
125
+ class S3StorageAdapter {
126
+ provider = "S3";
127
+ config;
128
+ constructor(options) {
129
+ this.config = options;
130
+ }
131
+ async upload(_options) {
132
+ throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the upload method.");
133
+ }
134
+ async download(_filePath) {
135
+ throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the download method.");
136
+ }
137
+ async delete(_filePath) {
138
+ throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the delete method.");
139
+ }
140
+ async exists(_filePath) {
141
+ throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the exists method.");
142
+ }
143
+ async getMetadata(_filePath) {
144
+ throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the getMetadata method.");
145
+ }
146
+ async list(_options) {
147
+ throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the list method.");
148
+ }
149
+ async createPresignedUpload(_options) {
150
+ throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the createPresignedUpload method.");
151
+ }
152
+ async createPresignedDownload(_options) {
153
+ throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the createPresignedDownload method.");
154
+ }
155
+ getPublicUrl(filePath) {
156
+ const { bucket, region, endpoint } = this.config;
157
+ if (endpoint) {
158
+ return `${endpoint}/${bucket}/${filePath}`;
159
+ }
160
+ return `https://${bucket}.s3.${region}.amazonaws.com/${filePath}`;
161
+ }
162
+ async copy(_sourcePath, _destinationPath) {
163
+ throw new Error("S3 adapter requires @aws-sdk/client-s3. Install it and implement the copy method.");
164
+ }
265
165
  }
266
166
 
267
- //#endregion
268
- export { InMemoryStorageAdapter, LocalStorageAdapter, S3StorageAdapter, createStorageAdapter };
269
- //# sourceMappingURL=index.js.map
167
+ class InMemoryStorageAdapter {
168
+ provider = "LOCAL";
169
+ files = new Map;
170
+ async upload(options) {
171
+ const content = typeof options.content === "string" ? Buffer.from(options.content, "base64") : options.content;
172
+ const checksum = crypto.createHash("sha256").update(content).digest("hex");
173
+ const metadata = {
174
+ path: options.path,
175
+ size: content.length,
176
+ mimeType: options.mimeType,
177
+ checksum,
178
+ metadata: options.metadata
179
+ };
180
+ this.files.set(options.path, { content, metadata });
181
+ return metadata;
182
+ }
183
+ async download(filePath) {
184
+ const file = this.files.get(filePath);
185
+ if (!file) {
186
+ throw new Error(`File not found: ${filePath}`);
187
+ }
188
+ return file.content;
189
+ }
190
+ async delete(filePath) {
191
+ this.files.delete(filePath);
192
+ }
193
+ async exists(filePath) {
194
+ return this.files.has(filePath);
195
+ }
196
+ async getMetadata(filePath) {
197
+ const file = this.files.get(filePath);
198
+ return file?.metadata || null;
199
+ }
200
+ async list(options) {
201
+ const prefix = options?.prefix || "";
202
+ const files = [];
203
+ for (const [path2, file] of this.files) {
204
+ if (path2.startsWith(prefix)) {
205
+ files.push(file.metadata);
206
+ }
207
+ }
208
+ const limit = options?.limit || files.length;
209
+ return {
210
+ files: files.slice(0, limit),
211
+ hasMore: files.length > limit
212
+ };
213
+ }
214
+ async createPresignedUpload(options) {
215
+ const expiresAt = new Date(Date.now() + (options.expiresIn || 3600) * 1000);
216
+ return {
217
+ url: `/upload?path=${encodeURIComponent(options.path)}`,
218
+ fields: { path: options.path },
219
+ expiresAt
220
+ };
221
+ }
222
+ async createPresignedDownload(options) {
223
+ const expiresAt = new Date(Date.now() + (options.expiresIn || 3600) * 1000);
224
+ return {
225
+ url: `/download/${options.path}`,
226
+ expiresAt
227
+ };
228
+ }
229
+ getPublicUrl(filePath) {
230
+ return `/files/${filePath}`;
231
+ }
232
+ async copy(sourcePath, destinationPath) {
233
+ const source = this.files.get(sourcePath);
234
+ if (!source) {
235
+ throw new Error(`Source file not found: ${sourcePath}`);
236
+ }
237
+ const metadata = {
238
+ ...source.metadata,
239
+ path: destinationPath
240
+ };
241
+ this.files.set(destinationPath, { content: source.content, metadata });
242
+ return metadata;
243
+ }
244
+ clear() {
245
+ this.files.clear();
246
+ }
247
+ }
248
+ function createStorageAdapter(config) {
249
+ switch (config.provider) {
250
+ case "LOCAL":
251
+ if (!config.local) {
252
+ throw new Error("Local storage configuration required");
253
+ }
254
+ return new LocalStorageAdapter(config.local);
255
+ case "S3":
256
+ if (!config.s3) {
257
+ throw new Error("S3 storage configuration required");
258
+ }
259
+ return new S3StorageAdapter(config.s3);
260
+ default:
261
+ throw new Error(`Unsupported storage provider: ${config.provider}`);
262
+ }
263
+ }
264
+ export {
265
+ createStorageAdapter,
266
+ S3StorageAdapter,
267
+ LocalStorageAdapter,
268
+ InMemoryStorageAdapter
269
+ };