@dismissible/nestjs-storage 0.1.0-canary.4b708a5.0

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/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@dismissible/nestjs-storage",
3
+ "version": "0.1.0-canary.4b708a5.0",
4
+ "description": "In-memory storage adapter for Dismissible",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./src/index.mjs",
10
+ "require": "./src/index.js",
11
+ "types": "./src/index.d.ts"
12
+ }
13
+ },
14
+ "peerDependencies": {
15
+ "@nestjs/common": "^11.0.0",
16
+ "@dismissible/nestjs-logger": "^0.0.1",
17
+ "@dismissible/nestjs-dismissible-item": "^0.0.1"
18
+ },
19
+ "peerDependenciesMeta": {
20
+ "@nestjs/common": {
21
+ "optional": false
22
+ },
23
+ "@dismissible/nestjs-logger": {
24
+ "optional": false
25
+ },
26
+ "@dismissible/nestjs-dismissible-item": {
27
+ "optional": false
28
+ }
29
+ },
30
+ "keywords": [
31
+ "nestjs",
32
+ "dismissible",
33
+ "storage",
34
+ "storage",
35
+ "adapter"
36
+ ],
37
+ "author": "",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": ""
42
+ },
43
+ "type": "commonjs"
44
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './memory-storage.adapter';
2
+ export * from './storage.interface';
3
+ export * from './storage.module';
package/src/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./memory-storage.adapter"), exports);
5
+ tslib_1.__exportStar(require("./storage.interface"), exports);
6
+ tslib_1.__exportStar(require("./storage.module"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/storage/src/index.ts"],"names":[],"mappings":";;;AAAA,mEAAyC;AACzC,8DAAoC;AACpC,2DAAiC"}
@@ -0,0 +1,29 @@
1
+ import { IDismissibleLogger } from '@dismissible/nestjs-logger';
2
+ import { IDismissibleStorage } from './storage.interface';
3
+ import { BaseMetadata, DismissibleItemDto } from '@dismissible/nestjs-dismissible-item';
4
+ /**
5
+ * In-memory storage provider for dismissible items.
6
+ * Suitable for development and testing; not for production use.
7
+ */
8
+ export declare class MemoryStorageAdapter<TMetadata extends BaseMetadata = BaseMetadata> implements IDismissibleStorage<TMetadata> {
9
+ private readonly logger;
10
+ private readonly storage;
11
+ constructor(logger: IDismissibleLogger);
12
+ /**
13
+ * Create a storage key from userId and itemId.
14
+ */
15
+ private createKey;
16
+ get(userId: string, itemId: string): Promise<DismissibleItemDto<TMetadata> | null>;
17
+ create(item: DismissibleItemDto<TMetadata>): Promise<DismissibleItemDto<TMetadata>>;
18
+ update(item: DismissibleItemDto<TMetadata>): Promise<DismissibleItemDto<TMetadata>>;
19
+ /**
20
+ * Clear all stored items.
21
+ * Useful for testing.
22
+ */
23
+ clear(): void;
24
+ /**
25
+ * Get the number of stored items.
26
+ * Useful for testing/debugging.
27
+ */
28
+ get size(): number;
29
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryStorageAdapter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const nestjs_logger_1 = require("@dismissible/nestjs-logger");
7
+ /**
8
+ * In-memory storage provider for dismissible items.
9
+ * Suitable for development and testing; not for production use.
10
+ */
11
+ let MemoryStorageAdapter = class MemoryStorageAdapter {
12
+ constructor(logger) {
13
+ this.logger = logger;
14
+ this.storage = new Map();
15
+ }
16
+ /**
17
+ * Create a storage key from userId and itemId.
18
+ */
19
+ createKey(userId, itemId) {
20
+ return `${userId}:${itemId}`;
21
+ }
22
+ async get(userId, itemId) {
23
+ const key = this.createKey(userId, itemId);
24
+ this.logger.debug(`Storage get`, { userId, itemId, key });
25
+ const item = this.storage.get(key);
26
+ if (!item) {
27
+ this.logger.debug(`Storage miss`, { userId, itemId });
28
+ return null;
29
+ }
30
+ this.logger.debug(`Storage hit`, { userId, itemId });
31
+ return item;
32
+ }
33
+ async create(item) {
34
+ const key = this.createKey(item.userId, item.id);
35
+ this.logger.debug(`Storage create`, { userId: item.userId, itemId: item.id, key });
36
+ this.storage.set(key, item);
37
+ return item;
38
+ }
39
+ async update(item) {
40
+ const key = this.createKey(item.userId, item.id);
41
+ this.logger.debug(`Storage update`, { userId: item.userId, itemId: item.id, key });
42
+ this.storage.set(key, item);
43
+ return item;
44
+ }
45
+ /**
46
+ * Clear all stored items.
47
+ * Useful for testing.
48
+ */
49
+ clear() {
50
+ this.logger.debug(`Storage clear`, { previousSize: this.storage.size });
51
+ this.storage.clear();
52
+ }
53
+ /**
54
+ * Get the number of stored items.
55
+ * Useful for testing/debugging.
56
+ */
57
+ get size() {
58
+ return this.storage.size;
59
+ }
60
+ };
61
+ exports.MemoryStorageAdapter = MemoryStorageAdapter;
62
+ exports.MemoryStorageAdapter = MemoryStorageAdapter = tslib_1.__decorate([
63
+ (0, common_1.Injectable)(),
64
+ tslib_1.__param(0, (0, common_1.Inject)(nestjs_logger_1.DISMISSIBLE_LOGGER)),
65
+ tslib_1.__metadata("design:paramtypes", [Object])
66
+ ], MemoryStorageAdapter);
67
+ //# sourceMappingURL=memory-storage.adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-storage.adapter.js","sourceRoot":"","sources":["../../../../libs/storage/src/memory-storage.adapter.ts"],"names":[],"mappings":";;;;AAAA,2CAAoD;AACpD,8DAAoF;AAIpF;;;GAGG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAK/B,YAAwC,MAA2C;QAA1B,WAAM,GAAN,MAAM,CAAoB;QAFlE,YAAO,GAAG,IAAI,GAAG,EAAyC,CA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AAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF,CAAA;AA3DY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAME,mBAAA,IAAA,eAAM,EAAC,kCAAkB,CAAC,CAAA;;GAL5B,oBAAoB,CA2DhC"}
@@ -0,0 +1,30 @@
1
+ import { BaseMetadata, DismissibleItemDto } from '@dismissible/nestjs-dismissible-item';
2
+ /**
3
+ * Injection token for the storage provider.
4
+ */
5
+ export declare const DISMISSIBLE_STORAGE_ADAPTER: unique symbol;
6
+ /**
7
+ * Interface for storage providers.
8
+ * Implementations handle the persistence of dismissible items.
9
+ */
10
+ export interface IDismissibleStorage<TMetadata extends BaseMetadata = BaseMetadata> {
11
+ /**
12
+ * Retrieve an item by user ID and item ID.
13
+ * @param userId The user identifier
14
+ * @param itemId The item identifier
15
+ * @returns The item or null if not found
16
+ */
17
+ get(userId: string, itemId: string): Promise<DismissibleItemDto<TMetadata> | null>;
18
+ /**
19
+ * Create a new item.
20
+ * @param item The item to create (contains userId and id)
21
+ * @returns The created item
22
+ */
23
+ create(item: DismissibleItemDto<TMetadata>): Promise<DismissibleItemDto<TMetadata>>;
24
+ /**
25
+ * Update an existing item.
26
+ * @param item The item to update (contains userId and id)
27
+ * @returns The updated item
28
+ */
29
+ update(item: DismissibleItemDto<TMetadata>): Promise<DismissibleItemDto<TMetadata>>;
30
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DISMISSIBLE_STORAGE_ADAPTER = void 0;
4
+ /**
5
+ * Injection token for the storage provider.
6
+ */
7
+ exports.DISMISSIBLE_STORAGE_ADAPTER = Symbol('DISMISSIBLE_STORAGE_ADAPTER');
8
+ //# sourceMappingURL=storage.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.interface.js","sourceRoot":"","sources":["../../../../libs/storage/src/storage.interface.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACU,QAAA,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { DynamicModule, Type } from '@nestjs/common';
2
+ export type IDismissibleStorageModuleOptions = {
3
+ storage?: Type<any> | DynamicModule;
4
+ };
5
+ export declare class StorageModule {
6
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageModule = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const storage_interface_1 = require("./storage.interface");
7
+ const memory_storage_adapter_1 = require("./memory-storage.adapter");
8
+ let StorageModule = class StorageModule {
9
+ };
10
+ exports.StorageModule = StorageModule;
11
+ exports.StorageModule = StorageModule = tslib_1.__decorate([
12
+ (0, common_1.Module)({
13
+ providers: [
14
+ {
15
+ provide: storage_interface_1.DISMISSIBLE_STORAGE_ADAPTER,
16
+ useClass: memory_storage_adapter_1.MemoryStorageAdapter,
17
+ },
18
+ ],
19
+ exports: [storage_interface_1.DISMISSIBLE_STORAGE_ADAPTER],
20
+ })
21
+ ], StorageModule);
22
+ //# sourceMappingURL=storage.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.module.js","sourceRoot":"","sources":["../../../../libs/storage/src/storage.module.ts"],"names":[],"mappings":";;;;AAAA,2CAA6D;AAC7D,2DAAkE;AAClE,qEAAgE;AAezD,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IATzB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,+CAA2B;gBACpC,QAAQ,EAAE,6CAAoB;aAC/B;SACF;QACD,OAAO,EAAE,CAAC,+CAA2B,CAAC;KACvC,CAAC;GACW,aAAa,CAAG"}