@vercube/storage 0.0.14 → 0.0.16

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,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,83 +1,21 @@
1
+ import { Storage } from "./Storage-DZ-jzAK_.mjs";
1
2
  import { IOC } from "@vercube/di";
2
3
 
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
4
  //#region src/Types/StorageTypes.d.ts
70
5
  declare namespace StorageTypes {
71
6
  interface BaseOptions {
72
7
  storage?: string;
73
8
  }
74
- interface Mount {
9
+ type Mount<T extends Storage<unknown>> = {
75
10
  name?: string;
76
- storage: IOC.Newable<Storage>;
11
+ storage: IOC.Newable<T>;
12
+ } & (T extends Storage<undefined> ? {
77
13
  initOptions?: unknown;
78
- }
14
+ } : T extends Storage<infer U> ? {
15
+ initOptions: U;
16
+ } : never);
79
17
  interface Storages<T = unknown> {
80
- storage: Storage;
18
+ storage: Storage<T>;
81
19
  initOptions?: T;
82
20
  }
83
21
  interface GetItem extends BaseOptions {
@@ -119,11 +57,11 @@ declare class StorageManager {
119
57
  * @param {IOC.Newable<Storage>} params.storage - Storage implementation to mount
120
58
  * @returns {Promise<void>} A promise that resolves when mounting is complete
121
59
  */
122
- mount({
60
+ mount<T extends Storage<unknown>>({
123
61
  name,
124
62
  storage,
125
63
  initOptions
126
- }: StorageTypes.Mount): Promise<void>;
64
+ }: StorageTypes.Mount<T>): Promise<void>;
127
65
  /**
128
66
  * Retrieves a registered storage instance by name
129
67
  * @param {string} name - Name of the storage instance to retrieve
@@ -214,62 +152,4 @@ declare class StorageManager {
214
152
  private init;
215
153
  }
216
154
  //#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 };
155
+ export { Storage, StorageManager, StorageTypes };
package/dist/index.mjs CHANGED
@@ -1,35 +1,9 @@
1
- import "node:module";
1
+ import { __commonJS, __toESM } from "./chunk-UoOzN6Vc.mjs";
2
2
  import { Container, Init, Inject, InjectOptional } from "@vercube/di";
3
3
  import { Logger } from "@vercube/logger";
4
4
 
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.75.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js
32
- var require_decorate = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.75.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js"(exports, module) {
5
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.75.1/node_modules/@oxc-project/runtime/src/helpers/decorate.js
6
+ var require_decorate = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.75.1/node_modules/@oxc-project/runtime/src/helpers/decorate.js"(exports, module) {
33
7
  function __decorate(decorators, target, key, desc) {
34
8
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
35
9
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -41,7 +15,7 @@ var require_decorate = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runti
41
15
 
42
16
  //#endregion
43
17
  //#region src/Service/StorageManager.ts
44
- var import_decorate = __toESM(require_decorate());
18
+ var import_decorate = __toESM(require_decorate(), 1);
45
19
  /**
46
20
  * Manages multiple storage instances and provides a unified interface for storage operations.
47
21
  * Each storage instance is identified by a unique name and implements the Storage interface.
@@ -185,77 +159,4 @@ var StorageManager = class {
185
159
  var Storage = class {};
186
160
 
187
161
  //#endregion
188
- //#region src/Storages/MemoryStorage.ts
189
- /**
190
- * In-memory storage implementation of the Storage interface
191
- * Provides a simple key-value store that persists only for the duration of the application runtime
192
- * Useful for testing, caching, and scenarios where temporary storage is needed
193
- *
194
- * @implements {Storage}
195
- */
196
- var MemoryStorage = class {
197
- /** Internal storage map to hold key-value pairs */
198
- storage = /* @__PURE__ */ new Map();
199
- /**
200
- * Initializes the memory storage
201
- * No initialization is needed for in-memory storage as the Map is created on instantiation
202
- */
203
- initialize() {}
204
- /**
205
- * Retrieves a value from memory storage by its key
206
- * @template T - Type of the stored value
207
- * @param {string} key - The key to retrieve the value for
208
- * @returns {T} The stored value cast to type T
209
- */
210
- getItem(key) {
211
- return this.storage.get(key);
212
- }
213
- /**
214
- * Stores a value in memory storage with the specified key
215
- * @template T - Type of the value to store
216
- * @template U - Type of the options object
217
- * @param {string} key - The key under which to store the value
218
- * @param {T} value - The value to store
219
- */
220
- setItem(key, value, options) {
221
- this.storage.set(key, value);
222
- }
223
- /**
224
- * Removes a value from memory storage by its key
225
- * @param {string} key - The key of the value to delete
226
- */
227
- deleteItem(key) {
228
- this.storage.delete(key);
229
- }
230
- /**
231
- * Checks if a value exists in memory storage for the given key
232
- * @param {string} key - The key to check
233
- * @returns {boolean} True if the key exists, false otherwise
234
- */
235
- hasItem(key) {
236
- return this.storage.has(key);
237
- }
238
- /**
239
- * Retrieves all keys currently stored in memory storage
240
- * @returns {string[]} Array of all stored keys
241
- */
242
- getKeys() {
243
- return [...this.storage.keys()];
244
- }
245
- /**
246
- * Removes all stored values from memory storage
247
- */
248
- clear() {
249
- this.storage.clear();
250
- }
251
- /**
252
- * Gets the number of key-value pairs stored in memory storage
253
- * @returns {number} The number of stored items
254
- */
255
- size() {
256
- return this.storage.size;
257
- }
258
- };
259
-
260
- //#endregion
261
- export { MemoryStorage, Storage, StorageManager };
162
+ export { Storage, StorageManager };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercube/storage",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Storage module for Vercube framework",
5
5
  "repository": "@vercube/storage",
6
6
  "license": "MIT",
@@ -10,6 +10,8 @@
10
10
  "module": "./dist/index.mjs",
11
11
  "exports": {
12
12
  ".": "./dist/index.mjs",
13
+ "./drivers/MemoryStorage": "./dist/Drivers/MemoryStorage.mjs",
14
+ "./drivers/S3Storage": "./dist/Drivers/S3Storage.mjs",
13
15
  "./package.json": "./package.json"
14
16
  },
15
17
  "types": "./dist/index.d.mts",
@@ -18,10 +20,19 @@
18
20
  "README.md"
19
21
  ],
20
22
  "dependencies": {
21
- "@vercube/di": "0.0.14",
22
- "@vercube/logger": "0.0.14"
23
+ "@vercube/di": "0.0.16",
24
+ "@vercube/logger": "0.0.16"
25
+ },
26
+ "optionalDependencies": {
27
+ "@aws-sdk/client-s3": "3.842.0"
28
+ },
29
+ "resolutions": {
30
+ "@vercube/storage": "workspace:*"
23
31
  },
24
32
  "publishConfig": {
25
33
  "access": "public"
34
+ },
35
+ "scripts": {
36
+ "build": "tsdown --config tsdown.config.ts"
26
37
  }
27
38
  }