@vercube/storage 0.0.3 → 0.0.4
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/index.d.mts +275 -0
- package/dist/index.mjs +46 -15
- package/package.json +5 -11
- package/dist/Service/Storage.d.ts +0 -66
- package/dist/Service/StorageManager.d.ts +0 -94
- package/dist/Storages/MemoryStorage.d.ts +0 -60
- package/dist/Types/StorageTypes.d.ts +0 -36
- package/dist/index.cjs +0 -262
- package/dist/index.d.ts +0 -4
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { IOC } from "@vercube/di";
|
|
2
|
+
|
|
3
|
+
//#region src/Service/Storage.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Abstract base class for storage implementations
|
|
7
|
+
* Provides a common interface for different storage providers
|
|
8
|
+
*
|
|
9
|
+
* @abstract
|
|
10
|
+
* @class Storage
|
|
11
|
+
* @description
|
|
12
|
+
* The Storage class defines a standard interface for storing and retrieving data.
|
|
13
|
+
* It supports basic operations like get, set, delete, and querying storage state.
|
|
14
|
+
* Concrete implementations must provide the actual storage mechanism.
|
|
15
|
+
*/
|
|
16
|
+
declare abstract class Storage {
|
|
17
|
+
/**
|
|
18
|
+
* Initializes the storage implementation
|
|
19
|
+
* Must be called before using any other storage operations
|
|
20
|
+
* @param {unknown} [options] - Optional initialization parameters
|
|
21
|
+
* @returns {Promise<void>} A promise that resolves when initialization is complete
|
|
22
|
+
*/
|
|
23
|
+
abstract initialize(options?: unknown): void | Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves a value from storage by its key
|
|
26
|
+
* @template T - The type of the stored value
|
|
27
|
+
* @param {string} key - The key to retrieve the value for
|
|
28
|
+
* @returns {Promise<T>} A promise that resolves with the stored value
|
|
29
|
+
*/
|
|
30
|
+
abstract getItem<T = unknown>(key: string): T | Promise<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Stores a value in storage with the specified key
|
|
33
|
+
* @template T - The type of the value to store
|
|
34
|
+
* @template U - The type of the optional options object
|
|
35
|
+
* @param {string} key - The key under which to store the value
|
|
36
|
+
* @param {T} value - The value to store
|
|
37
|
+
* @returns {Promise<void>} A promise that resolves when the value is stored
|
|
38
|
+
*/
|
|
39
|
+
abstract setItem<T = unknown, U = unknown>(key: string, value: T, options?: U): void | Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Removes a value from storage by its key
|
|
42
|
+
* @param {string} key - The key of the value to delete
|
|
43
|
+
* @returns {Promise<void>} A promise that resolves when the value is deleted
|
|
44
|
+
*/
|
|
45
|
+
abstract deleteItem(key: string): void | Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a value exists in storage for the given key
|
|
48
|
+
* @param {string} key - The key to check
|
|
49
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the key exists, false otherwise
|
|
50
|
+
*/
|
|
51
|
+
abstract hasItem(key: string): boolean | Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves all keys currently stored in storage
|
|
54
|
+
* @returns {Promise<string[]>} A promise that resolves with an array of all stored keys
|
|
55
|
+
*/
|
|
56
|
+
abstract getKeys(): string[] | Promise<string[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Removes all stored values from storage
|
|
59
|
+
* @returns {Promise<void>} A promise that resolves when all values are cleared
|
|
60
|
+
*/
|
|
61
|
+
abstract clear(): void | Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the number of key-value pairs stored in storage
|
|
64
|
+
* @returns {Promise<number>} A promise that resolves with the number of stored items
|
|
65
|
+
*/
|
|
66
|
+
abstract size(): number | Promise<number>;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/Types/StorageTypes.d.ts
|
|
70
|
+
declare namespace StorageTypes {
|
|
71
|
+
interface BaseOptions {
|
|
72
|
+
storage?: string;
|
|
73
|
+
}
|
|
74
|
+
interface Mount {
|
|
75
|
+
name?: string;
|
|
76
|
+
storage: IOC.Newable<Storage>;
|
|
77
|
+
initOptions?: unknown;
|
|
78
|
+
}
|
|
79
|
+
interface Storages<T = unknown> {
|
|
80
|
+
storage: Storage;
|
|
81
|
+
initOptions?: T;
|
|
82
|
+
}
|
|
83
|
+
interface GetItem extends BaseOptions {
|
|
84
|
+
key: string;
|
|
85
|
+
}
|
|
86
|
+
interface SetItem<T = unknown, U = unknown> extends BaseOptions {
|
|
87
|
+
key: string;
|
|
88
|
+
value: T;
|
|
89
|
+
options?: U;
|
|
90
|
+
}
|
|
91
|
+
interface DeleteItem extends BaseOptions {
|
|
92
|
+
key: string;
|
|
93
|
+
}
|
|
94
|
+
interface HasItem extends BaseOptions {
|
|
95
|
+
key: string;
|
|
96
|
+
}
|
|
97
|
+
interface GetKeys extends BaseOptions {}
|
|
98
|
+
interface Clear extends BaseOptions {}
|
|
99
|
+
interface Size extends BaseOptions {}
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/Service/StorageManager.d.ts
|
|
103
|
+
/**
|
|
104
|
+
* Manages multiple storage instances and provides a unified interface for storage operations.
|
|
105
|
+
* Each storage instance is identified by a unique name and implements the Storage interface.
|
|
106
|
+
* This class handles initialization, registration, and delegation of storage operations.
|
|
107
|
+
*/
|
|
108
|
+
declare class StorageManager {
|
|
109
|
+
private gContainer;
|
|
110
|
+
private gLogger;
|
|
111
|
+
/**
|
|
112
|
+
* Map of registered storage instances indexed by their names
|
|
113
|
+
*/
|
|
114
|
+
private fStorages;
|
|
115
|
+
/**
|
|
116
|
+
* Mounts a new storage instance with the specified name
|
|
117
|
+
* @param {StorageTypes.Mount} params - Mount parameters containing name and storage implementation
|
|
118
|
+
* @param {string} [params.name] - Optional name for the storage instance, defaults to 'default'
|
|
119
|
+
* @param {IOC.Newable<Storage>} params.storage - Storage implementation to mount
|
|
120
|
+
* @returns {Promise<void>} A promise that resolves when mounting is complete
|
|
121
|
+
*/
|
|
122
|
+
mount({
|
|
123
|
+
name,
|
|
124
|
+
storage,
|
|
125
|
+
initOptions
|
|
126
|
+
}: StorageTypes.Mount): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Retrieves a registered storage instance by name
|
|
129
|
+
* @param {string} name - Name of the storage instance to retrieve
|
|
130
|
+
* @returns {Storage | undefined} The storage instance if found, undefined otherwise
|
|
131
|
+
*/
|
|
132
|
+
getStorage(name?: string): Storage | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Retrieves an item from the specified storage
|
|
135
|
+
* @template T - Type of the stored value
|
|
136
|
+
* @param {StorageTypes.GetItem} params - Parameters for retrieving an item
|
|
137
|
+
* @param {string} [params.storage] - Name of the storage to retrieve from, defaults to 'default'
|
|
138
|
+
* @param {string} params.key - Key of the item to retrieve
|
|
139
|
+
* @returns {Promise<T | null>} A promise that resolves with the stored value or null if not found
|
|
140
|
+
*/
|
|
141
|
+
getItem<T = unknown>({
|
|
142
|
+
storage,
|
|
143
|
+
key
|
|
144
|
+
}: StorageTypes.GetItem): Promise<T | null>;
|
|
145
|
+
/**
|
|
146
|
+
* Stores an item in the specified storage
|
|
147
|
+
* @template T - Type of the value to store
|
|
148
|
+
* @param {StorageTypes.SetItem<T>} params - Parameters for storing an item
|
|
149
|
+
* @param {string} [params.storage] - Name of the storage to store in, defaults to 'default'
|
|
150
|
+
* @param {string} params.key - Key under which to store the value
|
|
151
|
+
* @param {T} params.value - Value to store
|
|
152
|
+
* @returns {Promise<void>} A promise that resolves when the value is stored
|
|
153
|
+
*/
|
|
154
|
+
setItem<T = unknown, U = unknown>({
|
|
155
|
+
storage,
|
|
156
|
+
key,
|
|
157
|
+
value,
|
|
158
|
+
options
|
|
159
|
+
}: StorageTypes.SetItem<T, U>): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Deletes an item from the specified storage
|
|
162
|
+
* @param {StorageTypes.DeleteItem} params - Parameters for deleting an item
|
|
163
|
+
* @param {string} [params.storage] - Name of the storage to delete from, defaults to 'default'
|
|
164
|
+
* @param {string} params.key - Key of the item to delete
|
|
165
|
+
* @returns {Promise<void>} A promise that resolves when the item is deleted
|
|
166
|
+
*/
|
|
167
|
+
deleteItem({
|
|
168
|
+
storage,
|
|
169
|
+
key
|
|
170
|
+
}: StorageTypes.DeleteItem): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Checks if an item exists in the specified storage
|
|
173
|
+
* @param {StorageTypes.HasItem} params - Parameters for checking item existence
|
|
174
|
+
* @param {string} [params.storage] - Name of the storage to check, defaults to 'default'
|
|
175
|
+
* @param {string} params.key - Key to check for
|
|
176
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the item exists, false otherwise
|
|
177
|
+
*/
|
|
178
|
+
hasItem({
|
|
179
|
+
storage,
|
|
180
|
+
key
|
|
181
|
+
}: StorageTypes.HasItem): Promise<boolean>;
|
|
182
|
+
/**
|
|
183
|
+
* Retrieves all keys from the specified storage
|
|
184
|
+
* @param {StorageTypes.GetKeys} params - Parameters for retrieving keys
|
|
185
|
+
* @param {string} [params.storage] - Name of the storage to get keys from, defaults to 'default'
|
|
186
|
+
* @returns {Promise<string[]>} A promise that resolves with an array of all keys
|
|
187
|
+
*/
|
|
188
|
+
getKeys({
|
|
189
|
+
storage
|
|
190
|
+
}: StorageTypes.GetKeys): Promise<string[]>;
|
|
191
|
+
/**
|
|
192
|
+
* Clears all items from the specified storage
|
|
193
|
+
* @param {StorageTypes.Clear} params - Parameters for clearing storage
|
|
194
|
+
* @param {string} [params.storage] - Name of the storage to clear, defaults to 'default'
|
|
195
|
+
* @returns {Promise<void>} A promise that resolves when the storage is cleared
|
|
196
|
+
*/
|
|
197
|
+
clear({
|
|
198
|
+
storage
|
|
199
|
+
}: StorageTypes.Clear): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Gets the number of items in the specified storage
|
|
202
|
+
* @param {StorageTypes.Size} params - Parameters for getting storage size
|
|
203
|
+
* @param {string} [params.storage] - Name of the storage to get size of, defaults to 'default'
|
|
204
|
+
* @returns {Promise<number>} A promise that resolves with the number of items
|
|
205
|
+
*/
|
|
206
|
+
size({
|
|
207
|
+
storage
|
|
208
|
+
}: StorageTypes.Size): Promise<number>;
|
|
209
|
+
/**
|
|
210
|
+
* Initializes all registered storage instances
|
|
211
|
+
* Called automatically with @Init() decorator
|
|
212
|
+
* @returns {Promise<void>} A promise that resolves when all storages are initialized
|
|
213
|
+
*/
|
|
214
|
+
private init;
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/Storages/MemoryStorage.d.ts
|
|
218
|
+
/**
|
|
219
|
+
* In-memory storage implementation of the Storage interface
|
|
220
|
+
* Provides a simple key-value store that persists only for the duration of the application runtime
|
|
221
|
+
* Useful for testing, caching, and scenarios where temporary storage is needed
|
|
222
|
+
*
|
|
223
|
+
* @implements {Storage}
|
|
224
|
+
*/
|
|
225
|
+
declare class MemoryStorage implements Storage {
|
|
226
|
+
/** Internal storage map to hold key-value pairs */
|
|
227
|
+
private storage;
|
|
228
|
+
/**
|
|
229
|
+
* Initializes the memory storage
|
|
230
|
+
* No initialization is needed for in-memory storage as the Map is created on instantiation
|
|
231
|
+
*/
|
|
232
|
+
initialize(): void;
|
|
233
|
+
/**
|
|
234
|
+
* Retrieves a value from memory storage by its key
|
|
235
|
+
* @template T - Type of the stored value
|
|
236
|
+
* @param {string} key - The key to retrieve the value for
|
|
237
|
+
* @returns {T} The stored value cast to type T
|
|
238
|
+
*/
|
|
239
|
+
getItem<T = unknown>(key: string): T;
|
|
240
|
+
/**
|
|
241
|
+
* Stores a value in memory storage with the specified key
|
|
242
|
+
* @template T - Type of the value to store
|
|
243
|
+
* @template U - Type of the options object
|
|
244
|
+
* @param {string} key - The key under which to store the value
|
|
245
|
+
* @param {T} value - The value to store
|
|
246
|
+
*/
|
|
247
|
+
setItem<T = unknown, U = unknown>(key: string, value: T, options?: U): void;
|
|
248
|
+
/**
|
|
249
|
+
* Removes a value from memory storage by its key
|
|
250
|
+
* @param {string} key - The key of the value to delete
|
|
251
|
+
*/
|
|
252
|
+
deleteItem(key: string): void;
|
|
253
|
+
/**
|
|
254
|
+
* Checks if a value exists in memory storage for the given key
|
|
255
|
+
* @param {string} key - The key to check
|
|
256
|
+
* @returns {boolean} True if the key exists, false otherwise
|
|
257
|
+
*/
|
|
258
|
+
hasItem(key: string): boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Retrieves all keys currently stored in memory storage
|
|
261
|
+
* @returns {string[]} Array of all stored keys
|
|
262
|
+
*/
|
|
263
|
+
getKeys(): string[];
|
|
264
|
+
/**
|
|
265
|
+
* Removes all stored values from memory storage
|
|
266
|
+
*/
|
|
267
|
+
clear(): void;
|
|
268
|
+
/**
|
|
269
|
+
* Gets the number of key-value pairs stored in memory storage
|
|
270
|
+
* @returns {number} The number of stored items
|
|
271
|
+
*/
|
|
272
|
+
size(): number;
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
export { MemoryStorage, Storage, StorageManager, StorageTypes };
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
|
+
import "node:module";
|
|
1
2
|
import { Container, Init, Inject, InjectOptional } from "@vercube/di";
|
|
2
3
|
import { Logger } from "@vercube/logger";
|
|
3
4
|
|
|
4
|
-
//#region
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
//#region rolldown:runtime
|
|
6
|
+
var __create = Object.create;
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __commonJS = (cb, mod) => function() {
|
|
13
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
17
|
+
key = keys[i];
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: ((k) => from[k]).bind(null, key),
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.1/node_modules/@oxc-project/runtime/src/helpers/decorate.js
|
|
32
|
+
var require_decorate = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.1/node_modules/@oxc-project/runtime/src/helpers/decorate.js"(exports, module) {
|
|
33
|
+
function __decorate(decorators, target, key, desc) {
|
|
34
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
35
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
36
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
37
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
38
|
+
}
|
|
39
|
+
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
40
|
+
} });
|
|
11
41
|
|
|
12
42
|
//#endregion
|
|
13
|
-
//#region
|
|
43
|
+
//#region src/Service/StorageManager.ts
|
|
44
|
+
var import_decorate = __toESM(require_decorate());
|
|
14
45
|
/**
|
|
15
46
|
* Manages multiple storage instances and provides a unified interface for storage operations.
|
|
16
47
|
* Each storage instance is identified by a unique name and implements the Storage interface.
|
|
@@ -22,7 +53,7 @@ var StorageManager = class {
|
|
|
22
53
|
/**
|
|
23
54
|
* Map of registered storage instances indexed by their names
|
|
24
55
|
*/
|
|
25
|
-
fStorages = new Map();
|
|
56
|
+
fStorages = /* @__PURE__ */ new Map();
|
|
26
57
|
/**
|
|
27
58
|
* Mounts a new storage instance with the specified name
|
|
28
59
|
* @param {StorageTypes.Mount} params - Mount parameters containing name and storage implementation
|
|
@@ -134,12 +165,12 @@ var StorageManager = class {
|
|
|
134
165
|
}
|
|
135
166
|
}
|
|
136
167
|
};
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
168
|
+
(0, import_decorate.default)([Inject(Container)], StorageManager.prototype, "gContainer", void 0);
|
|
169
|
+
(0, import_decorate.default)([InjectOptional(Logger)], StorageManager.prototype, "gLogger", void 0);
|
|
170
|
+
(0, import_decorate.default)([Init()], StorageManager.prototype, "init", null);
|
|
140
171
|
|
|
141
172
|
//#endregion
|
|
142
|
-
//#region
|
|
173
|
+
//#region src/Service/Storage.ts
|
|
143
174
|
/**
|
|
144
175
|
* Abstract base class for storage implementations
|
|
145
176
|
* Provides a common interface for different storage providers
|
|
@@ -154,7 +185,7 @@ __decorate([Init()], StorageManager.prototype, "init", null);
|
|
|
154
185
|
var Storage = class {};
|
|
155
186
|
|
|
156
187
|
//#endregion
|
|
157
|
-
//#region
|
|
188
|
+
//#region src/Storages/MemoryStorage.ts
|
|
158
189
|
/**
|
|
159
190
|
* In-memory storage implementation of the Storage interface
|
|
160
191
|
* Provides a simple key-value store that persists only for the duration of the application runtime
|
|
@@ -164,7 +195,7 @@ var Storage = class {};
|
|
|
164
195
|
*/
|
|
165
196
|
var MemoryStorage = class {
|
|
166
197
|
/** Internal storage map to hold key-value pairs */
|
|
167
|
-
storage = new Map();
|
|
198
|
+
storage = /* @__PURE__ */ new Map();
|
|
168
199
|
/**
|
|
169
200
|
* Initializes the memory storage
|
|
170
201
|
* No initialization is needed for in-memory storage as the Map is created on instantiation
|
package/package.json
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercube/storage",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Storage module for Vercube framework",
|
|
5
5
|
"repository": "@vercube/storage",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
|
-
".":
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.mjs",
|
|
13
|
-
"require": "./dist/index.cjs"
|
|
14
|
-
}
|
|
10
|
+
".": "./dist/index.mjs"
|
|
15
11
|
},
|
|
16
|
-
"
|
|
17
|
-
"module": "./dist/index.mjs",
|
|
18
|
-
"types": "./dist/index.d.ts",
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
19
13
|
"files": [
|
|
20
14
|
"dist",
|
|
21
15
|
"README.md"
|
|
22
16
|
],
|
|
23
17
|
"dependencies": {
|
|
24
|
-
"@vercube/
|
|
25
|
-
"@vercube/
|
|
18
|
+
"@vercube/di": "0.0.4",
|
|
19
|
+
"@vercube/logger": "0.0.4"
|
|
26
20
|
},
|
|
27
21
|
"publishConfig": {
|
|
28
22
|
"access": "public"
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Abstract base class for storage implementations
|
|
3
|
-
* Provides a common interface for different storage providers
|
|
4
|
-
*
|
|
5
|
-
* @abstract
|
|
6
|
-
* @class Storage
|
|
7
|
-
* @description
|
|
8
|
-
* The Storage class defines a standard interface for storing and retrieving data.
|
|
9
|
-
* It supports basic operations like get, set, delete, and querying storage state.
|
|
10
|
-
* Concrete implementations must provide the actual storage mechanism.
|
|
11
|
-
*/
|
|
12
|
-
export declare abstract class Storage {
|
|
13
|
-
/**
|
|
14
|
-
* Initializes the storage implementation
|
|
15
|
-
* Must be called before using any other storage operations
|
|
16
|
-
* @param {unknown} [options] - Optional initialization parameters
|
|
17
|
-
* @returns {Promise<void>} A promise that resolves when initialization is complete
|
|
18
|
-
*/
|
|
19
|
-
abstract initialize(options?: unknown): void | Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Retrieves a value from storage by its key
|
|
22
|
-
* @template T - The type of the stored value
|
|
23
|
-
* @param {string} key - The key to retrieve the value for
|
|
24
|
-
* @returns {Promise<T>} A promise that resolves with the stored value
|
|
25
|
-
*/
|
|
26
|
-
abstract getItem<T = unknown>(key: string): T | Promise<T>;
|
|
27
|
-
/**
|
|
28
|
-
* Stores a value in storage with the specified key
|
|
29
|
-
* @template T - The type of the value to store
|
|
30
|
-
* @template U - The type of the optional options object
|
|
31
|
-
* @param {string} key - The key under which to store the value
|
|
32
|
-
* @param {T} value - The value to store
|
|
33
|
-
* @returns {Promise<void>} A promise that resolves when the value is stored
|
|
34
|
-
*/
|
|
35
|
-
abstract setItem<
|
|
36
|
-
T = unknown,
|
|
37
|
-
U = unknown
|
|
38
|
-
>(key: string, value: T, options?: U): void | Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Removes a value from storage by its key
|
|
41
|
-
* @param {string} key - The key of the value to delete
|
|
42
|
-
* @returns {Promise<void>} A promise that resolves when the value is deleted
|
|
43
|
-
*/
|
|
44
|
-
abstract deleteItem(key: string): void | Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Checks if a value exists in storage for the given key
|
|
47
|
-
* @param {string} key - The key to check
|
|
48
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the key exists, false otherwise
|
|
49
|
-
*/
|
|
50
|
-
abstract hasItem(key: string): boolean | Promise<boolean>;
|
|
51
|
-
/**
|
|
52
|
-
* Retrieves all keys currently stored in storage
|
|
53
|
-
* @returns {Promise<string[]>} A promise that resolves with an array of all stored keys
|
|
54
|
-
*/
|
|
55
|
-
abstract getKeys(): string[] | Promise<string[]>;
|
|
56
|
-
/**
|
|
57
|
-
* Removes all stored values from storage
|
|
58
|
-
* @returns {Promise<void>} A promise that resolves when all values are cleared
|
|
59
|
-
*/
|
|
60
|
-
abstract clear(): void | Promise<void>;
|
|
61
|
-
/**
|
|
62
|
-
* Gets the number of key-value pairs stored in storage
|
|
63
|
-
* @returns {Promise<number>} A promise that resolves with the number of stored items
|
|
64
|
-
*/
|
|
65
|
-
abstract size(): number | Promise<number>;
|
|
66
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { Storage } from "./Storage.js";
|
|
2
|
-
import { StorageTypes } from "../Types/StorageTypes.js";
|
|
3
|
-
/**
|
|
4
|
-
* Manages multiple storage instances and provides a unified interface for storage operations.
|
|
5
|
-
* Each storage instance is identified by a unique name and implements the Storage interface.
|
|
6
|
-
* This class handles initialization, registration, and delegation of storage operations.
|
|
7
|
-
*/
|
|
8
|
-
export declare class StorageManager {
|
|
9
|
-
private gContainer;
|
|
10
|
-
private gLogger;
|
|
11
|
-
/**
|
|
12
|
-
* Map of registered storage instances indexed by their names
|
|
13
|
-
*/
|
|
14
|
-
private fStorages;
|
|
15
|
-
/**
|
|
16
|
-
* Mounts a new storage instance with the specified name
|
|
17
|
-
* @param {StorageTypes.Mount} params - Mount parameters containing name and storage implementation
|
|
18
|
-
* @param {string} [params.name] - Optional name for the storage instance, defaults to 'default'
|
|
19
|
-
* @param {IOC.Newable<Storage>} params.storage - Storage implementation to mount
|
|
20
|
-
* @returns {Promise<void>} A promise that resolves when mounting is complete
|
|
21
|
-
*/
|
|
22
|
-
mount({ name, storage, initOptions }: StorageTypes.Mount): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Retrieves a registered storage instance by name
|
|
25
|
-
* @param {string} name - Name of the storage instance to retrieve
|
|
26
|
-
* @returns {Storage | undefined} The storage instance if found, undefined otherwise
|
|
27
|
-
*/
|
|
28
|
-
getStorage(name?: string): Storage | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Retrieves an item from the specified storage
|
|
31
|
-
* @template T - Type of the stored value
|
|
32
|
-
* @param {StorageTypes.GetItem} params - Parameters for retrieving an item
|
|
33
|
-
* @param {string} [params.storage] - Name of the storage to retrieve from, defaults to 'default'
|
|
34
|
-
* @param {string} params.key - Key of the item to retrieve
|
|
35
|
-
* @returns {Promise<T | null>} A promise that resolves with the stored value or null if not found
|
|
36
|
-
*/
|
|
37
|
-
getItem<T = unknown>({ storage, key }: StorageTypes.GetItem): Promise<T | null>;
|
|
38
|
-
/**
|
|
39
|
-
* Stores an item in the specified storage
|
|
40
|
-
* @template T - Type of the value to store
|
|
41
|
-
* @param {StorageTypes.SetItem<T>} params - Parameters for storing an item
|
|
42
|
-
* @param {string} [params.storage] - Name of the storage to store in, defaults to 'default'
|
|
43
|
-
* @param {string} params.key - Key under which to store the value
|
|
44
|
-
* @param {T} params.value - Value to store
|
|
45
|
-
* @returns {Promise<void>} A promise that resolves when the value is stored
|
|
46
|
-
*/
|
|
47
|
-
setItem<
|
|
48
|
-
T = unknown,
|
|
49
|
-
U = unknown
|
|
50
|
-
>({ storage, key, value, options }: StorageTypes.SetItem<T, U>): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Deletes an item from the specified storage
|
|
53
|
-
* @param {StorageTypes.DeleteItem} params - Parameters for deleting an item
|
|
54
|
-
* @param {string} [params.storage] - Name of the storage to delete from, defaults to 'default'
|
|
55
|
-
* @param {string} params.key - Key of the item to delete
|
|
56
|
-
* @returns {Promise<void>} A promise that resolves when the item is deleted
|
|
57
|
-
*/
|
|
58
|
-
deleteItem({ storage, key }: StorageTypes.DeleteItem): Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Checks if an item exists in the specified storage
|
|
61
|
-
* @param {StorageTypes.HasItem} params - Parameters for checking item existence
|
|
62
|
-
* @param {string} [params.storage] - Name of the storage to check, defaults to 'default'
|
|
63
|
-
* @param {string} params.key - Key to check for
|
|
64
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the item exists, false otherwise
|
|
65
|
-
*/
|
|
66
|
-
hasItem({ storage, key }: StorageTypes.HasItem): Promise<boolean>;
|
|
67
|
-
/**
|
|
68
|
-
* Retrieves all keys from the specified storage
|
|
69
|
-
* @param {StorageTypes.GetKeys} params - Parameters for retrieving keys
|
|
70
|
-
* @param {string} [params.storage] - Name of the storage to get keys from, defaults to 'default'
|
|
71
|
-
* @returns {Promise<string[]>} A promise that resolves with an array of all keys
|
|
72
|
-
*/
|
|
73
|
-
getKeys({ storage }: StorageTypes.GetKeys): Promise<string[]>;
|
|
74
|
-
/**
|
|
75
|
-
* Clears all items from the specified storage
|
|
76
|
-
* @param {StorageTypes.Clear} params - Parameters for clearing storage
|
|
77
|
-
* @param {string} [params.storage] - Name of the storage to clear, defaults to 'default'
|
|
78
|
-
* @returns {Promise<void>} A promise that resolves when the storage is cleared
|
|
79
|
-
*/
|
|
80
|
-
clear({ storage }: StorageTypes.Clear): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Gets the number of items in the specified storage
|
|
83
|
-
* @param {StorageTypes.Size} params - Parameters for getting storage size
|
|
84
|
-
* @param {string} [params.storage] - Name of the storage to get size of, defaults to 'default'
|
|
85
|
-
* @returns {Promise<number>} A promise that resolves with the number of items
|
|
86
|
-
*/
|
|
87
|
-
size({ storage }: StorageTypes.Size): Promise<number>;
|
|
88
|
-
/**
|
|
89
|
-
* Initializes all registered storage instances
|
|
90
|
-
* Called automatically with @Init() decorator
|
|
91
|
-
* @returns {Promise<void>} A promise that resolves when all storages are initialized
|
|
92
|
-
*/
|
|
93
|
-
private init;
|
|
94
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Storage } from "../Service/Storage.js";
|
|
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
|
-
export declare class MemoryStorage implements Storage {
|
|
10
|
-
/** Internal storage map to hold key-value pairs */
|
|
11
|
-
private storage;
|
|
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(): void;
|
|
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<T = unknown>(key: string): T;
|
|
24
|
-
/**
|
|
25
|
-
* Stores a value in memory storage with the specified key
|
|
26
|
-
* @template T - Type of the value to store
|
|
27
|
-
* @template U - Type of the options object
|
|
28
|
-
* @param {string} key - The key under which to store the value
|
|
29
|
-
* @param {T} value - The value to store
|
|
30
|
-
*/
|
|
31
|
-
setItem<
|
|
32
|
-
T = unknown,
|
|
33
|
-
U = unknown
|
|
34
|
-
>(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
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { IOC } from "@vercube/di";
|
|
2
|
-
import { Storage } from "../Service/Storage.js";
|
|
3
|
-
export declare namespace StorageTypes {
|
|
4
|
-
interface BaseOptions {
|
|
5
|
-
storage?: string;
|
|
6
|
-
}
|
|
7
|
-
interface Mount {
|
|
8
|
-
name?: string;
|
|
9
|
-
storage: IOC.Newable<Storage>;
|
|
10
|
-
initOptions?: unknown;
|
|
11
|
-
}
|
|
12
|
-
interface Storages<T = unknown> {
|
|
13
|
-
storage: Storage;
|
|
14
|
-
initOptions?: T;
|
|
15
|
-
}
|
|
16
|
-
interface GetItem extends BaseOptions {
|
|
17
|
-
key: string;
|
|
18
|
-
}
|
|
19
|
-
interface SetItem<
|
|
20
|
-
T = unknown,
|
|
21
|
-
U = unknown
|
|
22
|
-
> extends BaseOptions {
|
|
23
|
-
key: string;
|
|
24
|
-
value: T;
|
|
25
|
-
options?: U;
|
|
26
|
-
}
|
|
27
|
-
interface DeleteItem extends BaseOptions {
|
|
28
|
-
key: string;
|
|
29
|
-
}
|
|
30
|
-
interface HasItem extends BaseOptions {
|
|
31
|
-
key: string;
|
|
32
|
-
}
|
|
33
|
-
interface GetKeys extends BaseOptions {}
|
|
34
|
-
interface Clear extends BaseOptions {}
|
|
35
|
-
interface Size extends BaseOptions {}
|
|
36
|
-
}
|
package/dist/index.cjs
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
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 __commonJS = (cb, mod) => function() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
-
key = keys[i];
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
-
get: ((k) => from[k]).bind(null, key),
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
-
value: mod,
|
|
23
|
-
enumerable: true
|
|
24
|
-
}) : target, mod));
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
const __vercube_di = __toESM(require("@vercube/di"));
|
|
28
|
-
const __vercube_logger = __toESM(require("@vercube/logger"));
|
|
29
|
-
|
|
30
|
-
//#region node_modules/.pnpm/@oxc-project+runtime@0.67.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js
|
|
31
|
-
var require_decorate = __commonJS({ "node_modules/.pnpm/@oxc-project+runtime@0.67.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js"(exports, module) {
|
|
32
|
-
function __decorate(decorators, target, key, desc) {
|
|
33
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
34
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
35
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
36
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
37
|
-
}
|
|
38
|
-
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
39
|
-
} });
|
|
40
|
-
var import_decorate = __toESM(require_decorate(), 1);
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region packages/storage/src/Service/StorageManager.ts
|
|
44
|
-
/**
|
|
45
|
-
* Manages multiple storage instances and provides a unified interface for storage operations.
|
|
46
|
-
* Each storage instance is identified by a unique name and implements the Storage interface.
|
|
47
|
-
* This class handles initialization, registration, and delegation of storage operations.
|
|
48
|
-
*/
|
|
49
|
-
var StorageManager = class {
|
|
50
|
-
gContainer;
|
|
51
|
-
gLogger;
|
|
52
|
-
/**
|
|
53
|
-
* Map of registered storage instances indexed by their names
|
|
54
|
-
*/
|
|
55
|
-
fStorages = new Map();
|
|
56
|
-
/**
|
|
57
|
-
* Mounts a new storage instance with the specified name
|
|
58
|
-
* @param {StorageTypes.Mount} params - Mount parameters containing name and storage implementation
|
|
59
|
-
* @param {string} [params.name] - Optional name for the storage instance, defaults to 'default'
|
|
60
|
-
* @param {IOC.Newable<Storage>} params.storage - Storage implementation to mount
|
|
61
|
-
* @returns {Promise<void>} A promise that resolves when mounting is complete
|
|
62
|
-
*/
|
|
63
|
-
async mount({ name, storage, initOptions }) {
|
|
64
|
-
this.fStorages.set(name ?? "default", {
|
|
65
|
-
storage: this.gContainer.resolve(storage),
|
|
66
|
-
initOptions
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Retrieves a registered storage instance by name
|
|
71
|
-
* @param {string} name - Name of the storage instance to retrieve
|
|
72
|
-
* @returns {Storage | undefined} The storage instance if found, undefined otherwise
|
|
73
|
-
*/
|
|
74
|
-
getStorage(name = "default") {
|
|
75
|
-
return this.fStorages.get(name)?.storage ?? void 0;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Retrieves an item from the specified storage
|
|
79
|
-
* @template T - Type of the stored value
|
|
80
|
-
* @param {StorageTypes.GetItem} params - Parameters for retrieving an item
|
|
81
|
-
* @param {string} [params.storage] - Name of the storage to retrieve from, defaults to 'default'
|
|
82
|
-
* @param {string} params.key - Key of the item to retrieve
|
|
83
|
-
* @returns {Promise<T | null>} A promise that resolves with the stored value or null if not found
|
|
84
|
-
*/
|
|
85
|
-
async getItem({ storage, key }) {
|
|
86
|
-
const storageInstance = this.getStorage(storage);
|
|
87
|
-
return storageInstance?.getItem(key) ?? null;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Stores an item in the specified storage
|
|
91
|
-
* @template T - Type of the value to store
|
|
92
|
-
* @param {StorageTypes.SetItem<T>} params - Parameters for storing an item
|
|
93
|
-
* @param {string} [params.storage] - Name of the storage to store in, defaults to 'default'
|
|
94
|
-
* @param {string} params.key - Key under which to store the value
|
|
95
|
-
* @param {T} params.value - Value to store
|
|
96
|
-
* @returns {Promise<void>} A promise that resolves when the value is stored
|
|
97
|
-
*/
|
|
98
|
-
async setItem({ storage, key, value, options }) {
|
|
99
|
-
const storageInstance = this.getStorage(storage);
|
|
100
|
-
storageInstance?.setItem(key, value, options);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Deletes an item from the specified storage
|
|
104
|
-
* @param {StorageTypes.DeleteItem} params - Parameters for deleting an item
|
|
105
|
-
* @param {string} [params.storage] - Name of the storage to delete from, defaults to 'default'
|
|
106
|
-
* @param {string} params.key - Key of the item to delete
|
|
107
|
-
* @returns {Promise<void>} A promise that resolves when the item is deleted
|
|
108
|
-
*/
|
|
109
|
-
async deleteItem({ storage, key }) {
|
|
110
|
-
const storageInstance = this.getStorage(storage);
|
|
111
|
-
storageInstance?.deleteItem(key);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Checks if an item exists in the specified storage
|
|
115
|
-
* @param {StorageTypes.HasItem} params - Parameters for checking item existence
|
|
116
|
-
* @param {string} [params.storage] - Name of the storage to check, defaults to 'default'
|
|
117
|
-
* @param {string} params.key - Key to check for
|
|
118
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the item exists, false otherwise
|
|
119
|
-
*/
|
|
120
|
-
async hasItem({ storage, key }) {
|
|
121
|
-
const storageInstance = this.getStorage(storage);
|
|
122
|
-
return storageInstance?.hasItem(key) ?? false;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Retrieves all keys from the specified storage
|
|
126
|
-
* @param {StorageTypes.GetKeys} params - Parameters for retrieving keys
|
|
127
|
-
* @param {string} [params.storage] - Name of the storage to get keys from, defaults to 'default'
|
|
128
|
-
* @returns {Promise<string[]>} A promise that resolves with an array of all keys
|
|
129
|
-
*/
|
|
130
|
-
async getKeys({ storage }) {
|
|
131
|
-
const storageInstance = this.getStorage(storage);
|
|
132
|
-
return storageInstance?.getKeys() ?? [];
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Clears all items from the specified storage
|
|
136
|
-
* @param {StorageTypes.Clear} params - Parameters for clearing storage
|
|
137
|
-
* @param {string} [params.storage] - Name of the storage to clear, defaults to 'default'
|
|
138
|
-
* @returns {Promise<void>} A promise that resolves when the storage is cleared
|
|
139
|
-
*/
|
|
140
|
-
async clear({ storage }) {
|
|
141
|
-
const storageInstance = this.getStorage(storage);
|
|
142
|
-
storageInstance?.clear();
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Gets the number of items in the specified storage
|
|
146
|
-
* @param {StorageTypes.Size} params - Parameters for getting storage size
|
|
147
|
-
* @param {string} [params.storage] - Name of the storage to get size of, defaults to 'default'
|
|
148
|
-
* @returns {Promise<number>} A promise that resolves with the number of items
|
|
149
|
-
*/
|
|
150
|
-
async size({ storage }) {
|
|
151
|
-
const storageInstance = this.getStorage(storage);
|
|
152
|
-
return storageInstance?.size() ?? 0;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Initializes all registered storage instances
|
|
156
|
-
* Called automatically with @Init() decorator
|
|
157
|
-
* @returns {Promise<void>} A promise that resolves when all storages are initialized
|
|
158
|
-
*/
|
|
159
|
-
async init() {
|
|
160
|
-
for (const { storage, initOptions } of this.fStorages.values()) try {
|
|
161
|
-
await storage?.initialize(initOptions);
|
|
162
|
-
} catch (error) {
|
|
163
|
-
this.gLogger?.error("Vercube/StorageManager::init", error);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(__vercube_di.Container)], StorageManager.prototype, "gContainer", void 0);
|
|
168
|
-
(0, import_decorate.default)([(0, __vercube_di.InjectOptional)(__vercube_logger.Logger)], StorageManager.prototype, "gLogger", void 0);
|
|
169
|
-
(0, import_decorate.default)([(0, __vercube_di.Init)()], StorageManager.prototype, "init", null);
|
|
170
|
-
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region packages/storage/src/Service/Storage.ts
|
|
173
|
-
/**
|
|
174
|
-
* Abstract base class for storage implementations
|
|
175
|
-
* Provides a common interface for different storage providers
|
|
176
|
-
*
|
|
177
|
-
* @abstract
|
|
178
|
-
* @class Storage
|
|
179
|
-
* @description
|
|
180
|
-
* The Storage class defines a standard interface for storing and retrieving data.
|
|
181
|
-
* It supports basic operations like get, set, delete, and querying storage state.
|
|
182
|
-
* Concrete implementations must provide the actual storage mechanism.
|
|
183
|
-
*/
|
|
184
|
-
var Storage = class {};
|
|
185
|
-
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region packages/storage/src/Storages/MemoryStorage.ts
|
|
188
|
-
/**
|
|
189
|
-
* In-memory storage implementation of the Storage interface
|
|
190
|
-
* Provides a simple key-value store that persists only for the duration of the application runtime
|
|
191
|
-
* Useful for testing, caching, and scenarios where temporary storage is needed
|
|
192
|
-
*
|
|
193
|
-
* @implements {Storage}
|
|
194
|
-
*/
|
|
195
|
-
var MemoryStorage = class {
|
|
196
|
-
/** Internal storage map to hold key-value pairs */
|
|
197
|
-
storage = new Map();
|
|
198
|
-
/**
|
|
199
|
-
* Initializes the memory storage
|
|
200
|
-
* No initialization is needed for in-memory storage as the Map is created on instantiation
|
|
201
|
-
*/
|
|
202
|
-
initialize() {}
|
|
203
|
-
/**
|
|
204
|
-
* Retrieves a value from memory storage by its key
|
|
205
|
-
* @template T - Type of the stored value
|
|
206
|
-
* @param {string} key - The key to retrieve the value for
|
|
207
|
-
* @returns {T} The stored value cast to type T
|
|
208
|
-
*/
|
|
209
|
-
getItem(key) {
|
|
210
|
-
return this.storage.get(key);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Stores a value in memory storage with the specified key
|
|
214
|
-
* @template T - Type of the value to store
|
|
215
|
-
* @template U - Type of the options object
|
|
216
|
-
* @param {string} key - The key under which to store the value
|
|
217
|
-
* @param {T} value - The value to store
|
|
218
|
-
*/
|
|
219
|
-
setItem(key, value, options) {
|
|
220
|
-
this.storage.set(key, value);
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Removes a value from memory storage by its key
|
|
224
|
-
* @param {string} key - The key of the value to delete
|
|
225
|
-
*/
|
|
226
|
-
deleteItem(key) {
|
|
227
|
-
this.storage.delete(key);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Checks if a value exists in memory storage for the given key
|
|
231
|
-
* @param {string} key - The key to check
|
|
232
|
-
* @returns {boolean} True if the key exists, false otherwise
|
|
233
|
-
*/
|
|
234
|
-
hasItem(key) {
|
|
235
|
-
return this.storage.has(key);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Retrieves all keys currently stored in memory storage
|
|
239
|
-
* @returns {string[]} Array of all stored keys
|
|
240
|
-
*/
|
|
241
|
-
getKeys() {
|
|
242
|
-
return [...this.storage.keys()];
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Removes all stored values from memory storage
|
|
246
|
-
*/
|
|
247
|
-
clear() {
|
|
248
|
-
this.storage.clear();
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Gets the number of key-value pairs stored in memory storage
|
|
252
|
-
* @returns {number} The number of stored items
|
|
253
|
-
*/
|
|
254
|
-
size() {
|
|
255
|
-
return this.storage.size;
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
//#endregion
|
|
260
|
-
exports.MemoryStorage = MemoryStorage
|
|
261
|
-
exports.Storage = Storage
|
|
262
|
-
exports.StorageManager = StorageManager
|
package/dist/index.d.ts
DELETED