@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.
@@ -0,0 +1,62 @@
1
+ import { Storage } from "../Storage-DZ-jzAK_.mjs";
2
+
3
+ //#region src/Drivers/MemoryStorage.d.ts
4
+
5
+ /**
6
+ * In-memory storage implementation of the Storage interface
7
+ * Provides a simple key-value store that persists only for the duration of the application runtime
8
+ * Useful for testing, caching, and scenarios where temporary storage is needed
9
+ *
10
+ * @implements {Storage}
11
+ */
12
+ declare class MemoryStorage implements Storage {
13
+ /** Internal storage map to hold key-value pairs */
14
+ private storage;
15
+ /**
16
+ * Initializes the memory storage
17
+ * No initialization is needed for in-memory storage as the Map is created on instantiation
18
+ */
19
+ initialize(): void;
20
+ /**
21
+ * Retrieves a value from memory storage by its key
22
+ * @template T - Type of the stored value
23
+ * @param {string} key - The key to retrieve the value for
24
+ * @returns {T} The stored value cast to type T
25
+ */
26
+ getItem<T = unknown>(key: string): T;
27
+ /**
28
+ * Stores a value in memory storage with the specified key
29
+ * @template T - Type of the value to store
30
+ * @template U - Type of the options object
31
+ * @param {string} key - The key under which to store the value
32
+ * @param {T} value - The value to store
33
+ */
34
+ setItem<T = unknown, U = unknown>(key: string, value: T, options?: U): void;
35
+ /**
36
+ * Removes a value from memory storage by its key
37
+ * @param {string} key - The key of the value to delete
38
+ */
39
+ deleteItem(key: string): void;
40
+ /**
41
+ * Checks if a value exists in memory storage for the given key
42
+ * @param {string} key - The key to check
43
+ * @returns {boolean} True if the key exists, false otherwise
44
+ */
45
+ hasItem(key: string): boolean;
46
+ /**
47
+ * Retrieves all keys currently stored in memory storage
48
+ * @returns {string[]} Array of all stored keys
49
+ */
50
+ getKeys(): string[];
51
+ /**
52
+ * Removes all stored values from memory storage
53
+ */
54
+ clear(): void;
55
+ /**
56
+ * Gets the number of key-value pairs stored in memory storage
57
+ * @returns {number} The number of stored items
58
+ */
59
+ size(): number;
60
+ }
61
+ //#endregion
62
+ export { MemoryStorage };
@@ -0,0 +1,74 @@
1
+ //#region src/Drivers/MemoryStorage.ts
2
+ /**
3
+ * In-memory storage implementation of the Storage interface
4
+ * Provides a simple key-value store that persists only for the duration of the application runtime
5
+ * Useful for testing, caching, and scenarios where temporary storage is needed
6
+ *
7
+ * @implements {Storage}
8
+ */
9
+ var MemoryStorage = class {
10
+ /** Internal storage map to hold key-value pairs */
11
+ storage = /* @__PURE__ */ new Map();
12
+ /**
13
+ * Initializes the memory storage
14
+ * No initialization is needed for in-memory storage as the Map is created on instantiation
15
+ */
16
+ initialize() {}
17
+ /**
18
+ * Retrieves a value from memory storage by its key
19
+ * @template T - Type of the stored value
20
+ * @param {string} key - The key to retrieve the value for
21
+ * @returns {T} The stored value cast to type T
22
+ */
23
+ getItem(key) {
24
+ return this.storage.get(key);
25
+ }
26
+ /**
27
+ * Stores a value in memory storage with the specified key
28
+ * @template T - Type of the value to store
29
+ * @template U - Type of the options object
30
+ * @param {string} key - The key under which to store the value
31
+ * @param {T} value - The value to store
32
+ */
33
+ setItem(key, value, options) {
34
+ this.storage.set(key, value);
35
+ }
36
+ /**
37
+ * Removes a value from memory storage by its key
38
+ * @param {string} key - The key of the value to delete
39
+ */
40
+ deleteItem(key) {
41
+ this.storage.delete(key);
42
+ }
43
+ /**
44
+ * Checks if a value exists in memory storage for the given key
45
+ * @param {string} key - The key to check
46
+ * @returns {boolean} True if the key exists, false otherwise
47
+ */
48
+ hasItem(key) {
49
+ return this.storage.has(key);
50
+ }
51
+ /**
52
+ * Retrieves all keys currently stored in memory storage
53
+ * @returns {string[]} Array of all stored keys
54
+ */
55
+ getKeys() {
56
+ return [...this.storage.keys()];
57
+ }
58
+ /**
59
+ * Removes all stored values from memory storage
60
+ */
61
+ clear() {
62
+ this.storage.clear();
63
+ }
64
+ /**
65
+ * Gets the number of key-value pairs stored in memory storage
66
+ * @returns {number} The number of stored items
67
+ */
68
+ size() {
69
+ return this.storage.size;
70
+ }
71
+ };
72
+
73
+ //#endregion
74
+ export { MemoryStorage };
@@ -0,0 +1,87 @@
1
+ import { Storage } from "../Storage-DZ-jzAK_.mjs";
2
+ import { S3ClientConfig } from "@aws-sdk/client-s3";
3
+
4
+ //#region src/Drivers/S3Storage.d.ts
5
+ interface S3BaseOptions extends S3ClientConfig {
6
+ bucket: string;
7
+ }
8
+ /**
9
+ * S3 storage implementation of the Storage interface.
10
+ * Provides key-value operations backed by AWS S3.
11
+ *
12
+ * @implements {Storage}
13
+ */
14
+ declare class S3Storage implements Storage<S3BaseOptions> {
15
+ private s3;
16
+ private bucket;
17
+ /**
18
+ * Initializes the S3 storage client.
19
+ *
20
+ * @param {S3BaseOptions} options - Configuration options for the S3 client.
21
+ * @returns {Promise<void>} A promise that resolves when initialization is complete.
22
+ */
23
+ initialize(options: S3BaseOptions): Promise<void>;
24
+ /**
25
+ * Retrieves and parses a value from S3 storage by its key.
26
+ *
27
+ * @template T
28
+ * @param {string} key - The key whose value should be retrieved.
29
+ * @returns {Promise<T | undefined>} The stored value parsed as type T, or undefined if the key does not exist.
30
+ * @throws Will rethrow any S3 error except for missing key (`NoSuchKey`).
31
+ */
32
+ getItem<T = unknown>(key: string): Promise<T>;
33
+ /**
34
+ * Stores a value in S3 storage under the specified key.
35
+ *
36
+ * @template T
37
+ * @template U
38
+ * @param {string} key - The key under which to store the value.
39
+ * @param {T} value - The value to store (will be JSON serialized).
40
+ * @param {U} [options] - Additional options (currently unused).
41
+ * @returns {Promise<void>} A promise that resolves when the value has been stored.
42
+ */
43
+ setItem<T = unknown, U = unknown>(key: string, value: T, options?: U): Promise<void>;
44
+ /**
45
+ * Removes an item from S3 storage by its key.
46
+ *
47
+ * @param {string} key - The key of the item to delete.
48
+ * @returns {Promise<void>} A promise that resolves when the item has been deleted.
49
+ */
50
+ deleteItem(key: string): Promise<void>;
51
+ /**
52
+ * Checks if a key exists in S3 storage.
53
+ *
54
+ * @param {string} key - The key to check.
55
+ * @returns {Promise<boolean>} True if the key exists, false otherwise.
56
+ * @throws Will rethrow any S3 error except for missing key (`NoSuchKey`).
57
+ */
58
+ hasItem(key: string): Promise<boolean>;
59
+ /**
60
+ * Retrieves a list of all keys stored in the S3 bucket.
61
+ *
62
+ * @returns {Promise<string[]>} An array of all stored keys.
63
+ */
64
+ getKeys(): Promise<string[]>;
65
+ /**
66
+ * Deletes all items from S3 storage.
67
+ *
68
+ * @returns {Promise<void>} A promise that resolves when all items have been deleted.
69
+ */
70
+ clear(): Promise<void>;
71
+ /**
72
+ * Gets the total number of stored items.
73
+ *
74
+ * @returns {Promise<number>} The count of stored items.
75
+ */
76
+ size(): Promise<number>;
77
+ /**
78
+ * Converts a Node.js readable stream into a UTF-8 string.
79
+ *
80
+ * @private
81
+ * @param {Readable} stream - The readable stream to convert.
82
+ * @returns {Promise<string>} The stream contents as a string.
83
+ */
84
+ private streamToString;
85
+ }
86
+ //#endregion
87
+ export { S3BaseOptions, S3Storage };