@vercube/storage 0.0.15 → 0.0.17
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/Drivers/MemoryStorage.d.mts +62 -0
- package/dist/Drivers/MemoryStorage.mjs +74 -0
- package/dist/Drivers/S3Storage.d.mts +87 -0
- package/dist/Drivers/S3Storage.mjs +34366 -0
- package/dist/Storage-DZ-jzAK_.d.mts +67 -0
- package/dist/chunk-UoOzN6Vc.mjs +40 -0
- package/dist/index.d.mts +2 -210
- package/dist/index.mjs +13 -34486
- package/package.json +11 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region src/Service/Storage.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for storage implementations
|
|
4
|
+
* Provides a common interface for different storage providers
|
|
5
|
+
*
|
|
6
|
+
* @abstract
|
|
7
|
+
* @class Storage
|
|
8
|
+
* @description
|
|
9
|
+
* The Storage class defines a standard interface for storing and retrieving data.
|
|
10
|
+
* It supports basic operations like get, set, delete, and querying storage state.
|
|
11
|
+
* Concrete implementations must provide the actual storage mechanism.
|
|
12
|
+
*/
|
|
13
|
+
declare abstract class Storage<T = undefined> {
|
|
14
|
+
/**
|
|
15
|
+
* Initializes the storage implementation.
|
|
16
|
+
* Must be called before using any other storage operations.
|
|
17
|
+
*
|
|
18
|
+
* @param {T} options - Initialization parameters. May be omitted if not required by the storage implementation.
|
|
19
|
+
* @returns {Promise<void>} A promise that resolves when initialization is complete.
|
|
20
|
+
*/
|
|
21
|
+
abstract initialize(options: T): void | Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves a value from storage by its key
|
|
24
|
+
* @template T - The type of the stored value
|
|
25
|
+
* @param {string} key - The key to retrieve the value for
|
|
26
|
+
* @returns {Promise<T>} A promise that resolves with the stored value
|
|
27
|
+
*/
|
|
28
|
+
abstract getItem<T = unknown>(key: string): T | Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Stores a value in storage with the specified key
|
|
31
|
+
* @template T - The type of the value to store
|
|
32
|
+
* @template U - The type of the optional options object
|
|
33
|
+
* @param {string} key - The key under which to store the value
|
|
34
|
+
* @param {T} value - The value to store
|
|
35
|
+
* @returns {Promise<void>} A promise that resolves when the value is stored
|
|
36
|
+
*/
|
|
37
|
+
abstract setItem<T = unknown, U = unknown>(key: string, value: T, options?: U): void | Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Removes a value from storage by its key
|
|
40
|
+
* @param {string} key - The key of the value to delete
|
|
41
|
+
* @returns {Promise<void>} A promise that resolves when the value is deleted
|
|
42
|
+
*/
|
|
43
|
+
abstract deleteItem(key: string): void | Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Checks if a value exists in storage for the given key
|
|
46
|
+
* @param {string} key - The key to check
|
|
47
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the key exists, false otherwise
|
|
48
|
+
*/
|
|
49
|
+
abstract hasItem(key: string): boolean | Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves all keys currently stored in storage
|
|
52
|
+
* @returns {Promise<string[]>} A promise that resolves with an array of all stored keys
|
|
53
|
+
*/
|
|
54
|
+
abstract getKeys(): string[] | Promise<string[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Removes all stored values from storage
|
|
57
|
+
* @returns {Promise<void>} A promise that resolves when all values are cleared
|
|
58
|
+
*/
|
|
59
|
+
abstract clear(): void | Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the number of key-value pairs stored in storage
|
|
62
|
+
* @returns {Promise<number>} A promise that resolves with the number of stored items
|
|
63
|
+
*/
|
|
64
|
+
abstract size(): number | Promise<number>;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { Storage };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __esm = (fn, res) => function() {
|
|
11
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
|
+
};
|
|
13
|
+
var __commonJS = (cb, mod) => function() {
|
|
14
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
|
+
};
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all) __defProp(target, name, {
|
|
18
|
+
get: all[name],
|
|
19
|
+
enumerable: true
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __copyProps = (to, from, except, desc) => {
|
|
23
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
24
|
+
key = keys[i];
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
26
|
+
get: ((k) => from[k]).bind(null, key),
|
|
27
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
33
|
+
value: mod,
|
|
34
|
+
enumerable: true
|
|
35
|
+
}) : target, mod));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { __commonJS, __esm, __export, __require, __toCommonJS, __toESM };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,73 +1,6 @@
|
|
|
1
|
+
import { Storage } from "./Storage-DZ-jzAK_.mjs";
|
|
1
2
|
import { IOC } from "@vercube/di";
|
|
2
|
-
import { S3ClientConfig } from "@aws-sdk/client-s3";
|
|
3
3
|
|
|
4
|
-
//#region src/Service/Storage.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Abstract base class for storage implementations
|
|
8
|
-
* Provides a common interface for different storage providers
|
|
9
|
-
*
|
|
10
|
-
* @abstract
|
|
11
|
-
* @class Storage
|
|
12
|
-
* @description
|
|
13
|
-
* The Storage class defines a standard interface for storing and retrieving data.
|
|
14
|
-
* It supports basic operations like get, set, delete, and querying storage state.
|
|
15
|
-
* Concrete implementations must provide the actual storage mechanism.
|
|
16
|
-
*/
|
|
17
|
-
declare abstract class Storage<T = undefined> {
|
|
18
|
-
/**
|
|
19
|
-
* Initializes the storage implementation.
|
|
20
|
-
* Must be called before using any other storage operations.
|
|
21
|
-
*
|
|
22
|
-
* @param {T} options - Initialization parameters. May be omitted if not required by the storage implementation.
|
|
23
|
-
* @returns {Promise<void>} A promise that resolves when initialization is complete.
|
|
24
|
-
*/
|
|
25
|
-
abstract initialize(options: T): void | Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Retrieves a value from storage by its key
|
|
28
|
-
* @template T - The type of the stored value
|
|
29
|
-
* @param {string} key - The key to retrieve the value for
|
|
30
|
-
* @returns {Promise<T>} A promise that resolves with the stored value
|
|
31
|
-
*/
|
|
32
|
-
abstract getItem<T = unknown>(key: string): T | Promise<T>;
|
|
33
|
-
/**
|
|
34
|
-
* Stores a value in storage with the specified key
|
|
35
|
-
* @template T - The type of the value to store
|
|
36
|
-
* @template U - The type of the optional options object
|
|
37
|
-
* @param {string} key - The key under which to store the value
|
|
38
|
-
* @param {T} value - The value to store
|
|
39
|
-
* @returns {Promise<void>} A promise that resolves when the value is stored
|
|
40
|
-
*/
|
|
41
|
-
abstract setItem<T = unknown, U = unknown>(key: string, value: T, options?: U): void | Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Removes a value from storage by its key
|
|
44
|
-
* @param {string} key - The key of the value to delete
|
|
45
|
-
* @returns {Promise<void>} A promise that resolves when the value is deleted
|
|
46
|
-
*/
|
|
47
|
-
abstract deleteItem(key: string): void | Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* Checks if a value exists in storage for the given key
|
|
50
|
-
* @param {string} key - The key to check
|
|
51
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the key exists, false otherwise
|
|
52
|
-
*/
|
|
53
|
-
abstract hasItem(key: string): boolean | Promise<boolean>;
|
|
54
|
-
/**
|
|
55
|
-
* Retrieves all keys currently stored in storage
|
|
56
|
-
* @returns {Promise<string[]>} A promise that resolves with an array of all stored keys
|
|
57
|
-
*/
|
|
58
|
-
abstract getKeys(): string[] | Promise<string[]>;
|
|
59
|
-
/**
|
|
60
|
-
* Removes all stored values from storage
|
|
61
|
-
* @returns {Promise<void>} A promise that resolves when all values are cleared
|
|
62
|
-
*/
|
|
63
|
-
abstract clear(): void | Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Gets the number of key-value pairs stored in storage
|
|
66
|
-
* @returns {Promise<number>} A promise that resolves with the number of stored items
|
|
67
|
-
*/
|
|
68
|
-
abstract size(): number | Promise<number>;
|
|
69
|
-
}
|
|
70
|
-
//#endregion
|
|
71
4
|
//#region src/Types/StorageTypes.d.ts
|
|
72
5
|
declare namespace StorageTypes {
|
|
73
6
|
interface BaseOptions {
|
|
@@ -102,9 +35,6 @@ declare namespace StorageTypes {
|
|
|
102
35
|
interface GetKeys extends BaseOptions {}
|
|
103
36
|
interface Clear extends BaseOptions {}
|
|
104
37
|
interface Size extends BaseOptions {}
|
|
105
|
-
interface S3BaseOptions extends S3ClientConfig {
|
|
106
|
-
bucket: string;
|
|
107
|
-
}
|
|
108
38
|
}
|
|
109
39
|
//#endregion
|
|
110
40
|
//#region src/Service/StorageManager.d.ts
|
|
@@ -222,142 +152,4 @@ declare class StorageManager {
|
|
|
222
152
|
private init;
|
|
223
153
|
}
|
|
224
154
|
//#endregion
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* In-memory storage implementation of the Storage interface
|
|
228
|
-
* Provides a simple key-value store that persists only for the duration of the application runtime
|
|
229
|
-
* Useful for testing, caching, and scenarios where temporary storage is needed
|
|
230
|
-
*
|
|
231
|
-
* @implements {Storage}
|
|
232
|
-
*/
|
|
233
|
-
declare class MemoryStorage implements Storage {
|
|
234
|
-
/** Internal storage map to hold key-value pairs */
|
|
235
|
-
private storage;
|
|
236
|
-
/**
|
|
237
|
-
* Initializes the memory storage
|
|
238
|
-
* No initialization is needed for in-memory storage as the Map is created on instantiation
|
|
239
|
-
*/
|
|
240
|
-
initialize(): void;
|
|
241
|
-
/**
|
|
242
|
-
* Retrieves a value from memory storage by its key
|
|
243
|
-
* @template T - Type of the stored value
|
|
244
|
-
* @param {string} key - The key to retrieve the value for
|
|
245
|
-
* @returns {T} The stored value cast to type T
|
|
246
|
-
*/
|
|
247
|
-
getItem<T = unknown>(key: string): T;
|
|
248
|
-
/**
|
|
249
|
-
* Stores a value in memory storage with the specified key
|
|
250
|
-
* @template T - Type of the value to store
|
|
251
|
-
* @template U - Type of the options object
|
|
252
|
-
* @param {string} key - The key under which to store the value
|
|
253
|
-
* @param {T} value - The value to store
|
|
254
|
-
*/
|
|
255
|
-
setItem<T = unknown, U = unknown>(key: string, value: T, options?: U): void;
|
|
256
|
-
/**
|
|
257
|
-
* Removes a value from memory storage by its key
|
|
258
|
-
* @param {string} key - The key of the value to delete
|
|
259
|
-
*/
|
|
260
|
-
deleteItem(key: string): void;
|
|
261
|
-
/**
|
|
262
|
-
* Checks if a value exists in memory storage for the given key
|
|
263
|
-
* @param {string} key - The key to check
|
|
264
|
-
* @returns {boolean} True if the key exists, false otherwise
|
|
265
|
-
*/
|
|
266
|
-
hasItem(key: string): boolean;
|
|
267
|
-
/**
|
|
268
|
-
* Retrieves all keys currently stored in memory storage
|
|
269
|
-
* @returns {string[]} Array of all stored keys
|
|
270
|
-
*/
|
|
271
|
-
getKeys(): string[];
|
|
272
|
-
/**
|
|
273
|
-
* Removes all stored values from memory storage
|
|
274
|
-
*/
|
|
275
|
-
clear(): void;
|
|
276
|
-
/**
|
|
277
|
-
* Gets the number of key-value pairs stored in memory storage
|
|
278
|
-
* @returns {number} The number of stored items
|
|
279
|
-
*/
|
|
280
|
-
size(): number;
|
|
281
|
-
}
|
|
282
|
-
//#endregion
|
|
283
|
-
//#region src/Storages/S3Storage.d.ts
|
|
284
|
-
/**
|
|
285
|
-
* S3 storage implementation of the Storage interface.
|
|
286
|
-
* Provides key-value operations backed by AWS S3.
|
|
287
|
-
*
|
|
288
|
-
* @implements {Storage}
|
|
289
|
-
*/
|
|
290
|
-
declare class S3Storage implements Storage<StorageTypes.S3BaseOptions> {
|
|
291
|
-
private s3;
|
|
292
|
-
private bucket;
|
|
293
|
-
/**
|
|
294
|
-
* Initializes the S3 storage client.
|
|
295
|
-
*
|
|
296
|
-
* @param {StorageTypes.S3BaseOptions} options - Configuration options for the S3 client.
|
|
297
|
-
* @returns {Promise<void>} A promise that resolves when initialization is complete.
|
|
298
|
-
*/
|
|
299
|
-
initialize(options: StorageTypes.S3BaseOptions): Promise<void>;
|
|
300
|
-
/**
|
|
301
|
-
* Retrieves and parses a value from S3 storage by its key.
|
|
302
|
-
*
|
|
303
|
-
* @template T
|
|
304
|
-
* @param {string} key - The key whose value should be retrieved.
|
|
305
|
-
* @returns {Promise<T | undefined>} The stored value parsed as type T, or undefined if the key does not exist.
|
|
306
|
-
* @throws Will rethrow any S3 error except for missing key (`NoSuchKey`).
|
|
307
|
-
*/
|
|
308
|
-
getItem<T = unknown>(key: string): Promise<T>;
|
|
309
|
-
/**
|
|
310
|
-
* Stores a value in S3 storage under the specified key.
|
|
311
|
-
*
|
|
312
|
-
* @template T
|
|
313
|
-
* @template U
|
|
314
|
-
* @param {string} key - The key under which to store the value.
|
|
315
|
-
* @param {T} value - The value to store (will be JSON serialized).
|
|
316
|
-
* @param {U} [options] - Additional options (currently unused).
|
|
317
|
-
* @returns {Promise<void>} A promise that resolves when the value has been stored.
|
|
318
|
-
*/
|
|
319
|
-
setItem<T = unknown, U = unknown>(key: string, value: T, options?: U): Promise<void>;
|
|
320
|
-
/**
|
|
321
|
-
* Removes an item from S3 storage by its key.
|
|
322
|
-
*
|
|
323
|
-
* @param {string} key - The key of the item to delete.
|
|
324
|
-
* @returns {Promise<void>} A promise that resolves when the item has been deleted.
|
|
325
|
-
*/
|
|
326
|
-
deleteItem(key: string): Promise<void>;
|
|
327
|
-
/**
|
|
328
|
-
* Checks if a key exists in S3 storage.
|
|
329
|
-
*
|
|
330
|
-
* @param {string} key - The key to check.
|
|
331
|
-
* @returns {Promise<boolean>} True if the key exists, false otherwise.
|
|
332
|
-
* @throws Will rethrow any S3 error except for missing key (`NoSuchKey`).
|
|
333
|
-
*/
|
|
334
|
-
hasItem(key: string): Promise<boolean>;
|
|
335
|
-
/**
|
|
336
|
-
* Retrieves a list of all keys stored in the S3 bucket.
|
|
337
|
-
*
|
|
338
|
-
* @returns {Promise<string[]>} An array of all stored keys.
|
|
339
|
-
*/
|
|
340
|
-
getKeys(): Promise<string[]>;
|
|
341
|
-
/**
|
|
342
|
-
* Deletes all items from S3 storage.
|
|
343
|
-
*
|
|
344
|
-
* @returns {Promise<void>} A promise that resolves when all items have been deleted.
|
|
345
|
-
*/
|
|
346
|
-
clear(): Promise<void>;
|
|
347
|
-
/**
|
|
348
|
-
* Gets the total number of stored items.
|
|
349
|
-
*
|
|
350
|
-
* @returns {Promise<number>} The count of stored items.
|
|
351
|
-
*/
|
|
352
|
-
size(): Promise<number>;
|
|
353
|
-
/**
|
|
354
|
-
* Converts a Node.js readable stream into a UTF-8 string.
|
|
355
|
-
*
|
|
356
|
-
* @private
|
|
357
|
-
* @param {Readable} stream - The readable stream to convert.
|
|
358
|
-
* @returns {Promise<string>} The stream contents as a string.
|
|
359
|
-
*/
|
|
360
|
-
private streamToString;
|
|
361
|
-
}
|
|
362
|
-
//#endregion
|
|
363
|
-
export { MemoryStorage, S3Storage, Storage, StorageManager, StorageTypes };
|
|
155
|
+
export { Storage, StorageManager, StorageTypes };
|