@vercube/storage 0.0.14 → 0.0.15
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 +101 -13
- package/dist/index.mjs +34404 -30
- package/package.json +6 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IOC } from "@vercube/di";
|
|
2
|
+
import { S3ClientConfig } from "@aws-sdk/client-s3";
|
|
2
3
|
|
|
3
4
|
//#region src/Service/Storage.d.ts
|
|
4
5
|
|
|
@@ -13,14 +14,15 @@ import { IOC } from "@vercube/di";
|
|
|
13
14
|
* It supports basic operations like get, set, delete, and querying storage state.
|
|
14
15
|
* Concrete implementations must provide the actual storage mechanism.
|
|
15
16
|
*/
|
|
16
|
-
declare abstract class Storage {
|
|
17
|
+
declare abstract class Storage<T = undefined> {
|
|
17
18
|
/**
|
|
18
|
-
* Initializes the storage implementation
|
|
19
|
-
* Must be called before using any other storage operations
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
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.
|
|
22
24
|
*/
|
|
23
|
-
abstract initialize(options
|
|
25
|
+
abstract initialize(options: T): void | Promise<void>;
|
|
24
26
|
/**
|
|
25
27
|
* Retrieves a value from storage by its key
|
|
26
28
|
* @template T - The type of the stored value
|
|
@@ -71,13 +73,16 @@ declare namespace StorageTypes {
|
|
|
71
73
|
interface BaseOptions {
|
|
72
74
|
storage?: string;
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
type Mount<T extends Storage<unknown>> = {
|
|
75
77
|
name?: string;
|
|
76
|
-
storage: IOC.Newable<
|
|
78
|
+
storage: IOC.Newable<T>;
|
|
79
|
+
} & (T extends Storage<undefined> ? {
|
|
77
80
|
initOptions?: unknown;
|
|
78
|
-
}
|
|
81
|
+
} : T extends Storage<infer U> ? {
|
|
82
|
+
initOptions: U;
|
|
83
|
+
} : never);
|
|
79
84
|
interface Storages<T = unknown> {
|
|
80
|
-
storage: Storage
|
|
85
|
+
storage: Storage<T>;
|
|
81
86
|
initOptions?: T;
|
|
82
87
|
}
|
|
83
88
|
interface GetItem extends BaseOptions {
|
|
@@ -97,6 +102,9 @@ declare namespace StorageTypes {
|
|
|
97
102
|
interface GetKeys extends BaseOptions {}
|
|
98
103
|
interface Clear extends BaseOptions {}
|
|
99
104
|
interface Size extends BaseOptions {}
|
|
105
|
+
interface S3BaseOptions extends S3ClientConfig {
|
|
106
|
+
bucket: string;
|
|
107
|
+
}
|
|
100
108
|
}
|
|
101
109
|
//#endregion
|
|
102
110
|
//#region src/Service/StorageManager.d.ts
|
|
@@ -119,11 +127,11 @@ declare class StorageManager {
|
|
|
119
127
|
* @param {IOC.Newable<Storage>} params.storage - Storage implementation to mount
|
|
120
128
|
* @returns {Promise<void>} A promise that resolves when mounting is complete
|
|
121
129
|
*/
|
|
122
|
-
mount({
|
|
130
|
+
mount<T extends Storage<unknown>>({
|
|
123
131
|
name,
|
|
124
132
|
storage,
|
|
125
133
|
initOptions
|
|
126
|
-
}: StorageTypes.Mount): Promise<void>;
|
|
134
|
+
}: StorageTypes.Mount<T>): Promise<void>;
|
|
127
135
|
/**
|
|
128
136
|
* Retrieves a registered storage instance by name
|
|
129
137
|
* @param {string} name - Name of the storage instance to retrieve
|
|
@@ -272,4 +280,84 @@ declare class MemoryStorage implements Storage {
|
|
|
272
280
|
size(): number;
|
|
273
281
|
}
|
|
274
282
|
//#endregion
|
|
275
|
-
|
|
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 };
|